From fcd50b34c3118acfa1b9930ac3440c704f20caf2 Mon Sep 17 00:00:00 2001 From: KAMKEEL Date: Thu, 3 Nov 2022 20:07:28 -0400 Subject: [PATCH] ScriptIgnoreFrequency --- src/main/java/noppes/npcs/CustomNpcs.java | 6 ++++- src/main/java/noppes/npcs/LogWriter.java | 33 ++++++++++++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index df11433aa..3abb6503a 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -62,9 +62,13 @@ public class CustomNpcs { @ConfigProp(info = "Enables if Scripting Information should be printed to CustomNPCs Logs") public static boolean ScriptLogging = false; - @ConfigProp(info = "Amount of logs per minute that would be marked as SPAM [10, 300]") + @ConfigProp(info = "Amount of Messages marked as SPAM [5, 3000]. Higher 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 = 30; + @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; diff --git a/src/main/java/noppes/npcs/LogWriter.java b/src/main/java/noppes/npcs/LogWriter.java index 353ef3556..e501a5b6c 100644 --- a/src/main/java/noppes/npcs/LogWriter.java +++ b/src/main/java/noppes/npcs/LogWriter.java @@ -1,7 +1,5 @@ package noppes.npcs; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import noppes.npcs.constants.EnumScriptType; import java.io.File; @@ -143,22 +141,36 @@ public class LogWriter { 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.date.getTime()); - stamp.counter++; + 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; - if(secondsSinceFirst < 10 && stamp.counter < 5) { + stamp.counter++; + + // Reset Log if 3 Minutes Pass + if (secondsSinceFirst > 180) { 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 < 4) { + 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; - } else if (secondsSinceFirst > 60) { - LogWriter.script(message); - stamp.counter = 1; - stamp.date = new Date(); + stamp.recentDate = new Date(); } + } else { map.put(npcUUID, new NPCStamp()); LogWriter.script(message); @@ -194,6 +206,7 @@ public class LogWriter { class NPCStamp { - public Date date = new Date(); + public Date makeDate = new Date(); + public Date recentDate = new Date(); public int counter = 1; };