Null out the loader.

This commit is contained in:
somehussar committed 2025-12-13 18:21:36 +01:00
1 parent b4608ffe19
commit 4d825b6cf3
6 files changed
+55 -15

No files matched your search

+12
View File
@@ -14,6 +14,8 @@ import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.relauncher.Side;
import foxz.command.CommandNoppes;
import io.github.somehussar.janinoloader.api.IDynamicCompiler;
import io.github.somehussar.janinoloader.api.IDynamicCompilerBuilder;
import kamkeel.npcs.addon.AddonManager;
import kamkeel.npcs.command.CommandKamkeel;
import kamkeel.npcs.command.profile.CommandProfile;
@@ -140,6 +142,16 @@ public class CustomNpcs {
instance = this;
}
private static IDynamicCompiler jls;
public static IDynamicCompiler getDynamicCompiler() {
if (jls == null) {
jls = IDynamicCompilerBuilder.createBuilder().getCompiler();
}
return jls;
}
@EventHandler
public void load(FMLPreInitializationEvent ev) {
PacketHandler.Instance = new PacketHandler();
@@ -316,6 +316,8 @@ 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);
return result;
}
@@ -4,6 +4,8 @@ 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;
@@ -157,9 +159,12 @@ 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;
@@ -247,6 +252,20 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
if (!this.isRemote() && this.wrappedNPC == null) {
this.wrappedNPC = new ScriptNpc<>(this);
}
if (!this.isRemote()) {
IScriptClassBody<AbstractNPCJavaHandler> 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();
}
@@ -41,6 +41,7 @@ public class ItemNpcScripter extends Item {
}
return itemStack;
}
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptEvent, player);
return itemStack;
}
@@ -2,7 +2,6 @@ package somehussar.janino.wrapper;
import io.github.somehussar.janinoloader.annotations.PermissableScriptHandler;
import noppes.npcs.api.event.INpcEvent;
import noppes.npcs.scripted.event.NpcEvent;
import noppes.npcs.scripted.event.ProjectileEvent;
public abstract class AbstractNPCJavaHandler {
@@ -13,48 +12,51 @@ public abstract class AbstractNPCJavaHandler {
public void onInitialize(INpcEvent.InitEvent event) {
}
public void onUpdate(NpcEvent.UpdateEvent event) {
public void onUpdate(INpcEvent.UpdateEvent event) {
}
public void onDialog(NpcEvent.DialogEvent event) {
public void onDialog(INpcEvent.DialogEvent event) {
}
public void onProjectileTick(ProjectileEvent.UpdateEvent event) {
}
public void onDialogClosed(NpcEvent.DialogClosedEvent event) {
public void onDialogClosed(INpcEvent.DialogClosedEvent event) {
}
public void onAttack(NpcEvent.MeleeAttackEvent event) {
public void onAttack(INpcEvent.MeleeAttackEvent event) {
}
public void onRangedAttack(NpcEvent.RangedLaunchedEvent event) {
public void onRangedAttack(INpcEvent.RangedLaunchedEvent event) {
}
public void onMeleeSwing(NpcEvent.SwingEvent event) {
public void onMeleeSwing(INpcEvent.SwingEvent event) {
}
public void onKillEntity(NpcEvent.KilledEntityEvent event) {
public void onKillEntity(INpcEvent.KilledEntityEvent event) {
}
public void onTarget(NpcEvent.TargetEvent event) {
public void onTarget(INpcEvent.TargetEvent event) {
}
public void onTargetLost(NpcEvent.TargetLostEvent event) {
public void onTargetLost(INpcEvent.TargetLostEvent event) {
}
public void onCollide(NpcEvent.CollideEvent event) {
public void onCollide(INpcEvent.CollideEvent event) {
}
public void onDamaged(NpcEvent.DamagedEvent event) {
public void onDamaged(INpcEvent.DamagedEvent event) {
}
public void onNPCKilled(NpcEvent.DiedEvent event) {
public void onNPCKilled(INpcEvent.DiedEvent event) {
}
public void onTimer(NpcEvent.TimerEvent event) {
public void onTimer(INpcEvent.TimerEvent event) {
}
public void onProjectileImpact(ProjectileEvent.ImpactEvent event) {
}
public void onInteract(INpcEvent.InteractEvent event) {
}
}
@@ -1,12 +1,13 @@
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;
private final IScriptClassBody<AbstractNPCJavaHandler> scriptBody;
public final IScriptClassBody<AbstractNPCJavaHandler> scriptBody;
public NPCWrapper(Sandbox sandbox, IScriptClassBody<AbstractNPCJavaHandler> scriptBody) {
this.sandbox = sandbox;
@@ -81,4 +82,7 @@ public final class NPCWrapper {
sandbox.confine((java.security.PrivilegedAction<Void>) () -> { scriptBody.get().onProjectileImpact(event); return null; });
}
public void onInteract(NpcEvent.InteractEvent event) {
sandbox.confine((java.security.PrivilegedAction<Void>) () -> { scriptBody.get().onInteract(event); return null; });
}
}