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.entity.Entity;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void callScript(EnumScriptType type, Event event, Object... obs) {
|
|
|
|
|
if(this.isEnabled()) {
|
|
|
|
|
// CustomNpcs.getServer().func_152344_a(() -> {
|
|
|
|
|
Minecraft.getMinecraft().func_152344_a(() -> {
|
|
|
|
|
if (ScriptController.Instance.lastLoaded > this.lastInited) {
|
|
|
|
|
this.lastInited = ScriptController.Instance.lastLoaded;
|
2021-10-17 16:11:29 -05:00
|
|
|
if (!type.equals(EnumScriptType.FORGE_INIT)) {
|
2021-10-11 06:49:30 -05:00
|
|
|
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-11 06:49:30 -05:00
|
|
|
if(script.type != type.function)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
script.setEngine(scriptLanguage);
|
|
|
|
|
if(script.engine == null)
|
|
|
|
|
return;
|
|
|
|
|
for(int i = 0; i + 1 < obs.length; i += 2){
|
|
|
|
|
Object ob = obs[i + 1];
|
|
|
|
|
if(ob instanceof Entity)
|
|
|
|
|
ob = ScriptController.Instance.getScriptForEntity((Entity)ob);
|
|
|
|
|
script.engine.put(obs[i].toString(), ob);
|
|
|
|
|
}
|
|
|
|
|
ScriptEngine engine = script.engine;
|
|
|
|
|
|
|
|
|
|
//script.run(EnumScriptType.valueOf(type), event);
|
|
|
|
|
script.run(engine);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void callScript(String type, Event event) {
|
|
|
|
|
if(this.isEnabled()) {
|
2021-10-12 02:57:32 -05:00
|
|
|
//CustomNpcs.getServer().func_152344_a(() -> {
|
2021-10-11 06:49:30 -05:00
|
|
|
Minecraft.getMinecraft().func_152344_a(() -> {
|
|
|
|
|
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-11 06:49:30 -05:00
|
|
|
//script.run(EnumScriptType.valueOf(type), event);
|
|
|
|
|
|
|
|
|
|
script.setEngine(scriptLanguage);
|
|
|
|
|
if(script.engine == null)
|
|
|
|
|
return;
|
|
|
|
|
ScriptEngine engine = script.engine;
|
|
|
|
|
|
|
|
|
|
script.run(engine);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|