diff --git a/pom.xml b/pom.xml index 43a91e8..57014a2 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ -LOCAL - 2.15.0 + 2.16.0 BentoBoxWorld_Level bentobox-world https://sonarcloud.io diff --git a/src/main/java/world/bentobox/level/LevelsManager.java b/src/main/java/world/bentobox/level/LevelsManager.java index 7e6163e..39316f6 100644 --- a/src/main/java/world/bentobox/level/LevelsManager.java +++ b/src/main/java/world/bentobox/level/LevelsManager.java @@ -36,16 +36,8 @@ public class LevelsManager { private static final String INTOPTEN = "intopten"; - private static final TreeMap LEVELS; + private static final TreeMap LEVELS = new TreeMap<>(); private static final BigInteger THOUSAND = BigInteger.valueOf(1000); - static { - LEVELS = new TreeMap<>(); - - LEVELS.put(THOUSAND, "k"); - LEVELS.put(THOUSAND.pow(2), "M"); - LEVELS.put(THOUSAND.pow(3), "G"); - LEVELS.put(THOUSAND.pow(4), "T"); - } private final Level addon; // Database handler for level data @@ -67,6 +59,12 @@ public LevelsManager(Level addon) { levelsCache = new HashMap<>(); // Initialize top ten lists topTenLists = new ConcurrentHashMap<>(); + // Units + LEVELS.put(THOUSAND, addon.getSettings().getKilo()); + LEVELS.put(THOUSAND.pow(2), addon.getSettings().getMega()); + LEVELS.put(THOUSAND.pow(3), addon.getSettings().getGiga()); + LEVELS.put(THOUSAND.pow(4), addon.getSettings().getTera()); + } public void migrate() { diff --git a/src/main/java/world/bentobox/level/config/ConfigSettings.java b/src/main/java/world/bentobox/level/config/ConfigSettings.java index c287d2a..e865f47 100644 --- a/src/main/java/world/bentobox/level/config/ConfigSettings.java +++ b/src/main/java/world/bentobox/level/config/ConfigSettings.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.configuration.ConfigComment; @@ -120,6 +121,17 @@ public class ConfigSettings implements ConfigObject { @ConfigComment("Shows large level values rounded down, e.g., 10,345 -> 10k") @ConfigEntry(path = "shorthand") private boolean shorthand = false; + + @ConfigComment("Shorthand units") + @ConfigEntry(path = "units.kilo") + private String kilo = "k"; + @ConfigEntry(path = "units.mega") + private String mega = "M"; + @ConfigEntry(path = "units.giga") + private String giga = "G"; + @ConfigEntry(path = "units.tera") + private String tera = "T"; + @ConfigComment("") @ConfigComment("Include Shulker Box content in chests in level calculations.") @ConfigComment("Will count blocks in Shulker Boxes inside of chests.") @@ -419,4 +431,60 @@ public List getDisabledPluginHooks() { public void setDisabledPluginHooks(List disabledPluginHooks) { this.disabledPluginHooks = disabledPluginHooks; } + + /** + * @return the kilo + */ + public String getKilo() { + return Objects.requireNonNullElse(kilo, "k"); + } + + /** + * @param kilo the kilo to set + */ + public void setKilo(String kilo) { + this.kilo = kilo; + } + + /** + * @return the mega + */ + public String getMega() { + return Objects.requireNonNullElse(mega, "M"); + } + + /** + * @param mega the mega to set + */ + public void setMega(String mega) { + this.mega = mega; + } + + /** + * @return the giga + */ + public String getGiga() { + return Objects.requireNonNullElse(giga, "G"); + } + + /** + * @param giga the giga to set + */ + public void setGiga(String giga) { + this.giga = giga; + } + + /** + * @return the tera + */ + public String getTera() { + return Objects.requireNonNullElse(tera, "T"); + } + + /** + * @param tera the tera to set + */ + public void setTera(String tera) { + this.tera = tera; + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7f2ed95..4b98666 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,22 +4,22 @@ # Disabled Game Mode Addons # Level will NOT hook into these game mode addons. disabled-game-modes: [] -# +# # When executing level command from console, should a report be shown? log-report-to-console: true -# +# # Number of concurrent island calculations # If your CPU can handle it, you can run parallel island calcs if there are more than one in the queue concurrent-island-calcs: 1 -# +# # Island level calculation timeout in minutes. # If an island takes longer that this time to calculate, then the calculation will abort. # Generally, calculation should only take a few seconds, so if this ever triggers then something is not right. calculation-timeout: 5 -# +# # Zero island levels on new island or island reset # If true, Level will calculate the starter island's level and remove it from any future level calculations. -# If this is false, the player's starter island blocks will count towards their level. +# If false, the player's starter island blocks will count towards their level. # This will reduce CPU if false. zero-new-island-levels: true # @@ -72,3 +72,18 @@ sumteamdeaths: false # Shorthand island level # Shows large level values rounded down, e.g., 10,345 -> 10k shorthand: false +units: + # Shorthand units + kilo: k + mega: M + giga: G + tera: T +# +# Include Shulker Box content in chests in level calculations. +# Will count blocks in Shulker Boxes inside of chests. +# NOTE: include-chests needs to be enabled for this to work!. +include-shulkers-in-chest: false +# +# Disables hooking with other plugins. +# Example: disabled-plugin-hooks: [UltimateStacker, RoseStacker] +disabled-plugin-hooks: [] \ No newline at end of file diff --git a/src/test/java/world/bentobox/level/LevelsManagerTest.java b/src/test/java/world/bentobox/level/LevelsManagerTest.java index c0be60c..e8b0361 100644 --- a/src/test/java/world/bentobox/level/LevelsManagerTest.java +++ b/src/test/java/world/bentobox/level/LevelsManagerTest.java @@ -95,7 +95,7 @@ public class LevelsManagerTest { private World world; @Mock private Player player; - @Mock + private ConfigSettings settings; @Mock private User user; @@ -176,6 +176,7 @@ public void setUp() throws Exception { when(world.getName()).thenReturn("bskyblock-world"); // Settings + settings = new ConfigSettings(); when(addon.getSettings()).thenReturn(settings); // User @@ -334,7 +335,7 @@ public void testGetLevelsData() { @Test public void testFormatLevel() { assertEquals("123456789", lm.formatLevel(123456789L)); - when(settings.isShorthand()).thenReturn(true); + settings.setShorthand(true); assertEquals("123.5M", lm.formatLevel(123456789L)); assertEquals("1.2k", lm.formatLevel(1234L)); assertEquals("123.5G", lm.formatLevel(123456789352L));