mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 17:39:39 +00:00
Script Token Handling
This commit is contained in:
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user