mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 12:39:05 +00:00
Implemented local NPC event scripts.
This commit is contained in:
1 parent
46d668f44c
commit
29935a1c6d
17 files changed
+339
-225
No files matched your search
@@ -202,7 +202,7 @@ public class CustomNpcs {
|
||||
new AnimationController();
|
||||
ScriptController.Instance.loadStoredData();
|
||||
ScriptController.Instance.loadForgeScripts();
|
||||
ScriptController.Instance.loadNPCScripts();
|
||||
ScriptController.Instance.loadGlobalNPCScripts();
|
||||
ScriptController.Instance.loadPlayerScripts();
|
||||
ScriptController.HasStart = false;
|
||||
NpcAPI.clearCache();
|
||||
@@ -239,7 +239,7 @@ public class CustomNpcs {
|
||||
GlobalDataController.instance.saveData();
|
||||
ScriptController.Instance.saveForgeScripts();
|
||||
ScriptController.Instance.savePlayerScripts();
|
||||
ScriptController.Instance.saveNpcScripts();
|
||||
ScriptController.Instance.saveGlobalNpcScripts();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -118,7 +118,7 @@ public class EventHooks {
|
||||
return;
|
||||
|
||||
noppes.npcs.scripted.event.NpcEvent.InitEvent event = new noppes.npcs.scripted.event.NpcEvent.InitEvent(npc.wrappedNPC);
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.INIT, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.INIT, event);
|
||||
npc.script.callScript(EnumScriptType.INIT, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
npc.advanced.soulStoneInit = false;
|
||||
@@ -129,7 +129,7 @@ public class EventHooks {
|
||||
return;
|
||||
|
||||
noppes.npcs.scripted.event.NpcEvent.UpdateEvent event = new noppes.npcs.scripted.event.NpcEvent.UpdateEvent(npc.wrappedNPC);
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.TICK, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TICK, event);
|
||||
npc.script.callScript(EnumScriptType.TICK, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ public class EventHooks {
|
||||
return false;
|
||||
|
||||
NpcEvent.DialogEvent event = new NpcEvent.DialogEvent(npc.wrappedNPC, player, dialogId, optionId, dialog);
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.DIALOG, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.DIALOG, event);
|
||||
npc.script.callScript(EnumScriptType.DIALOG, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog());
|
||||
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
@@ -150,7 +150,7 @@ public class EventHooks {
|
||||
return;
|
||||
|
||||
NpcEvent.DialogClosedEvent event = new NpcEvent.DialogClosedEvent(npc.wrappedNPC, player, dialogId, optionId, dialog);
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.DIALOG_CLOSE, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.DIALOG_CLOSE, event);
|
||||
npc.script.callScript(EnumScriptType.DIALOG_CLOSE, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog());
|
||||
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
@@ -161,7 +161,7 @@ public class EventHooks {
|
||||
return false;
|
||||
|
||||
NpcEvent.InteractEvent event = new NpcEvent.InteractEvent(npc.wrappedNPC,player);
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.INTERACT, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.INTERACT, event);
|
||||
boolean result = npc.script.callScript(EnumScriptType.INTERACT, event, "player", player);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
return result;
|
||||
@@ -171,7 +171,7 @@ public class EventHooks {
|
||||
if(npc == null || npc.wrappedNPC == null)
|
||||
return false;
|
||||
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.ATTACK_MELEE, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.ATTACK_MELEE, event);
|
||||
npc.script.callScript(EnumScriptType.ATTACK, event, "target", event.target);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
@@ -180,7 +180,7 @@ public class EventHooks {
|
||||
if(npc == null || npc.wrappedNPC == null)
|
||||
return false;
|
||||
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.RANGED_LAUNCHED, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.RANGED_LAUNCHED, event);
|
||||
npc.script.callScript(EnumScriptType.ATTACK, event, "target", event.target);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ public class EventHooks {
|
||||
return;
|
||||
|
||||
NpcEvent.KilledEntityEvent event = new NpcEvent.KilledEntityEvent(npc.wrappedNPC,entity);
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.KILLS, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.KILLS, event);
|
||||
npc.script.callScript(EnumScriptType.KILLS, event, "target", entity);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
@@ -199,7 +199,7 @@ public class EventHooks {
|
||||
if(npc == null || npc.wrappedNPC == null)
|
||||
return false;
|
||||
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.TARGET, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TARGET, event);
|
||||
npc.script.callScript(EnumScriptType.TARGET, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
@@ -209,7 +209,7 @@ public class EventHooks {
|
||||
return;
|
||||
|
||||
NpcEvent.CollideEvent event = new NpcEvent.CollideEvent(npc.wrappedNPC,entity);
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.COLLIDE, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.COLLIDE, event);
|
||||
npc.script.callScript(EnumScriptType.COLLIDE, event, "entity", entity);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
@@ -218,7 +218,7 @@ public class EventHooks {
|
||||
if(npc == null || npc.wrappedNPC == null)
|
||||
return false;
|
||||
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.DAMAGED, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.DAMAGED, event);
|
||||
npc.script.callScript(EnumScriptType.DAMAGED, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
@@ -227,7 +227,7 @@ public class EventHooks {
|
||||
if(npc == null || npc.wrappedNPC == null)
|
||||
return false;
|
||||
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.KILLED, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.KILLED, event);
|
||||
npc.script.callScript(EnumScriptType.KILLED, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
@@ -238,7 +238,7 @@ public class EventHooks {
|
||||
|
||||
NpcEvent.TimerEvent event = new NpcEvent.TimerEvent(npc.wrappedNPC, id);
|
||||
npc.script.callScript(EnumScriptType.TIMER, event);
|
||||
ScriptController.Instance.npcScripts.callScript(EnumScriptType.TIMER, event);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TIMER, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ public class PacketHandlerServer{
|
||||
else if(type.hasPermission() && !CustomNpcsPermissions.hasPermission(player, type.permission)){
|
||||
//player doesnt have permission to do this
|
||||
}
|
||||
else if(item == null && (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave || type == EnumPacketServer.ScriptNPCGet || type == EnumPacketServer.ScriptNPCSave || type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave))
|
||||
else if(item == null && (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave || type == EnumPacketServer.ScriptGlobalNPCGet || type == EnumPacketServer.ScriptGlobalNPCSave || type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave))
|
||||
warn(player, "tried to use custom npcs without a tool in hand, probably a hacker");
|
||||
else {
|
||||
if (item != null) {
|
||||
@@ -120,10 +120,12 @@ public class PacketHandlerServer{
|
||||
else if (item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock))
|
||||
blockPackets(type, buffer, player);
|
||||
else if (ConfigScript.isScriptDev(player)) {
|
||||
if (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave)
|
||||
if (type == EnumPacketServer.EventScriptDataGet || type == EnumPacketServer.EventScriptDataSave)
|
||||
npcEventScriptPackets(type, buffer, player, npc);
|
||||
else if (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave)
|
||||
playerScriptPackets(type, buffer, player);
|
||||
else if (type == EnumPacketServer.ScriptNPCGet || type == EnumPacketServer.ScriptNPCSave)
|
||||
npcScriptPackets(type, buffer, player);
|
||||
else if (type == EnumPacketServer.ScriptGlobalNPCGet || type == EnumPacketServer.ScriptGlobalNPCSave)
|
||||
npcGlobalScriptPackets(type, buffer, player);
|
||||
else if (type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave)
|
||||
forgeScriptPackets(type, buffer, player);
|
||||
else if (type == EnumPacketServer.ScriptItemDataGet || type == EnumPacketServer.ScriptItemDataSave)
|
||||
@@ -225,8 +227,12 @@ public class PacketHandlerServer{
|
||||
|
||||
private void saveScripts(IScriptHandler data, ByteBuf buffer, EntityPlayerMP player) throws Exception {
|
||||
int tab = buffer.readInt();
|
||||
int totalScripts = buffer.readInt();
|
||||
if (totalScripts == 0) {
|
||||
data.getScripts().clear();
|
||||
}
|
||||
|
||||
if (tab >= 0) {
|
||||
int totalScripts = buffer.readInt();
|
||||
if (data.getScripts().size() > totalScripts) {
|
||||
data.setScripts(data.getScripts().subList(0,totalScripts));
|
||||
} else while (data.getScripts().size() < totalScripts) {
|
||||
@@ -248,6 +254,20 @@ public class PacketHandlerServer{
|
||||
}
|
||||
}
|
||||
|
||||
private void npcEventScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception {
|
||||
DataScript data = npc.script;
|
||||
if(type == EnumPacketServer.EventScriptDataGet) {
|
||||
this.getScripts(data,buffer,player);
|
||||
} else if(type == EnumPacketServer.EventScriptDataSave) {
|
||||
this.saveScripts(data,buffer,player);
|
||||
npc.updateAI = true;
|
||||
npc.script.hasInited = false;
|
||||
if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
|
||||
LogWriter.script(String.format("[%s] (Player) %s SAVED NPC %s (%s, %s, %s) [%s]", "SCRIPTER", player.getCommandSenderName(), npc.display.getName(), (int)npc.posX, (int)(npc).posY, (int)npc.posZ, npc.worldObj.getWorldInfo().getWorldName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void playerScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
|
||||
PlayerDataScript data = ScriptController.Instance.playerScripts;
|
||||
if(type == EnumPacketServer.ScriptPlayerGet) {
|
||||
@@ -268,13 +288,13 @@ public class PacketHandlerServer{
|
||||
}
|
||||
}
|
||||
|
||||
private void npcScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
|
||||
NPCDataScript data = ScriptController.Instance.npcScripts;
|
||||
if(type == EnumPacketServer.ScriptNPCGet) {
|
||||
private void npcGlobalScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
|
||||
GlobalNPCDataScript data = ScriptController.Instance.globalNpcScripts;
|
||||
if(type == EnumPacketServer.ScriptGlobalNPCGet) {
|
||||
this.getScripts(data,buffer,player);
|
||||
} else if(type == EnumPacketServer.ScriptNPCSave) {
|
||||
} else if(type == EnumPacketServer.ScriptGlobalNPCSave) {
|
||||
this.saveScripts(data,buffer,player);
|
||||
ScriptController.Instance.lastNpcUpdate = System.currentTimeMillis();
|
||||
ScriptController.Instance.lastGlobalNpcUpdate = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -305,7 +305,7 @@ public class ClientProxy extends CommonProxy {
|
||||
return new GuiScript(npc);
|
||||
|
||||
else if (gui == EnumGuiType.ScriptItem)
|
||||
return new GuiScriptItem(Minecraft.getMinecraft().thePlayer);
|
||||
return new GuiScriptItem();
|
||||
|
||||
else if(gui == EnumGuiType.PlayerAnvil)
|
||||
return new GuiNpcCarpentryBench((ContainerCarpentryBench) container);
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.server.MinecraftServer;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.script.GuiNPCEventScripts;
|
||||
import noppes.npcs.client.gui.swing.GuiJTextArea;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
@@ -43,6 +44,7 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
guiTop += 10;
|
||||
GuiMenuTopButton top;
|
||||
addTopButton(top = new GuiMenuTopButton(13, guiLeft + 4, guiTop - 17, "script.scripts"));
|
||||
addTopButton(new GuiMenuTopButton(16, guiLeft + (xSize - 100), guiTop - 17, "eventscript.eventScripts"));
|
||||
top.active = showScript;
|
||||
addTopButton(top = new GuiMenuTopButton(14, top, "gui.settings"));
|
||||
top.active = !showScript;
|
||||
@@ -162,6 +164,10 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
GuiConfirmOpenLink guiyesno = new GuiConfirmOpenLink(this, "https://kamkeel.github.io/CustomNPC-Plus/", 0, true);
|
||||
mc.displayGuiScreen(guiyesno);
|
||||
}
|
||||
if(guibutton.id == 16){
|
||||
close();
|
||||
mc.displayGuiScreen(new GuiNPCEventScripts(npc));
|
||||
}
|
||||
if (guibutton.id == 100) {
|
||||
NoppesStringUtils.setClipboardContents(getTextField(2).getText());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package noppes.npcs.client.gui.script;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.data.DataScript;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiNPCEventScripts extends GuiScriptInterface {
|
||||
private final DataScript script;
|
||||
|
||||
public GuiNPCEventScripts(EntityNPCInterface npc) {
|
||||
this.hookList = new ArrayList<>();
|
||||
hookList.add("init");
|
||||
hookList.add("tick");
|
||||
hookList.add("interact");
|
||||
hookList.add("dialog");
|
||||
hookList.add("damaged");
|
||||
hookList.add("killed");
|
||||
hookList.add("meleeAttack");
|
||||
hookList.add("rangedLaunched");
|
||||
hookList.add("target");
|
||||
hookList.add("collide");
|
||||
hookList.add("kills");
|
||||
hookList.add("dialogClose");
|
||||
hookList.add("timer");
|
||||
|
||||
this.script = new DataScript(npc);
|
||||
this.handler = this.script;
|
||||
Client.sendData(EnumPacketServer.EventScriptDataGet);
|
||||
}
|
||||
|
||||
public void setGuiData(NBTTagCompound 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();
|
||||
List<ScriptContainer> containers = this.script.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
Client.sendData(EnumPacketServer.EventScriptDataSave, i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||
Client.sendData(EnumPacketServer.EventScriptDataSave, -1, containers.size(), scriptData);
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,30 @@ import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.data.NPCDataScript;
|
||||
import noppes.npcs.controllers.data.GlobalNPCDataScript;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GuiScriptAllNPCs extends GuiScriptInterface {
|
||||
private NPCDataScript script = new NPCDataScript(null);
|
||||
private GlobalNPCDataScript script = new GlobalNPCDataScript(null);
|
||||
|
||||
public GuiScriptAllNPCs() {
|
||||
hookList.add("init");
|
||||
hookList.add("tick");
|
||||
hookList.add("interact");
|
||||
hookList.add("dialog");
|
||||
hookList.add("damaged");
|
||||
hookList.add("killed");
|
||||
hookList.add("meleeAttack");
|
||||
hookList.add("rangedLaunched");
|
||||
hookList.add("target");
|
||||
hookList.add("collide");
|
||||
hookList.add("kills");
|
||||
hookList.add("dialogClose");
|
||||
hookList.add("timer");
|
||||
|
||||
this.handler = this.script;
|
||||
Client.sendData(EnumPacketServer.ScriptNPCGet);
|
||||
Client.sendData(EnumPacketServer.ScriptGlobalNPCGet);
|
||||
}
|
||||
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
@@ -41,12 +55,12 @@ public class GuiScriptAllNPCs extends GuiScriptInterface {
|
||||
List<ScriptContainer> containers = this.script.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
Client.sendData(EnumPacketServer.ScriptNPCSave, i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
Client.sendData(EnumPacketServer.ScriptGlobalNPCSave, i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||
Client.sendData(EnumPacketServer.ScriptNPCSave, -1, scriptData);
|
||||
Client.sendData(EnumPacketServer.ScriptGlobalNPCSave, -1, containers.size(), scriptData);
|
||||
}
|
||||
}
|
||||
@@ -5,19 +5,67 @@
|
||||
|
||||
package noppes.npcs.client.gui.script;
|
||||
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.event.world.ChunkDataEvent;
|
||||
import net.minecraftforge.event.world.ChunkEvent;
|
||||
import net.minecraftforge.event.world.ChunkWatchEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.data.ForgeDataScript;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiScriptForge extends GuiScriptInterface {
|
||||
private ForgeDataScript script = new ForgeDataScript();
|
||||
|
||||
public GuiScriptForge() {
|
||||
hookList.add("init");
|
||||
|
||||
ArrayList<ClassPath.ClassInfo> list = new ArrayList();
|
||||
try {
|
||||
list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("cpw.mods.fml.common.gameevent"));
|
||||
list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event"));
|
||||
list.removeAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event.terraingen"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for(ClassPath.ClassInfo e1 : list){
|
||||
ClassPath.ClassInfo classLoader = e1;
|
||||
Class infoClass = classLoader.load();
|
||||
ArrayList c = new ArrayList(Arrays.asList(infoClass.getDeclaredClasses()));
|
||||
if(c.isEmpty()) {
|
||||
c.add(infoClass);
|
||||
}
|
||||
Iterator var10 = c.iterator();
|
||||
while(var10.hasNext()) {
|
||||
Class c1 = (Class) var10.next();
|
||||
if(!EntityEvent.EntityConstructing.class.isAssignableFrom(c1) && !WorldEvent.PotentialSpawns.class.isAssignableFrom(c1) && !TickEvent.RenderTickEvent.class.isAssignableFrom(c1) && !TickEvent.ClientTickEvent.class.isAssignableFrom(c1) && !FMLNetworkEvent.ClientCustomPacketEvent.class.isAssignableFrom(c1) && !ItemTooltipEvent.class.isAssignableFrom(c1) && Event.class.isAssignableFrom(c1) && !Modifier.isAbstract(c1.getModifiers()) && Modifier.isPublic(c1.getModifiers()) && !ChunkEvent.class.isAssignableFrom(c1) && !ChunkWatchEvent.class.isAssignableFrom(c1) && !ChunkDataEvent.class.isAssignableFrom(c1)) {
|
||||
String eventName = c1.getName();
|
||||
int i = eventName.lastIndexOf(".");
|
||||
eventName = StringUtils.uncapitalize(eventName.substring(i + 1).replace("$", ""));
|
||||
|
||||
hookList.add(eventName);
|
||||
}
|
||||
}
|
||||
}
|
||||
hookList.add("onCNPCNaturalSpawn");
|
||||
|
||||
this.handler = this.script;
|
||||
Client.sendData(EnumPacketServer.ScriptForgeGet);
|
||||
}
|
||||
@@ -52,6 +100,6 @@ public class GuiScriptForge extends GuiScriptInterface {
|
||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||
Client.sendData(EnumPacketServer.ScriptForgeSave, -1, scriptData);
|
||||
Client.sendData(EnumPacketServer.ScriptForgeSave, -1, containers.size(), scriptData);
|
||||
}
|
||||
}
|
||||
@@ -5,22 +5,12 @@
|
||||
|
||||
package noppes.npcs.client.gui.script;
|
||||
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiConfirmOpenLink;
|
||||
import net.minecraft.client.gui.GuiYesNo;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.event.world.ChunkDataEvent;
|
||||
import net.minecraftforge.event.world.ChunkEvent;
|
||||
import net.minecraftforge.event.world.ChunkWatchEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.swing.GuiJTextArea;
|
||||
@@ -29,13 +19,8 @@ import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.ForgeDataScript;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
import noppes.npcs.controllers.data.NPCDataScript;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@@ -44,6 +29,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
public IScriptHandler handler;
|
||||
public Map<String, List<String>> languages = new HashMap();
|
||||
private int scriptLimit = 1;
|
||||
public List<String> hookList = new ArrayList<String>();
|
||||
|
||||
public GuiScriptInterface() {
|
||||
this.drawDefaultBackground = true;
|
||||
@@ -91,132 +77,15 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
|
||||
top.active = true;
|
||||
if(this.activeTab > 0) {
|
||||
List<String> hookList = new ArrayList<String>();
|
||||
|
||||
GuiCustomScroll hooks = new GuiCustomScroll(this, 1);
|
||||
hooks.allowUserInput = false;
|
||||
hooks.setSize(108, 198);
|
||||
hooks.guiLeft = guiLeft - 110;
|
||||
hooks.guiTop = guiTop + 14;
|
||||
|
||||
if(handler instanceof PlayerDataScript) {
|
||||
hookList.add("init");
|
||||
hookList.add("tick");
|
||||
hookList.add("interact");
|
||||
hookList.add("attack");
|
||||
hookList.add("attacked");
|
||||
hookList.add("damagedEntity");
|
||||
hookList.add("damaged");
|
||||
hookList.add("kills");
|
||||
hookList.add("killed");
|
||||
hookList.add("drop");
|
||||
hookList.add("respawn");
|
||||
hookList.add("breakBlock");
|
||||
hookList.add("chat");
|
||||
hookList.add("login");
|
||||
hookList.add("logout");
|
||||
hookList.add("keyPressed");
|
||||
hookList.add("mouseClicked");
|
||||
hookList.add("toss");
|
||||
hookList.add("pickUp");
|
||||
hookList.add("pickupXP");
|
||||
hookList.add("rangedCharge");
|
||||
hookList.add("rangedLaunched");
|
||||
hookList.add("timer");
|
||||
hookList.add("startItem");
|
||||
hookList.add("usingItem");
|
||||
hookList.add("stopItem");
|
||||
hookList.add("finishItem");
|
||||
hookList.add("containerOpen");
|
||||
hookList.add("useHoe");
|
||||
hookList.add("bonemeal");
|
||||
hookList.add("fillBucket");
|
||||
hookList.add("jump");
|
||||
hookList.add("fall");
|
||||
hookList.add("wakeUp");
|
||||
hookList.add("sleep");
|
||||
hookList.add("playSound");
|
||||
hookList.add("lightning");
|
||||
hookList.add("changedDim");
|
||||
hookList.add("questStart");
|
||||
hookList.add("questCompleted");
|
||||
hookList.add("questTurnIn");
|
||||
hookList.add("factionPoints");
|
||||
hookList.add("dialogOpen");
|
||||
hookList.add("dialogOption");
|
||||
hookList.add("dialogClose");
|
||||
hookList.add("customGuiClosed");
|
||||
hookList.add("customGuiButton");
|
||||
hookList.add("customGuiSlot");
|
||||
hookList.add("customGuiSlotClicked");
|
||||
hookList.add("customGuiScroll");
|
||||
hookList.add("customGuiTextfield");
|
||||
|
||||
}
|
||||
else if(handler instanceof NPCDataScript) {
|
||||
hookList.add("init");
|
||||
hookList.add("tick");
|
||||
hookList.add("interact");
|
||||
hookList.add("dialog");
|
||||
hookList.add("damaged");
|
||||
hookList.add("killed");
|
||||
hookList.add("meleeAttack");
|
||||
hookList.add("rangedLaunched");
|
||||
hookList.add("target");
|
||||
hookList.add("collide");
|
||||
hookList.add("kills");
|
||||
hookList.add("dialogClose");
|
||||
hookList.add("timer");
|
||||
}
|
||||
else if(handler instanceof ScriptCustomItem) {
|
||||
hookList.add("init");
|
||||
hookList.add("tick");
|
||||
hookList.add("tossed");
|
||||
hookList.add("pickedUp");
|
||||
hookList.add("spawn");
|
||||
hookList.add("interact");
|
||||
hookList.add("attack");
|
||||
hookList.add("startItem");
|
||||
hookList.add("usingItem");
|
||||
hookList.add("stopItem");
|
||||
hookList.add("finishItem");
|
||||
}
|
||||
else if(handler instanceof ForgeDataScript) {
|
||||
if(handler instanceof ForgeDataScript) {
|
||||
hooks.setSize(238, 198);
|
||||
hooks.guiLeft = guiLeft - 240;
|
||||
|
||||
hookList.add("init");
|
||||
|
||||
ArrayList<ClassPath.ClassInfo> list = new ArrayList();
|
||||
try {
|
||||
list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("cpw.mods.fml.common.gameevent"));
|
||||
list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event"));
|
||||
list.removeAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event.terraingen"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for(ClassPath.ClassInfo e1 : list){
|
||||
ClassPath.ClassInfo classLoader = e1;
|
||||
Class infoClass = classLoader.load();
|
||||
ArrayList c = new ArrayList(Arrays.asList(infoClass.getDeclaredClasses()));
|
||||
if(c.isEmpty()) {
|
||||
c.add(infoClass);
|
||||
}
|
||||
Iterator var10 = c.iterator();
|
||||
while(var10.hasNext()) {
|
||||
Class c1 = (Class) var10.next();
|
||||
if(!EntityEvent.EntityConstructing.class.isAssignableFrom(c1) && !WorldEvent.PotentialSpawns.class.isAssignableFrom(c1) && !TickEvent.RenderTickEvent.class.isAssignableFrom(c1) && !TickEvent.ClientTickEvent.class.isAssignableFrom(c1) && !FMLNetworkEvent.ClientCustomPacketEvent.class.isAssignableFrom(c1) && !ItemTooltipEvent.class.isAssignableFrom(c1) && Event.class.isAssignableFrom(c1) && !Modifier.isAbstract(c1.getModifiers()) && Modifier.isPublic(c1.getModifiers()) && !ChunkEvent.class.isAssignableFrom(c1) && !ChunkWatchEvent.class.isAssignableFrom(c1) && !ChunkDataEvent.class.isAssignableFrom(c1)) {
|
||||
String eventName = c1.getName();
|
||||
int i = eventName.lastIndexOf(".");
|
||||
eventName = StringUtils.uncapitalize(eventName.substring(i + 1).replace("$", ""));
|
||||
|
||||
hookList.add(eventName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hookList.add("onCNPCNaturalSpawn");
|
||||
}
|
||||
hooks.setUnsortedList(hookList);
|
||||
addScroll(hooks);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package noppes.npcs.client.gui.script;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomItems;
|
||||
@@ -11,7 +10,19 @@ import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
public class GuiScriptItem extends GuiScriptInterface {
|
||||
private ScriptCustomItem item;
|
||||
|
||||
public GuiScriptItem(EntityPlayer player) {
|
||||
public GuiScriptItem() {
|
||||
hookList.add("init");
|
||||
hookList.add("tick");
|
||||
hookList.add("tossed");
|
||||
hookList.add("pickedUp");
|
||||
hookList.add("spawn");
|
||||
hookList.add("interact");
|
||||
hookList.add("attack");
|
||||
hookList.add("startItem");
|
||||
hookList.add("usingItem");
|
||||
hookList.add("stopItem");
|
||||
hookList.add("finishItem");
|
||||
|
||||
this.handler = this.item = new ScriptCustomItem(new ItemStack(CustomItems.scripted_item));
|
||||
Client.sendData(EnumPacketServer.ScriptItemDataGet, new Object[0]);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,58 @@ public class GuiScriptPlayers extends GuiScriptInterface {
|
||||
private PlayerDataScript script = new PlayerDataScript((EntityPlayer)null);
|
||||
|
||||
public GuiScriptPlayers() {
|
||||
hookList.add("init");
|
||||
hookList.add("tick");
|
||||
hookList.add("interact");
|
||||
hookList.add("attack");
|
||||
hookList.add("attacked");
|
||||
hookList.add("damagedEntity");
|
||||
hookList.add("damaged");
|
||||
hookList.add("kills");
|
||||
hookList.add("killed");
|
||||
hookList.add("drop");
|
||||
hookList.add("respawn");
|
||||
hookList.add("breakBlock");
|
||||
hookList.add("chat");
|
||||
hookList.add("login");
|
||||
hookList.add("logout");
|
||||
hookList.add("keyPressed");
|
||||
hookList.add("mouseClicked");
|
||||
hookList.add("toss");
|
||||
hookList.add("pickUp");
|
||||
hookList.add("pickupXP");
|
||||
hookList.add("rangedCharge");
|
||||
hookList.add("rangedLaunched");
|
||||
hookList.add("timer");
|
||||
hookList.add("startItem");
|
||||
hookList.add("usingItem");
|
||||
hookList.add("stopItem");
|
||||
hookList.add("finishItem");
|
||||
hookList.add("containerOpen");
|
||||
hookList.add("useHoe");
|
||||
hookList.add("bonemeal");
|
||||
hookList.add("fillBucket");
|
||||
hookList.add("jump");
|
||||
hookList.add("fall");
|
||||
hookList.add("wakeUp");
|
||||
hookList.add("sleep");
|
||||
hookList.add("playSound");
|
||||
hookList.add("lightning");
|
||||
hookList.add("changedDim");
|
||||
hookList.add("questStart");
|
||||
hookList.add("questCompleted");
|
||||
hookList.add("questTurnIn");
|
||||
hookList.add("factionPoints");
|
||||
hookList.add("dialogOpen");
|
||||
hookList.add("dialogOption");
|
||||
hookList.add("dialogClose");
|
||||
hookList.add("customGuiClosed");
|
||||
hookList.add("customGuiButton");
|
||||
hookList.add("customGuiSlot");
|
||||
hookList.add("customGuiSlotClicked");
|
||||
hookList.add("customGuiScroll");
|
||||
hookList.add("customGuiTextfield");
|
||||
|
||||
this.handler = this.script;
|
||||
Client.sendData(EnumPacketServer.ScriptPlayerGet);
|
||||
}
|
||||
@@ -54,6 +106,6 @@ public class GuiScriptPlayers extends GuiScriptInterface {
|
||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||
Client.sendData(EnumPacketServer.ScriptPlayerSave, -1, scriptData);
|
||||
Client.sendData(EnumPacketServer.ScriptPlayerSave, -1, containers.size(), scriptData);
|
||||
}
|
||||
}
|
||||
@@ -44,14 +44,15 @@ public enum EnumPacketServer {
|
||||
ScriptForgeSave(CustomNpcsPermissions.TOOL_SCRIPTER, false),
|
||||
ScriptForgeGet(false),
|
||||
|
||||
ScriptNPCSave(CustomNpcsPermissions.TOOL_SCRIPTER, false),
|
||||
ScriptNPCGet(false),
|
||||
ScriptGlobalNPCSave(CustomNpcsPermissions.TOOL_SCRIPTER, false),
|
||||
ScriptGlobalNPCGet(false),
|
||||
|
||||
ScriptItemDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false),
|
||||
ScriptItemDataGet(false),
|
||||
|
||||
LinkedGetAll, LinkedRemove(CustomNpcsPermissions.GLOBAL_LINKED), LinkedAdd(CustomNpcsPermissions.GLOBAL_LINKED),
|
||||
ScriptDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, true), ScriptDataGet(true),
|
||||
EventScriptDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, true), EventScriptDataGet(true),
|
||||
PlayerDataRemove(CustomNpcsPermissions.GLOBAL_PLAYERDATA),
|
||||
BankSave(CustomNpcsPermissions.GLOBAL_BANK), BanksGet, BankGet,
|
||||
BankRemove(CustomNpcsPermissions.GLOBAL_BANK),
|
||||
|
||||
@@ -10,7 +10,7 @@ import net.minecraftforge.event.world.WorldEvent;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.controllers.data.ForgeDataScript;
|
||||
import noppes.npcs.controllers.data.NPCDataScript;
|
||||
import noppes.npcs.controllers.data.GlobalNPCDataScript;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.ScriptWorld;
|
||||
@@ -49,8 +49,8 @@ public class ScriptController {
|
||||
public ForgeDataScript forgeScripts = new ForgeDataScript();
|
||||
public long lastForgeUpdate = 0L;
|
||||
|
||||
public NPCDataScript npcScripts = new NPCDataScript((EntityNPCInterface) null);
|
||||
public long lastNpcUpdate = 0L;
|
||||
public GlobalNPCDataScript globalNpcScripts = new GlobalNPCDataScript((EntityNPCInterface) null);
|
||||
public long lastGlobalNpcUpdate = 0L;
|
||||
|
||||
public ScriptController(){
|
||||
loaded = false;
|
||||
@@ -137,15 +137,15 @@ public class ScriptController {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean loadNPCScripts() {
|
||||
this.npcScripts.clear();
|
||||
public boolean loadGlobalNPCScripts() {
|
||||
this.globalNpcScripts.clear();
|
||||
File file = this.npcScriptsFile();
|
||||
|
||||
try {
|
||||
if(!file.exists()) {
|
||||
return false;
|
||||
} else {
|
||||
this.npcScripts.readFromNBT(NBTJsonUtil.LoadFile(file));
|
||||
this.globalNpcScripts.readFromNBT(NBTJsonUtil.LoadFile(file));
|
||||
shouldSave = false;
|
||||
return true;
|
||||
}
|
||||
@@ -155,11 +155,11 @@ public class ScriptController {
|
||||
}
|
||||
}
|
||||
|
||||
public void saveNpcScripts() {
|
||||
public void saveGlobalNpcScripts() {
|
||||
File file = this.npcScriptsFile();
|
||||
try {
|
||||
NBTJsonUtil.SaveFile(file, this.npcScripts.writeToNBT(new NBTTagCompound()));
|
||||
this.npcScripts.lastInited = -1L;
|
||||
NBTJsonUtil.SaveFile(file, this.globalNpcScripts.writeToNBT(new NBTTagCompound()));
|
||||
this.globalNpcScripts.lastInited = -1L;
|
||||
} catch (IOException | JsonException var4) {
|
||||
var4.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.config.ConfigDebug;
|
||||
@@ -29,6 +30,8 @@ import javax.script.ScriptEngine;
|
||||
import java.util.*;
|
||||
|
||||
public class DataScript implements IScriptHandler {
|
||||
public List<ScriptContainer> eventScripts = new ArrayList();
|
||||
|
||||
public List<ScriptContainer> scripts = new ArrayList();
|
||||
private final static EntityType entities = new EntityType();
|
||||
private final static JobType jobs = new JobType();
|
||||
@@ -72,6 +75,10 @@ public class DataScript implements IScriptHandler {
|
||||
enabled = compound.getBoolean("ScriptEnabled");
|
||||
}
|
||||
|
||||
public void readEventsFromNBT(NBTTagCompound compound) {
|
||||
eventScripts = NBTTags.GetScript(compound,this);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setTag("ScriptsContainers", writeScript(scripts));
|
||||
compound.setString("ScriptLanguage", scriptLanguage);
|
||||
@@ -79,6 +86,14 @@ public class DataScript implements IScriptHandler {
|
||||
return compound;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeEventsToNBT(NBTTagCompound compound) {
|
||||
compound.setInteger("TotalScripts",this.eventScripts.size());
|
||||
for (int i = 0; i < this.eventScripts.size(); i++) {
|
||||
compound.setTag("Tab"+i,this.eventScripts.get(i).writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
return compound;
|
||||
}
|
||||
|
||||
private List<ScriptContainer> readScript(NBTTagList list){
|
||||
List<ScriptContainer> scripts = new ArrayList<>();
|
||||
for (int i = 0; i < 12; i++) {
|
||||
@@ -118,10 +133,15 @@ public class DataScript implements IScriptHandler {
|
||||
}
|
||||
if(!isEnabled())
|
||||
return false;
|
||||
|
||||
if(!hasInited && !npc.isRemote() && type != EnumScriptType.INIT){
|
||||
hasInited = true;
|
||||
EventHooks.onNPCInit(this.npc);
|
||||
}
|
||||
for (ScriptContainer script : eventScripts) {
|
||||
script.run(type, event);
|
||||
}
|
||||
|
||||
ScriptContainer script = scripts.get(type.ordinal());
|
||||
if(script == null || script.errored || !script.hasCode())
|
||||
return false;
|
||||
@@ -178,7 +198,7 @@ public class DataScript implements IScriptHandler {
|
||||
public Map<Long, String> getConsoleText() {
|
||||
Map<Long, String> map = new TreeMap();
|
||||
int tab = 0;
|
||||
Iterator var3 = this.getScripts().iterator();
|
||||
Iterator var3 = this.scripts.iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
ScriptContainer script = (ScriptContainer)var3.next();
|
||||
@@ -195,7 +215,7 @@ public class DataScript implements IScriptHandler {
|
||||
}
|
||||
|
||||
public void clearConsole() {
|
||||
Iterator var1 = this.getScripts().iterator();
|
||||
Iterator var1 = this.scripts.iterator();
|
||||
|
||||
while(var1.hasNext()) {
|
||||
ScriptContainer script = (ScriptContainer)var1.next();
|
||||
@@ -205,8 +225,8 @@ public class DataScript implements IScriptHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callScript(EnumScriptType var1, Event var2) {
|
||||
callScript(var1, var2, "$$IGNORED$$", null);
|
||||
public void callScript(EnumScriptType type, Event event) {
|
||||
callScript(type, event, "$$IGNORED$$", null);
|
||||
}
|
||||
|
||||
public boolean isClient() {
|
||||
@@ -234,7 +254,7 @@ public class DataScript implements IScriptHandler {
|
||||
}
|
||||
|
||||
public List<ScriptContainer> getScripts() {
|
||||
return this.scripts;
|
||||
return this.eventScripts;
|
||||
}
|
||||
|
||||
public String noticeString() {
|
||||
|
||||
+41
-41
@@ -17,7 +17,7 @@ import javax.annotation.CheckForNull;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
|
||||
public class NPCDataScript implements IScriptHandler {
|
||||
public class GlobalNPCDataScript implements IScriptHandler {
|
||||
public List<ScriptContainer> scripts = new ArrayList();
|
||||
public String scriptLanguage = "ECMAScript";
|
||||
private EntityNPCInterface npc;
|
||||
@@ -26,7 +26,7 @@ public class NPCDataScript implements IScriptHandler {
|
||||
private long lastNpcUpdate = -1L;
|
||||
public boolean enabled = false;
|
||||
|
||||
public NPCDataScript(EntityNPCInterface npc) {
|
||||
public GlobalNPCDataScript(EntityNPCInterface npc) {
|
||||
if(npc != null) {
|
||||
this.npc = npc;
|
||||
}
|
||||
@@ -62,9 +62,9 @@ public class NPCDataScript implements IScriptHandler {
|
||||
|
||||
public void callScript(EnumScriptType type, Event event) {
|
||||
if (this.isEnabled()) {
|
||||
if (ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastNpcUpdate > this.lastNpcUpdate) {
|
||||
if (ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastGlobalNpcUpdate > this.lastNpcUpdate) {
|
||||
this.lastInited = ScriptController.Instance.lastLoaded;
|
||||
this.lastNpcUpdate = ScriptController.Instance.lastNpcUpdate;
|
||||
this.lastNpcUpdate = ScriptController.Instance.lastGlobalNpcUpdate;
|
||||
|
||||
for (ScriptContainer script : this.scripts) {
|
||||
script.errored = false;
|
||||
@@ -109,7 +109,7 @@ public class NPCDataScript implements IScriptHandler {
|
||||
return "Global script";
|
||||
} else {
|
||||
BlockPos pos = new BlockPos(this.npc);
|
||||
return NPCDataScript.toStringHelper(this.npc).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString();
|
||||
return GlobalNPCDataScript.toStringHelper(this.npc).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString();
|
||||
}
|
||||
}
|
||||
public ICustomNpc getNpc() {
|
||||
@@ -140,61 +140,61 @@ public class NPCDataScript implements IScriptHandler {
|
||||
|
||||
public static final class ToStringHelper {
|
||||
private final String className;
|
||||
private final NPCDataScript.ToStringHelper.ValueHolder holderHead;
|
||||
private NPCDataScript.ToStringHelper.ValueHolder holderTail;
|
||||
private final GlobalNPCDataScript.ToStringHelper.ValueHolder holderHead;
|
||||
private GlobalNPCDataScript.ToStringHelper.ValueHolder holderTail;
|
||||
private boolean omitNullValues;
|
||||
private boolean omitEmptyValues;
|
||||
private ToStringHelper(String className) {
|
||||
this.holderHead = new NPCDataScript.ToStringHelper.ValueHolder();
|
||||
this.holderHead = new GlobalNPCDataScript.ToStringHelper.ValueHolder();
|
||||
this.holderTail = this.holderHead;
|
||||
this.omitNullValues = false;
|
||||
this.omitEmptyValues = false;
|
||||
this.className = (String) Preconditions.checkNotNull(className);
|
||||
}
|
||||
public NPCDataScript.ToStringHelper omitNullValues() {
|
||||
public GlobalNPCDataScript.ToStringHelper omitNullValues() {
|
||||
this.omitNullValues = true;
|
||||
return this;
|
||||
}
|
||||
public NPCDataScript.ToStringHelper add(String name, @CheckForNull Object value) {
|
||||
public GlobalNPCDataScript.ToStringHelper add(String name, @CheckForNull Object value) {
|
||||
return this.addHolder(name, value);
|
||||
}
|
||||
public NPCDataScript.ToStringHelper add(String name, boolean value) {
|
||||
public GlobalNPCDataScript.ToStringHelper add(String name, boolean value) {
|
||||
return this.addUnconditionalHolder(name, String.valueOf(value));
|
||||
}
|
||||
public NPCDataScript.ToStringHelper add(String name, char value) {
|
||||
public GlobalNPCDataScript.ToStringHelper add(String name, char value) {
|
||||
return this.addUnconditionalHolder(name, String.valueOf(value));
|
||||
}
|
||||
public NPCDataScript.ToStringHelper add(String name, double value) {
|
||||
public GlobalNPCDataScript.ToStringHelper add(String name, double value) {
|
||||
return this.addUnconditionalHolder(name, String.valueOf(value));
|
||||
}
|
||||
public NPCDataScript.ToStringHelper add(String name, float value) {
|
||||
public GlobalNPCDataScript.ToStringHelper add(String name, float value) {
|
||||
return this.addUnconditionalHolder(name, String.valueOf(value));
|
||||
}
|
||||
public NPCDataScript.ToStringHelper add(String name, int value) {
|
||||
public GlobalNPCDataScript.ToStringHelper add(String name, int value) {
|
||||
return this.addUnconditionalHolder(name, String.valueOf(value));
|
||||
}
|
||||
public NPCDataScript.ToStringHelper add(String name, long value) {
|
||||
public GlobalNPCDataScript.ToStringHelper add(String name, long value) {
|
||||
return this.addUnconditionalHolder(name, String.valueOf(value));
|
||||
}
|
||||
public NPCDataScript.ToStringHelper addValue(@CheckForNull Object value) {
|
||||
public GlobalNPCDataScript.ToStringHelper addValue(@CheckForNull Object value) {
|
||||
return this.addHolder(value);
|
||||
}
|
||||
public NPCDataScript.ToStringHelper addValue(boolean value) {
|
||||
public GlobalNPCDataScript.ToStringHelper addValue(boolean value) {
|
||||
return this.addUnconditionalHolder(String.valueOf(value));
|
||||
}
|
||||
public NPCDataScript.ToStringHelper addValue(char value) {
|
||||
public GlobalNPCDataScript.ToStringHelper addValue(char value) {
|
||||
return this.addUnconditionalHolder(String.valueOf(value));
|
||||
}
|
||||
public NPCDataScript.ToStringHelper addValue(double value) {
|
||||
public GlobalNPCDataScript.ToStringHelper addValue(double value) {
|
||||
return this.addUnconditionalHolder(String.valueOf(value));
|
||||
}
|
||||
public NPCDataScript.ToStringHelper addValue(float value) {
|
||||
public GlobalNPCDataScript.ToStringHelper addValue(float value) {
|
||||
return this.addUnconditionalHolder(String.valueOf(value));
|
||||
}
|
||||
public NPCDataScript.ToStringHelper addValue(int value) {
|
||||
public GlobalNPCDataScript.ToStringHelper addValue(int value) {
|
||||
return this.addUnconditionalHolder(String.valueOf(value));
|
||||
}
|
||||
public NPCDataScript.ToStringHelper addValue(long value) {
|
||||
public GlobalNPCDataScript.ToStringHelper addValue(long value) {
|
||||
return this.addUnconditionalHolder(String.valueOf(value));
|
||||
}
|
||||
private static boolean isEmpty(Object value) {
|
||||
@@ -225,9 +225,9 @@ public class NPCDataScript implements IScriptHandler {
|
||||
boolean omitEmptyValuesSnapshot = this.omitEmptyValues;
|
||||
String nextSeparator = "";
|
||||
StringBuilder builder = (new StringBuilder(32)).append(this.className).append('{');
|
||||
for(NPCDataScript.ToStringHelper.ValueHolder valueHolder = this.holderHead.next; valueHolder != null; valueHolder = valueHolder.next) {
|
||||
for(GlobalNPCDataScript.ToStringHelper.ValueHolder valueHolder = this.holderHead.next; valueHolder != null; valueHolder = valueHolder.next) {
|
||||
Object value = valueHolder.value;
|
||||
if (!(valueHolder instanceof NPCDataScript.ToStringHelper.UnconditionalValueHolder)) {
|
||||
if (!(valueHolder instanceof GlobalNPCDataScript.ToStringHelper.UnconditionalValueHolder)) {
|
||||
if (value == null) {
|
||||
if (omitNullValuesSnapshot) {
|
||||
continue;
|
||||
@@ -251,39 +251,39 @@ public class NPCDataScript implements IScriptHandler {
|
||||
}
|
||||
return builder.append('}').toString();
|
||||
}
|
||||
private NPCDataScript.ToStringHelper.ValueHolder addHolder() {
|
||||
NPCDataScript.ToStringHelper.ValueHolder valueHolder = new NPCDataScript.ToStringHelper.ValueHolder();
|
||||
private GlobalNPCDataScript.ToStringHelper.ValueHolder addHolder() {
|
||||
GlobalNPCDataScript.ToStringHelper.ValueHolder valueHolder = new GlobalNPCDataScript.ToStringHelper.ValueHolder();
|
||||
this.holderTail = this.holderTail.next = valueHolder;
|
||||
return valueHolder;
|
||||
}
|
||||
private NPCDataScript.ToStringHelper addHolder(@CheckForNull Object value) {
|
||||
NPCDataScript.ToStringHelper.ValueHolder valueHolder = this.addHolder();
|
||||
private GlobalNPCDataScript.ToStringHelper addHolder(@CheckForNull Object value) {
|
||||
GlobalNPCDataScript.ToStringHelper.ValueHolder valueHolder = this.addHolder();
|
||||
valueHolder.value = value;
|
||||
return this;
|
||||
}
|
||||
private NPCDataScript.ToStringHelper addHolder(String name, @CheckForNull Object value) {
|
||||
NPCDataScript.ToStringHelper.ValueHolder valueHolder = this.addHolder();
|
||||
private GlobalNPCDataScript.ToStringHelper addHolder(String name, @CheckForNull Object value) {
|
||||
GlobalNPCDataScript.ToStringHelper.ValueHolder valueHolder = this.addHolder();
|
||||
valueHolder.value = value;
|
||||
valueHolder.name = (String)Preconditions.checkNotNull(name);
|
||||
return this;
|
||||
}
|
||||
private NPCDataScript.ToStringHelper.UnconditionalValueHolder addUnconditionalHolder() {
|
||||
NPCDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = new NPCDataScript.ToStringHelper.UnconditionalValueHolder();
|
||||
private GlobalNPCDataScript.ToStringHelper.UnconditionalValueHolder addUnconditionalHolder() {
|
||||
GlobalNPCDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = new GlobalNPCDataScript.ToStringHelper.UnconditionalValueHolder();
|
||||
this.holderTail = this.holderTail.next = valueHolder;
|
||||
return valueHolder;
|
||||
}
|
||||
private NPCDataScript.ToStringHelper addUnconditionalHolder(Object value) {
|
||||
NPCDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder();
|
||||
private GlobalNPCDataScript.ToStringHelper addUnconditionalHolder(Object value) {
|
||||
GlobalNPCDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder();
|
||||
valueHolder.value = value;
|
||||
return this;
|
||||
}
|
||||
private NPCDataScript.ToStringHelper addUnconditionalHolder(String name, Object value) {
|
||||
NPCDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder();
|
||||
private GlobalNPCDataScript.ToStringHelper addUnconditionalHolder(String name, Object value) {
|
||||
GlobalNPCDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder();
|
||||
valueHolder.value = value;
|
||||
valueHolder.name = (String)Preconditions.checkNotNull(name);
|
||||
return this;
|
||||
}
|
||||
private static final class UnconditionalValueHolder extends NPCDataScript.ToStringHelper.ValueHolder {
|
||||
private static final class UnconditionalValueHolder extends GlobalNPCDataScript.ToStringHelper.ValueHolder {
|
||||
private UnconditionalValueHolder() {
|
||||
super();
|
||||
}
|
||||
@@ -294,12 +294,12 @@ public class NPCDataScript implements IScriptHandler {
|
||||
@CheckForNull
|
||||
Object value;
|
||||
@CheckForNull
|
||||
NPCDataScript.ToStringHelper.ValueHolder next;
|
||||
GlobalNPCDataScript.ToStringHelper.ValueHolder next;
|
||||
private ValueHolder() {
|
||||
}
|
||||
}
|
||||
}
|
||||
public static NPCDataScript.ToStringHelper toStringHelper(Object self) {
|
||||
return new NPCDataScript.ToStringHelper(self.getClass().getSimpleName());
|
||||
public static GlobalNPCDataScript.ToStringHelper toStringHelper(Object self) {
|
||||
return new GlobalNPCDataScript.ToStringHelper(self.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
@@ -943,6 +943,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
stats.readToNBT(compound);
|
||||
ai.readToNBT(compound);
|
||||
script.readFromNBT(compound);
|
||||
script.readEventsFromNBT(compound);
|
||||
timers.readFromNBT(compound);
|
||||
if (compound.hasKey("ItemGiverId")) {
|
||||
itemGiverId = compound.getInteger("ItemGiverId");
|
||||
@@ -980,6 +981,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
stats.writeToNBT(compound);
|
||||
ai.writeToNBT(compound);
|
||||
script.writeToNBT(compound);
|
||||
script.writeEventsToNBT(compound);
|
||||
timers.writeToNBT(compound);
|
||||
advanced.writeToNBT(compound);
|
||||
if (advanced.role != EnumRoleType.None && roleInterface != null)
|
||||
|
||||
Reference in new issue
Block a user