Skip to content

Commit 8caf0c4

Browse files
authored
Merge pull request #327 from BentoBoxWorld/custom_units
Custom units
2 parents e2a62c1 + a09f68e commit 8caf0c4

File tree

5 files changed

+99
-17
lines changed

5 files changed

+99
-17
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<!-- Do not change unless you want different name for local builds. -->
7272
<build.number>-LOCAL</build.number>
7373
<!-- This allows to change between versions. -->
74-
<build.version>2.15.0</build.version>
74+
<build.version>2.16.0</build.version>
7575
<sonar.projectKey>BentoBoxWorld_Level</sonar.projectKey>
7676
<sonar.organization>bentobox-world</sonar.organization>
7777
<sonar.host.url>https://sonarcloud.io</sonar.host.url>

src/main/java/world/bentobox/level/LevelsManager.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,8 @@
3636

3737
public class LevelsManager {
3838
private static final String INTOPTEN = "intopten";
39-
private static final TreeMap<BigInteger, String> LEVELS;
39+
private static final TreeMap<BigInteger, String> LEVELS = new TreeMap<>();
4040
private static final BigInteger THOUSAND = BigInteger.valueOf(1000);
41-
static {
42-
LEVELS = new TreeMap<>();
43-
44-
LEVELS.put(THOUSAND, "k");
45-
LEVELS.put(THOUSAND.pow(2), "M");
46-
LEVELS.put(THOUSAND.pow(3), "G");
47-
LEVELS.put(THOUSAND.pow(4), "T");
48-
}
4941
private final Level addon;
5042

5143
// Database handler for level data
@@ -67,6 +59,12 @@ public LevelsManager(Level addon) {
6759
levelsCache = new HashMap<>();
6860
// Initialize top ten lists
6961
topTenLists = new ConcurrentHashMap<>();
62+
// Units
63+
LEVELS.put(THOUSAND, addon.getSettings().getKilo());
64+
LEVELS.put(THOUSAND.pow(2), addon.getSettings().getMega());
65+
LEVELS.put(THOUSAND.pow(3), addon.getSettings().getGiga());
66+
LEVELS.put(THOUSAND.pow(4), addon.getSettings().getTera());
67+
7068
}
7169

7270
public void migrate() {

src/main/java/world/bentobox/level/config/ConfigSettings.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.Collections;
55
import java.util.List;
6+
import java.util.Objects;
67

78
import world.bentobox.bentobox.BentoBox;
89
import world.bentobox.bentobox.api.configuration.ConfigComment;
@@ -120,6 +121,17 @@ public class ConfigSettings implements ConfigObject {
120121
@ConfigComment("Shows large level values rounded down, e.g., 10,345 -> 10k")
121122
@ConfigEntry(path = "shorthand")
122123
private boolean shorthand = false;
124+
125+
@ConfigComment("Shorthand units")
126+
@ConfigEntry(path = "units.kilo")
127+
private String kilo = "k";
128+
@ConfigEntry(path = "units.mega")
129+
private String mega = "M";
130+
@ConfigEntry(path = "units.giga")
131+
private String giga = "G";
132+
@ConfigEntry(path = "units.tera")
133+
private String tera = "T";
134+
123135
@ConfigComment("")
124136
@ConfigComment("Include Shulker Box content in chests in level calculations.")
125137
@ConfigComment("Will count blocks in Shulker Boxes inside of chests.")
@@ -419,4 +431,60 @@ public List<String> getDisabledPluginHooks() {
419431
public void setDisabledPluginHooks(List<String> disabledPluginHooks) {
420432
this.disabledPluginHooks = disabledPluginHooks;
421433
}
434+
435+
/**
436+
* @return the kilo
437+
*/
438+
public String getKilo() {
439+
return Objects.requireNonNullElse(kilo, "k");
440+
}
441+
442+
/**
443+
* @param kilo the kilo to set
444+
*/
445+
public void setKilo(String kilo) {
446+
this.kilo = kilo;
447+
}
448+
449+
/**
450+
* @return the mega
451+
*/
452+
public String getMega() {
453+
return Objects.requireNonNullElse(mega, "M");
454+
}
455+
456+
/**
457+
* @param mega the mega to set
458+
*/
459+
public void setMega(String mega) {
460+
this.mega = mega;
461+
}
462+
463+
/**
464+
* @return the giga
465+
*/
466+
public String getGiga() {
467+
return Objects.requireNonNullElse(giga, "G");
468+
}
469+
470+
/**
471+
* @param giga the giga to set
472+
*/
473+
public void setGiga(String giga) {
474+
this.giga = giga;
475+
}
476+
477+
/**
478+
* @return the tera
479+
*/
480+
public String getTera() {
481+
return Objects.requireNonNullElse(tera, "T");
482+
}
483+
484+
/**
485+
* @param tera the tera to set
486+
*/
487+
public void setTera(String tera) {
488+
this.tera = tera;
489+
}
422490
}

src/main/resources/config.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
# Disabled Game Mode Addons
55
# Level will NOT hook into these game mode addons.
66
disabled-game-modes: []
7-
#
7+
#
88
# When executing level command from console, should a report be shown?
99
log-report-to-console: true
10-
#
10+
#
1111
# Number of concurrent island calculations
1212
# If your CPU can handle it, you can run parallel island calcs if there are more than one in the queue
1313
concurrent-island-calcs: 1
14-
#
14+
#
1515
# Island level calculation timeout in minutes.
1616
# If an island takes longer that this time to calculate, then the calculation will abort.
1717
# Generally, calculation should only take a few seconds, so if this ever triggers then something is not right.
1818
calculation-timeout: 5
19-
#
19+
#
2020
# Zero island levels on new island or island reset
2121
# If true, Level will calculate the starter island's level and remove it from any future level calculations.
22-
# If this is false, the player's starter island blocks will count towards their level.
22+
# If false, the player's starter island blocks will count towards their level.
2323
# This will reduce CPU if false.
2424
zero-new-island-levels: true
2525
#
@@ -72,3 +72,18 @@ sumteamdeaths: false
7272
# Shorthand island level
7373
# Shows large level values rounded down, e.g., 10,345 -> 10k
7474
shorthand: false
75+
units:
76+
# Shorthand units
77+
kilo: k
78+
mega: M
79+
giga: G
80+
tera: T
81+
#
82+
# Include Shulker Box content in chests in level calculations.
83+
# Will count blocks in Shulker Boxes inside of chests.
84+
# NOTE: include-chests needs to be enabled for this to work!.
85+
include-shulkers-in-chest: false
86+
#
87+
# Disables hooking with other plugins.
88+
# Example: disabled-plugin-hooks: [UltimateStacker, RoseStacker]
89+
disabled-plugin-hooks: []

src/test/java/world/bentobox/level/LevelsManagerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public class LevelsManagerTest {
9595
private World world;
9696
@Mock
9797
private Player player;
98-
@Mock
98+
9999
private ConfigSettings settings;
100100
@Mock
101101
private User user;
@@ -176,6 +176,7 @@ public void setUp() throws Exception {
176176
when(world.getName()).thenReturn("bskyblock-world");
177177

178178
// Settings
179+
settings = new ConfigSettings();
179180
when(addon.getSettings()).thenReturn(settings);
180181

181182
// User
@@ -334,7 +335,7 @@ public void testGetLevelsData() {
334335
@Test
335336
public void testFormatLevel() {
336337
assertEquals("123456789", lm.formatLevel(123456789L));
337-
when(settings.isShorthand()).thenReturn(true);
338+
settings.setShorthand(true);
338339
assertEquals("123.5M", lm.formatLevel(123456789L));
339340
assertEquals("1.2k", lm.formatLevel(1234L));
340341
assertEquals("123.5G", lm.formatLevel(123456789352L));

0 commit comments

Comments
 (0)