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 java.util.ArrayList;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.TreeMap;
|
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import noppes.npcs.EventHooks;
|
2021-10-17 16:11:29 -05:00
|
|
|
import noppes.npcs.EventScriptContainer;
|
2021-10-11 06:49:30 -05:00
|
|
|
import noppes.npcs.NBTTags;
|
|
|
|
|
import noppes.npcs.constants.EnumScriptType;
|
|
|
|
|
import noppes.npcs.controllers.IScriptHandler;
|
|
|
|
|
import noppes.npcs.controllers.ScriptController;
|
2021-10-18 06:33:39 -05:00
|
|
|
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
|
2021-10-11 06:49:30 -05:00
|
|
|
|
|
|
|
|
import javax.script.ScriptEngine;
|
|
|
|
|
|
|
|
|
|
public class ForgeDataScript implements IScriptHandler {
|
2021-10-17 16:11:29 -05:00
|
|
|
private List<EventScriptContainer> scripts = new ArrayList();
|
2021-10-11 06:49:30 -05:00
|
|
|
private String scriptLanguage = "ECMAScript";
|
|
|
|
|
public long lastInited = -1L;
|
|
|
|
|
private boolean enabled = false;
|
|
|
|
|
|
|
|
|
|
public ForgeDataScript() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clear() {
|
|
|
|
|
this.scripts = new ArrayList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readFromNBT(NBTTagCompound compound) {
|
|
|
|
|
this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this);
|
|
|
|
|
this.scriptLanguage = compound.getString("ScriptLanguage");
|
|
|
|
|
this.enabled = compound.getBoolean("ScriptEnabled");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
|
|
|
|
compound.setTag("Scripts", NBTTags.NBTScript(this.scripts));
|
|
|
|
|
compound.setString("ScriptLanguage", this.scriptLanguage);
|
|
|
|
|
compound.setBoolean("ScriptEnabled", this.enabled);
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 06:33:39 -05:00
|
|
|
@Override
|
|
|
|
|
public void callScript(EnumScriptType var1, Event var2, Object... obs) {
|
|
|
|
|
callScript(var1.function, var2);
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void callScript(String type, Event event) {
|
|
|
|
|
if(this.isEnabled()) {
|
2021-10-20 20:27:42 -05:00
|
|
|
//Minecraft.getMinecraft().func_152344_a(() -> {
|
2021-10-11 06:49:30 -05:00
|
|
|
if (ScriptController.Instance.lastLoaded > this.lastInited) {
|
|
|
|
|
this.lastInited = ScriptController.Instance.lastLoaded;
|
|
|
|
|
if (!type.equals("init")) {
|
|
|
|
|
EventHooks.onForgeInit(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Iterator var3 = this.scripts.iterator();
|
|
|
|
|
|
|
|
|
|
while (var3.hasNext()) {
|
2021-10-17 16:11:29 -05:00
|
|
|
EventScriptContainer script = (EventScriptContainer) var3.next();
|
2021-10-18 06:33:39 -05:00
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
script.setEngine(scriptLanguage);
|
|
|
|
|
if(script.engine == null)
|
|
|
|
|
return;
|
2021-10-18 06:33:39 -05:00
|
|
|
|
|
|
|
|
Event result = (Event) script.engine.get("event");
|
|
|
|
|
if(result == null)
|
|
|
|
|
script.engine.put("event", event);
|
|
|
|
|
script.engine.put("API", new WrapperNpcAPI());
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
ScriptEngine engine = script.engine;
|
|
|
|
|
|
2021-10-18 22:01:15 -05:00
|
|
|
script.run(type, event);
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
2021-10-20 20:27:42 -05:00
|
|
|
//});
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isEnabled() {
|
|
|
|
|
return this.enabled && ScriptController.HasStart && this.scripts.size() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isClient() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getEnabled() {
|
|
|
|
|
return this.enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setEnabled(boolean bo) {
|
|
|
|
|
this.enabled = bo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getLanguage() {
|
|
|
|
|
return this.scriptLanguage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setLanguage(String lang) {
|
|
|
|
|
this.scriptLanguage = lang;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-17 16:11:29 -05:00
|
|
|
public List<EventScriptContainer> getScripts() {
|
2021-10-11 06:49:30 -05:00
|
|
|
return this.scripts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String noticeString() {
|
|
|
|
|
return "ForgeScript";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Map<Long, String> getConsoleText() {
|
|
|
|
|
TreeMap map = new TreeMap();
|
|
|
|
|
int tab = 0;
|
|
|
|
|
Iterator var3 = this.getScripts().iterator();
|
|
|
|
|
|
|
|
|
|
while(var3.hasNext()) {
|
2021-10-17 16:11:29 -05:00
|
|
|
EventScriptContainer script = (EventScriptContainer)var3.next();
|
2021-10-11 06:49:30 -05:00
|
|
|
++tab;
|
|
|
|
|
Iterator var5 = script.console.entrySet().iterator();
|
|
|
|
|
|
|
|
|
|
while(var5.hasNext()) {
|
|
|
|
|
Entry entry = (Entry)var5.next();
|
|
|
|
|
map.put(entry.getKey(), " tab " + tab + ":\n" + (String)entry.getValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clearConsole() {
|
|
|
|
|
Iterator var1 = this.getScripts().iterator();
|
|
|
|
|
|
|
|
|
|
while(var1.hasNext()) {
|
2021-10-17 16:11:29 -05:00
|
|
|
EventScriptContainer script = (EventScriptContainer)var1.next();
|
2021-10-11 06:49:30 -05:00
|
|
|
script.console.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|