fixed logger issues #156 and #155

This commit is contained in:
gnembon committed 2020-02-23 02:25:51 -04:00
1 parent 56d681560a
commit 72a7bed11a
9 files changed
+95 -29

No files matched your search

+17 -4
View File
@@ -1,16 +1,29 @@
package carpet.logging;
import carpet.utils.HUDController;
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.BaseText;
import java.lang.reflect.Field;
public class HUDLogger extends Logger
{
public HUDLogger(String logName, String def, String[] options)
static Logger stardardHUDLogger(String logName, String def, String [] options)
{
super(logName, def, options);
// should convert to factory method if more than 2 classes are here
try
{
return new HUDLogger(LoggerRegistry.class.getField("__"+logName), logName, def, options);
}
catch (NoSuchFieldException e)
{
throw new RuntimeException("Failed to create logger "+logName);
}
}
public HUDLogger(Field field, String logName, String def, String[] options)
{
super(field, logName, def, options);
}
@Override
+25 -2
View File
@@ -6,6 +6,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.BaseText;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -28,13 +29,30 @@ public class Logger
private String[] options;
public Logger(String logName, String def, String [] options)
private Field acceleratorField;
static Logger stardardLogger(String logName, String def, String [] options)
{
try
{
return new Logger(LoggerRegistry.class.getField("__"+logName), logName, def, options);
}
catch (NoSuchFieldException e)
{
throw new RuntimeException("Failed to create logger "+logName);
}
}
public Logger(Field acceleratorField, String logName, String def, String [] options)
{
subscribedOnlinePlayers = new HashMap<>();
subscribedOfflinePlayers = new HashMap<>();
this.acceleratorField = acceleratorField;
this.logName = logName;
this.default_option = def;
this.options = options;
if (acceleratorField == null)
CarpetSettings.LOG.error("[CM] Logger "+getLogName()+" is missing a specified accelerator");
}
public String getDefault()
@@ -94,6 +112,11 @@ public class Logger
subscribedOfflinePlayers.clear();
}
public Field getField()
{
return acceleratorField;
}
/**
* serves messages to players fetching them from the promise
* will repeat invocation for players that share the same option
@@ -185,7 +208,7 @@ public class Logger
Set<String> loggingOptions = new HashSet<>(Arrays.asList(CarpetSettings.defaultLoggers.split(",")));
if (loggingOptions.contains(getLogName()))
{
subscribedOnlinePlayers.put(playerName, getDefault());
LoggerRegistry.subscribePlayer(playerName, getLogName(), getDefault());
}
}
LoggerRegistry.setAccess(this);
@@ -1,5 +1,6 @@
package carpet.logging;
import carpet.CarpetServer;
import carpet.CarpetSettings;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.DyeColor;
@@ -32,18 +33,26 @@ public class LoggerRegistry
public static void initLoggers()
{
registerLogger("tnt", new Logger("tnt", "brief", new String[]{"brief", "full"}));
registerLogger("projectiles", new Logger("projectiles", "brief", new String[]{"brief", "full"}));
registerLogger("fallingBlocks",new Logger("fallingBlocks", "brief", new String[]{"brief", "full"}));
stopLoggers();
registerLoggers();
CarpetServer.registerExtensionLoggers();
}
public static void registerLoggers()
{
registerLogger("tnt", Logger.stardardLogger( "tnt", "brief", new String[]{"brief", "full"}));
registerLogger("projectiles", Logger.stardardLogger("projectiles", "brief", new String[]{"brief", "full"}));
registerLogger("fallingBlocks",Logger.stardardLogger("fallingBlocks", "brief", new String[]{"brief", "full"}));
//registerLogger("kills", new Logger("kills", null, null));
//registerLogger("damage", new Logger("damage", "all", new String[]{"all","players","me"}));
//registerLogger("weather", new Logger("weather", null, null));
registerLogger( "pathfinding", new Logger("pathfinding", "20", new String[]{"2", "5", "10"}));
registerLogger( "pathfinding", Logger.stardardLogger("pathfinding", "20", new String[]{"2", "5", "10"}));
registerLogger("tps", HUDLogger.stardardHUDLogger("tps", null, null));
registerLogger("packets", HUDLogger.stardardHUDLogger("packets", null, null));
registerLogger("counter",HUDLogger.stardardHUDLogger("counter","white", Arrays.stream(DyeColor.values()).map(Object::toString).toArray(String[]::new)));
registerLogger("mobcaps", HUDLogger.stardardHUDLogger("mobcaps", "dynamic",new String[]{"dynamic", "overworld", "nether","end"}));
registerLogger("tps", new HUDLogger("tps", null, null));
registerLogger("packets", new HUDLogger("packets", null, null));
registerLogger("counter",new HUDLogger("counter","white", Arrays.stream(DyeColor.values()).map(Object::toString).toArray(String[]::new)));
registerLogger("mobcaps", new HUDLogger("mobcaps", "dynamic",new String[]{"dynamic", "overworld", "nether","end"}));
}
/**
@@ -117,22 +126,18 @@ public class LoggerRegistry
boolean value = logger.hasOnlineSubscribers();
try
{
Field f = LoggerRegistry.class.getDeclaredField("__"+name);
Field f = logger.getField();
f.setBoolean(null, value);
}
catch (IllegalAccessException e)
{
CarpetSettings.LOG.error("Cannot change logger quick access field");
}
catch (NoSuchFieldException e)
{
CarpetSettings.LOG.error("Wrong logger name");
}
}
/**
* Called when the server starts. Creates the logs used by Carpet mod.
*/
private static void registerLogger(String name, Logger logger)
public static void registerLogger(String name, Logger logger)
{
loggerRegistry.put(name, logger);
setAccess(logger);
@@ -142,11 +147,13 @@ public class LoggerRegistry
public static void stopLoggers()
{
seenPlayers.clear();
for(Logger log: loggerRegistry.values() )
{
log.serverStopped();
}
seenPlayers.clear();
loggerRegistry.clear();
playerSubscriptions.clear();
}
public static void playerConnected(PlayerEntity player)
{