Skip to content

Introduce more granular debug flags #5270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: 2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/ISettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +19,8 @@
import java.util.regex.Pattern;

public interface ISettings extends IConf {
String DEBUG_FLAG_NAMESPACE = "net.essentialsx";

File getConfigFile();

boolean areSignsDisabled();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}

}
33 changes: 31 additions & 2 deletions Essentials/src/main/java/com/earth2me/essentials/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<>();
}

Expand Down
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/constants.kt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const val RUN_PAPER_MINECRAFT_VERSION = "1.19.2"
const val RUN_PAPER_MINECRAFT_VERSION = "1.19.3"