diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index 4da7f52549b..926a23ac452 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -3,6 +3,7 @@ import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.signs.EssentialsSign; import com.earth2me.essentials.textreader.IText; +import com.earth2me.essentials.utils.NumberUtil; import org.bukkit.Material; import org.bukkit.event.EventPriority; import org.spongepowered.configurate.CommentedConfigurationNode; @@ -18,6 +19,8 @@ import java.util.regex.Pattern; public interface ISettings extends IConf { + String DEBUG_FLAG_NAMESPACE = "net.essentialsx"; + File getConfigFile(); boolean areSignsDisabled(); @@ -141,6 +144,10 @@ public interface ISettings extends IConf { boolean isDebug(); + boolean isDebug(DebugFlag flag); + + Long getDebugLong(DebugFlag flag); + void setDebug(boolean debug); boolean isEcoDisabled(); @@ -416,4 +423,52 @@ enum TeleportWhenFreePolicy { OFF } + // TODO: consider separating out non-bool values? or replace this with an object-mapped class? + enum DebugFlag { + GENERIC("debug.generic", true), + USERMAP_PRINT_STACK("usermap.print-stack", false), + USERMAP_MAX_WARNS("usermap.max-warns", false), + ; + + private final String flagKey; + private final boolean isSetByGlobal; + + DebugFlag(final String flagKey, final boolean isSetByGlobal) { + this.flagKey = flagKey; + this.isSetByGlobal = isSetByGlobal; + } + + public String getFlagKey() { + return flagKey; + } + + public boolean isSetByGlobal() { + return isSetByGlobal; + } + + public String getSystemPropertyKey() { + return DEBUG_FLAG_NAMESPACE + "." + flagKey; + } + + public String getConfigKey() { + return "debug." + (flagKey.replace("debug.", "")); + } + + public String getSystemPropertyValue() { + return System.getProperty(getSystemPropertyKey(), "false"); + } + + public boolean getSystemPropertyBoolean() { + return Boolean.parseBoolean(getSystemPropertyValue()); + } + + public Long getSystemPropertyLong() { + final String value = getSystemPropertyValue(); + if (NumberUtil.isLong(value)) { + return Long.parseLong(value); + } + return null; + } + } + } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index c0b1c618245..3d02712d893 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -855,12 +855,41 @@ public boolean warnOnBuildDisallow() { } private boolean _isDebug() { - return config.getBoolean("debug", false); + if (config.isBoolean("debug")) { + return config.getBoolean("debug", false); + } + + if (config.isBoolean("debug.enabled")) { + return config.getBoolean("debug.enabled", false); + } + + return false; } @Override public boolean isDebug() { - return debug || configDebug; + return isDebug(DebugFlag.GENERIC); + } + + @Override + public boolean isDebug(DebugFlag flag) { + if (flag.isSetByGlobal() && (debug || configDebug)) { + return true; + } + final String flagConfigPath = flag.getConfigKey(); + if (config.isBoolean(flagConfigPath)) { + return config.getBoolean(flagConfigPath, false); + } + return flag.getSystemPropertyBoolean(); + } + + @Override + public Long getDebugLong(DebugFlag flag) { + final String flagConfigPath = flag.getConfigKey(); + if (config.hasProperty(flagConfigPath)) { + return config.getLong(flagConfigPath, 0); + } + return flag.getSystemPropertyLong(); } @Override diff --git a/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java b/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java index eaab42c0f87..62330044859 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java +++ b/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java @@ -1,8 +1,8 @@ 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; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -36,13 +36,13 @@ public ModernUserMap(final IEssentials ess) { .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"); + final Long maxWarnSetting = ess.getSettings().getDebugLong(ISettings.DebugFlag.USERMAP_MAX_WARNS); + this.debugMaxWarnsPerType = maxWarnSetting != null ? maxWarnSetting : -1; + + // -Dnet.essentialsx.usermap.print-stack=true + this.debugPrintStackWithWarn = ess.getSettings().isDebug(ISettings.DebugFlag.USERMAP_PRINT_STACK); - this.debugMaxWarnsPerType = NumberUtil.isLong(maxWarnProperty) ? Long.parseLong(maxWarnProperty) : -1; - this.debugPrintStackWithWarn = Boolean.parseBoolean(printStackProperty); this.debugNonPlayerWarnCounts = new ConcurrentHashMap<>(); } diff --git a/build-logic/src/main/kotlin/constants.kt b/build-logic/src/main/kotlin/constants.kt index 5aebfc557a3..5cc2ea1602e 100644 --- a/build-logic/src/main/kotlin/constants.kt +++ b/build-logic/src/main/kotlin/constants.kt @@ -1 +1 @@ -const val RUN_PAPER_MINECRAFT_VERSION = "1.19.2" +const val RUN_PAPER_MINECRAFT_VERSION = "1.19.3"