diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 8385467de..9ecbecdf2 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -23,6 +23,7 @@ import net.minecraftforge.common.MinecraftForge; import nikedemos.markovnames.generators.*; import noppes.npcs.config.ConfigLoader; import noppes.npcs.config.ConfigProp; +import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.*; import noppes.npcs.enchants.EnchantInterface; import noppes.npcs.entity.*; @@ -32,6 +33,7 @@ import noppes.npcs.scripted.NpcAPI; import java.io.File; import java.util.ArrayList; import java.util.Set; +import java.util.Timer; import java.util.UUID; @Mod(modid = "customnpcs", name = "CustomNpcs", version = "1.6.4") @@ -59,7 +61,12 @@ public class CustomNpcs { "Every additional compound tag adds 65535 more characters to your script length limit. Use incrementally, with caution.") public static int ExpandedScriptLimit = 2; - @ConfigProp(info = "Enables if Scripting Information should be printed to CustomNPCs Logs") + @ConfigProp(info = "Enables if Player Information (WAND-USE) should be printed to CustomNPCs Logs. IF on Server \n" + + "Logs will only be present SERVER-SIDE only in CustomNPCs-latest, -1, -2, and -3") + public static boolean PlayerLogging = false; + + @ConfigProp(info = "Enables if Scripting Information should be printed to CustomNPCs Logs. IF on Server \n" + + "Logs will only be present SERVER-SIDE only in CustomNPCs-latest, -1, -2, and -3") public static boolean ScriptLogging = false; @ConfigProp(info = "Amount of Messages marked as SPAM [5, 3000]. Lower Number means MORE accurate messages \n" + @@ -69,6 +76,10 @@ public class CustomNpcs { @ConfigProp(info = "IN Milliseconds 1s = 1000s. If a recent LOG of the same event is SENT within this threshold it will be ignored.") public static int ScriptIgnoreTime = 2000; + @ConfigProp(info = "Comma separated list of NPC Script Types that will omit these from the logs,\n" + + "INIT,TICK,INTERACT,DIALOG,DAMAGED,KILLED,ATTACK,TARGET,COLLIDE,KILLS,DIALOG_CLOSE,TIMER") + public static String ScriptLogIgnoreType = "TICK"; + @ConfigProp(info = "Navigation search range for NPCs. Not recommended to increase if you have a slow pc or on a server. Minimum of 16, maximum of 96.") public static int NpcNavRange = 32; @@ -119,7 +130,7 @@ public class CustomNpcs { "Get a player's UUID from a site like NameMC or the API IPlayer.getUniqueID() function!\n" + "If left empty and ScriptsOpsOnly is false, anyone can see and edit scripts with a scripter.") public static String ScriptDevIDs = ""; - + @ConfigProp(info = "Default interact line. Leave empty to not have one") public static String DefaultInteractLine = "Hello @p"; @@ -129,7 +140,7 @@ public class CustomNpcs { public static int EnchantStartId = 100; @ConfigProp(info = "Number of chunk loading npcs that can be active at the same time") - public static int ChunkLoaders = 20; + public static int ChuckLoaders = 20; @ConfigProp(info = "The maximum number of images any dialog can hold.") public static int DialogImageLimit = 10; @@ -144,43 +155,56 @@ public class CustomNpcs { @ConfigProp(info = "Enables leaves decay") public static boolean LeavesDecayEnabled = true; - + @ConfigProp(info = "Enables Vine Growth") public static boolean VineGrowthEnabled = true; @ConfigProp(info = "Enables Ice Melting") public static boolean IceMeltsEnabled = true; - + @ConfigProp(info = "Normal players can use soulstone on animals") - public static boolean SoulStoneAnimals = true; - + public static boolean SoulStoneAnimals = true; + @ConfigProp(info = "Normal players can use soulstone on villagers") - public static boolean SoulStoneVillagers = false; - + public static boolean SoulStoneVillagers = false; + @ConfigProp(info = "Normal players can use soulstone on all npcs") - public static boolean SoulStoneNPCs = false; - + public static boolean SoulStoneNPCs = false; + @ConfigProp(info = "Normal players can use soulstone on friendly npcs") - public static boolean SoulStoneFriendlyNPCs = false; + public static boolean SoulStoneFriendlyNPCs = false; - @ConfigProp(info="When set to Minecraft it will use minecrafts font, when Default it will use OpenSans. Can only use fonts installed on your PC") - public static String FontType = "Default"; + @ConfigProp(info="When set to Minecraft it will use minecrafts font, when Default it will use OpenSans. Can only use fonts installed on your PC") + public static String FontType = "Default"; - @ConfigProp(info="Font size for custom fonts (doesn't work with minecrafts font)") - public static int FontSize = 18; + @ConfigProp(info="Font size for custom fonts (doesn't work with minecrafts font)") + public static int FontSize = 18; @ConfigProp(info = "Enables Overlay Mixins for Conflicts relating to Optifine or other Skin Renderers. If crashes occur, please disable.") public static boolean EntityRendererMixin = true; public static FMLEventChannel Channel; public static FMLEventChannel ChannelPlayer; - + public static ConfigLoader Config; public static ArrayList ScriptDevs = new ArrayList<>(); public static final MarkovGenerator[] MARKOV_GENERATOR = new MarkovGenerator[10]; + public static boolean InitIgnore = false; + public static boolean TickIgnore = false; + public static boolean InteractIgnore = false; + public static boolean DialogIgnore = false; + public static boolean DamagedIgnore = false; + public static boolean KilledIgnore = false; + public static boolean AttackIgnore = false; + public static boolean TargetIgnore = false; + public static boolean CollideIgnore = false; + public static boolean KillsIgnore = false; + public static boolean DialogCloseIgnore = false; + public static boolean TimerIgnore = false; + public CustomNpcs() { instance = this; } @@ -205,7 +229,7 @@ public class CustomNpcs { try { ScriptDevs.clear(); - String[] uuidStrings = ScriptDevIDs.split(";"); + String[] uuidStrings = ScriptDevIDs.split(","); for (String s : uuidStrings) { ScriptDevs.add(UUID.fromString(s)); } @@ -245,9 +269,58 @@ public class CustomNpcs { if (ScriptIgnoreTime < 0) ScriptIgnoreTime = 0; + try { + String[] ignoreTypes = ScriptLogIgnoreType.split(","); + for (String s : ignoreTypes) { + EnumScriptType type = EnumScriptType.valueOfIgnoreCase(s); + if(type != null){ + switch (type){ + case INIT: + InitIgnore = true; + break; + case TICK: + TickIgnore = true; + break; + case INTERACT: + InteractIgnore = true; + break; + case DIALOG: + DialogIgnore = true; + break; + case DAMAGED: + DamagedIgnore = true; + break; + case KILLED: + KilledIgnore = true; + break; + case ATTACK: + AttackIgnore = true; + break; + case TARGET: + TargetIgnore = true; + break; + case COLLIDE: + CollideIgnore = true; + break; + case KILLS: + KillsIgnore = true; + break; + case DIALOG_CLOSE: + DialogCloseIgnore = true; + break; + case TIMER: + TimerIgnore = true; + break; + default: + break; + } + } + } + } catch (Exception ignored) {} + EnchantInterface.load(); CustomItems.load(); - + proxy.load(); NetworkRegistry.INSTANCE.registerGuiHandler(this, proxy); @@ -266,8 +339,8 @@ public class CustomNpcs { MinecraftForge.EVENT_BUS.register(scriptItemEventHandler); FMLCommonHandler.instance().bus().register(scriptItemEventHandler); - FMLCommonHandler.instance().bus().register(new ServerTickHandler()); - + FMLCommonHandler.instance().bus().register(new ServerTickHandler()); + registerNpc(EntityNPCHumanMale.class, "npchumanmale"); registerNpc(EntityNPCVillager.class, "npcvillager"); registerNpc(EntityNpcPony.class, "npcpony"); @@ -302,7 +375,7 @@ public class CustomNpcs { ForgeChunkManager.setForcedChunkLoadingCallback(this, new ChunkController()); new CustomNpcsPermissions(); - + PixelmonHelper.load(); } @@ -324,7 +397,7 @@ public class CustomNpcs { @EventHandler public void setAboutToStart(FMLServerAboutToStartEvent event) { - ChunkController.instance.clear(); + ChunkController.instance.clear(); new QuestController(); new PlayerDataController(); new FactionController(); @@ -341,30 +414,30 @@ public class CustomNpcs { Set names = Block.blockRegistry.getKeys(); for(String name : names){ - Block block = (Block) Block.blockRegistry.getObject(name); - if(block instanceof BlockLeavesBase){ - block.setTickRandomly(LeavesDecayEnabled); - } - if(block instanceof BlockVine){ - block.setTickRandomly(VineGrowthEnabled); - } - if(block instanceof BlockIce){ - block.setTickRandomly(IceMeltsEnabled); - } + Block block = (Block) Block.blockRegistry.getObject(name); + if(block instanceof BlockLeavesBase){ + block.setTickRandomly(LeavesDecayEnabled); + } + if(block instanceof BlockVine){ + block.setTickRandomly(VineGrowthEnabled); + } + if(block instanceof BlockIce){ + block.setTickRandomly(IceMeltsEnabled); + } } } - + //Loading items in the about to start event was corrupting items with a damage value @EventHandler public void started(FMLServerStartedEvent event) { - RecipeController.instance.load(); + RecipeController.instance.load(); new DialogController(); new BankController(); QuestController.instance.load(); ScriptController.HasStart = true; ServerCloneController.Instance = new ServerCloneController(); } - + @EventHandler public void stopped(FMLServerStoppedEvent event){ ServerCloneController.Instance = null; @@ -438,4 +511,4 @@ public class CustomNpcs { return true; } else return ScriptDevIDs.isEmpty(); } -} +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/LogWriter.java b/src/main/java/noppes/npcs/LogWriter.java index 6a0911139..e1f459569 100644 --- a/src/main/java/noppes/npcs/LogWriter.java +++ b/src/main/java/noppes/npcs/LogWriter.java @@ -22,6 +22,7 @@ import java.util.logging.StreamHandler; public class LogWriter { private final static String name = "CustomNPCs"; + private final static String nameLog = "CustomNPCLog"; private final static Logger logger = Logger.getLogger(name); private final static WeakHashMap InitCacheMap = new WeakHashMap(); @@ -49,10 +50,10 @@ public class LogWriter { File file1 = new File(dir, name + "-1.log"); File file2 = new File(dir, name + "-2.log"); File file3 = new File(dir, name + "-3.log"); - + if(lock.exists()) lock.delete(); - + if(file3.exists()) file3.delete(); if(file2.exists()) @@ -61,12 +62,15 @@ public class LogWriter { file1.renameTo(file2); if(file.exists()) file.renameTo(file1); - + handler = new StreamHandler(new FileOutputStream(file), new Formatter() { @Override public String format(LogRecord record) { - StackTraceElement element = Thread.currentThread().getStackTrace()[8]; - String line = "[" + element.getClassName() + ":" + element.getLineNumber() + "] "; + String line = ""; + if (record.getLevel() != NPCLogLevel.CNPCLog){ + StackTraceElement element = Thread.currentThread().getStackTrace()[8]; + line = "[" + element.getClassName() + ":" + element.getLineNumber() + "] "; + } String time = "[" + dateformat.format(new Date(record.getMillis())) + "][" + record.getLevel() + "]" + line; if(record.getThrown() != null){ StringWriter sw = new StringWriter(); @@ -82,9 +86,8 @@ public class LogWriter { logger.setUseParentHandlers(false); Handler consoleHandler = new ConsoleHandler(); consoleHandler.setFormatter(handler.getFormatter()); - consoleHandler.setLevel(Level.FINEST); + consoleHandler.setLevel(Level.ALL); logger.addHandler(consoleHandler); - logger.setLevel(Level.ALL); info(new Date().toString()); } catch (SecurityException e) { @@ -99,39 +102,63 @@ public class LogWriter { public static void postScriptLog(UUID npcUUID, EnumScriptType type, String message) { switch (type){ case INIT: - scriptLogCalculator(InitCacheMap, npcUUID, message); + if(!CustomNpcs.InitIgnore){ + scriptLogCalculator(InitCacheMap, npcUUID, message); + } break; case TICK: - scriptLogCalculator(TickCacheMap, npcUUID, message); + if(!CustomNpcs.TickIgnore){ + scriptLogCalculator(TickCacheMap, npcUUID, message); + } break; case INTERACT: - scriptLogCalculator(InteractCacheMap, npcUUID, message); + if(!CustomNpcs.InteractIgnore){ + scriptLogCalculator(InteractCacheMap, npcUUID, message); + } break; case DIALOG: - scriptLogCalculator(DialogCacheMap, npcUUID, message); + if(!CustomNpcs.DialogIgnore){ + scriptLogCalculator(DialogCacheMap, npcUUID, message); + } break; case DAMAGED: - scriptLogCalculator(DamagedCacheMap, npcUUID, message); + if(!CustomNpcs.DamagedIgnore){ + scriptLogCalculator(DamagedCacheMap, npcUUID, message); + } break; case KILLED: - scriptLogCalculator(KilledCacheMap, npcUUID, message); + if(!CustomNpcs.KilledIgnore){ + scriptLogCalculator(KilledCacheMap, npcUUID, message); + } break; case ATTACK: - scriptLogCalculator(AttackCacheMap, npcUUID, message); + if(!CustomNpcs.AttackIgnore){ + scriptLogCalculator(AttackCacheMap, npcUUID, message); + } break; case TARGET: - scriptLogCalculator(TargetCacheMap, npcUUID, message); + if(!CustomNpcs.TargetIgnore){ + scriptLogCalculator(TargetCacheMap, npcUUID, message); + } break; case COLLIDE: - scriptLogCalculator(CollideCacheMap, npcUUID, message); + if(!CustomNpcs.CollideIgnore){ + scriptLogCalculator(CollideCacheMap, npcUUID, message); + } break; case KILLS: - scriptLogCalculator(KillsCacheMap, npcUUID, message); + if(!CustomNpcs.KillsIgnore){ + scriptLogCalculator(KillsCacheMap, npcUUID, message); + } case DIALOG_CLOSE: - scriptLogCalculator(DialogCloseCacheMap, npcUUID, message); + if(!CustomNpcs.DialogCloseIgnore){ + scriptLogCalculator(DialogCloseCacheMap, npcUUID, message); + } break; case TIMER: - scriptLogCalculator(TimerCacheMap, npcUUID, message); + if(!CustomNpcs.TimerIgnore){ + scriptLogCalculator(TimerCacheMap, npcUUID, message); + } break; default: break; @@ -145,10 +172,7 @@ public class LogWriter { long millisecSinceLast = TimeUnit.MILLISECONDS.toMillis(stamp.recentDate.getTime() - stamp.makeDate.getTime()); double frequency = (float)CustomNpcs.ScriptFrequency / 60; - - - - // Reset Log if 3 Minutes Pass + // Reset Log if 2 Minutes Pass if (secondsSinceFirst > 120) { LogWriter.script(message); stamp.counter = 1; @@ -178,7 +202,7 @@ public class LogWriter { } public static void script(Object msg) { - logger.log(Level.ALL, msg.toString()); + logger.log(NPCLogLevel.CNPCLog, msg.toString()); handler.flush(); } @@ -209,4 +233,4 @@ class NPCStamp public Date makeDate = new Date(); public Date recentDate = new Date(); public int counter = 1; -}; +}; \ No newline at end of file diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 0837aa329..ace3cc5ec 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -1,5 +1,7 @@ package noppes.npcs; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; import foxz.utils.Market; import io.netty.buffer.ByteBuf; @@ -100,11 +102,11 @@ public class PacketHandlerServer{ } if(type.needsNpc && npc == null){ - + } 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)) warn(player, "tried to use custom npcs without a tool in hand, probably a hacker"); else { @@ -196,6 +198,9 @@ public class PacketHandlerServer{ npc.script.readFromNBT(Server.readNBT(buffer)); npc.updateAI = true; npc.script.hasInited = false; + if(CustomNpcs.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())); + } } else if(type == EnumPacketServer.ScriptDataGet){ NBTTagCompound compound = npc.script.writeToNBT(new NBTTagCompound()); @@ -291,7 +296,7 @@ public class PacketHandlerServer{ NoppesUtilPlayer.teleportPlayer(player, coords.posX, coords.posY, coords.posZ, dimension); } } - + private void movingPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws IOException { if(type == EnumPacketServer.MovingPathGet){ Server.sendData(player, EnumPacketClient.GUI_DATA, npc.ai.writeToNBT(new NBTTagCompound())); @@ -311,7 +316,7 @@ public class PacketHandlerServer{ tile.writeToNBT(compound); Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } - else if(type == EnumPacketServer.DialogCategoriesGet){ + else if(type == EnumPacketServer.DialogCategoriesGet){ NoppesUtilServer.sendScrollData(player, DialogController.instance.getScroll()); } else if(type == EnumPacketServer.DialogsGetFromDialog){ @@ -368,6 +373,9 @@ public class PacketHandlerServer{ private void wandPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws IOException{ if(type == EnumPacketServer.Delete){ + if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ + LogWriter.script(String.format("[%s] (Player) %s DELETE NPC %s (%s, %s, %s) [%s]", "WAND", player.getCommandSenderName(), npc.display.getName(), (int)npc.posX, (int)npc.posY, (int)npc.posZ, npc.worldObj.getWorldInfo().getWorldName())); + } npc.delete(); NoppesUtilServer.deleteNpc(npc,player); } @@ -403,6 +411,9 @@ public class PacketHandlerServer{ npc.reset(); if(npc.linkedData != null) LinkedNpcController.Instance.saveNpcData(npc); + if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ + LogWriter.script(String.format("[%s] (Player) %s CLOSE NPC %s (%s, %s, %s) [%s]", "WAND", player.getCommandSenderName(), npc.display.getName(), (int)npc.posX, (int)npc.posY, (int)npc.posZ, npc.worldObj.getWorldInfo().getWorldName())); + } NoppesUtilServer.setEditingNpc(player, null); } else if(type == EnumPacketServer.BanksGet){ @@ -420,7 +431,7 @@ public class PacketHandlerServer{ NoppesUtilServer.sendBank(player,bank); } else if(type == EnumPacketServer.BankRemove){ - BankController.getInstance().removeBank(buffer.readInt()); + BankController.getInstance().removeBank(buffer.readInt()); NoppesUtilServer.sendBankDataAll(player); NoppesUtilServer.sendBank(player,new Bank()); } @@ -429,12 +440,18 @@ public class PacketHandlerServer{ if(entity == null || !(entity instanceof EntityNPCInterface)) return; NoppesUtilServer.sendOpenGui(player, EnumGuiType.MainMenuDisplay, (EntityNPCInterface) entity); + if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ + LogWriter.script(String.format("[%s] (Player) %s OPEN NPC %s (%s, %s, %s) [%s]", "WAND", player.getCommandSenderName(), ((EntityNPCInterface)entity).display.getName(), entity.posX, entity.posY, entity.posZ, entity.worldObj.getWorldInfo().getWorldName())); + } } else if(type == EnumPacketServer.RemoteDelete){ Entity entity = player.worldObj.getEntityByID(buffer.readInt()); if(entity == null || !(entity instanceof EntityNPCInterface)) return; npc = (EntityNPCInterface) entity; + if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ + LogWriter.script(String.format("[%s] (Player) %s DELETE NPC %s (%s, %s, %s) [%s]", "WAND", player.getCommandSenderName(), npc.display.getName(), (int)npc.posX, (int)npc.posY, (int)npc.posZ, npc.worldObj.getWorldInfo().getWorldName())); + } npc.delete(); NoppesUtilServer.deleteNpc(npc,player); NoppesUtilServer.sendNearbyNpcs(player); @@ -717,7 +734,7 @@ public class PacketHandlerServer{ npc.updateClient = true; } else if(type == EnumPacketServer.JobSave){ - NBTTagCompound original = npc.jobInterface.writeToNBT(new NBTTagCompound()); + NBTTagCompound original = npc.jobInterface.writeToNBT(new NBTTagCompound()); NBTTagCompound compound = Server.readNBT(buffer); Set names = compound.func_150296_c(); for(String name : names) @@ -731,10 +748,10 @@ public class PacketHandlerServer{ NBTTagCompound compound = new NBTTagCompound(); compound.setBoolean("JobData", true); npc.jobInterface.writeToNBT(compound); - + if(npc.advanced.job == EnumJobType.Spawner) ((JobSpawner)npc.jobInterface).cleanCompound(compound); - + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); if(npc.advanced.job == EnumJobType.Spawner) @@ -818,10 +835,10 @@ public class PacketHandlerServer{ } else blockPackets(type, buffer, player); - + } private void mountPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException{ - if(type == EnumPacketServer.SpawnRider){ + if(type == EnumPacketServer.SpawnRider){ Entity entity = EntityList.createEntityFromNBT(Server.readNBT(buffer), player.worldObj); player.worldObj.spawnEntityInWorld(entity); entity.mountEntity(ServerEventsHandler.mounted); @@ -830,15 +847,15 @@ public class PacketHandlerServer{ player.mountEntity(ServerEventsHandler.mounted); } else if(type == EnumPacketServer.CloneList){ - NBTTagList list = new NBTTagList(); - - for(String name : ServerCloneController.Instance.getClones(buffer.readInt())) - list.appendTag(new NBTTagString(name)); - - NBTTagCompound compound = new NBTTagCompound(); - compound.setTag("List", list); - - Server.sendData(player, EnumPacketClient.GUI_DATA, compound); + NBTTagList list = new NBTTagList(); + + for(String name : ServerCloneController.Instance.getClones(buffer.readInt())) + list.appendTag(new NBTTagString(name)); + + NBTTagCompound compound = new NBTTagCompound(); + compound.setTag("List", list); + + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } else warn(player,"tried todo something with the wrong tool, probably a hacker"); @@ -862,6 +879,9 @@ public class PacketHandlerServer{ player.addChatMessage(new ChatComponentText("Failed to create an entity out of your clone")); return; } + if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ + LogWriter.script(String.format("[%s] (Player) %s SPAWNED ENTITY %s", "CLONER", player.getCommandSenderName(), entity)); + } } else if(type == EnumPacketServer.MobSpawner){ boolean server = buffer.readBoolean(); @@ -892,26 +912,26 @@ public class PacketHandlerServer{ int tab = buffer.readInt(); ServerCloneController.Instance.removeClone(Server.readString(buffer), tab); - NBTTagList list = new NBTTagList(); - - for(String name : ServerCloneController.Instance.getClones(tab)) - list.appendTag(new NBTTagString(name)); - - NBTTagCompound compound = new NBTTagCompound(); - compound.setTag("List", list); - - Server.sendData(player, EnumPacketClient.GUI_DATA, compound); + NBTTagList list = new NBTTagList(); + + for(String name : ServerCloneController.Instance.getClones(tab)) + list.appendTag(new NBTTagString(name)); + + NBTTagCompound compound = new NBTTagCompound(); + compound.setTag("List", list); + + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } else if(type == EnumPacketServer.CloneList){ - NBTTagList list = new NBTTagList(); - - for(String name : ServerCloneController.Instance.getClones(buffer.readInt())) - list.appendTag(new NBTTagString(name)); - - NBTTagCompound compound = new NBTTagCompound(); - compound.setTag("List", list); - - Server.sendData(player, EnumPacketClient.GUI_DATA, compound); + NBTTagList list = new NBTTagList(); + + for(String name : ServerCloneController.Instance.getClones(buffer.readInt())) + list.appendTag(new NBTTagString(name)); + + NBTTagCompound compound = new NBTTagCompound(); + compound.setTag("List", list); + + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } else warn(player,"tried todo something with the wrong tool, probably a hacker"); @@ -920,4 +940,4 @@ public class PacketHandlerServer{ private void warn(EntityPlayer player, String warning){ MinecraftServer.getServer().logWarning(player.getCommandSenderName() + ": " + warning); } -} +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index 1f7a81cde..9094a2a1c 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -4,7 +4,9 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; @@ -50,25 +52,6 @@ public class ServerEventsHandler { public static EntityVillager Merchant; public static Entity mounted; -// private HashMap exps = new HashMap(); -// -// @SubscribeEvent -// public void onUpdate(LivingUpdateEvent event){ -// if(!(event.entityLiving instanceof EntityPlayer)) -// return; -// EntityPlayer player = (EntityPlayer) event.entityLiving; -// if(exps.containsKey(player.getCommandSenderName())){ -// int prevExp = exps.get(player.getCommandSenderName()); -// if(prevExp > player.experienceTotal){ -// player.addChatMessage(new ChatComponentText("Omg exp was gotten:" + (player.experienceTotal - prevExp))); -// } -// else if(prevExp < player.experienceTotal){ -// player.addChatMessage(new ChatComponentText("Omg exp was lost:" + (prevExp - player.experienceTotal))); -// } -// } -// exps.put(player.getCommandSenderName(), player.experienceTotal); -// } - @SubscribeEvent public void invoke(EntityInteractEvent event) { ItemStack item = event.entityPlayer.getCurrentEquippedItem(); @@ -83,6 +66,9 @@ public class ServerEventsHandler { if(!isRemote && item.getItem() == CustomItems.soulstoneEmpty && event.target instanceof EntityLivingBase) { ((ItemSoulstoneEmpty)item.getItem()).store((EntityLivingBase)event.target, item, event.entityPlayer); + if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ + LogWriter.script(String.format("[%s] (Player) %s PICKED ENTITY %s", "SOULSTONE", event.entityPlayer.getCommandSenderName(), event.target)); + } } if(item.getItem() == CustomItems.wand && npcInteracted && !isRemote){ @@ -91,6 +77,9 @@ public class ServerEventsHandler { } event.setCanceled(true); NoppesUtilServer.sendOpenGui(event.entityPlayer, EnumGuiType.MainMenuDisplay, (EntityNPCInterface) event.target); + if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ + LogWriter.script(String.format("[%s] (Player) %s OPEN NPC %s (%s, %s, %s) [%s]", "WAND", event.entityPlayer.getCommandSenderName(), ((EntityNPCInterface)(event.target)).display.getName(), (int)(event.target).posX, (int)(event.target).posY, (int)(event.target).posZ, (event.target).worldObj.getWorldInfo().getWorldName())); + } } else if(item.getItem() == CustomItems.cloner && !isRemote && !(event.target instanceof EntityPlayer)){ NBTTagCompound compound = new NBTTagCompound(); @@ -109,6 +98,9 @@ public class ServerEventsHandler { NoppesUtilServer.setEditingNpc(event.entityPlayer, (EntityNPCInterface)event.target); event.setCanceled(true); Server.sendData((EntityPlayerMP)event.entityPlayer, EnumPacketClient.GUI, EnumGuiType.Script.ordinal()); + if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ + LogWriter.script(String.format("[%s] (Player) %s OPEN NPC %s (%s, %s, %s) [%s]", "SCRIPTER", event.entityPlayer.getCommandSenderName(), ((EntityNPCInterface)(event.target)).display.getName(), (int)(event.target).posX, (int)(event.target).posY, (int)(event.target).posZ, (event.target).worldObj.getWorldInfo().getWorldName())); + } } else if(item.getItem() == CustomItems.mount){ if(!CustomNpcsPermissions.Instance.hasPermission(event.entityPlayer, CustomNpcsPermissions.TOOL_MOUNTER)) @@ -364,4 +356,4 @@ public class ServerEventsHandler { public void populateChunk(PopulateChunkEvent.Post event){ NPCSpawning.performWorldGenSpawning(event.world, event.chunkX, event.chunkZ, event.rand); } -} +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java index 24fc568be..46abaf364 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java @@ -5,6 +5,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.Entity; @@ -13,6 +15,8 @@ import net.minecraft.entity.EntityLiving; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; +import noppes.npcs.CustomNpcs; +import noppes.npcs.LogWriter; import noppes.npcs.client.Client; import noppes.npcs.client.controllers.ClientCloneController; import noppes.npcs.client.gui.util.GuiCustomScroll; @@ -23,62 +27,63 @@ import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IGuiData; import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.entity.EntityNPCInterface; public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData{ - - private GuiCustomScroll scroll; - private int posX,posY,posZ; - - private List list; - - private static int showingClones = 0; + + private GuiCustomScroll scroll; + private int posX,posY,posZ; + + private List list; + + private static int showingClones = 0; private static String search = ""; - + private int activeTab = 1; - + public GuiNpcMobSpawner(int i, int j, int k) { super(); - xSize = 354; - posX = i; - posY = j; - posZ = k; - - this.closeOnEsc = true; - - setBackground("menubg.png"); - } - public void initGui() - { - super.initGui(); - guiTop += 10; - guiLeft += 30; - - if(scroll == null){ - scroll = new GuiCustomScroll(this,0); - scroll.setSize(293, 188); - } - else - scroll.clear(); - scroll.guiLeft = guiLeft + 4; - scroll.guiTop = guiTop + 26; - addScroll(scroll); - - addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 4, guiTop + 4, 293, 20, search)); + xSize = 354; + posX = i; + posY = j; + posZ = k; - GuiMenuTopButton button; - addTopButton(button = new GuiMenuTopButton(3,guiLeft + 4, guiTop - 17, "spawner.clones")); - button.active = showingClones == 0; - addTopButton(button = new GuiMenuTopButton(5, button, "gui.server")); - button.active = showingClones == 2; + this.closeOnEsc = true; + + setBackground("menubg.png"); + } + public void initGui() + { + super.initGui(); + guiTop += 10; + guiLeft += 30; + + if(scroll == null){ + scroll = new GuiCustomScroll(this,0); + scroll.setSize(293, 188); + } + else + scroll.clear(); + scroll.guiLeft = guiLeft + 4; + scroll.guiTop = guiTop + 26; + addScroll(scroll); + + addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 4, guiTop + 4, 293, 20, search)); + + GuiMenuTopButton button; + addTopButton(button = new GuiMenuTopButton(3,guiLeft + 4, guiTop - 17, "spawner.clones")); + button.active = showingClones == 0; + addTopButton(button = new GuiMenuTopButton(5, button, "gui.server")); + button.active = showingClones == 2; addTopButton(button = new GuiMenuTopButton(4, button, "spawner.entities")); button.active = showingClones == 1; - - addButton(new GuiNpcButton(1, guiLeft + 298, guiTop + 6, 52, 20, "item.monsterPlacer.name")); - - addButton(new GuiNpcButton(2, guiLeft + 298, guiTop + 100, 52, 20, "spawner.mobspawner")); - - if(showingClones == 0 || showingClones == 2){ + + addButton(new GuiNpcButton(1, guiLeft + 298, guiTop + 6, 52, 20, "item.monsterPlacer.name")); + + addButton(new GuiNpcButton(2, guiLeft + 298, guiTop + 100, 52, 20, "spawner.mobspawner")); + + if(showingClones == 0 || showingClones == 2){ addSideButton(new GuiMenuSideButton(21,guiLeft - 70, this.guiTop + 2, 70,22, "1")); addSideButton(new GuiMenuSideButton(22,guiLeft - 70, this.guiTop + 23, 70,22, "2")); @@ -101,149 +106,148 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData{ // addButton(new GuiNpcButton(6, guiLeft + 298, guiTop + 190, 82, 20, "gui.remove")); addButton(new GuiNpcButton(6, guiLeft + 298, guiTop + 190, 52, 20, "gui.remove")); - getSideButton(20 + activeTab).active = true; - showClones(); - } - else{ - showEntities(); - } - } + getSideButton(20 + activeTab).active = true; + showClones(); + } + else{ + showEntities(); + } + } private void showEntities() { - Map data = EntityList.stringToClassMapping; - ArrayList list = new ArrayList(); - for(Object name : data.keySet()){ - Class c = (Class) data.get(name); - try { - if(EntityLiving.class.isAssignableFrom(c) && c.getConstructor(new Class[] {World.class}) != null && !Modifier.isAbstract(c.getModifiers())) - list.add(name.toString()); + Map data = EntityList.stringToClassMapping; + ArrayList list = new ArrayList(); + for(Object name : data.keySet()){ + Class c = (Class) data.get(name); + try { + if(EntityLiving.class.isAssignableFrom(c) && c.getConstructor(new Class[] {World.class}) != null && !Modifier.isAbstract(c.getModifiers())) + list.add(name.toString()); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { } - } - this.list = list; - scroll.setList(getSearchList()); + } + this.list = list; + scroll.setList(getSearchList()); } private void showClones() { if(showingClones == 2){ Client.sendData(EnumPacketServer.CloneList, activeTab); return; } - ArrayList list = new ArrayList(); - this.list = ClientCloneController.Instance.getClones(activeTab); - scroll.setList(getSearchList()); + ArrayList list = new ArrayList(); + this.list = ClientCloneController.Instance.getClones(activeTab); + scroll.setList(getSearchList()); + } + public void keyTyped(char c, int i) + { + super.keyTyped(c, i); + + if(search.equals(getTextField(1).getText())) + return; + search = getTextField(1).getText().toLowerCase(); + scroll.setList(getSearchList()); + } + private List getSearchList(){ + if(search.isEmpty()) + return new ArrayList(list); + List list = new ArrayList(); + for(String name : this.list){ + if(name.toLowerCase().contains(search)) + list.add(name); + } + return list; } - public void keyTyped(char c, int i) - { - super.keyTyped(c, i); - - if(search.equals(getTextField(1).getText())) - return; - search = getTextField(1).getText().toLowerCase(); - scroll.setList(getSearchList()); - } - private List getSearchList(){ - if(search.isEmpty()) - return new ArrayList(list); - List list = new ArrayList(); - for(String name : this.list){ - if(name.toLowerCase().contains(search)) - list.add(name); - } - return list; - } private NBTTagCompound getCompound(){ - String sel = scroll.getSelected(); - if(sel == null) - return null; - - if(showingClones == 0){ - return ClientCloneController.Instance.getCloneData(player, sel, activeTab); - } - else{ - Entity entity = EntityList.createEntityByName(sel, Minecraft.getMinecraft().theWorld); - if(entity == null) - return null; - NBTTagCompound compound = new NBTTagCompound(); - entity.writeToNBTOptional(compound); - return compound; - } + String sel = scroll.getSelected(); + if(sel == null) + return null; + + if(showingClones == 0){ + return ClientCloneController.Instance.getCloneData(player, sel, activeTab); + } + else{ + Entity entity = EntityList.createEntityByName(sel, Minecraft.getMinecraft().theWorld); + if(entity == null) + return null; + NBTTagCompound compound = new NBTTagCompound(); + entity.writeToNBTOptional(compound); + return compound; + } } - + @Override protected void actionPerformed(GuiButton guibutton){ int id = guibutton.id; - if(id == 0){ - close(); - } - if(id == 1){ - if(showingClones == 2){ - String sel = scroll.getSelected(); - if(sel == null) - return; - Client.sendData(EnumPacketServer.SpawnMob, true, posX, posY, posZ, sel, activeTab); - close(); - } - else{ - NBTTagCompound compound = getCompound(); - if(compound == null) - return; - Client.sendData(EnumPacketServer.SpawnMob, false, posX, posY, posZ, compound); - close(); - - } - } - if(id == 2){ - if(showingClones == 2){ - String sel = scroll.getSelected(); - if(sel == null) - return; - Client.sendData(EnumPacketServer.MobSpawner, true, posX, posY, posZ, sel, activeTab); - close(); - } - else{ - NBTTagCompound compound = getCompound(); - if(compound == null) - return; - Client.sendData(EnumPacketServer.MobSpawner, false, posX, posY, posZ, compound); - close(); - - } - } - if(id == 3){ - showingClones = 0; - initGui(); - } - if(id == 4){ - showingClones = 1; - initGui(); - } - if(id == 5){ - showingClones = 2; - initGui(); - } - if(id == 6){ - if(scroll.getSelected() != null){ - if(showingClones == 2){ - Client.sendData(EnumPacketServer.CloneRemove, activeTab, scroll.getSelected()); - return; - } - ClientCloneController.Instance.removeClone(scroll.getSelected(), activeTab); - scroll.selected = -1; - initGui(); - } - } - if(id > 20){ - activeTab = id - 20; - initGui(); - } - } - + if(id == 0){ + close(); + } + if(id == 1){ + if(showingClones == 2){ + String sel = scroll.getSelected(); + if(sel == null) + return; + Client.sendData(EnumPacketServer.SpawnMob, true, posX, posY, posZ, sel, activeTab); + close(); + } + else{ + NBTTagCompound compound = getCompound(); + if(compound == null) + return; + Client.sendData(EnumPacketServer.SpawnMob, false, posX, posY, posZ, compound); + close(); + } + } + if(id == 2){ + if(showingClones == 2){ + String sel = scroll.getSelected(); + if(sel == null) + return; + Client.sendData(EnumPacketServer.MobSpawner, true, posX, posY, posZ, sel, activeTab); + close(); + } + else{ + NBTTagCompound compound = getCompound(); + if(compound == null) + return; + Client.sendData(EnumPacketServer.MobSpawner, false, posX, posY, posZ, compound); + close(); + + } + } + if(id == 3){ + showingClones = 0; + initGui(); + } + if(id == 4){ + showingClones = 1; + initGui(); + } + if(id == 5){ + showingClones = 2; + initGui(); + } + if(id == 6){ + if(scroll.getSelected() != null){ + if(showingClones == 2){ + Client.sendData(EnumPacketServer.CloneRemove, activeTab, scroll.getSelected()); + return; + } + ClientCloneController.Instance.removeClone(scroll.getSelected(), activeTab); + scroll.selected = -1; + initGui(); + } + } + if(id > 20){ + activeTab = id - 20; + initGui(); + } + } + @Override public void save() { // TODO Auto-generated method stub - + } @Override public void setGuiData(NBTTagCompound compound) { @@ -253,7 +257,7 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData{ list.add(nbtlist.getStringTagAt(i)); } this.list = list; - scroll.setList(getSearchList()); + scroll.setList(getSearchList()); } -} +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index d72f555a5..f38458e15 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -85,6 +85,11 @@ public enum EnumScriptType { public String function; + public static EnumScriptType valueOfIgnoreCase(String channelName) { + channelName = channelName.toUpperCase(); + return valueOf(channelName); + } + private EnumScriptType(String function) { this.function = function; } diff --git a/src/main/java/noppes/npcs/controllers/data/DataScript.java b/src/main/java/noppes/npcs/controllers/data/DataScript.java index c4a3bb652..522391912 100644 --- a/src/main/java/noppes/npcs/controllers/data/DataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/DataScript.java @@ -35,17 +35,17 @@ public class DataScript implements IScriptHandler { private final static EntityType entities = new EntityType(); private final static JobType jobs = new JobType(); private final static RoleType roles = new RoleType(); - + public String scriptLanguage = "ECMAScript"; private EntityNPCInterface npc; public boolean enabled = false; - + public ICustomNpc dummyNpc; public IWorld dummyWorld; public boolean clientNeedsUpdate = false; public boolean aiNeedsUpdate = false; public boolean hasInited = false; - + public DataScript(EntityNPCInterface npc) { for (int i = 0; i < 12; i++) { scripts.add(new ScriptContainer(this)); @@ -80,7 +80,7 @@ public class DataScript implements IScriptHandler { compound.setBoolean("ScriptEnabled", enabled); return compound; } - + private List readScript(NBTTagList list){ List scripts = new ArrayList<>(); for (int i = 0; i < 12; i++) { @@ -96,7 +96,7 @@ public class DataScript implements IScriptHandler { } return scripts; } - + private NBTTagList writeScript(List scripts){ NBTTagList list = new NBTTagList(); for(int type = 0; type < scripts.size(); type++){ @@ -137,7 +137,11 @@ public class DataScript implements IScriptHandler { script.engine.put(obs[i].toString(), ob); } if(CustomNpcs.ScriptLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ - LogWriter.postScriptLog(npc.field_110179_h, type, String.format("[%s] NPC %s (%s, %s, %s) | Objects: %s", ((String)type.function).toUpperCase(), npc.display.name, (int)npc.posX, (int)npc.posY, (int)npc.posZ, Arrays.toString(obs))); + if(obs.length > 1 && obs[1] == null){ + LogWriter.postScriptLog(npc.field_110179_h, type, String.format("[%s] NPC %s (%s, %s, %s)", ((String)type.function).toUpperCase(), npc.display.name, (int)npc.posX, (int)npc.posY, (int)npc.posZ)); + } else { + LogWriter.postScriptLog(npc.field_110179_h, type, String.format("[%s] NPC %s (%s, %s, %s) | Objects: %s", ((String)type.function).toUpperCase(), npc.display.name, (int)npc.posX, (int)npc.posY, (int)npc.posZ, Arrays.toString(obs))); + } } return callScript(script, event); } @@ -163,7 +167,7 @@ public class DataScript implements IScriptHandler { } return event.isCanceled(); } - + public boolean isEnabled(){ return enabled && ScriptController.HasStart && !npc.worldObj.isRemote && !scripts.isEmpty() && CustomNpcs.ScriptingEnabled; } @@ -236,5 +240,5 @@ public class DataScript implements IScriptHandler { if(world instanceof WorldServer) dummyWorld = new ScriptWorld((WorldServer) world); } - -} + +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/items/ItemSoulstoneFilled.java b/src/main/java/noppes/npcs/items/ItemSoulstoneFilled.java index 11c21e8e1..914ba7bba 100644 --- a/src/main/java/noppes/npcs/items/ItemSoulstoneFilled.java +++ b/src/main/java/noppes/npcs/items/ItemSoulstoneFilled.java @@ -2,6 +2,7 @@ package noppes.npcs.items; import java.util.List; +import cpw.mods.fml.common.FMLCommonHandler; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.player.EntityPlayer; @@ -11,6 +12,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraft.world.World; +import noppes.npcs.CustomNpcs; +import noppes.npcs.LogWriter; import noppes.npcs.constants.EnumRoleType; import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.controllers.PlayerDataController; @@ -73,6 +76,9 @@ public class ItemSoulstoneFilled extends Item { if(entity == null) return false; entity.setPosition(x + 0.5, y + 1 + 0.2F, z + 0.5); + if(CustomNpcs.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ + LogWriter.script(String.format("[%s] %s PLACED ENTITY %s", "SOULSTONE", player.getCommandSenderName(), entity)); + } if(entity instanceof EntityNPCInterface){ EntityNPCInterface npc = (EntityNPCInterface) entity; npc.ai.startPos = new int[]{x, y, z};