mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 18:49:39 +00:00
ScriptHandler refactor:
- ScriptHandler now holds a list of containers - Delegated single container handling to SingleScriptHandler IScriptHandler refactor: - Moved ScriptContext/Hook logic to it - More default methods + hooked them to GuIScriptInterface
This commit is contained in:
1 parent
44f71ddb81
commit
eecb5b0b3b
4 files changed
+294
-51
No files matched your search
@@ -5,24 +5,36 @@ import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ScriptHandler implements IScriptHandler {
|
||||
public IScriptUnit container;
|
||||
public List<IScriptUnit> scripts = new ArrayList<>();
|
||||
protected String scriptLanguage = "ECMAScript";
|
||||
protected boolean enabled = false;
|
||||
protected long lastInited = -1;
|
||||
|
||||
protected boolean canRunScripts() {
|
||||
return enabled && ScriptController.HasStart && ConfigScript.ScriptingEnabled && container != null;
|
||||
return enabled && ScriptController.HasStart && ConfigScript.ScriptingEnabled && scripts != null && !scripts.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callScript(String hookName, Event event) {
|
||||
if (!canRunScripts()) {
|
||||
if (!canRunScripts())
|
||||
return;
|
||||
|
||||
if (ScriptController.Instance.lastLoaded > lastInited) {
|
||||
lastInited = ScriptController.Instance.lastLoaded;
|
||||
for (IScriptUnit script : scripts) {
|
||||
if (script != null)
|
||||
script.setErrored(false);
|
||||
}
|
||||
}
|
||||
|
||||
for (IScriptUnit script : scripts) {
|
||||
if (script == null || script.hasErrored() || !script.hasCode())
|
||||
continue;
|
||||
script.run(hookName, event);
|
||||
}
|
||||
container.run(hookName, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,20 +57,11 @@ public abstract class ScriptHandler implements IScriptHandler {
|
||||
this.scriptLanguage = language;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScripts(List<IScriptUnit> list) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
container = null;
|
||||
return;
|
||||
}
|
||||
container = list.get(0);
|
||||
this.scripts = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IScriptUnit> getScripts() {
|
||||
if (container == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return Collections.singletonList(container);
|
||||
return this.scripts;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user