fixed logger option bug (#1124)
* fixed logger option bug * implemented strict option for logger args * added back deprecated logger constructor Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com>
This commit is contained in:
1 parent
f17b63a8f7
commit
50b3aa8832
4 files changed
+46
-9
No files matched your search
@@ -8,11 +8,16 @@ import java.lang.reflect.Field;
|
||||
public class HUDLogger extends Logger
|
||||
{
|
||||
static Logger stardardHUDLogger(String logName, String def, String [] options)
|
||||
{
|
||||
return stardardHUDLogger(logName, def, options, false);
|
||||
}
|
||||
|
||||
static Logger stardardHUDLogger(String logName, String def, String [] options, boolean strictOptions)
|
||||
{
|
||||
// should convert to factory method if more than 2 classes are here
|
||||
try
|
||||
{
|
||||
return new HUDLogger(LoggerRegistry.class.getField("__"+logName), logName, def, options);
|
||||
return new HUDLogger(LoggerRegistry.class.getField("__"+logName), logName, def, options, strictOptions);
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
@@ -20,9 +25,14 @@ public class HUDLogger extends Logger
|
||||
}
|
||||
}
|
||||
|
||||
public HUDLogger(Field field, String logName, String def, String[] options)
|
||||
public HUDLogger(Field field, String logName, String def, String[] options, boolean strictOptions)
|
||||
{
|
||||
super(field, logName, def, options);
|
||||
super(field, logName, def, options, strictOptions);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public HUDLogger(Field field, String logName, String def, String[] options) {
|
||||
super(field, logName, def, options, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,11 +32,18 @@ public class Logger
|
||||
|
||||
private Field acceleratorField;
|
||||
|
||||
private boolean strictOptions;
|
||||
|
||||
static Logger stardardLogger(String logName, String def, String [] options)
|
||||
{
|
||||
return stardardLogger(logName, def, options, false);
|
||||
}
|
||||
|
||||
static Logger stardardLogger(String logName, String def, String [] options, boolean strictOptions)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new Logger(LoggerRegistry.class.getField("__"+logName), logName, def, options);
|
||||
return new Logger(LoggerRegistry.class.getField("__"+logName), logName, def, options, strictOptions);
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
@@ -44,7 +51,12 @@ public class Logger
|
||||
}
|
||||
}
|
||||
|
||||
public Logger(Field acceleratorField, String logName, String def, String [] options)
|
||||
@Deprecated
|
||||
public Logger(Field acceleratorField, String logName, String def, String [] options) {
|
||||
this(acceleratorField, logName, def, options, false);
|
||||
}
|
||||
|
||||
public Logger(Field acceleratorField, String logName, String def, String [] options, boolean strictOptions)
|
||||
{
|
||||
subscribedOnlinePlayers = new HashMap<>();
|
||||
subscribedOfflinePlayers = new HashMap<>();
|
||||
@@ -52,6 +64,7 @@ public class Logger
|
||||
this.logName = logName;
|
||||
this.default_option = def;
|
||||
this.options = options;
|
||||
this.strictOptions = strictOptions;
|
||||
if (acceleratorField == null)
|
||||
CarpetSettings.LOG.error("[CM] Logger "+getLogName()+" is missing a specified accelerator");
|
||||
}
|
||||
@@ -232,4 +245,12 @@ public class Logger
|
||||
if (options != null && Arrays.asList(options).contains(arg)) return arg;
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isOptionValid(String option) {
|
||||
if (strictOptions)
|
||||
{
|
||||
return Arrays.asList(this.options).contains(option);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class LoggerRegistry
|
||||
|
||||
public static void registerLoggers()
|
||||
{
|
||||
registerLogger("tnt", Logger.stardardLogger( "tnt", "brief", new String[]{"brief", "full"}));
|
||||
registerLogger("tnt", Logger.stardardLogger( "tnt", "brief", new String[]{"brief", "full"}, true));
|
||||
registerLogger("projectiles", Logger.stardardLogger("projectiles", "brief", new String[]{"brief", "full"}));
|
||||
registerLogger("fallingBlocks",Logger.stardardLogger("fallingBlocks", "brief", new String[]{"brief", "full"}));
|
||||
registerLogger("pathfinding", Logger.stardardLogger("pathfinding", "20", new String[]{"2", "5", "10"}));
|
||||
@@ -47,7 +47,7 @@ public class LoggerRegistry
|
||||
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("explosions", HUDLogger.stardardLogger("explosions", "brief",new String[]{"brief", "full"}));
|
||||
registerLogger("explosions", Logger.stardardLogger("explosions", "brief",new String[]{"brief", "full"}, true));
|
||||
registerLogger("updateSuppressedCrashes", Logger.stardardLogger("updateSuppressedCrashes", null,null));
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user