mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 01:27:27 +00:00
Merge branch 'janino-scripts' of https://github.com/KAMKEEL/CustomNPC-Plus into janino-scripts
This commit is contained in:
commit
8da42e7b7c
6 files changed
+17
-36
No files matched your search
@@ -3,7 +3,6 @@ package noppes.npcs.controllers;
|
||||
import noppes.npcs.api.handler.IScriptHookHandler;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.constants.ScriptContext;
|
||||
import noppes.npcs.controllers.data.EffectScript;
|
||||
import noppes.npcs.controllers.data.RecipeScript;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -230,6 +229,16 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerHooks(ScriptContext context, String functionName) {
|
||||
registerHook(context.hookContext, functionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerHooks(ScriptContext context, String... functionNames) {
|
||||
registerHooks(context.hookContext, functionNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerHook(String context, String functionName) {
|
||||
if (context == null || functionName == null || functionName.isEmpty()) {
|
||||
|
||||
@@ -21,13 +21,7 @@ import java.util.TreeMap;
|
||||
* - Override isEnabled() if custom enable logic is needed
|
||||
*/
|
||||
public abstract class MultiScriptHandler extends ScriptHandler implements IScriptHandlerPacket {
|
||||
|
||||
/** Tracks when scripts were last updated (for reload detection) */
|
||||
protected long lastUpdate = -1L;
|
||||
|
||||
/** Console output storage */
|
||||
protected Map<Long, String> console = new TreeMap<>();
|
||||
|
||||
|
||||
// ==================== NBT SERIALIZATION ====================
|
||||
|
||||
/**
|
||||
@@ -44,10 +38,6 @@ public abstract class MultiScriptHandler extends ScriptHandler implements IScrip
|
||||
normalizeLanguage();
|
||||
|
||||
this.enabled = compound.getBoolean("ScriptEnabled");
|
||||
|
||||
if (compound.hasKey("ScriptConsole")) {
|
||||
this.console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +50,6 @@ public abstract class MultiScriptHandler extends ScriptHandler implements IScrip
|
||||
}
|
||||
compound.setString("ScriptLanguage", this.scriptLanguage);
|
||||
compound.setBoolean("ScriptEnabled", this.enabled);
|
||||
compound.setTag("ScriptConsole", NBTTags.NBTLongStringMap(console));
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -119,23 +108,4 @@ public abstract class MultiScriptHandler extends ScriptHandler implements IScrip
|
||||
script.run(hookName, event);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== CONSOLE HANDLING ====================
|
||||
|
||||
@Override
|
||||
public Map<Long, String> getConsoleText() {
|
||||
return console;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearConsole() {
|
||||
console.clear();
|
||||
}
|
||||
|
||||
// ==================== UTILITY ====================
|
||||
|
||||
public void clear() {
|
||||
this.scripts = new ArrayList<>();
|
||||
this.console = new TreeMap<>();
|
||||
}
|
||||
}
|
||||
@@ -40,11 +40,10 @@ public class PlayerDataScript extends MultiScriptHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
staticConsole = new TreeMap<>();
|
||||
errored = new ArrayList<>();
|
||||
scripts = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -65,6 +65,9 @@ public abstract class ScriptHandler implements IScriptHandler {
|
||||
return this.scripts;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.scripts = new ArrayList<>();
|
||||
}
|
||||
/**
|
||||
* Reset the lastInited timestamp to force re-initialization on next script call.
|
||||
*/
|
||||
|
||||
@@ -68,7 +68,7 @@ public abstract class JaninoScript<T> implements IScriptUnit {
|
||||
}
|
||||
|
||||
protected JaninoScript(Class<T> type, String[] defaultImports) {
|
||||
this(type, defaultImports, true);
|
||||
this(type, defaultImports, false);
|
||||
}
|
||||
|
||||
protected T getUnsafe() {
|
||||
|
||||
@@ -41,7 +41,7 @@ import noppes.npcs.janino.annotations.ScriptHook;
|
||||
public class JaninoPlayerScript extends JaninoScript<JaninoPlayerScript.Functions> {
|
||||
|
||||
public JaninoPlayerScript() {
|
||||
super(Functions.class, null, false);
|
||||
super(Functions.class, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user