From eed73e315792fff7610cf4d9b774ecf8fe942829 Mon Sep 17 00:00:00 2001 From: MD <1917406+mdcfe@users.noreply.github.com> Date: Sun, 11 Jul 2021 17:25:25 +0100 Subject: [PATCH] Cache overridden-commands and player-commands in Settings (#4345) --- .../com/earth2me/essentials/Settings.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 5bab531ed..94d310277 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -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 disabledCommands = new HashSet<>(); + private List overriddenCommands = Collections.emptyList(); + private List playerCommands = Collections.emptyList(); private final transient Map disabledBukkitCommands = new HashMap<>(); private Map commandCosts; private Set 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 _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 _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(); }