mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 00:58:50 +01:00
Allow setting flags via config; add flags with long values
This commit is contained in:
parent
1a09c49b29
commit
9e5bdeb7d5
@ -3,6 +3,7 @@ package com.earth2me.essentials;
|
||||
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;
|
||||
@ -145,6 +146,8 @@ public interface ISettings extends IConf {
|
||||
|
||||
boolean isDebug(DebugFlag flag);
|
||||
|
||||
Long getDebugLong(DebugFlag flag);
|
||||
|
||||
void setDebug(boolean debug);
|
||||
|
||||
boolean isEcoDisabled();
|
||||
@ -420,30 +423,51 @@ public interface ISettings extends IConf {
|
||||
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 propertyKey;
|
||||
private final boolean isSetByConfig;
|
||||
private final String flagKey;
|
||||
private final boolean isSetByGlobal;
|
||||
|
||||
DebugFlag(final String propertyKey, final boolean isSetByConfig) {
|
||||
this.propertyKey = propertyKey;
|
||||
this.isSetByConfig = isSetByConfig;
|
||||
DebugFlag(final String flagKey, final boolean isSetByGlobal) {
|
||||
this.flagKey = flagKey;
|
||||
this.isSetByGlobal = isSetByGlobal;
|
||||
}
|
||||
|
||||
public String getSystemProperty() {
|
||||
return DEBUG_FLAG_NAMESPACE + "." + propertyKey;
|
||||
public String getFlagKey() {
|
||||
return flagKey;
|
||||
}
|
||||
|
||||
public boolean getSystemPropertyValue() {
|
||||
final String value = System.getProperty(getSystemProperty(), "false");
|
||||
return Boolean.parseBoolean(value);
|
||||
public boolean isSetByGlobal() {
|
||||
return isSetByGlobal;
|
||||
}
|
||||
|
||||
public boolean isSetByConfig() {
|
||||
return isSetByConfig;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -855,7 +855,15 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
|
||||
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
|
||||
@ -865,10 +873,23 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
|
||||
@Override
|
||||
public boolean isDebug(DebugFlag flag) {
|
||||
if (flag.isSetByConfig() && (debug || configDebug)) {
|
||||
if (flag.isSetByGlobal() && (debug || configDebug)) {
|
||||
return true;
|
||||
}
|
||||
return flag.getSystemPropertyValue();
|
||||
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
|
||||
|
@ -3,7 +3,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;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
@ -38,11 +37,12 @@ public class ModernUserMap extends CacheLoader<UUID, User> implements IUserMap {
|
||||
.build(this);
|
||||
|
||||
// -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;
|
||||
|
||||
this.debugMaxWarnsPerType = NumberUtil.isLong(maxWarnProperty) ? Long.parseLong(maxWarnProperty) : -1;
|
||||
// -Dnet.essentialsx.usermap.print-stack=true
|
||||
this.debugPrintStackWithWarn = ess.getSettings().isDebug(ISettings.DebugFlag.USERMAP_PRINT_STACK);
|
||||
|
||||
this.debugNonPlayerWarnCounts = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user