Skip to content

Commit dbf3621

Browse files
authored
Merge pull request #330 from BentoBoxWorld/329_Add_+/-_option_to_handicap_setting
Adds a +/- tp the sethandicap admin command #329
2 parents 8caf0c4 + 09c83fa commit dbf3621

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

src/main/java/world/bentobox/level/commands/AdminSetInitialLevelCommand.java

+27-7
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/resources/locales/en-US.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ admin:
88
parameters: "<player>"
99
description: "calculate the island level for player"
1010
sethandicap:
11-
parameters: <player> <handicap>
12-
description: "set the island handicap, usually the level of the starter island"
11+
parameters: <player> [+/-]<handicap>
12+
description: |
13+
set or change the island *handicap*
14+
e.g. +10 will remove 10 levels,
15+
30 will set handicap to 30,
16+
-20 will add 20 levels
1317
changed: "&a Initial island handicap changed from [number] to [new_number]."
1418
invalid-level: "&c Invalid handicap. Use an integer."
1519
levelstatus:

0 commit comments

Comments
 (0)