Cache overridden-commands and player-commands in Settings (#4345)

This commit is contained in:
MD 2021-07-11 17:25:25 +01:00 committed by GitHub
parent c020526b1e
commit eed73e3157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,8 +48,8 @@ import static com.earth2me.essentials.I18n.tl;
public class Settings implements net.ess3.api.ISettings {
private static final Logger logger = Logger.getLogger("Essentials");
private static final BigDecimal MAXMONEY = new BigDecimal("10000000000000");
private static final BigDecimal MINMONEY = new BigDecimal("-10000000000000");
private static final BigDecimal DEFAULT_MAX_MONEY = new BigDecimal("10000000000000");
private static final BigDecimal DEFAULT_MIN_MONEY = new BigDecimal("-10000000000000");
private final transient EssentialsConfiguration config;
private final transient IEssentials ess;
private final transient AtomicInteger reloadCount = new AtomicInteger(0);
@ -62,6 +62,8 @@ public class Settings implements net.ess3.api.ISettings {
private boolean teleportSafety;
private boolean forceDisableTeleportSafety;
private Set<String> disabledCommands = new HashSet<>();
private List<String> overriddenCommands = Collections.emptyList();
private List<String> playerCommands = Collections.emptyList();
private final transient Map<String, Command> disabledBukkitCommands = new HashMap<>();
private Map<String, BigDecimal> commandCosts;
private Set<String> socialSpyCommands = new HashSet<>();
@ -76,8 +78,8 @@ public class Settings implements net.ess3.api.ISettings {
private boolean configDebug = false;
// #easteregg
private boolean economyDisabled = false;
private BigDecimal maxMoney = MAXMONEY;
private BigDecimal minMoney = MINMONEY;
private BigDecimal maxMoney = DEFAULT_MAX_MONEY;
private BigDecimal minMoney = DEFAULT_MIN_MONEY;
private boolean economyLog = false;
// #easteregg
private boolean economyLogUpdate = false;
@ -317,9 +319,13 @@ public class Settings implements net.ess3.api.ISettings {
return disCommands;
}
private List<String> _getPlayerCommands() {
return config.getList("player-commands", String.class);
}
@Override
public boolean isPlayerCommand(final String label) {
for (final String c : config.getList("player-commands", String.class)) {
for (final String c : playerCommands) {
if (!c.equalsIgnoreCase(label)) {
continue;
}
@ -328,9 +334,13 @@ public class Settings implements net.ess3.api.ISettings {
return false;
}
private List<String> _getOverriddenCommands() {
return config.getList("overridden-commands", String.class);
}
@Override
public boolean isCommandOverridden(final String name) {
for (final String c : config.getList("overridden-commands", String.class)) {
for (final String c : overriddenCommands) {
if (!c.equalsIgnoreCase(name)) {
continue;
}
@ -643,6 +653,8 @@ public class Settings implements net.ess3.api.ISettings {
chatFormats.clear();
changeDisplayName = _changeDisplayName();
disabledCommands = _getDisabledCommands();
overriddenCommands = _getOverriddenCommands();
playerCommands = _getPlayerCommands();
// This will be late loaded
if (ess.getKnownCommandsProvider() != null) {
@ -934,7 +946,7 @@ public class Settings implements net.ess3.api.ISettings {
}
private BigDecimal _getMaxMoney() {
return config.getBigDecimal("max-money", MAXMONEY);
return config.getBigDecimal("max-money", DEFAULT_MAX_MONEY);
}
@Override
@ -943,7 +955,7 @@ public class Settings implements net.ess3.api.ISettings {
}
private BigDecimal _getMinMoney() {
BigDecimal min = config.getBigDecimal("min-money", MINMONEY);
BigDecimal min = config.getBigDecimal("min-money", DEFAULT_MIN_MONEY);
if (min.signum() > 0) {
min = min.negate();
}