mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 00:22:19 +00:00
Merge branch 'dev' into syntax-highlighter-unified
This commit is contained in:
commit
5271f90fa9
20 files changed
+31
-161
No files matched your search
@@ -6,7 +6,6 @@ import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
@@ -79,8 +78,5 @@ public class ServerTickHandler {
|
||||
|
||||
// Save and unload the player's profile data on logout
|
||||
ProfileController.Instance.logout(event.player);
|
||||
|
||||
// Clear script session tokens
|
||||
PacketUtil.clearScriptSession(event.player);
|
||||
}
|
||||
}
|
||||
@@ -188,11 +188,8 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler, ISc
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sync(String sessionToken) {
|
||||
NBTTagCompound compound = getNBT(new NBTTagCompound());
|
||||
if (sessionToken != null && !sessionToken.isEmpty())
|
||||
compound.setString("ScriptSessionToken", sessionToken);
|
||||
sendSavePacket(-1, getScripts().size(), compound);
|
||||
public void sync() {
|
||||
sendSavePacket(-1, getScripts().size(), getNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -369,8 +369,6 @@ public class GuiScript extends GuiScriptInterface {
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
script.readFromNBT(compound);
|
||||
if (compound.hasKey("ScriptSessionToken"))
|
||||
scriptSessionToken = compound.getString("ScriptSessionToken");
|
||||
loadLanguagesData(compound);
|
||||
loaded = true;
|
||||
}
|
||||
@@ -379,10 +377,7 @@ public class GuiScript extends GuiScriptInterface {
|
||||
public void save() {
|
||||
if (loaded) {
|
||||
setScript();
|
||||
NBTTagCompound compound = script.writeToNBT(new NBTTagCompound());
|
||||
if (scriptSessionToken != null)
|
||||
compound.setString("ScriptSessionToken", scriptSessionToken);
|
||||
NPCScriptPacket.Save(compound);
|
||||
NPCScriptPacket.Save(script.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,9 +46,8 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
public Map<String, List<String>> languages = new HashMap();
|
||||
protected int scriptLimit = 1;
|
||||
public List<String> hookList = new ArrayList<String>();
|
||||
protected volatile boolean loaded = false;
|
||||
protected boolean loaded = false;
|
||||
protected boolean serverDataReceived = false;
|
||||
protected String scriptSessionToken = null;
|
||||
|
||||
protected Map<Integer, GuiScriptTextArea> textAreas = new HashMap<>();
|
||||
protected GuiScreen parent;
|
||||
@@ -780,8 +779,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
return;
|
||||
}
|
||||
if (result.kind == IScriptHandlerPacket.GuiDataKind.METADATA) {
|
||||
if (compound.hasKey("ScriptSessionToken"))
|
||||
scriptSessionToken = compound.getString("ScriptSessionToken");
|
||||
loadLanguagesData(compound);
|
||||
return;
|
||||
}
|
||||
@@ -792,8 +789,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
return;
|
||||
}
|
||||
|
||||
if (compound.hasKey("ScriptSessionToken"))
|
||||
scriptSessionToken = compound.getString("ScriptSessionToken");
|
||||
loadLanguagesData(compound);
|
||||
}
|
||||
|
||||
@@ -843,7 +838,9 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
this.setScript();
|
||||
|
||||
if (handler instanceof IScriptHandlerPacket)
|
||||
((IScriptHandlerPacket) handler).sync(scriptSessionToken);
|
||||
((IScriptHandlerPacket) handler).sync();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void textUpdate(String text) {
|
||||
|
||||
@@ -71,29 +71,16 @@ public interface IScriptHandlerPacket extends IScriptHandler {
|
||||
* GuiScriptInterface is responsible for updating the active {@link IScriptUnit} with current editor text first.
|
||||
*/
|
||||
default void sync() {
|
||||
sync(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit save packets with a session token for server-side verification.
|
||||
* The token prevents saving unloaded default data due to race conditions.
|
||||
*/
|
||||
default void sync(String sessionToken) {
|
||||
List<IScriptUnit> containers = getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
IScriptUnit container = containers.get(i);
|
||||
NBTTagCompound nbt = container.writeToNBT(new NBTTagCompound());
|
||||
if (sessionToken != null && !sessionToken.isEmpty())
|
||||
nbt.setString("ScriptSessionToken", sessionToken);
|
||||
sendSavePacket(i, containers.size(), nbt);
|
||||
sendSavePacket(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(getConsoleText()));
|
||||
if (sessionToken != null && !sessionToken.isEmpty())
|
||||
scriptData.setString("ScriptSessionToken", sessionToken);
|
||||
sendSavePacket(-1, containers.size(), scriptData);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,7 @@ 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;
|
||||
@@ -119,16 +117,9 @@ public abstract class SingleScriptHandler extends ScriptHandler {
|
||||
* - tab == 0: Script content NBT follows
|
||||
* - tab != 0 (typically -1): Script metadata (language, enabled) follows
|
||||
*/
|
||||
public boolean saveScript(ByteBuf buffer, EntityPlayer player) throws IOException {
|
||||
public void saveScript(ByteBuf buffer) 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;
|
||||
@@ -136,14 +127,15 @@ public abstract class SingleScriptHandler extends ScriptHandler {
|
||||
|
||||
if (tab == 0) {
|
||||
// Script content
|
||||
this.container = IScriptUnit.createFromNBT(compound, this);
|
||||
NBTTagCompound tabCompound = ByteBufUtils.readNBT(buffer);
|
||||
this.container = IScriptUnit.createFromNBT(tabCompound, this);
|
||||
} else {
|
||||
// Metadata (language, enabled)
|
||||
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
|
||||
this.setLanguage(compound.getString("ScriptLanguage"));
|
||||
normalizeLanguage();
|
||||
this.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -99,11 +99,8 @@ public class ScriptCustomItem extends ScriptCustomizableItem implements IItemCus
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sync(String sessionToken) {
|
||||
NBTTagCompound compound = getMCNbt();
|
||||
if (sessionToken != null && !sessionToken.isEmpty())
|
||||
compound.setString("ScriptSessionToken", sessionToken);
|
||||
sendSavePacket(-1, getScripts().size(), compound);
|
||||
public void sync() {
|
||||
sendSavePacket(-1, getScripts().size(), getMCNbt());
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
|
||||
Reference in new issue
Block a user