mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-15 19:34:49 +00:00
Abstracted ScriptContainer & JaninoScript to IScriptUnit + global implementation
This commit is contained in:
1 parent
1372127266
commit
c3e032dcf2
21 files changed
+518
-220
No files matched your search
@@ -16,7 +16,7 @@ import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class ForgeDataScript implements INpcScriptHandler {
|
||||
private List<ScriptContainer> scripts = new ArrayList();
|
||||
private List<IScriptUnit> scripts = new ArrayList<>();
|
||||
private String scriptLanguage = "ECMAScript";
|
||||
public long lastInited = -1L;
|
||||
private long lastForgeUpdate = -1L;
|
||||
@@ -26,14 +26,14 @@ public class ForgeDataScript implements INpcScriptHandler {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.scripts = new ArrayList();
|
||||
this.scripts = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
if (compound.hasKey("Scripts")) {
|
||||
this.scripts = NBTTags.GetScriptOld(compound.getTagList("Scripts", 10), this);
|
||||
this.scripts = new ArrayList<>(NBTTags.GetScriptOld(compound.getTagList("Scripts", 10), this));
|
||||
} else {
|
||||
this.scripts = NBTTags.GetScript(compound, this);
|
||||
this.scripts = new ArrayList<>(NBTTags.GetScript(compound, this));
|
||||
}
|
||||
this.scriptLanguage = compound.getString("ScriptLanguage");
|
||||
if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) {
|
||||
@@ -67,8 +67,9 @@ public class ForgeDataScript implements INpcScriptHandler {
|
||||
this.lastInited = ScriptController.Instance.lastLoaded;
|
||||
this.lastForgeUpdate = ScriptController.Instance.lastForgeUpdate;
|
||||
|
||||
for (ScriptContainer script : this.scripts) {
|
||||
script.errored = false;
|
||||
for (IScriptUnit script : this.scripts) {
|
||||
if (script instanceof ScriptContainer)
|
||||
((ScriptContainer) script).errored = false;
|
||||
}
|
||||
|
||||
if (!type.equals("init")) {
|
||||
@@ -76,11 +77,15 @@ public class ForgeDataScript implements INpcScriptHandler {
|
||||
}
|
||||
}
|
||||
|
||||
for (ScriptContainer script : this.scripts) {
|
||||
if (script == null || script.errored || !script.hasCode())
|
||||
for (IScriptUnit script : this.scripts) {
|
||||
if (script == null || !script.hasCode())
|
||||
continue;
|
||||
|
||||
script.run(type, event);
|
||||
if (script instanceof ScriptContainer) {
|
||||
ScriptContainer container = (ScriptContainer) script;
|
||||
if (container.errored)
|
||||
continue;
|
||||
container.run(type, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,11 +114,11 @@ public class ForgeDataScript implements INpcScriptHandler {
|
||||
this.scriptLanguage = lang;
|
||||
}
|
||||
|
||||
public void setScripts(List<ScriptContainer> list) {
|
||||
public void setScripts(List<IScriptUnit> list) {
|
||||
this.scripts = list;
|
||||
}
|
||||
|
||||
public List<ScriptContainer> getScripts() {
|
||||
public List<IScriptUnit> getScripts() {
|
||||
return this.scripts;
|
||||
}
|
||||
|
||||
@@ -124,19 +129,18 @@ public class ForgeDataScript implements INpcScriptHandler {
|
||||
public Map<Long, String> getConsoleText() {
|
||||
TreeMap<Long, String> map = new TreeMap<>();
|
||||
int tab = 0;
|
||||
for (ScriptContainer script : this.getScripts()) {
|
||||
for (IScriptUnit script : this.getScripts()) {
|
||||
++tab;
|
||||
|
||||
for (Entry<Long, String> longStringEntry : script.console.entrySet()) {
|
||||
map.put(longStringEntry.getKey(), " tab " + tab + ":\n" + longStringEntry.getValue());
|
||||
for (Entry<Long, String> entry : script.getConsole().entrySet()) {
|
||||
map.put(entry.getKey(), " tab " + tab + ":\n" + entry.getValue());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public void clearConsole() {
|
||||
for (ScriptContainer script : this.getScripts()) {
|
||||
script.console.clear();
|
||||
for (IScriptUnit script : this.getScripts()) {
|
||||
script.clearConsole();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user