mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 08:45:11 +00:00
NPC Script Logging Config V 1.0
Added V 1.0 (CNPC+ Script Logging) > Logs Activities for when CNPC+ Scripts are called (Writes to CustomNPCs-latest.log) Configuration Options Available in Config
This commit is contained in:
1 parent
29b716a25c
commit
37da3f6069
3 files changed
+118
-3
No files matched your search
@@ -59,6 +59,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")
|
||||
public static boolean ScriptLogging = false;
|
||||
|
||||
@ConfigProp(info = "Amount of logs per minute that would be marked as SPAM [10, 300]")
|
||||
public static int ScriptFrequency = 30;
|
||||
|
||||
@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 +233,11 @@ public class CustomNpcs {
|
||||
if (ExpandedScriptLimit < 0)
|
||||
ExpandedScriptLimit = 0;
|
||||
|
||||
if (ScriptFrequency < 10)
|
||||
ScriptFrequency = 10;
|
||||
if (ScriptFrequency > 300)
|
||||
ScriptFrequency = 300;
|
||||
|
||||
EnchantInterface.load();
|
||||
CustomItems.load();
|
||||
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
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 +25,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<UUID, NPCStamp> InitCacheMap = new WeakHashMap<UUID, NPCStamp>();
|
||||
private final static WeakHashMap<UUID, NPCStamp> TickCacheMap = new WeakHashMap<UUID, NPCStamp>();
|
||||
private final static WeakHashMap<UUID, NPCStamp> InteractCacheMap = new WeakHashMap<UUID, NPCStamp>();
|
||||
private final static WeakHashMap<UUID, NPCStamp> DialogCacheMap = new WeakHashMap<UUID, NPCStamp>();
|
||||
private final static WeakHashMap<UUID, NPCStamp> DamagedCacheMap = new WeakHashMap<UUID, NPCStamp>();
|
||||
private final static WeakHashMap<UUID, NPCStamp> KilledCacheMap = new WeakHashMap<UUID, NPCStamp>();
|
||||
private final static WeakHashMap<UUID, NPCStamp> AttackCacheMap = new WeakHashMap<UUID, NPCStamp>();
|
||||
private final static WeakHashMap<UUID, NPCStamp> TargetCacheMap = new WeakHashMap<UUID, NPCStamp>();
|
||||
private final static WeakHashMap<UUID, NPCStamp> CollideCacheMap = new WeakHashMap<UUID, NPCStamp>();
|
||||
private final static WeakHashMap<UUID, NPCStamp> KillsCacheMap = new WeakHashMap<UUID, NPCStamp>();
|
||||
private final static WeakHashMap<UUID, NPCStamp> DialogCloseCacheMap = new WeakHashMap<UUID, NPCStamp>();
|
||||
private final static WeakHashMap<UUID, NPCStamp> TimerCacheMap = new WeakHashMap<UUID, NPCStamp>();
|
||||
|
||||
private final static SimpleDateFormat dateformat = new SimpleDateFormat("HH:mm:ss");
|
||||
private static Handler handler;
|
||||
static {
|
||||
@@ -64,7 +84,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 +98,78 @@ 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<UUID, NPCStamp> 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++;
|
||||
double frequency = (float)CustomNpcs.ScriptFrequency / 60;
|
||||
|
||||
if(secondsSinceFirst < 10 && stamp.counter < 5) {
|
||||
LogWriter.script(message);
|
||||
}
|
||||
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();
|
||||
}
|
||||
} 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 +191,9 @@ public class LogWriter {
|
||||
handler.flush();
|
||||
}
|
||||
}
|
||||
|
||||
class NPCStamp
|
||||
{
|
||||
public Date date = new Date();
|
||||
public int counter = 1;
|
||||
};
|
||||
@@ -4,7 +4,10 @@ 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;
|
||||
@@ -12,6 +15,7 @@ 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;
|
||||
@@ -132,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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user