From 24733892a0dae429eece24107d442768736a3e5b Mon Sep 17 00:00:00 2001 From: somehussar <148253652+somehussar@users.noreply.github.com> Date: Mon, 15 Dec 2025 21:07:19 +0100 Subject: [PATCH] Remove my shitty janino-loader --- src/main/java/noppes/npcs/EventHooks.java | 66 ++++---------- .../npcs/entity/EntityNPCInterface.java | 21 ----- .../janino/EntityUnloadListener.java | 4 +- .../wrapper/AbstractNPCJavaHandler.java | 62 ------------- .../somehussar/janino/wrapper/NPCWrapper.java | 88 ------------------- 5 files changed, 17 insertions(+), 224 deletions(-) delete mode 100644 src/main/java/somehussar/janino/wrapper/AbstractNPCJavaHandler.java delete mode 100644 src/main/java/somehussar/janino/wrapper/NPCWrapper.java diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 4f6d2b909..0dfac34ff 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -266,9 +266,7 @@ public class EventHooks { noppes.npcs.scripted.event.NpcEvent.InitEvent event = new noppes.npcs.scripted.event.NpcEvent.InitEvent(npc.wrappedNPC); ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.INIT, event); npc.script.callScript(EnumScriptType.INIT, event); - if (npc.janinoHandler != null) - npc.janinoHandler.onInitialize(event); - NpcAPI.EVENT_BUS.post(event); + NpcAPI.EVENT_BUS.post(event); npc.advanced.soulStoneInit = false; } @@ -279,9 +277,7 @@ public class EventHooks { noppes.npcs.scripted.event.NpcEvent.UpdateEvent event = new noppes.npcs.scripted.event.NpcEvent.UpdateEvent(npc.wrappedNPC); ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TICK, event); npc.script.callScript(EnumScriptType.TICK, event); - if (npc.janinoHandler != null) - npc.janinoHandler.onUpdate(event); - NpcAPI.EVENT_BUS.post(event); + NpcAPI.EVENT_BUS.post(event); } public static boolean onNPCDialog(EntityNPCInterface npc, EntityPlayer player, int dialogId, int optionId, Dialog dialog) { @@ -291,8 +287,6 @@ public class EventHooks { NpcEvent.DialogEvent event = new NpcEvent.DialogEvent(npc.wrappedNPC, player, dialogId, optionId, dialog); ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.DIALOG, event); npc.script.callScript(EnumScriptType.DIALOG, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog()); - if (npc.janinoHandler != null) - npc.janinoHandler.onDialog(event); return NpcAPI.EVENT_BUS.post(event); } @@ -304,9 +298,7 @@ public class EventHooks { NpcEvent.DialogClosedEvent event = new NpcEvent.DialogClosedEvent(npc.wrappedNPC, player, dialogId, optionId, dialog); ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.DIALOG_CLOSE, event); npc.script.callScript(EnumScriptType.DIALOG_CLOSE, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog()); - if (npc.janinoHandler != null) - npc.janinoHandler.onDialogClosed(event); - NpcAPI.EVENT_BUS.post(event); + NpcAPI.EVENT_BUS.post(event); } public static boolean onNPCInteract(EntityNPCInterface npc, EntityPlayer player) { @@ -316,9 +308,7 @@ public class EventHooks { NpcEvent.InteractEvent event = new NpcEvent.InteractEvent(npc.wrappedNPC, player); ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.INTERACT, event); boolean result = npc.script.callScript(EnumScriptType.INTERACT, event, "player", player); - if (npc.janinoHandler != null) - npc.janinoHandler.onInteract(event); - NpcAPI.EVENT_BUS.post(event); + NpcAPI.EVENT_BUS.post(event); return result; } @@ -329,9 +319,7 @@ public class EventHooks { ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.ATTACK_MELEE, event); npc.script.callScript(EnumScriptType.ATTACK_MELEE, event, "target", event.target); npc.script.callScript(EnumScriptType.ATTACK, event, "target", event.target); - if (npc.janinoHandler != null) - npc.janinoHandler.onAttack(event); - return NpcAPI.EVENT_BUS.post(event); + return NpcAPI.EVENT_BUS.post(event); } public static boolean onNPCMeleeSwing(EntityNPCInterface npc, NpcEvent.SwingEvent event) { @@ -340,9 +328,7 @@ public class EventHooks { ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.ATTACK_SWING, event); npc.script.callScript(EnumScriptType.ATTACK_SWING, event); - if (npc.janinoHandler != null) - npc.janinoHandler.onMeleeSwing(event); - return NpcAPI.EVENT_BUS.post(event); + return NpcAPI.EVENT_BUS.post(event); } public static boolean onNPCRangedAttack(EntityNPCInterface npc, NpcEvent.RangedLaunchedEvent event) { @@ -352,9 +338,7 @@ public class EventHooks { ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.RANGED_LAUNCHED, event); npc.script.callScript(EnumScriptType.RANGED_LAUNCHED, event, "target", event.target); npc.script.callScript(EnumScriptType.ATTACK, event, "target", event.target); - if (npc.janinoHandler != null) - npc.janinoHandler.onRangedAttack(event); - return NpcAPI.EVENT_BUS.post(event); + return NpcAPI.EVENT_BUS.post(event); } public static void onNPCKilledEntity(EntityNPCInterface npc, EntityLivingBase entity) { @@ -364,9 +348,7 @@ public class EventHooks { NpcEvent.KilledEntityEvent event = new NpcEvent.KilledEntityEvent(npc.wrappedNPC, entity); ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.KILLS, event); npc.script.callScript(EnumScriptType.KILLS, event, "target", entity); - if (npc.janinoHandler != null) - npc.janinoHandler.onKillEntity(event); - NpcAPI.EVENT_BUS.post(event); + NpcAPI.EVENT_BUS.post(event); } public static boolean onNPCTarget(EntityNPCInterface npc, NpcEvent.TargetEvent event) { @@ -375,9 +357,7 @@ public class EventHooks { ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TARGET, event); npc.script.callScript(EnumScriptType.TARGET, event); - if (npc.janinoHandler != null) - npc.janinoHandler.onTarget(event); - return NpcAPI.EVENT_BUS.post(event); + return NpcAPI.EVENT_BUS.post(event); } public static boolean onNPCTargetLost(EntityNPCInterface npc, EntityLivingBase prevtarget, EntityLivingBase newTarget) { @@ -387,9 +367,7 @@ public class EventHooks { ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TARGET_LOST, event); npc.script.callScript(EnumScriptType.TARGET_LOST, event); - if (npc.janinoHandler != null) - npc.janinoHandler.onTargetLost(event); - return NpcAPI.EVENT_BUS.post(event); + return NpcAPI.EVENT_BUS.post(event); } public static void onNPCCollide(EntityNPCInterface npc, Entity entity) { @@ -399,9 +377,7 @@ public class EventHooks { NpcEvent.CollideEvent event = new NpcEvent.CollideEvent(npc.wrappedNPC, entity); ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.COLLIDE, event); npc.script.callScript(EnumScriptType.COLLIDE, event, "entity", entity); - if (npc.janinoHandler != null) - npc.janinoHandler.onCollide(event); - NpcAPI.EVENT_BUS.post(event); + NpcAPI.EVENT_BUS.post(event); } public static boolean onNPCDamaged(EntityNPCInterface npc, NpcEvent.DamagedEvent event) { @@ -410,9 +386,7 @@ public class EventHooks { ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.DAMAGED, event); npc.script.callScript(EnumScriptType.DAMAGED, event); - if (npc.janinoHandler != null) - npc.janinoHandler.onDamaged(event); - return NpcAPI.EVENT_BUS.post(event); + return NpcAPI.EVENT_BUS.post(event); } public static boolean onNPCKilled(EntityNPCInterface npc, NpcEvent.DiedEvent event) { @@ -421,9 +395,7 @@ public class EventHooks { ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.KILLED, event); npc.script.callScript(EnumScriptType.KILLED, event); - if (npc.janinoHandler != null) - npc.janinoHandler.onNPCKilled(event); - return NpcAPI.EVENT_BUS.post(event); + return NpcAPI.EVENT_BUS.post(event); } public static void onNPCTimer(EntityNPCInterface npc, int id) { @@ -433,9 +405,7 @@ public class EventHooks { NpcEvent.TimerEvent event = new NpcEvent.TimerEvent(npc.wrappedNPC, id); ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TIMER, event); npc.script.callScript(EnumScriptType.TIMER, event); - if (npc.janinoHandler != null) - npc.janinoHandler.onTimer(event); - NpcAPI.EVENT_BUS.post(event); + NpcAPI.EVENT_BUS.post(event); } public static void onProjectileTick(EntityProjectile projectile) { @@ -453,9 +423,7 @@ public class EventHooks { EntityNPCInterface npc = (EntityNPCInterface) thrower; npc.script.callScript(EnumScriptType.PROJECTILE_TICK, event); - if (npc.janinoHandler != null) - npc.janinoHandler.onProjectileTick(event); - } + } } NpcAPI.EVENT_BUS.post(event); @@ -475,9 +443,7 @@ public class EventHooks { EntityNPCInterface npc = (EntityNPCInterface) thrower; npc.script.callScript(EnumScriptType.PROJECTILE_IMPACT, event); - if (npc.janinoHandler != null) - npc.janinoHandler.onProjectileImpact(event); - } + } } NpcAPI.EVENT_BUS.post(event); diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 185f2966f..96310a01e 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -4,8 +4,6 @@ import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import io.github.somehussar.janinoloader.api.script.IScriptBodyBuilder; -import io.github.somehussar.janinoloader.api.script.IScriptClassBody; import io.netty.buffer.ByteBuf; import kamkeel.npcs.addon.DBCAddon; import kamkeel.npcs.addon.client.DBCClient; @@ -162,12 +160,8 @@ import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.entity.ScriptNpc; import noppes.npcs.scripted.event.NpcEvent; import noppes.npcs.util.GameProfileAlt; -import org.codehaus.commons.compiler.Sandbox; -import somehussar.janino.wrapper.AbstractNPCJavaHandler; -import somehussar.janino.wrapper.NPCWrapper; import java.io.IOException; -import java.security.Permissions; import java.util.ArrayList; import java.util.ConcurrentModificationException; import java.util.HashMap; @@ -197,7 +191,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public float baseHeight = 1.8f; public float scaleX, scaleY, scaleZ; - public NPCWrapper janinoHandler; private boolean wasKilled = false; public RoleInterface roleInterface; public JobInterface jobInterface; @@ -257,20 +250,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if (!this.isRemote() && this.wrappedNPC == null) { this.wrappedNPC = new ScriptNpc<>(this); } - if (!this.isRemote()) { - IScriptClassBody javaCompiler = IScriptBodyBuilder.getBuilder(AbstractNPCJavaHandler.class, CustomNpcs.getDynamicCompiler()) - .setDefaultImports("noppes.npcs.api.event.INpcEvent").build(); - javaCompiler.setScript("" + - "" + - "void onInteract(INpcEvent.InteractEvent event) {" + - " event.getNpc().say(\"Lol this is from a script!\");" + - "}" + - ""); - - Permissions permissions = new Permissions(); - Sandbox sandbox = new Sandbox(permissions); - this.janinoHandler = new NPCWrapper(sandbox, javaCompiler); - } } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/somehussar/janino/EntityUnloadListener.java b/src/main/java/somehussar/janino/EntityUnloadListener.java index 8e7d917bb..592b0750c 100644 --- a/src/main/java/somehussar/janino/EntityUnloadListener.java +++ b/src/main/java/somehussar/janino/EntityUnloadListener.java @@ -45,9 +45,7 @@ public class EntityUnloadListener implements IWorldAccess { public void onEntityDestroy(Entity entity) { if (entity instanceof EntityNPCInterface) { EntityNPCInterface npc = (EntityNPCInterface) entity; - if (npc.janinoHandler != null) - npc.janinoHandler.prepareToUnload(); - npc.janinoHandler = null; + // TODO: REMOVE SCRIPTED OBJECT AND CLASSLOADER FOR IT } } diff --git a/src/main/java/somehussar/janino/wrapper/AbstractNPCJavaHandler.java b/src/main/java/somehussar/janino/wrapper/AbstractNPCJavaHandler.java deleted file mode 100644 index 058219d48..000000000 --- a/src/main/java/somehussar/janino/wrapper/AbstractNPCJavaHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -package somehussar.janino.wrapper; - -import io.github.somehussar.janinoloader.annotations.PermissableScriptHandler; -import noppes.npcs.api.event.INpcEvent; -import noppes.npcs.scripted.event.ProjectileEvent; - -public abstract class AbstractNPCJavaHandler { - - public void prepareToUnload() { - } - - public void onInitialize(INpcEvent.InitEvent event) { - } - - public void onUpdate(INpcEvent.UpdateEvent event) { - } - - public void onDialog(INpcEvent.DialogEvent event) { - } - - public void onProjectileTick(ProjectileEvent.UpdateEvent event) { - } - - public void onDialogClosed(INpcEvent.DialogClosedEvent event) { - } - - public void onAttack(INpcEvent.MeleeAttackEvent event) { - } - - public void onRangedAttack(INpcEvent.RangedLaunchedEvent event) { - } - - public void onMeleeSwing(INpcEvent.SwingEvent event) { - } - - public void onKillEntity(INpcEvent.KilledEntityEvent event) { - } - - public void onTarget(INpcEvent.TargetEvent event) { - } - - public void onTargetLost(INpcEvent.TargetLostEvent event) { - } - - public void onCollide(INpcEvent.CollideEvent event) { - } - - public void onDamaged(INpcEvent.DamagedEvent event) { - } - - public void onNPCKilled(INpcEvent.DiedEvent event) { - } - - public void onTimer(INpcEvent.TimerEvent event) { - } - - public void onProjectileImpact(ProjectileEvent.ImpactEvent event) { - } - - public void onInteract(INpcEvent.InteractEvent event) { - } -} diff --git a/src/main/java/somehussar/janino/wrapper/NPCWrapper.java b/src/main/java/somehussar/janino/wrapper/NPCWrapper.java deleted file mode 100644 index 6158e2279..000000000 --- a/src/main/java/somehussar/janino/wrapper/NPCWrapper.java +++ /dev/null @@ -1,88 +0,0 @@ -package somehussar.janino.wrapper; - -import io.github.somehussar.janinoloader.api.script.IScriptClassBody; -import noppes.npcs.scripted.event.NpcEvent; -import org.codehaus.commons.compiler.Sandbox; - -public final class NPCWrapper { - - private final Sandbox sandbox; - public final IScriptClassBody scriptBody; - - public NPCWrapper(Sandbox sandbox, IScriptClassBody scriptBody) { - this.sandbox = sandbox; - this.scriptBody = scriptBody; - } - - public void prepareToUnload() { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().prepareToUnload(); return null; }); - } - - public void onInitialize(noppes.npcs.api.event.INpcEvent.InitEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onInitialize(event); return null; }); - } - - public void onUpdate(noppes.npcs.scripted.event.NpcEvent.UpdateEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onUpdate(event); return null; }); - } - - public void onDialog(noppes.npcs.scripted.event.NpcEvent.DialogEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onDialog(event); return null; }); - } - - public void onProjectileTick(noppes.npcs.scripted.event.ProjectileEvent.UpdateEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onProjectileTick(event); return null; }); - } - - public void onDialogClosed(noppes.npcs.scripted.event.NpcEvent.DialogClosedEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onDialogClosed(event); return null; }); - } - - public void onAttack(noppes.npcs.scripted.event.NpcEvent.MeleeAttackEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onAttack(event); return null; }); - } - - public void onRangedAttack(noppes.npcs.scripted.event.NpcEvent.RangedLaunchedEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onRangedAttack(event); return null; }); - } - - public void onMeleeSwing(noppes.npcs.scripted.event.NpcEvent.SwingEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onMeleeSwing(event); return null; }); - } - - public void onKillEntity(noppes.npcs.scripted.event.NpcEvent.KilledEntityEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onKillEntity(event); return null; }); - } - - public void onTarget(noppes.npcs.scripted.event.NpcEvent.TargetEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onTarget(event); return null; }); - } - - public void onTargetLost(noppes.npcs.scripted.event.NpcEvent.TargetLostEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onTargetLost(event); return null; }); - } - - public void onCollide(noppes.npcs.scripted.event.NpcEvent.CollideEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onCollide(event); return null; }); - } - - public void onDamaged(noppes.npcs.scripted.event.NpcEvent.DamagedEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onDamaged(event); return null; }); - } - - public void onNPCKilled(noppes.npcs.scripted.event.NpcEvent.DiedEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onNPCKilled(event); return null; }); - } - - public void onTimer(noppes.npcs.scripted.event.NpcEvent.TimerEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onTimer(event); return null; }); - } - - public void onProjectileImpact(noppes.npcs.scripted.event.ProjectileEvent.ImpactEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onProjectileImpact(event); return null; }); - } - - public void onInteract(NpcEvent.InteractEvent event) { - sandbox.confine((java.security.PrivilegedAction) () -> { scriptBody.get().onInteract(event); return null; }); - } -}