Add flags to isDebug for more granular debug toggles

This commit is contained in:
MD 2023-03-12 15:08:08 +00:00
parent a7f39c5e0d
commit 1a09c49b29
No known key found for this signature in database
GPG Key ID: 7458A1E1C8FB76B1
3 changed files with 43 additions and 4 deletions

View File

@ -18,6 +18,8 @@ import java.util.function.Predicate;
import java.util.regex.Pattern;
public interface ISettings extends IConf {
String DEBUG_FLAG_NAMESPACE = "net.essentialsx";
File getConfigFile();
boolean areSignsDisabled();
@ -141,6 +143,8 @@ public interface ISettings extends IConf {
boolean isDebug();
boolean isDebug(DebugFlag flag);
void setDebug(boolean debug);
boolean isEcoDisabled();
@ -416,4 +420,31 @@ public interface ISettings extends IConf {
OFF
}
enum DebugFlag {
GENERIC("debug.generic", true),
USERMAP_PRINT_STACK("usermap.print-stack", false),
;
private final String propertyKey;
private final boolean isSetByConfig;
DebugFlag(final String propertyKey, final boolean isSetByConfig) {
this.propertyKey = propertyKey;
this.isSetByConfig = isSetByConfig;
}
public String getSystemProperty() {
return DEBUG_FLAG_NAMESPACE + "." + propertyKey;
}
public boolean getSystemPropertyValue() {
final String value = System.getProperty(getSystemProperty(), "false");
return Boolean.parseBoolean(value);
}
public boolean isSetByConfig() {
return isSetByConfig;
}
}
}

View File

@ -860,7 +860,15 @@ public class Settings implements net.ess3.api.ISettings {
@Override
public boolean isDebug() {
return debug || configDebug;
return isDebug(DebugFlag.GENERIC);
}
@Override
public boolean isDebug(DebugFlag flag) {
if (flag.isSetByConfig() && (debug || configDebug)) {
return true;
}
return flag.getSystemPropertyValue();
}
@Override

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials.userstorage;
import com.earth2me.essentials.ISettings;
import com.earth2me.essentials.OfflinePlayer;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.NumberUtil;
@ -36,13 +37,12 @@ public class ModernUserMap extends CacheLoader<UUID, User> implements IUserMap {
.softValues()
.build(this);
// -Dnet.essentialsx.usermap.print-stack=true
final String printStackProperty = System.getProperty("net.essentialsx.usermap.print-stack", "false");
// -Dnet.essentialsx.usermap.max-warns=20
final String maxWarnProperty = System.getProperty("net.essentialsx.usermap.max-warns", "100");
this.debugMaxWarnsPerType = NumberUtil.isLong(maxWarnProperty) ? Long.parseLong(maxWarnProperty) : -1;
this.debugPrintStackWithWarn = Boolean.parseBoolean(printStackProperty);
// -Dnet.essentialsx.usermap.print-stack=true
this.debugPrintStackWithWarn = ess.getSettings().isDebug(ISettings.DebugFlag.USERMAP_PRINT_STACK);
this.debugNonPlayerWarnCounts = new ConcurrentHashMap<>();
}