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

@@ -9,29 +9,49 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.Client;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.data.PlayerDataScript;
import java.util.List;
public class GuiScriptPlayers extends GuiScriptInterface {
private PlayerDataScript script = new PlayerDataScript((EntityPlayer)null);
public GuiScriptPlayers() {
this.handler = this.script;
Client.sendData(EnumPacketServer.ScriptPlayerGet, new Object[0]);
Client.sendData(EnumPacketServer.ScriptPlayerGet);
}
public void setGuiData(NBTTagCompound compound) {
this.script.readFromNBT(compound);
super.setGuiData(compound);
if (!compound.hasKey("Tab")) {
script.setLanguage(compound.getString("ScriptLanguage"));
script.setEnabled(compound.getBoolean("ScriptEnabled"));
super.setGuiData(compound);
} else {
int tab = compound.getInteger("Tab");
ScriptContainer container = new ScriptContainer(script);
container.readFromNBT(compound.getCompoundTag("Script"));
if (script.getScripts().isEmpty()) {
for (int i = 0; i < compound.getInteger("TotalScripts"); i++) {
script.getScripts().add(new ScriptContainer(script));
}
}
script.getScripts().set(tab,container);
initGui();
}
}
public void save() {
super.save();
Client.sendData(EnumPacketServer.ScriptPlayerSave, new Object[]{this.script.writeToNBT(new NBTTagCompound())});
}
public void close() {
super.close();
ScriptController.Instance.playerScripts.errored.clear();
List<ScriptContainer> containers = this.script.getScripts();
for (int i = 0; i < containers.size(); i++) {
ScriptContainer container = containers.get(i);
Client.sendData(EnumPacketServer.ScriptPlayerSave, i, container.writeToNBT(new NBTTagCompound()));
}
NBTTagCompound scriptData = new NBTTagCompound();
scriptData.setString("ScriptLanguage", this.script.getLanguage());
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
Client.sendData(EnumPacketServer.ScriptPlayerSave, -1, scriptData);
}
}