Skip to content

Commit f947450

Browse files
Merge pull request #16 from TechnicallyCoded/codex/add-admin-commands-for-bounties
Add admin bounty editing commands
2 parents cf2c447 + b9255ab commit f947450

File tree

9 files changed

+289
-2
lines changed

9 files changed

+289
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.tcoded</groupId>
88
<artifactId>PlayerBountiesPlus</artifactId>
9-
<version>1.4.13</version>
9+
<version>1.4.14</version>
1010
<packaging>jar</packaging>
1111

1212
<name>PlayerBountiesPlus</name>

src/main/java/com/tcoded/playerbountiesplus/command/PlayerBountiesPlusAdminCmd.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
55
import com.tcoded.playerbountiesplus.command.admin.PlayerBountiesPlusReloadCmd;
66
import com.tcoded.playerbountiesplus.command.admin.PlayerBountiesPlusVersionCmd;
7+
import com.tcoded.playerbountiesplus.command.admin.bounty.AdminBountyCmd;
78
import org.bukkit.ChatColor;
89
import org.bukkit.command.Command;
910
import org.bukkit.command.CommandExecutor;
@@ -17,7 +18,7 @@
1718
import java.util.stream.Collectors;
1819

1920
public class PlayerBountiesPlusAdminCmd implements CommandExecutor, TabCompleter {
20-
private static final ArrayList<String> completions = Lists.newArrayList("reload", "version", "help");
21+
private static final ArrayList<String> completions = Lists.newArrayList("reload", "version", "admin", "help");
2122

2223
private final PlayerBountiesPlus plugin;
2324

@@ -40,6 +41,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
4041
return PlayerBountiesPlusReloadCmd.handleCmd(plugin, sender, command, label, args);
4142
case "version":
4243
return PlayerBountiesPlusVersionCmd.handleCmd(plugin, sender, command, label, args);
44+
case "admin":
45+
return AdminBountyCmd.handleCmd(plugin, sender, command, label, args);
4346
default:
4447
sendHelpMsg(sender);
4548
return true;
@@ -52,6 +55,10 @@ private void sendHelpMsg(CommandSender sender) {
5255
"&fAdmin Commands:\n" +
5356
"&f/pbp reload &7- Reload the configuration file and the messages.\n" +
5457
"&f/pbp version &7- Check the version of the plugin.\n" +
58+
"&f/pbp bounty set <player> <amount> &7- Set a player's bounty.\n" +
59+
"&f/pbp bounty add <player> <amount> &7- Add to a player's bounty.\n" +
60+
"&f/pbp bounty remove <player> <amount> &7- Remove from a player's bounty.\n" +
61+
"&f/pbp bounty delete <player> &7- Delete a player's bounty.\n" +
5562
"&f/pbp help &7- Get this message."
5663
));
5764
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.tcoded.playerbountiesplus.command.admin.bounty;
2+
3+
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
4+
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
5+
import org.bukkit.OfflinePlayer;
6+
import org.bukkit.command.Command;
7+
import org.bukkit.command.CommandSender;
8+
9+
import java.util.UUID;
10+
11+
public class AdminBountyAddCmd {
12+
13+
private static final String PERMISSION = "playerbountiesplus.command.playerbountiesplus.admin.add";
14+
15+
public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String label, String[] args) {
16+
if (!sender.hasPermission(PERMISSION)) {
17+
String noPerm = plugin.getLang().getColored("command.no-permission");
18+
String noPermDetailed = plugin.getLang().getColored("command.no-permission-detailed")
19+
.replace("{no-permission-msg}", noPerm)
20+
.replace("{permission}", PERMISSION);
21+
sender.sendMessage(noPermDetailed);
22+
return true;
23+
}
24+
25+
if (args.length < 4) {
26+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.add.missing-args"));
27+
return true;
28+
}
29+
30+
String playerName = args[2];
31+
int amount;
32+
try {
33+
amount = Integer.parseInt(args[3]);
34+
} catch (NumberFormatException ex) {
35+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.add.amount-nan"));
36+
return true;
37+
}
38+
39+
OfflinePlayer target = plugin.getServer().getOfflinePlayer(playerName);
40+
if (target == null || (!target.hasPlayedBefore() && !target.isOnline())) {
41+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.add.player-not-found"));
42+
return true;
43+
}
44+
45+
UUID uuid = target.getUniqueId();
46+
BountyDataManager m = plugin.getBountyDataManager();
47+
int current = m.getBounty(uuid);
48+
int total = current + amount;
49+
m.setBounty(uuid, total);
50+
m.saveBountiesAsync();
51+
52+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.add.success")
53+
.replace("{target}", target.getName())
54+
.replace("{amount}", String.valueOf(amount))
55+
.replace("{total}", String.valueOf(total)));
56+
return true;
57+
}
58+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.tcoded.playerbountiesplus.command.admin.bounty;
2+
3+
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
4+
import org.bukkit.command.Command;
5+
import org.bukkit.command.CommandSender;
6+
7+
public class AdminBountyCmd {
8+
9+
public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String label, String[] args) {
10+
if (args.length < 2) {
11+
sender.sendMessage(plugin.getLang().getColored("command.bounty.no-action"));
12+
return true;
13+
}
14+
15+
String action = args[1].toLowerCase();
16+
switch (action) {
17+
case "set":
18+
return AdminBountySetCmd.handleCmd(plugin, sender, cmd, label, args);
19+
case "add":
20+
return AdminBountyAddCmd.handleCmd(plugin, sender, cmd, label, args);
21+
case "remove":
22+
return AdminBountyRemoveCmd.handleCmd(plugin, sender, cmd, label, args);
23+
case "delete":
24+
return AdminBountyDeleteCmd.handleCmd(plugin, sender, cmd, label, args);
25+
default:
26+
sender.sendMessage(plugin.getLang().getColored("command.bounty.invalid-action"));
27+
return true;
28+
}
29+
}
30+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.tcoded.playerbountiesplus.command.admin.bounty;
2+
3+
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
4+
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
5+
import org.bukkit.OfflinePlayer;
6+
import org.bukkit.command.Command;
7+
import org.bukkit.command.CommandSender;
8+
9+
import java.util.UUID;
10+
11+
public class AdminBountyDeleteCmd {
12+
13+
private static final String PERMISSION = "playerbountiesplus.command.playerbountiesplus.admin.delete";
14+
15+
public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String label, String[] args) {
16+
if (!sender.hasPermission(PERMISSION)) {
17+
String noPerm = plugin.getLang().getColored("command.no-permission");
18+
String noPermDetailed = plugin.getLang().getColored("command.no-permission-detailed")
19+
.replace("{no-permission-msg}", noPerm)
20+
.replace("{permission}", PERMISSION);
21+
sender.sendMessage(noPermDetailed);
22+
return true;
23+
}
24+
25+
if (args.length < 3) {
26+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.delete.missing-args"));
27+
return true;
28+
}
29+
30+
String playerName = args[2];
31+
OfflinePlayer target = plugin.getServer().getOfflinePlayer(playerName);
32+
if (target == null || (!target.hasPlayedBefore() && !target.isOnline())) {
33+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.delete.player-not-found"));
34+
return true;
35+
}
36+
37+
UUID uuid = target.getUniqueId();
38+
BountyDataManager m = plugin.getBountyDataManager();
39+
m.removeBounty(uuid);
40+
m.saveBountiesAsync();
41+
42+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.delete.success")
43+
.replace("{target}", target.getName()));
44+
return true;
45+
}
46+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.tcoded.playerbountiesplus.command.admin.bounty;
2+
3+
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
4+
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
5+
import org.bukkit.OfflinePlayer;
6+
import org.bukkit.command.Command;
7+
import org.bukkit.command.CommandSender;
8+
9+
import java.util.UUID;
10+
11+
public class AdminBountyRemoveCmd {
12+
13+
private static final String PERMISSION = "playerbountiesplus.command.playerbountiesplus.admin.remove";
14+
15+
public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String label, String[] args) {
16+
if (!sender.hasPermission(PERMISSION)) {
17+
String noPerm = plugin.getLang().getColored("command.no-permission");
18+
String noPermDetailed = plugin.getLang().getColored("command.no-permission-detailed")
19+
.replace("{no-permission-msg}", noPerm)
20+
.replace("{permission}", PERMISSION);
21+
sender.sendMessage(noPermDetailed);
22+
return true;
23+
}
24+
25+
if (args.length < 4) {
26+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.remove.missing-args"));
27+
return true;
28+
}
29+
30+
String playerName = args[2];
31+
int amount;
32+
try {
33+
amount = Integer.parseInt(args[3]);
34+
} catch (NumberFormatException ex) {
35+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.remove.amount-nan"));
36+
return true;
37+
}
38+
39+
OfflinePlayer target = plugin.getServer().getOfflinePlayer(playerName);
40+
if (target == null || (!target.hasPlayedBefore() && !target.isOnline())) {
41+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.remove.player-not-found"));
42+
return true;
43+
}
44+
45+
UUID uuid = target.getUniqueId();
46+
BountyDataManager m = plugin.getBountyDataManager();
47+
int current = m.getBounty(uuid);
48+
int total = current - amount;
49+
if (total <= 0) {
50+
m.removeBounty(uuid);
51+
total = 0;
52+
} else {
53+
m.setBounty(uuid, total);
54+
}
55+
m.saveBountiesAsync();
56+
57+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.remove.success")
58+
.replace("{target}", target.getName())
59+
.replace("{amount}", String.valueOf(amount))
60+
.replace("{total}", String.valueOf(total)));
61+
return true;
62+
}
63+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.tcoded.playerbountiesplus.command.admin.bounty;
2+
3+
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
4+
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
5+
import org.bukkit.OfflinePlayer;
6+
import org.bukkit.command.Command;
7+
import org.bukkit.command.CommandSender;
8+
9+
import java.util.UUID;
10+
11+
public class AdminBountySetCmd {
12+
13+
private static final String PERMISSION = "playerbountiesplus.command.playerbountiesplus.admin.set";
14+
15+
public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String label, String[] args) {
16+
if (!sender.hasPermission(PERMISSION)) {
17+
String noPerm = plugin.getLang().getColored("command.no-permission");
18+
String noPermDetailed = plugin.getLang().getColored("command.no-permission-detailed")
19+
.replace("{no-permission-msg}", noPerm)
20+
.replace("{permission}", PERMISSION);
21+
sender.sendMessage(noPermDetailed);
22+
return true;
23+
}
24+
25+
if (args.length < 4) {
26+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.set.missing-args"));
27+
return true;
28+
}
29+
30+
String playerName = args[2];
31+
int amount;
32+
try {
33+
amount = Integer.parseInt(args[3]);
34+
} catch (NumberFormatException ex) {
35+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.set.amount-nan"));
36+
return true;
37+
}
38+
39+
OfflinePlayer target = plugin.getServer().getOfflinePlayer(playerName);
40+
if (target == null || (!target.hasPlayedBefore() && !target.isOnline())) {
41+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.set.player-not-found"));
42+
return true;
43+
}
44+
45+
UUID uuid = target.getUniqueId();
46+
BountyDataManager m = plugin.getBountyDataManager();
47+
m.setBounty(uuid, amount);
48+
m.saveBountiesAsync();
49+
50+
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.set.success")
51+
.replace("{target}", target.getName())
52+
.replace("{bounty}", String.valueOf(amount)));
53+
return true;
54+
}
55+
}

