mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 06:07:27 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
7dc0c25330
10 files changed
+146
-10
No files matched your search
@@ -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();
|
||||
|
||||
|
||||
@@ -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<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 +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<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.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;
|
||||
};
|
||||
@@ -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");
|
||||
|
||||
@@ -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"};
|
||||
|
||||
@@ -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<Long, String> getConsoleText() {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user