Custom units for shorthand levels added to config.yml

This commit is contained in:
tastybento 2024-08-29 08:24:55 -07:00
parent 48fbd4b38d
commit a09f68e8af
4 changed files with 98 additions and 16 deletions

View File

@ -36,16 +36,8 @@ import world.bentobox.level.util.CachedData;
public class LevelsManager { public class LevelsManager {
private static final String INTOPTEN = "intopten"; private static final String INTOPTEN = "intopten";
private static final TreeMap<BigInteger, String> LEVELS; private static final TreeMap<BigInteger, String> LEVELS = new TreeMap<>();
private static final BigInteger THOUSAND = BigInteger.valueOf(1000); 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; private final Level addon;
// Database handler for level data // Database handler for level data
@ -67,6 +59,12 @@ public class LevelsManager {
levelsCache = new HashMap<>(); levelsCache = new HashMap<>();
// Initialize top ten lists // Initialize top ten lists
topTenLists = new ConcurrentHashMap<>(); 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() { public void migrate() {

View File

@ -3,6 +3,7 @@ package world.bentobox.level.config;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.configuration.ConfigComment; 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") @ConfigComment("Shows large level values rounded down, e.g., 10,345 -> 10k")
@ConfigEntry(path = "shorthand") @ConfigEntry(path = "shorthand")
private boolean shorthand = false; 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("")
@ConfigComment("Include Shulker Box content in chests in level calculations.") @ConfigComment("Include Shulker Box content in chests in level calculations.")
@ConfigComment("Will count blocks in Shulker Boxes inside of chests.") @ConfigComment("Will count blocks in Shulker Boxes inside of chests.")
@ -419,4 +431,60 @@ public class ConfigSettings implements ConfigObject {
public void setDisabledPluginHooks(List<String> disabledPluginHooks) { public void setDisabledPluginHooks(List<String> disabledPluginHooks) {
this.disabledPluginHooks = 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;
}
} }

View File

@ -4,22 +4,22 @@
# Disabled Game Mode Addons # Disabled Game Mode Addons
# Level will NOT hook into these game mode addons. # Level will NOT hook into these game mode addons.
disabled-game-modes: [] disabled-game-modes: []
# #
# When executing level command from console, should a report be shown? # When executing level command from console, should a report be shown?
log-report-to-console: true log-report-to-console: true
# #
# Number of concurrent island calculations # 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 # 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 concurrent-island-calcs: 1
# #
# Island level calculation timeout in minutes. # Island level calculation timeout in minutes.
# If an island takes longer that this time to calculate, then the calculation will abort. # 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. # Generally, calculation should only take a few seconds, so if this ever triggers then something is not right.
calculation-timeout: 5 calculation-timeout: 5
# #
# Zero island levels on new island or island reset # 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 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. # This will reduce CPU if false.
zero-new-island-levels: true zero-new-island-levels: true
# #
@ -72,3 +72,18 @@ sumteamdeaths: false
# Shorthand island level # Shorthand island level
# Shows large level values rounded down, e.g., 10,345 -> 10k # Shows large level values rounded down, e.g., 10,345 -> 10k
shorthand: false 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: []

View File

@ -95,7 +95,7 @@ public class LevelsManagerTest {
private World world; private World world;
@Mock @Mock
private Player player; private Player player;
@Mock
private ConfigSettings settings; private ConfigSettings settings;
@Mock @Mock
private User user; private User user;
@ -176,6 +176,7 @@ public class LevelsManagerTest {
when(world.getName()).thenReturn("bskyblock-world"); when(world.getName()).thenReturn("bskyblock-world");
// Settings // Settings
settings = new ConfigSettings();
when(addon.getSettings()).thenReturn(settings); when(addon.getSettings()).thenReturn(settings);
// User // User
@ -334,7 +335,7 @@ public class LevelsManagerTest {
@Test @Test
public void testFormatLevel() { public void testFormatLevel() {
assertEquals("123456789", lm.formatLevel(123456789L)); assertEquals("123456789", lm.formatLevel(123456789L));
when(settings.isShorthand()).thenReturn(true); settings.setShorthand(true);
assertEquals("123.5M", lm.formatLevel(123456789L)); assertEquals("123.5M", lm.formatLevel(123456789L));
assertEquals("1.2k", lm.formatLevel(1234L)); assertEquals("1.2k", lm.formatLevel(1234L));
assertEquals("123.5G", lm.formatLevel(123456789352L)); assertEquals("123.5G", lm.formatLevel(123456789352L));