2021-10-11 06:49:30 -05:00
|
|
|
//
|
|
|
|
|
// Source code recreated from a .class file by IntelliJ IDEA
|
|
|
|
|
// (powered by Fernflower decompiler)
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
package noppes.npcs.controllers.data;
|
|
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import noppes.npcs.EventHooks;
|
|
|
|
|
import noppes.npcs.NBTTags;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.config.ConfigScript;
|
2021-10-11 06:49:30 -05:00
|
|
|
import noppes.npcs.constants.EnumScriptType;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.controllers.ScriptContainer;
|
2021-10-11 06:49:30 -05:00
|
|
|
import noppes.npcs.controllers.ScriptController;
|
|
|
|
|
|
2023-01-12 21:33:06 -05:00
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public class ForgeDataScript implements IScriptHandler {
|
2021-12-01 15:31:05 -06:00
|
|
|
private List<ScriptContainer> scripts = new ArrayList();
|
2021-10-11 06:49:30 -05:00
|
|
|
private String scriptLanguage = "ECMAScript";
|
|
|
|
|
public long lastInited = -1L;
|
|
|
|
|
private boolean enabled = false;
|
2023-02-19 15:20:51 -06:00
|
|
|
private Map<Long, String> console = new TreeMap();
|
2021-10-11 06:49:30 -05:00
|
|
|
|
|
|
|
|
public ForgeDataScript() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clear() {
|
|
|
|
|
this.scripts = new ArrayList();
|
2023-02-19 15:20:51 -06:00
|
|
|
this.console = new TreeMap();
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readFromNBT(NBTTagCompound compound) {
|
2023-02-19 13:38:43 -06:00
|
|
|
if (compound.hasKey("Scripts")) {
|
|
|
|
|
this.scripts = NBTTags.GetScriptOld(compound.getTagList("Scripts", 10), this);
|
|
|
|
|
} else {
|
|
|
|
|
this.scripts = NBTTags.GetScript(compound,this);
|
|
|
|
|
}
|
2021-10-11 06:49:30 -05:00
|
|
|
this.scriptLanguage = compound.getString("ScriptLanguage");
|
2022-05-29 16:01:05 -05:00
|
|
|
if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) {
|
|
|
|
|
if (!ScriptController.Instance.languages.isEmpty()) {
|
|
|
|
|
this.scriptLanguage = (String) ScriptController.Instance.languages.keySet().toArray()[0];
|
|
|
|
|
} else {
|
|
|
|
|
this.scriptLanguage = "ECMAScript";
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-11 06:49:30 -05:00
|
|
|
this.enabled = compound.getBoolean("ScriptEnabled");
|
2023-02-19 15:20:51 -06:00
|
|
|
this.console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10));
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
2023-02-19 13:38:43 -06:00
|
|
|
compound.setInteger("TotalScripts",this.scripts.size());
|
|
|
|
|
for (int i = 0; i < this.scripts.size(); i++) {
|
|
|
|
|
compound.setTag("Tab"+i,this.scripts.get(i).writeToNBT(new NBTTagCompound()));
|
|
|
|
|
}
|
2021-10-11 06:49:30 -05:00
|
|
|
compound.setString("ScriptLanguage", this.scriptLanguage);
|
|
|
|
|
compound.setBoolean("ScriptEnabled", this.enabled);
|
2023-02-19 15:20:51 -06:00
|
|
|
compound.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.console));
|
2021-10-11 06:49:30 -05:00
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 06:33:39 -05:00
|
|
|
@Override
|
2021-12-16 21:54:05 -06:00
|
|
|
public void callScript(EnumScriptType var1, Event var2) {
|
2021-10-18 06:33:39 -05:00
|
|
|
callScript(var1.function, var2);
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void callScript(String type, Event event) {
|
|
|
|
|
if(this.isEnabled()) {
|
2022-12-23 20:45:04 -06:00
|
|
|
if (ScriptController.Instance.lastLoaded > this.lastInited) {
|
|
|
|
|
this.lastInited = ScriptController.Instance.lastLoaded;
|
|
|
|
|
if (!type.equals("init")) {
|
|
|
|
|
EventHooks.onForgeInit(this);
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
2022-12-23 20:45:04 -06:00
|
|
|
}
|
2021-10-11 06:49:30 -05:00
|
|
|
|
2023-02-19 15:20:51 -06:00
|
|
|
int i = 0;
|
2022-12-23 20:45:04 -06:00
|
|
|
for (ScriptContainer script : this.scripts) {
|
|
|
|
|
script.run(type, event);
|
2023-02-19 15:20:51 -06:00
|
|
|
|
|
|
|
|
for (Entry<Long, String> longStringEntry : script.console.entrySet()) {
|
|
|
|
|
if (!ScriptController.Instance.forgeScripts.console.containsKey(longStringEntry.getKey())) {
|
|
|
|
|
ScriptController.Instance.forgeScripts.console.put(longStringEntry.getKey(), " tab " + (i + 1) + ":\n" + longStringEntry.getValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
i++;
|
2022-12-23 20:45:04 -06:00
|
|
|
}
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isEnabled() {
|
2023-01-07 00:21:08 -05:00
|
|
|
return this.enabled && ConfigScript.GlobalForgeScripts && ScriptController.HasStart && this.scripts.size() > 0;
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isClient() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getEnabled() {
|
2022-11-02 14:00:03 -04:00
|
|
|
return this.enabled;
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setEnabled(boolean bo) {
|
|
|
|
|
this.enabled = bo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getLanguage() {
|
|
|
|
|
return this.scriptLanguage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setLanguage(String lang) {
|
|
|
|
|
this.scriptLanguage = lang;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-19 16:22:28 -06:00
|
|
|
public void setScripts(List<ScriptContainer> list) {
|
|
|
|
|
this.scripts = list;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 15:31:05 -06:00
|
|
|
public List<ScriptContainer> getScripts() {
|
2021-10-11 06:49:30 -05:00
|
|
|
return this.scripts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String noticeString() {
|
|
|
|
|
return "ForgeScript";
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-19 15:20:51 -06:00
|
|
|
public void setConsoleText(Map<Long, String> map) {
|
|
|
|
|
this.console = map;
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
|
|
|
|
|
2023-02-19 15:20:51 -06:00
|
|
|
public Map<Long, String> getConsoleText() {
|
|
|
|
|
return this.console;
|
|
|
|
|
}
|
2021-10-11 06:49:30 -05:00
|
|
|
public void clearConsole() {
|
2023-02-19 15:20:51 -06:00
|
|
|
this.console.clear();
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
|
|
|
|
}
|