2021-09-30 00:56:49 -05:00
|
|
|
//
|
|
|
|
|
// Source code recreated from a .class file by IntelliJ IDEA
|
|
|
|
|
// (powered by Fernflower decompiler)
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
package noppes.npcs.controllers.data;
|
|
|
|
|
|
|
|
|
|
import com.google.common.base.MoreObjects;
|
|
|
|
|
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 net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
|
|
|
|
import noppes.npcs.EventHooks;
|
2021-09-30 01:48:54 -05:00
|
|
|
import noppes.npcs.EventScriptContainer;
|
2021-09-30 00:56:49 -05:00
|
|
|
import noppes.npcs.NBTTags;
|
2021-09-30 01:48:54 -05:00
|
|
|
import noppes.npcs.scripted.ScriptPlayer;
|
2021-09-30 00:56:49 -05:00
|
|
|
import noppes.npcs.constants.EnumScriptType;
|
|
|
|
|
import noppes.npcs.controllers.IScriptHandler;
|
|
|
|
|
import noppes.npcs.controllers.ScriptController;
|
|
|
|
|
|
|
|
|
|
public class PlayerScriptData implements IScriptHandler {
|
2021-09-30 01:48:54 -05:00
|
|
|
private List<EventScriptContainer> scripts = new ArrayList();
|
2021-09-30 00:56:49 -05:00
|
|
|
private String scriptLanguage = "ECMAScript";
|
|
|
|
|
private EntityPlayer player;
|
2021-09-30 01:48:54 -05:00
|
|
|
private ScriptPlayer playerAPI;
|
2021-09-30 00:56:49 -05:00
|
|
|
private long lastPlayerUpdate = 0L;
|
|
|
|
|
public long lastInited = -1L;
|
|
|
|
|
public boolean hadInteract = true;
|
|
|
|
|
private boolean enabled = false;
|
|
|
|
|
private static Map<Long, String> console = new TreeMap();
|
|
|
|
|
private static List<Integer> errored = new ArrayList();
|
|
|
|
|
|
|
|
|
|
public PlayerScriptData(EntityPlayer player) {
|
|
|
|
|
this.player = player;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clear() {
|
|
|
|
|
console = new TreeMap();
|
|
|
|
|
errored = new ArrayList();
|
|
|
|
|
this.scripts = new ArrayList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readFromNBT(NBTTagCompound compound) {
|
2021-09-30 01:48:54 -05:00
|
|
|
this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this);
|
|
|
|
|
this.scriptLanguage = compound.getString("ScriptLanguage");
|
|
|
|
|
this.enabled = compound.getBoolean("ScriptEnabled");
|
|
|
|
|
console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10));
|
2021-09-30 00:56:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
2021-09-30 01:48:54 -05:00
|
|
|
compound.setTag("Scripts", NBTTags.NBTScript(this.scripts));
|
|
|
|
|
compound.setString("ScriptLanguage", this.scriptLanguage);
|
|
|
|
|
compound.setBoolean("ScriptEnabled", this.enabled);
|
|
|
|
|
compound.setTag("ScriptConsole", NBTTags.NBTLongStringMap(console));
|
2021-09-30 00:56:49 -05:00
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void runScript(EnumScriptType type, Event event) {
|
|
|
|
|
if(this.isEnabled()) {
|
2021-09-30 01:48:54 -05:00
|
|
|
EventScriptContainer script;
|
2021-09-30 00:56:49 -05:00
|
|
|
if(ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastPlayerUpdate > this.lastPlayerUpdate) {
|
|
|
|
|
this.lastInited = ScriptController.Instance.lastLoaded;
|
|
|
|
|
errored.clear();
|
|
|
|
|
if(this.player != null) {
|
|
|
|
|
this.scripts.clear();
|
|
|
|
|
Iterator i = ScriptController.Instance.playerScripts.scripts.iterator();
|
|
|
|
|
|
|
|
|
|
while(i.hasNext()) {
|
2021-09-30 01:48:54 -05:00
|
|
|
script = ( EventScriptContainer)i.next();
|
|
|
|
|
EventScriptContainer s = new EventScriptContainer(this);
|
2021-09-30 00:56:49 -05:00
|
|
|
s.readFromNBT(script.writeToNBT(new NBTTagCompound()));
|
|
|
|
|
this.scripts.add(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.lastPlayerUpdate = ScriptController.Instance.lastPlayerUpdate;
|
|
|
|
|
if(type != EnumScriptType.INIT) {
|
|
|
|
|
EventHooks.onPlayerInit(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int var7 = 0; var7 < this.scripts.size(); ++var7) {
|
2021-09-30 01:48:54 -05:00
|
|
|
script = (EventScriptContainer)this.scripts.get(var7);
|
2021-09-30 00:56:49 -05:00
|
|
|
if(!errored.contains(Integer.valueOf(var7))) {
|
|
|
|
|
script.run(type, event);
|
|
|
|
|
if(script.errored) {
|
|
|
|
|
errored.add(Integer.valueOf(var7));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Iterator var8 = script.console.entrySet().iterator();
|
|
|
|
|
|
|
|
|
|
while(var8.hasNext()) {
|
|
|
|
|
Entry entry = (Entry)var8.next();
|
|
|
|
|
if(!console.containsKey(entry.getKey())) {
|
2021-09-30 01:48:54 -05:00
|
|
|
console.put((Long)entry.getKey(), " tab " + (var7 + 1) + ":\n" + (String)entry.getValue());
|
2021-09-30 00:56:49 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
script.console.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isEnabled() {
|
2021-09-30 01:48:54 -05:00
|
|
|
return ScriptController.Instance.playerScripts.enabled && ScriptController.HasStart && (this.player == null || !this.player.worldObj.isRemote);
|
2021-09-30 00:56:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isClient() {
|
2021-09-30 01:48:54 -05:00
|
|
|
return this.player.isClientWorld();
|
2021-09-30 00:56:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getEnabled() {
|
|
|
|
|
return ScriptController.Instance.playerScripts.enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setEnabled(boolean bo) {
|
|
|
|
|
this.enabled = bo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getLanguage() {
|
|
|
|
|
return ScriptController.Instance.playerScripts.scriptLanguage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setLanguage(String lang) {
|
|
|
|
|
this.scriptLanguage = lang;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-30 01:48:54 -05:00
|
|
|
public List<EventScriptContainer> getScripts() {
|
2021-09-30 00:56:49 -05:00
|
|
|
return this.scripts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String noticeString() {
|
|
|
|
|
if(this.player == null) {
|
|
|
|
|
return "Global script";
|
|
|
|
|
} else {
|
2021-09-30 01:48:54 -05:00
|
|
|
BlockPos pos = new BlockPos(this.player);
|
|
|
|
|
return MoreObjects.toStringHelper(this.player).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString();
|
2021-09-30 00:56:49 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-30 01:48:54 -05:00
|
|
|
public ScriptPlayer getPlayer() {
|
2021-09-30 00:56:49 -05:00
|
|
|
if(this.playerAPI == null) {
|
2021-09-30 01:48:54 -05:00
|
|
|
this.playerAPI = (ScriptPlayer) ScriptController.Instance.getScriptForEntity(this.player);
|
2021-09-30 00:56:49 -05:00
|
|
|
}
|
|
|
|
|
return this.playerAPI;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Map<Long, String> getConsoleText() {
|
|
|
|
|
return console;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clearConsole() {
|
|
|
|
|
console.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|