From f03516b00fbb82fca5fc70a8b4b37726ac337b4a Mon Sep 17 00:00:00 2001 From: luisc Date: Fri, 17 Dec 2021 08:10:21 -0600 Subject: [PATCH] Fixed console and console spam with scripted player events. --- .../controllers/data/PlayerDataScript.java | 75 ++++--------------- 1 file changed, 13 insertions(+), 62 deletions(-) diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index d6f7110ab..288e35846 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -2,13 +2,10 @@ // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // - package noppes.npcs.controllers.data; - import java.lang.reflect.Array; import java.util.*; import java.util.Map.Entry; - import com.google.common.base.Preconditions; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -27,10 +24,8 @@ import noppes.npcs.scripted.event.PlayerEvent; import noppes.npcs.scripted.interfaces.IPlayer; import noppes.npcs.scripted.interfaces.IWorld; import noppes.npcs.scripted.wrapper.WrapperNpcAPI; - import javax.annotation.CheckForNull; import javax.script.ScriptEngine; - public class PlayerDataScript implements IScriptHandler { public List scripts = new ArrayList(); public String scriptLanguage = "ECMAScript"; @@ -42,10 +37,8 @@ public class PlayerDataScript implements IScriptHandler { public boolean enabled = false; private Map console = new TreeMap(); public List errored = new ArrayList(); - public IPlayer dummyPlayer; public IWorld dummyWorld; - public PlayerDataScript(EntityPlayer player) { if(player != null) { this.player = player; @@ -55,20 +48,17 @@ public class PlayerDataScript implements IScriptHandler { dummyWorld = (IWorld) NpcAPI.Instance().getIWorld((WorldServer) this.player.worldObj); } } - public void clear() { this.console = new TreeMap(); this.errored = new ArrayList(); 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"); this.console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10)); } - public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setTag("Scripts", NBTTags.NBTScript(this.scripts)); compound.setString("ScriptLanguage", this.scriptLanguage); @@ -83,14 +73,15 @@ public class PlayerDataScript implements IScriptHandler { if (ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastPlayerUpdate > this.lastPlayerUpdate) { this.lastInited = ScriptController.Instance.lastLoaded; errored.clear(); - if (this.player != null) { + if(this.player != null) { this.scripts.clear(); - Iterator var3 = ScriptController.Instance.playerScripts.scripts.iterator(); + Iterator i = ScriptController.Instance.playerScripts.scripts.iterator(); - while(var3.hasNext()) { - script = (ScriptContainer)var3.next(); + while(i.hasNext()) { + script = (ScriptContainer)i.next(); ScriptContainer s = new ScriptContainer(this); s.readFromNBT(script.writeToNBT(new NBTTagCompound())); + this.scripts.add(s); } } @@ -104,17 +95,21 @@ public class PlayerDataScript implements IScriptHandler { for(int i = 0; i < this.scripts.size(); ++i) { script = (ScriptContainer)this.scripts.get(i); if (!errored.contains(i)) { + if(script == null || script.errored || !script.hasCode() || ScriptController.Instance.playerScripts.errored.contains(i)) + return; + script.run(type, event); + if (script.errored) { - errored.add(i); + ScriptController.Instance.playerScripts.errored.add(i); } Iterator var8 = script.console.entrySet().iterator(); while(var8.hasNext()) { Entry entry = (Entry)var8.next(); - if (!console.containsKey(entry.getKey())) { - console.put(entry.getKey(), " tab " + (i + 1) + ":\n" + (String)entry.getValue()); + if (!ScriptController.Instance.playerScripts.console.containsKey(entry.getKey())) { + ScriptController.Instance.playerScripts.console.put(entry.getKey(), " tab " + (i + 1) + ":\n" + (String)entry.getValue()); } } @@ -128,32 +123,25 @@ public class PlayerDataScript implements IScriptHandler { public boolean isEnabled() { return ScriptController.Instance.playerScripts.enabled && ScriptController.HasStart && (this.player == null || !this.player.worldObj.isRemote); } - public boolean isClient() { return this.player.isClientWorld(); } - public boolean getEnabled() { return ScriptController.Instance.playerScripts.enabled; } - public void setEnabled(boolean bo) { ScriptController.Instance.playerScripts.enabled = bo; this.enabled = bo; } - public String getLanguage() { return ScriptController.Instance.playerScripts.scriptLanguage; } - public void setLanguage(String lang) { this.scriptLanguage = lang; } - public List getScripts() { return this.scripts; } - public String noticeString() { if(this.player == null) { return "Global script"; @@ -162,30 +150,24 @@ public class PlayerDataScript implements IScriptHandler { return PlayerDataScript.toStringHelper(this.player).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString(); } } - public IPlayer getPlayer() { if (this.playerAPI == null) { this.playerAPI = (IPlayer) NpcAPI.Instance().getIEntity(this.player); } - return this.playerAPI; } - public Map getConsoleText() { return this.console; } - public void clearConsole() { this.console.clear(); } - public static final class ToStringHelper { private final String className; private final PlayerDataScript.ToStringHelper.ValueHolder holderHead; private PlayerDataScript.ToStringHelper.ValueHolder holderTail; private boolean omitNullValues; private boolean omitEmptyValues; - private ToStringHelper(String className) { this.holderHead = new PlayerDataScript.ToStringHelper.ValueHolder(); this.holderTail = this.holderHead; @@ -193,68 +175,52 @@ public class PlayerDataScript implements IScriptHandler { this.omitEmptyValues = false; this.className = (String) Preconditions.checkNotNull(className); } - public PlayerDataScript.ToStringHelper omitNullValues() { this.omitNullValues = true; return this; } - public PlayerDataScript.ToStringHelper add(String name, @CheckForNull Object value) { return this.addHolder(name, value); } - public PlayerDataScript.ToStringHelper add(String name, boolean value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public PlayerDataScript.ToStringHelper add(String name, char value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public PlayerDataScript.ToStringHelper add(String name, double value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public PlayerDataScript.ToStringHelper add(String name, float value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public PlayerDataScript.ToStringHelper add(String name, int value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public PlayerDataScript.ToStringHelper add(String name, long value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public PlayerDataScript.ToStringHelper addValue(@CheckForNull Object value) { return this.addHolder(value); } - public PlayerDataScript.ToStringHelper addValue(boolean value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public PlayerDataScript.ToStringHelper addValue(char value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public PlayerDataScript.ToStringHelper addValue(double value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public PlayerDataScript.ToStringHelper addValue(float value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public PlayerDataScript.ToStringHelper addValue(int value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public PlayerDataScript.ToStringHelper addValue(long value) { return this.addUnconditionalHolder(String.valueOf(value)); } - private static boolean isEmpty(Object value) { if (value instanceof CharSequence) { return ((CharSequence)value).length() == 0; @@ -278,13 +244,11 @@ public class PlayerDataScript implements IScriptHandler { return false; } } - public String toString() { boolean omitNullValuesSnapshot = this.omitNullValues; boolean omitEmptyValuesSnapshot = this.omitEmptyValues; String nextSeparator = ""; StringBuilder builder = (new StringBuilder(32)).append(this.className).append('{'); - for(PlayerDataScript.ToStringHelper.ValueHolder valueHolder = this.holderHead.next; valueHolder != null; valueHolder = valueHolder.next) { Object value = valueHolder.value; if (!(valueHolder instanceof PlayerDataScript.ToStringHelper.UnconditionalValueHolder)) { @@ -296,13 +260,11 @@ public class PlayerDataScript implements IScriptHandler { continue; } } - builder.append(nextSeparator); nextSeparator = ", "; if (valueHolder.name != null) { builder.append(valueHolder.name).append('='); } - if (value != null && value.getClass().isArray()) { Object[] objectArray = new Object[]{value}; String arrayString = Arrays.deepToString(objectArray); @@ -311,54 +273,45 @@ public class PlayerDataScript implements IScriptHandler { builder.append(value); } } - return builder.append('}').toString(); } - private PlayerDataScript.ToStringHelper.ValueHolder addHolder() { PlayerDataScript.ToStringHelper.ValueHolder valueHolder = new PlayerDataScript.ToStringHelper.ValueHolder(); this.holderTail = this.holderTail.next = valueHolder; return valueHolder; } - private PlayerDataScript.ToStringHelper addHolder(@CheckForNull Object value) { PlayerDataScript.ToStringHelper.ValueHolder valueHolder = this.addHolder(); valueHolder.value = value; return this; } - private PlayerDataScript.ToStringHelper addHolder(String name, @CheckForNull Object value) { PlayerDataScript.ToStringHelper.ValueHolder valueHolder = this.addHolder(); valueHolder.value = value; valueHolder.name = (String)Preconditions.checkNotNull(name); return this; } - private PlayerDataScript.ToStringHelper.UnconditionalValueHolder addUnconditionalHolder() { PlayerDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = new PlayerDataScript.ToStringHelper.UnconditionalValueHolder(); this.holderTail = this.holderTail.next = valueHolder; return valueHolder; } - private PlayerDataScript.ToStringHelper addUnconditionalHolder(Object value) { PlayerDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder(); valueHolder.value = value; return this; } - private PlayerDataScript.ToStringHelper addUnconditionalHolder(String name, Object value) { PlayerDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder(); valueHolder.value = value; valueHolder.name = (String)Preconditions.checkNotNull(name); return this; } - private static final class UnconditionalValueHolder extends PlayerDataScript.ToStringHelper.ValueHolder { private UnconditionalValueHolder() { super(); } } - private static class ValueHolder { @CheckForNull String name; @@ -366,13 +319,11 @@ public class PlayerDataScript implements IScriptHandler { Object value; @CheckForNull PlayerDataScript.ToStringHelper.ValueHolder next; - private ValueHolder() { } } } - public static PlayerDataScript.ToStringHelper toStringHelper(Object self) { return new PlayerDataScript.ToStringHelper(self.getClass().getSimpleName()); } -} +} \ No newline at end of file