Individualized Player Scripts Config

This commit is contained in:
Kam committed 2025-04-09 01:55:34 -04:00
1 parent e8a3d4f369
commit 4fd0c31bee
19 files changed
+246 -131

No files matched your search

@@ -26,8 +26,13 @@ public class PlayerDataScript implements INpcScriptHandler {
private EntityPlayer player;
private IPlayer playerAPI;
private long lastPlayerUpdate = 0L;
public long lastInited = -1L;
public boolean enabled = false;
public long lastInited = -1;
public boolean hadInteract = true;
private boolean enabled = false;
private static Map<Long, String> console = new TreeMap<Long, String>();
private static List<Integer> errored = new ArrayList<Integer>();
public PlayerDataScript(EntityPlayer player) {
if (player != null) {
@@ -36,7 +41,9 @@ public class PlayerDataScript implements INpcScriptHandler {
}
public void clear() {
this.scripts = new ArrayList();
console = new TreeMap<Long, String>();
errored = new ArrayList<Integer>();
scripts = new ArrayList<ScriptContainer>();
}
public void readFromNBT(NBTTagCompound compound) {
@@ -54,6 +61,7 @@ public class PlayerDataScript implements INpcScriptHandler {
}
}
this.enabled = compound.getBoolean("ScriptEnabled");
console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10));
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
@@ -63,6 +71,7 @@ public class PlayerDataScript implements INpcScriptHandler {
}
compound.setString("ScriptLanguage", this.scriptLanguage);
compound.setBoolean("ScriptEnabled", this.enabled);
compound.setTag("ScriptConsole", NBTTags.NBTLongStringMap(console));
return compound;
}
@@ -76,7 +85,42 @@ public class PlayerDataScript implements INpcScriptHandler {
@Override
public void callScript(String hookName, Event event) {
if (this.isEnabled()) {
if(!isEnabled())
return;
if(ConfigScript.IndividualPlayerScripts){
if(ScriptController.Instance.lastLoaded > lastInited || ScriptController.Instance.lastPlayerUpdate > lastPlayerUpdate){
lastInited = ScriptController.Instance.lastLoaded;
errored.clear();
if(player != null) {
scripts.clear();
for(ScriptContainer script : ScriptController.Instance.playerScripts.scripts){
ScriptContainer s = new ScriptContainer(this);
s.readFromNBT(script.writeToNBT(new NBTTagCompound()));
scripts.add(s);
}
}
lastPlayerUpdate = ScriptController.Instance.lastPlayerUpdate;
if (!Objects.equals(hookName, EnumScriptType.INIT.function) && event instanceof PlayerEvent) {
PlayerEvent playerEvent = (PlayerEvent) event;
EventHooks.onPlayerInit(this, playerEvent.player);
}
}
for(int i = 0; i < scripts.size(); i++){
ScriptContainer script = scripts.get(i);
if(errored.contains(i))
continue;
script.run(hookName, event);
if(script.errored){
errored.add(i);
}
for(Entry<Long, String> entry : script.console.entrySet()){
if(!console.containsKey(entry.getKey()))
console.put(entry.getKey(), " tab " + (i + 1) + ":\n" + entry.getValue());
}
script.console.clear();
}
} else {
if (ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastPlayerUpdate > this.lastPlayerUpdate) {
this.lastInited = ScriptController.Instance.lastLoaded;
this.lastPlayerUpdate = ScriptController.Instance.lastPlayerUpdate;
@@ -146,6 +190,9 @@ public class PlayerDataScript implements INpcScriptHandler {
}
public Map<Long, String> getConsoleText() {
if(ConfigScript.IndividualPlayerScripts)
return console;
TreeMap<Long, String> map = new TreeMap<>();
int tab = 0;
for (ScriptContainer script : this.getScripts()) {
@@ -159,8 +206,12 @@ public class PlayerDataScript implements INpcScriptHandler {
}
public void clearConsole() {
for (ScriptContainer script : this.getScripts()) {
script.console.clear();
if(ConfigScript.IndividualPlayerScripts)
console.clear();
else {
for (ScriptContainer script : this.getScripts()) {
script.console.clear();
}
}
}