diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 8e7a5f64b..fe4b10378 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -126,6 +126,8 @@ public class PacketHandlerServer{ forgeScriptPackets(type, buffer, player); else if (type == EnumPacketServer.ScriptItemDataGet || type == EnumPacketServer.ScriptItemDataSave) itemScriptPackets(type, buffer, player); + else if (type == EnumPacketServer.ScriptGlobalGuiDataGet || type == EnumPacketServer.ScriptGlobalGuiDataSave) + getScriptsEnabled(type, buffer, player); else if (item.getItem() == CustomItems.scripter) scriptPackets(type, buffer, player, npc); else if (item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock)) @@ -141,6 +143,24 @@ public class PacketHandlerServer{ NoppesUtilServer.isGUIOpen(buffer, player); } + private void getScriptsEnabled(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException { + if (type == EnumPacketServer.ScriptGlobalGuiDataGet) { + NBTTagCompound compound = new NBTTagCompound(); + compound.setBoolean("ScriptsEnabled", CustomNpcs.GlobalPlayerScripts); + compound.setBoolean("PlayerScriptsEnabled", CustomNpcs.GlobalPlayerScripts); + compound.setBoolean("GlobalNPCScriptsEnabled", CustomNpcs.GlobalNPCScripts); + compound.setBoolean("ForgeScriptsEnabled", CustomNpcs.GlobalForgeScripts); + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); + } + else if (type == EnumPacketServer.ScriptGlobalGuiDataSave) { + NBTTagCompound compound = Server.readNBT(buffer); + CustomNpcs.GlobalPlayerScripts = compound.getBoolean("ScriptsEnabled"); + CustomNpcs.GlobalPlayerScripts = compound.getBoolean("PlayerScriptsEnabled"); + CustomNpcs.GlobalNPCScripts = compound.getBoolean("GlobalNPCScriptsEnabled"); + CustomNpcs.GlobalForgeScripts = compound.getBoolean("ForgeScriptsEnabled"); + } + } + private void scriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception { if(type == EnumPacketServer.ScriptDataSave){ npc.script.readFromNBT(Server.readNBT(buffer)); diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java index 23e37689f..5eb022c92 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java @@ -6,13 +6,16 @@ package noppes.npcs.client.gui.script; import net.minecraft.client.gui.GuiButton; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; -import noppes.npcs.CustomNpcs; +import noppes.npcs.client.Client; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; +import noppes.npcs.client.gui.util.IGuiData; +import noppes.npcs.constants.EnumPacketServer; import org.lwjgl.opengl.GL11; -public class GuiScriptGlobal extends GuiNPCInterface { +public class GuiScriptGlobal extends GuiNPCInterface implements IGuiData { private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/smallbg.png"); public GuiScriptGlobal() { @@ -24,16 +27,20 @@ public class GuiScriptGlobal extends GuiNPCInterface { public void initGui() { super.initGui(); + Client.sendData(EnumPacketServer.ScriptGlobalGuiDataGet, new Object[0]); + } + + public void setGuiData(NBTTagCompound compound) { GuiNpcButton playerButton = new GuiNpcButton(0, this.guiLeft + 38, this.guiTop + 20, 100, 20, "Players"); - playerButton.setEnabled(CustomNpcs.GlobalPlayerScripts && CustomNpcs.ScriptingEnabled); + playerButton.setEnabled(compound.getBoolean("PlayerScriptsEnabled") && compound.getBoolean("ScriptsEnabled")); this.addButton(playerButton); GuiNpcButton forgeButton = new GuiNpcButton(1, this.guiLeft + 38, this.guiTop + 50, 100, 20, "Forge"); - forgeButton.setEnabled(CustomNpcs.GlobalForgeScripts && CustomNpcs.ScriptingEnabled); + forgeButton.setEnabled(compound.getBoolean("ForgeScriptsEnabled") && compound.getBoolean("ScriptsEnabled")); this.addButton(forgeButton); GuiNpcButton npcButton = new GuiNpcButton(2, this.guiLeft + 38, this.guiTop + 80, 100, 20, "All NPCs"); - npcButton.setEnabled(CustomNpcs.GlobalNPCScripts && CustomNpcs.ScriptingEnabled); + npcButton.setEnabled(compound.getBoolean("GlobalNPCScriptsEnabled") && compound.getBoolean("ScriptsEnabled")); this.addButton(npcButton); } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 415f94855..d84364ca0 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -34,6 +34,9 @@ public enum EnumPacketServer { ClonePreSave(CustomNpcsPermissions.NPC_CLONE), CloneSave(CustomNpcsPermissions.NPC_CLONE), CloneRemove(CustomNpcsPermissions.NPC_CLONE), CloneList, + ScriptGlobalGuiDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), + ScriptGlobalGuiDataGet(false), + ScriptPlayerSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), ScriptPlayerGet(false), diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 98c1beba8..35eff98b7 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -320,6 +320,26 @@ public class NpcAPI extends AbstractNpcAPI { return new ScriptGui(id, width, height, pauseGame); } + public boolean arePlayerScriptsEnabled() { + return CustomNpcs.GlobalPlayerScripts; + } + public boolean areForgeScriptsEnabled() { + return CustomNpcs.GlobalForgeScripts; + } + public boolean areGlobalNPCScriptsEnabled() { + return CustomNpcs.GlobalNPCScripts; + } + + public void enablePlayerScripts(boolean enable) { + CustomNpcs.GlobalPlayerScripts = enable; + } + public void enableForgeScripts(boolean enable) { + CustomNpcs.GlobalForgeScripts = enable; + } + public void enableGlobalNPCScripts(boolean enable) { + CustomNpcs.GlobalNPCScripts = enable; + } + public ICustomOverlay createCustomOverlay(int id) { return new ScriptOverlay(id); }