-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master-1.20-lts' into master-1.20
- Loading branch information
Showing
15 changed files
with
147 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
As always, don't forget to backup your world before updating! | ||
Requires CyclopsCore version 1.19.0 or higher. | ||
|
||
Changes: | ||
* Add script context to errors during translation | ||
|
||
Fixes: | ||
* Automatically invalidate network errors on script changes, Closes #5 | ||
* Don't hard-crash on unsupported conversions to NBT, Closes #8 | ||
* Fix missing type checking for script variables in aspects, Closes #9 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
As always, don't forget to backup your world before updating! | ||
Requires CyclopsCore version 1.19.0 or higher. | ||
|
||
Changes: | ||
* Add script context to errors during translation | ||
|
||
Fixes: | ||
* Automatically invalidate network errors on script changes, Closes #5 | ||
* Don't hard-crash on unsupported conversions to NBT, Closes #8 | ||
* Fix missing type checking for script variables in aspects, Closes #9 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...n/java/org/cyclops/integratedscripting/evaluate/EvaluationExceptionResolutionHelpers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.cyclops.integratedscripting.evaluate; | ||
|
||
import org.cyclops.cyclopscore.datastructure.Wrapper; | ||
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException; | ||
import org.cyclops.integratedscripting.api.network.IScriptingData; | ||
import org.cyclops.integratedscripting.core.network.ScriptingNetworkHelpers; | ||
|
||
import java.lang.ref.ReferenceQueue; | ||
import java.lang.ref.WeakReference; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* @author rubensworks | ||
*/ | ||
public class EvaluationExceptionResolutionHelpers { | ||
|
||
// Holds weak references of created EvaluationExceptions | ||
private static final ReferenceQueue<? super EvaluationException> EVALUATION_EXCEPTION_REFERENCE_QUEUE = new ReferenceQueue<>(); | ||
|
||
/** | ||
* Indicate that the given EvaluationException must be resolved when the given script is changed. | ||
* @param evaluationException An evaluation exception. | ||
* @param disk A script disk. | ||
* @param path A script path. | ||
* @return The given exception. | ||
*/ | ||
public static EvaluationException resolveOnScriptChange(EvaluationException evaluationException, int disk, Path path) { | ||
Wrapper<IScriptingData.IDiskScriptsChangeListener> listener = new Wrapper<>(); | ||
listener.set(createListener(new EvaluationExceptionReference(evaluationException, EVALUATION_EXCEPTION_REFERENCE_QUEUE, disk, listener), disk, path)); | ||
ScriptingNetworkHelpers.getScriptingData().addListener(disk, listener.get()); | ||
return evaluationException; | ||
} | ||
|
||
/** | ||
* Call this periodically to flush stale entries in | ||
* {@link EvaluationExceptionResolutionHelpers#EVALUATION_EXCEPTION_REFERENCE_QUEUE}. | ||
*/ | ||
public static void expungeStaleEvaluationExceptions() { | ||
for (Object x; (x = EVALUATION_EXCEPTION_REFERENCE_QUEUE.poll()) != null; ) { | ||
((EvaluationExceptionReference) x).removeListener(); | ||
} | ||
} | ||
|
||
protected static IScriptingData.IDiskScriptsChangeListener createListener(EvaluationExceptionReference evaluationExceptionReference, int disk, Path path) { | ||
return scriptPathRelative -> { | ||
if (scriptPathRelative.equals(path)) { | ||
EvaluationException exception = evaluationExceptionReference.get(); | ||
if (exception != null) { | ||
exception.resolve(); | ||
} | ||
ScriptingNetworkHelpers.getScriptingData().removeListener(disk, evaluationExceptionReference.listener.get()); | ||
} | ||
}; | ||
} | ||
|
||
public static class EvaluationExceptionReference extends WeakReference<EvaluationException> { | ||
|
||
private final int disk; | ||
private final Wrapper<IScriptingData.IDiskScriptsChangeListener> listener; | ||
|
||
public EvaluationExceptionReference( | ||
EvaluationException referent, | ||
ReferenceQueue<? super EvaluationException> queue, | ||
int disk, | ||
Wrapper<IScriptingData.IDiskScriptsChangeListener> listener | ||
) { | ||
super(referent, queue); | ||
this.disk = disk; | ||
this.listener = listener; | ||
} | ||
|
||
public void removeListener() { | ||
ScriptingNetworkHelpers.getScriptingData().removeListener(disk, listener.get()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters