Improve JS exec return value handling (#1290)

This commit is contained in:
skbeh
2023-03-19 11:34:59 +08:00
committed by GitHub
parent 5200826333
commit ab3bcc95b4
13 changed files with 47 additions and 56 deletions

View File

@@ -18,7 +18,7 @@ index 32a303f9ac9768daf621e3aa561cd6b31e5f5dff..9c8713ef3aeb2ff203bd0328d15d80c2
org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(this, this.getMainHandItem(), entityarrow.getPickupItem(), entityarrow, net.minecraft.world.InteractionHand.MAIN_HAND, 0.8F, true); // Paper
if (event.isCancelled()) {
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
index 1913edafb83663f9aeacb7a525ee0f8f1f6719d6..3437bdba19c1bf8a711e4d27d9900928c17c2fb5 100644
index d582ebbd7b850bfe4b4e8c56d1ff704a87be3928..ccc6b223090ee71808909bb8e1a13adfdd9fae67 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
@@ -2409,6 +2409,8 @@ public class PurpurWorldConfig {
@@ -30,7 +30,7 @@ index 1913edafb83663f9aeacb7a525ee0f8f1f6719d6..3437bdba19c1bf8a711e4d27d9900928
private void skeletonSettings() {
skeletonRidable = getBoolean("mobs.skeleton.ridable", skeletonRidable);
skeletonRidableInWater = getBoolean("mobs.skeleton.ridable-in-water", skeletonRidableInWater);
@@ -2423,6 +2425,28 @@ public class PurpurWorldConfig {
@@ -2423,6 +2425,18 @@ public class PurpurWorldConfig {
skeletonAlwaysDropExp = getBoolean("mobs.skeleton.always-drop-exp", skeletonAlwaysDropExp);
skeletonHeadVisibilityPercent = getDouble("mobs.skeleton.head-visibility-percent", skeletonHeadVisibilityPercent);
skeletonFeedWitherRoses = getInt("mobs.skeleton.feed-wither-roses", skeletonFeedWitherRoses);
@@ -39,20 +39,10 @@ index 1913edafb83663f9aeacb7a525ee0f8f1f6719d6..3437bdba19c1bf8a711e4d27d9900928
+ for (int i = 1; i < 4; i++) {
+ final float divergence;
+ try {
+ Entity.scriptEngine.eval("difficulty = " + i);
+ final Object result = Entity.scriptEngine.eval(skeletonBowAccuracy);
+ if (result instanceof Long) {
+ divergence = ((Long) result).floatValue();
+ } else if (result instanceof Double) {
+ divergence = ((Double) result).floatValue();
+ } else {
+ set("mobs.skeleton.bow-accuracy", defaultSkeletonBowAccuracy);
+ skeletonBowAccuracy = defaultSkeletonBowAccuracy;
+ divergence = ((Long) Entity.scriptEngine.eval(skeletonBowAccuracy)).floatValue();
+ }
+ } catch (Exception e) {
+ divergence = ((Number) Entity.scriptEngine.eval("let difficulty = " + i + "; " + skeletonBowAccuracy)).floatValue();
+ } catch (javax.script.ScriptException e) {
+ e.printStackTrace();
+ continue;
+ break;
+ }
+ skeletonBowAccuracyMap.put(i, divergence);
+ }