Skip to content

Commit

Permalink
Merge pull request #327 from BentoBoxWorld/custom_units
Browse files Browse the repository at this point in the history
Custom units
  • Loading branch information
tastybento authored Aug 29, 2024
2 parents e2a62c1 + a09f68e commit 8caf0c4
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>2.15.0</build.version>
<build.version>2.16.0</build.version>
<sonar.projectKey>BentoBoxWorld_Level</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/world/bentobox/level/LevelsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,8 @@

public class LevelsManager {
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);
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
Expand All @@ -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() {
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/world/bentobox/level/config/ConfigSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -419,4 +431,60 @@ public List<String> getDisabledPluginHooks() {
public void setDisabledPluginHooks(List<String> 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;
}
}
25 changes: 20 additions & 5 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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: []
5 changes: 3 additions & 2 deletions src/test/java/world/bentobox/level/LevelsManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class LevelsManagerTest {
private World world;
@Mock
private Player player;
@Mock

private ConfigSettings settings;
@Mock
private User user;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 8caf0c4

Please sign in to comment.