Skip to content

Commit 5da21b8

Browse files
authored
Merge pull request #328 from BentoBoxWorld/develop
Release 2.16.0
2 parents fd20a9e + dbf3621 commit 5da21b8

File tree

13 files changed

+821
-674
lines changed

13 files changed

+821
-674
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<powermock.version>2.0.9</powermock.version>
6060
<!-- More visible way how to change dependency versions -->
6161
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
62-
<bentobox.version>2.4.0-SNAPSHOT</bentobox.version>
62+
<bentobox.version>2.5.1-SNAPSHOT</bentobox.version>
6363
<!-- Warps addon version -->
6464
<warps.version>1.12.0</warps.version>
6565
<!-- Visit addon version -->
@@ -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/commands/AdminSetInitialLevelCommand.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,20 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>
4646

4747
@Override
4848
public boolean execute(User user, String label, List<String> args) {
49-
String initialLevel = String.valueOf(addon.getManager().getInitialLevel(island));
50-
long lv = Long.parseLong(args.get(1));
49+
long initialLevel = addon.getManager().getInitialLevel(island);
50+
long lv = 0;
51+
if (args.get(1).startsWith("+")) {
52+
String change = args.get(1).substring(1);
53+
lv = initialLevel + Long.parseLong(change);
54+
} else if (args.get(1).startsWith("-")) {
55+
String change = args.get(1).substring(1);
56+
lv = initialLevel - Long.parseLong(change);
57+
} else {
58+
lv = Long.parseLong(args.get(1));
59+
}
5160
addon.getManager().setInitialIslandLevel(island, lv);
52-
user.sendMessage("admin.level.sethandicap.changed", TextVariables.NUMBER, initialLevel, "[new_number]", String.valueOf(lv));
61+
user.sendMessage("admin.level.sethandicap.changed", TextVariables.NUMBER, String.valueOf(initialLevel),
62+
"[new_number]", String.valueOf(lv));
5363
return true;
5464
}
5565

@@ -64,10 +74,20 @@ public boolean canExecute(User user, String label, List<String> args) {
6474
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
6575
return false;
6676
}
67-
// Check value
68-
if (!Util.isInteger(args.get(1), true)) {
69-
user.sendMessage("admin.level.sethandicap.invalid-level");
70-
return false;
77+
// Check if this is a add or remove
78+
if (args.get(1).startsWith("+") || args.get(1).startsWith("-")) {
79+
String change = args.get(1).substring(1);
80+
if (!Util.isInteger(change, true)) {
81+
user.sendMessage("admin.level.sethandicap.invalid-level");
82+
return false;
83+
}
84+
// Value is okay
85+
} else {
86+
// Check value
87+
if (!Util.isInteger(args.get(1), true)) {
88+
user.sendMessage("admin.level.sethandicap.invalid-level");
89+
return false;
90+
}
7191
}
7292
// Check island
7393
island = getAddon().getIslands().getIsland(getWorld(), targetUUID);

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.util.ArrayList;
56
import java.util.Arrays;
67
import java.util.EnumMap;
78
import java.util.HashMap;
9+
import java.util.List;
10+
import java.util.Locale;
811
import java.util.Map;
912
import java.util.Objects;
1013

@@ -26,6 +29,7 @@ public class BlockConfig {
2629
private Map<Material, Integer> blockLimits = new EnumMap<>(Material.class);
2730
private Map<Material, Integer> blockValues = new EnumMap<>(Material.class);
2831
private final Map<World, Map<Material, Integer>> worldBlockValues = new HashMap<>();
32+
private final List<Material> hiddenBlocks;
2933
private Level addon;
3034

3135
/**
@@ -49,6 +53,16 @@ public BlockConfig(Level addon, YamlConfiguration blockValues, File file) throws
4953
if (blockValues.isConfigurationSection("worlds")) {
5054
loadWorlds(blockValues);
5155
}
56+
// Hidden
57+
hiddenBlocks = blockValues.getStringList("hidden-blocks").stream().map(name -> {
58+
try {
59+
return Material.valueOf(name.toUpperCase(Locale.ENGLISH));
60+
61+
} catch (Exception e) {
62+
return null;
63+
}
64+
}).filter(Objects::nonNull).toList();
65+
5266
// All done
5367
blockValues.save(file);
5468
}
@@ -159,5 +173,22 @@ public Integer getValue(World world, Material md) {
159173
return null;
160174
}
161175

176+
/**
177+
* Return true if the block should be hidden
178+
* @param m block material
179+
* @return true if hidden
180+
*/
181+
public boolean isHiddenBlock(Material m) {
182+
return hiddenBlocks.contains(m);
183+
}
184+
185+
/**
186+
* Return true if the block should not be hidden
187+
* @param m block material
188+
* @return false if hidden
189+
*/
190+
public boolean isNotHiddenBlock(Material m) {
191+
return !hiddenBlocks.contains(m);
192+
}
162193

163194
}

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
}

0 commit comments

Comments
 (0)