From 1a09c49b293b03113470aca41c6b05c34516a376 Mon Sep 17 00:00:00 2001 From: MD <1917406+mdcfe@users.noreply.github.com> Date: Sun, 12 Mar 2023 15:08:08 +0000 Subject: [PATCH] Add flags to isDebug for more granular debug toggles --- .../com/earth2me/essentials/ISettings.java | 31 +++++++++++++++++++ .../com/earth2me/essentials/Settings.java | 10 +++++- .../essentials/userstorage/ModernUserMap.java | 6 ++-- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index 4da7f5254..e444cc2ab 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -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; + } + } + } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index c0b1c6182..e34602ee2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -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 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 eaab42c0f..f4db066b8 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java +++ b/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java @@ -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 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<>(); }