Player, Forge, & NPC scripts are saved in separate packets for separate tabs now, so script save/get packets aren't too big for the server.

This commit is contained in:
Luis C.M committed 2023-02-19 13:38:43 -06:00
1 parent 0ddcd15162
commit b8dc090db8
11 files changed
+190 -78

No files matched your search

@@ -89,19 +89,14 @@ public class ScriptController {
}
}
public void setForgeScripts(NBTTagCompound compound) {
this.forgeScripts.readFromNBT(compound);
public void saveForgeScripts() {
File file = this.forgeScriptsFile();
try {
NBTJsonUtil.SaveFile(file, compound);
NBTJsonUtil.SaveFile(file, this.forgeScripts.writeToNBT(new NBTTagCompound()));
this.forgeScripts.lastInited = -1L;
} catch (IOException var4) {
} catch (IOException | JsonException var4) {
var4.printStackTrace();
} catch (JsonException var5) {
var5.printStackTrace();
}
}
private File playerScriptsFile() {
@@ -130,17 +125,13 @@ public class ScriptController {
}
}
public void setPlayerScripts(NBTTagCompound compound) {
this.playerScripts.readFromNBT(compound);
public void savePlayerScripts() {
File file = this.playerScriptsFile();
try {
NBTJsonUtil.SaveFile(file, compound);
this.lastPlayerUpdate = System.currentTimeMillis();
} catch (IOException var4) {
NBTJsonUtil.SaveFile(file, this.playerScripts.writeToNBT(new NBTTagCompound()));
this.playerScripts.lastInited = -1L;
} catch (IOException | JsonException var4) {
var4.printStackTrace();
} catch (JsonException var5) {
var5.printStackTrace();
}
}
@@ -162,16 +153,13 @@ public class ScriptController {
}
}
public void setNPCScripts(NBTTagCompound compound) {
this.npcScripts.readFromNBT(compound);
public void saveNpcScripts() {
File file = this.npcScriptsFile();
try {
NBTJsonUtil.SaveFile(file, compound);
} catch (IOException var4) {
NBTJsonUtil.SaveFile(file, this.npcScripts.writeToNBT(new NBTTagCompound()));
this.npcScripts.lastInited = -1L;
} catch (IOException | JsonException var4) {
var4.printStackTrace();
} catch (JsonException var5) {
var5.printStackTrace();
}
}
@@ -31,7 +31,11 @@ public class ForgeDataScript implements IScriptHandler {
}
public void readFromNBT(NBTTagCompound compound) {
this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this);
if (compound.hasKey("Scripts")) {
this.scripts = NBTTags.GetScriptOld(compound.getTagList("Scripts", 10), this);
} else {
this.scripts = NBTTags.GetScript(compound,this);
}
this.scriptLanguage = compound.getString("ScriptLanguage");
if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) {
if (!ScriptController.Instance.languages.isEmpty()) {
@@ -44,7 +48,10 @@ public class ForgeDataScript implements IScriptHandler {
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setTag("Scripts", NBTTags.NBTScript(this.scripts));
compound.setInteger("TotalScripts",this.scripts.size());
for (int i = 0; i < this.scripts.size(); i++) {
compound.setTag("Tab"+i,this.scripts.get(i).writeToNBT(new NBTTagCompound()));
}
compound.setString("ScriptLanguage", this.scriptLanguage);
compound.setBoolean("ScriptEnabled", this.enabled);
return compound;
@@ -36,7 +36,11 @@ public class NPCDataScript implements IScriptHandler {
this.scripts = new ArrayList();
}
public void readFromNBT(NBTTagCompound compound) {
this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this);
if (compound.hasKey("Scripts")) {
this.scripts = NBTTags.GetScriptOld(compound.getTagList("Scripts", 10), this);
} else {
this.scripts = NBTTags.GetScript(compound,this);
}
this.scriptLanguage = compound.getString("ScriptLanguage");
if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) {
if (!ScriptController.Instance.languages.isEmpty()) {
@@ -49,7 +53,10 @@ public class NPCDataScript implements IScriptHandler {
this.console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10));
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setTag("Scripts", NBTTags.NBTScript(this.scripts));
compound.setInteger("TotalScripts",this.scripts.size());
for (int i = 0; i < this.scripts.size(); i++) {
compound.setTag("Tab"+i,this.scripts.get(i).writeToNBT(new NBTTagCompound()));
}
compound.setString("ScriptLanguage", this.scriptLanguage);
compound.setBoolean("ScriptEnabled", this.enabled);
compound.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.console));
@@ -45,7 +45,11 @@ public class PlayerDataScript implements IScriptHandler {
this.scripts = new ArrayList();
}
public void readFromNBT(NBTTagCompound compound) {
this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this);
if (compound.hasKey("Scripts")) {
this.scripts = NBTTags.GetScriptOld(compound.getTagList("Scripts", 10), this);
} else {
this.scripts = NBTTags.GetScript(compound,this);
}
this.scriptLanguage = compound.getString("ScriptLanguage");
if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) {
if (!ScriptController.Instance.languages.isEmpty()) {
@@ -58,7 +62,10 @@ public class PlayerDataScript implements IScriptHandler {
this.console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10));
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setTag("Scripts", NBTTags.NBTScript(this.scripts));
compound.setInteger("TotalScripts",this.scripts.size());
for (int i = 0; i < this.scripts.size(); i++) {
compound.setTag("Tab"+i,this.scripts.get(i).writeToNBT(new NBTTagCompound()));
}
compound.setString("ScriptLanguage", this.scriptLanguage);
compound.setBoolean("ScriptEnabled", this.enabled);
compound.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.console));