diff --git a/build.gradle b/build.gradle index 5c1774d68..49f75e853 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ configurations { apply plugin: 'forge' -version = "1.6.4" +version = "1.6.5-beta2" group= "com.kamkeel.customnpc-plus" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "CustomNPC-Plus" diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index aa11e469d..35f2e0683 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -59,6 +59,16 @@ 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") + public static boolean ScriptLogging = false; + + @ConfigProp(info = "Amount of Messages marked as SPAM [5, 3000]. Lower Number means MORE accurate messages \n" + + "This frequency will determine if the log will print a line with [SPAM] to warn the console.") + public static int ScriptFrequency = 20; + + @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 = "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; @@ -227,6 +237,14 @@ public class CustomNpcs { if (ExpandedScriptLimit < 0) ExpandedScriptLimit = 0; + if (ScriptFrequency < 5) + ScriptFrequency = 5; + if (ScriptFrequency > 3000) + ScriptFrequency = 3000; + + if (ScriptIgnoreTime < 0) + ScriptIgnoreTime = 0; + EnchantInterface.load(); CustomItems.load(); diff --git a/src/main/java/noppes/npcs/LogWriter.java b/src/main/java/noppes/npcs/LogWriter.java index 5e949c20c..6a0911139 100644 --- a/src/main/java/noppes/npcs/LogWriter.java +++ b/src/main/java/noppes/npcs/LogWriter.java @@ -1,13 +1,17 @@ package noppes.npcs; +import noppes.npcs.constants.EnumScriptType; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.io.PrintStream; import java.io.PrintWriter; import java.io.StringWriter; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.UUID; +import java.util.WeakHashMap; +import java.util.concurrent.TimeUnit; import java.util.logging.ConsoleHandler; import java.util.logging.Formatter; import java.util.logging.Handler; @@ -19,6 +23,20 @@ import java.util.logging.StreamHandler; public class LogWriter { private final static String name = "CustomNPCs"; private final static Logger logger = Logger.getLogger(name); + + private final static WeakHashMap InitCacheMap = new WeakHashMap(); + private final static WeakHashMap TickCacheMap = new WeakHashMap(); + private final static WeakHashMap InteractCacheMap = new WeakHashMap(); + private final static WeakHashMap DialogCacheMap = new WeakHashMap(); + private final static WeakHashMap DamagedCacheMap = new WeakHashMap(); + private final static WeakHashMap KilledCacheMap = new WeakHashMap(); + private final static WeakHashMap AttackCacheMap = new WeakHashMap(); + private final static WeakHashMap TargetCacheMap = new WeakHashMap(); + private final static WeakHashMap CollideCacheMap = new WeakHashMap(); + private final static WeakHashMap KillsCacheMap = new WeakHashMap(); + private final static WeakHashMap DialogCloseCacheMap = new WeakHashMap(); + private final static WeakHashMap TimerCacheMap = new WeakHashMap(); + private final static SimpleDateFormat dateformat = new SimpleDateFormat("HH:mm:ss"); private static Handler handler; static { @@ -64,7 +82,7 @@ public class LogWriter { logger.setUseParentHandlers(false); Handler consoleHandler = new ConsoleHandler(); consoleHandler.setFormatter(handler.getFormatter()); - consoleHandler.setLevel(Level.ALL); + consoleHandler.setLevel(Level.FINEST); logger.addHandler(consoleHandler); logger.setLevel(Level.ALL); @@ -78,6 +96,92 @@ public class LogWriter { } } + public static void postScriptLog(UUID npcUUID, EnumScriptType type, String message) { + switch (type){ + case INIT: + scriptLogCalculator(InitCacheMap, npcUUID, message); + break; + case TICK: + scriptLogCalculator(TickCacheMap, npcUUID, message); + break; + case INTERACT: + scriptLogCalculator(InteractCacheMap, npcUUID, message); + break; + case DIALOG: + scriptLogCalculator(DialogCacheMap, npcUUID, message); + break; + case DAMAGED: + scriptLogCalculator(DamagedCacheMap, npcUUID, message); + break; + case KILLED: + scriptLogCalculator(KilledCacheMap, npcUUID, message); + break; + case ATTACK: + scriptLogCalculator(AttackCacheMap, npcUUID, message); + break; + case TARGET: + scriptLogCalculator(TargetCacheMap, npcUUID, message); + break; + case COLLIDE: + scriptLogCalculator(CollideCacheMap, npcUUID, message); + break; + case KILLS: + scriptLogCalculator(KillsCacheMap, npcUUID, message); + case DIALOG_CLOSE: + scriptLogCalculator(DialogCloseCacheMap, npcUUID, message); + break; + case TIMER: + scriptLogCalculator(TimerCacheMap, npcUUID, message); + break; + default: + break; + } + } + + public static void scriptLogCalculator(WeakHashMap map, UUID npcUUID, String message) { + if(map.containsKey(npcUUID)){ + NPCStamp stamp = map.get(npcUUID); + long secondsSinceFirst = TimeUnit.MILLISECONDS.toSeconds(new Date().getTime() - stamp.makeDate.getTime()); + long millisecSinceLast = TimeUnit.MILLISECONDS.toMillis(stamp.recentDate.getTime() - stamp.makeDate.getTime()); + + double frequency = (float)CustomNpcs.ScriptFrequency / 60; + + + + // Reset Log if 3 Minutes Pass + if (secondsSinceFirst > 120) { + LogWriter.script(message); + stamp.counter = 1; + stamp.makeDate = new Date(); + stamp.recentDate = new Date(); + } + // ALWAYS Log the First 3 of Event + else if(secondsSinceFirst < 10 && stamp.counter < 3) { + LogWriter.script(message); + stamp.recentDate = new Date(); + } + // IF event occurs to QUICKLY Ignore. + else if (millisecSinceLast < CustomNpcs.ScriptIgnoreTime){ + stamp.recentDate = new Date(); + } + else if(secondsSinceFirst > 10 && (double)stamp.counter / secondsSinceFirst > frequency){ + // WARN + LogWriter.script("[SPAM]:" + message); + stamp.counter = 0; + stamp.recentDate = new Date(); + } + stamp.counter++; + } else { + map.put(npcUUID, new NPCStamp()); + LogWriter.script(message); + } + } + + public static void script(Object msg) { + logger.log(Level.ALL, msg.toString()); + handler.flush(); + } + public static void info(Object msg) { logger.log(Level.INFO, msg.toString()); handler.flush(); @@ -99,3 +203,10 @@ public class LogWriter { handler.flush(); } } + +class NPCStamp +{ + public Date makeDate = new Date(); + public Date recentDate = new Date(); + public int counter = 1; +}; diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 51fd83e8c..0837aa329 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -176,7 +176,7 @@ public class PacketHandlerServer{ private void getScriptsEnabled(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException { if (type == EnumPacketServer.ScriptGlobalGuiDataGet) { NBTTagCompound compound = new NBTTagCompound(); - compound.setBoolean("ScriptsEnabled", CustomNpcs.GlobalPlayerScripts); + compound.setBoolean("ScriptsEnabled", CustomNpcs.ScriptingEnabled); compound.setBoolean("PlayerScriptsEnabled", CustomNpcs.GlobalPlayerScripts); compound.setBoolean("GlobalNPCScriptsEnabled", CustomNpcs.GlobalNPCScripts); compound.setBoolean("ForgeScriptsEnabled", CustomNpcs.GlobalForgeScripts); @@ -184,7 +184,7 @@ public class PacketHandlerServer{ } else if (type == EnumPacketServer.ScriptGlobalGuiDataSave) { NBTTagCompound compound = Server.readNBT(buffer); - CustomNpcs.GlobalPlayerScripts = compound.getBoolean("ScriptsEnabled"); + CustomNpcs.ScriptingEnabled = compound.getBoolean("ScriptsEnabled"); CustomNpcs.GlobalPlayerScripts = compound.getBoolean("PlayerScriptsEnabled"); CustomNpcs.GlobalNPCScripts = compound.getBoolean("GlobalNPCScriptsEnabled"); CustomNpcs.GlobalForgeScripts = compound.getBoolean("ForgeScriptsEnabled"); diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiModelBody.java b/src/main/java/noppes/npcs/client/gui/model/GuiModelBody.java index 89a5e1f96..e1bb8c373 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiModelBody.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiModelBody.java @@ -14,7 +14,7 @@ public class GuiModelBody extends GuiModelInterface{ private final String[] arrBody = new String[]{"gui.no","gui.yes"}; private final String[] arrBodywear = new String[]{"gui.no","gui.yes","Solid"}; private final String[] arrWing = new String[]{"gui.no","Player","Type1","Type2","Type3","Type4","Type5","Type6","Type7","Type8","Type9", - "Type10","Type11","Type12","Type13"}; + "Type10","Type11","Type12","Type13","Type14","Type15"}; private final String[] arrBreasts = new String[]{"gui.no","Type1","Type2","Type3"}; private final String[] arrParticles = new String[]{"gui.no","Player","Type1", "Type2", "Rainbow", "Type3", "Type4", "Type5", "Type6", "Type7"}; private final String[] arrfins = new String[]{"gui.no","Player","Type1","Type2","Type3","Type4","Type5","Type6"}; diff --git a/src/main/java/noppes/npcs/controllers/data/DataScript.java b/src/main/java/noppes/npcs/controllers/data/DataScript.java index 6e2998e67..c4a3bb652 100644 --- a/src/main/java/noppes/npcs/controllers/data/DataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/DataScript.java @@ -4,13 +4,18 @@ import java.util.*; import javax.script.ScriptEngine; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.Event; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import noppes.npcs.CustomNpcs; import noppes.npcs.EventHooks; +import noppes.npcs.LogWriter; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.IScriptHandler; @@ -131,7 +136,9 @@ public class DataScript implements IScriptHandler { ob = NpcAPI.Instance().getIEntity((Entity)ob); 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))); + } return callScript(script, event); } @@ -158,7 +165,7 @@ public class DataScript implements IScriptHandler { } public boolean isEnabled(){ - return enabled && ScriptController.HasStart && !npc.worldObj.isRemote && !scripts.isEmpty(); + return enabled && ScriptController.HasStart && !npc.worldObj.isRemote && !scripts.isEmpty() && CustomNpcs.ScriptingEnabled; } public Map getConsoleText() { diff --git a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java index 50c449e3c..c282e67db 100644 --- a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java @@ -81,7 +81,7 @@ public class ForgeDataScript implements IScriptHandler { } public boolean isEnabled() { - return this.enabled && ScriptController.HasStart && this.scripts.size() > 0; + return this.enabled && CustomNpcs.GlobalForgeScripts && ScriptController.HasStart && this.scripts.size() > 0; } public boolean isClient() { @@ -89,7 +89,7 @@ public class ForgeDataScript implements IScriptHandler { } public boolean getEnabled() { - return CustomNpcs.GlobalForgeScripts && this.enabled; + return this.enabled; } public void setEnabled(boolean bo) { diff --git a/src/main/resources/assets/customnpcs/textures/parts/wings/cwing1.png b/src/main/resources/assets/customnpcs/textures/parts/wings/cwing1.png new file mode 100644 index 000000000..3cdde5aff Binary files /dev/null and b/src/main/resources/assets/customnpcs/textures/parts/wings/cwing1.png differ diff --git a/src/main/resources/assets/customnpcs/textures/parts/wings/wing14.png b/src/main/resources/assets/customnpcs/textures/parts/wings/wing14.png new file mode 100644 index 000000000..e6310fa20 Binary files /dev/null and b/src/main/resources/assets/customnpcs/textures/parts/wings/wing14.png differ diff --git a/src/main/resources/assets/customnpcs/textures/parts/wings/wing15.png b/src/main/resources/assets/customnpcs/textures/parts/wings/wing15.png new file mode 100644 index 000000000..c95c7154b Binary files /dev/null and b/src/main/resources/assets/customnpcs/textures/parts/wings/wing15.png differ