Script Token Handling

This commit is contained in:
Kam committed 2026-03-03 01:58:45 -05:00
1 parent 6489f75b7d
commit 7df1cfbfb9
19 files changed
+150 -31

No files matched your search

@@ -2,7 +2,9 @@ package noppes.npcs.controllers.data;
import cpw.mods.fml.common.eventhandler.Event;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.PacketUtil;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.CustomNpcs;
@@ -117,9 +119,16 @@ public abstract class SingleScriptHandler extends ScriptHandler {
* - tab == 0: Script content NBT follows
* - tab != 0 (typically -1): Script metadata (language, enabled) follows
*/
public void saveScript(ByteBuf buffer) throws IOException {
public boolean saveScript(ByteBuf buffer, EntityPlayer player) throws IOException {
int tab = buffer.readInt();
int totalScripts = buffer.readInt();
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
// Verify session token
String token = compound.getString("ScriptSessionToken");
if (!PacketUtil.verifyScriptSession(player, token)) {
return false;
}
if (totalScripts == 0) {
this.container = null;
@@ -127,15 +136,14 @@ public abstract class SingleScriptHandler extends ScriptHandler {
if (tab == 0) {
// Script content
NBTTagCompound tabCompound = ByteBufUtils.readNBT(buffer);
this.container = IScriptUnit.createFromNBT(tabCompound, this);
this.container = IScriptUnit.createFromNBT(compound, this);
} else {
// Metadata (language, enabled)
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
this.setLanguage(compound.getString("ScriptLanguage"));
normalizeLanguage();
this.setEnabled(compound.getBoolean("ScriptEnabled"));
}
return true;
}
/**