src/main/resources/lang/en_us.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@ command:
1010
reloaded: "&aSuccessfully reloaded the configuration files!"
1111
version:
1212
no-permission: "&7(Version not visible: Missing permission)"
13+
bounty:
14+
set:
15+
missing-args: "&cUsage: /pbp bounty set <player> <amount>"
16+
amount-nan: "&cThat's not a valid number!"
17+
player-not-found: "&cThat player is not online or doesn't exist!"
18+
success: "&aSet {target}'s bounty to {bounty}."
19+
add:
20+
missing-args: "&cUsage: /pbp bounty add <player> <amount>"
21+
amount-nan: "&cThat's not a valid number!"
22+
player-not-found: "&cThat player is not online or doesn't exist!"
23+
success: "&aAdded {amount} bounty to {target}. Total: {total}."
24+
remove:
25+
missing-args: "&cUsage: /pbp bounty remove <player> <amount>"
26+
amount-nan: "&cThat's not a valid number!"
27+
player-not-found: "&cThat player is not online or doesn't exist!"
28+
success: "&aRemoved {amount} bounty from {target}. Total: {total}."
29+
delete:
30+
missing-args: "&cUsage: /pbp bounty delete <player>"
31+
player-not-found: "&cThat player is not online or doesn't exist!"
32+
success: "&aDeleted bounty for {target}."
1333
bounty:
1434
no-action: "&cYou need to specify an action! /bounty <set/top/check>"
1535
invalid-action: "&cThat's not a valid action!"

src/main/resources/plugin.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ permissions:
3232
default: true
3333
playerbountiesplus.command.playerbountiesplus.reload:
3434
default: op
35+
playerbountiesplus.command.playerbountiesplus.admin.set:
36+
default: op
37+
playerbountiesplus.command.playerbountiesplus.admin.add:
38+
default: op
39+
playerbountiesplus.command.playerbountiesplus.admin.remove:
40+
default: op
41+
playerbountiesplus.command.playerbountiesplus.admin.delete:
42+
default: op

0 commit comments

Comments
 (0)