mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-05 16:08:46 +01:00
Implemented optional argument to AdminGetrankCommand to specify which island to perform the check on.
Implements https://github.com/BentoBoxWorld/BentoBox/issues/1106 Updated en-US + added 'general.errors.player-is-not-owner' message.
This commit is contained in:
parent
abf5e1f071
commit
0559a86e8d
@ -24,6 +24,7 @@ public class AdminGetrankCommand extends CompositeCommand {
|
||||
|
||||
private Island island;
|
||||
private @Nullable UUID targetUUID;
|
||||
private @Nullable UUID ownerUUID;
|
||||
|
||||
public AdminGetrankCommand(CompositeCommand adminCommand) {
|
||||
super(adminCommand, "getrank");
|
||||
@ -39,7 +40,7 @@ public class AdminGetrankCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public boolean canExecute(User user, String label, List<String> args) {
|
||||
if (args.size() != 1) {
|
||||
if (args.size() != 1 && args.size() != 2) {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
@ -50,11 +51,33 @@ public class AdminGetrankCommand extends CompositeCommand {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
return false;
|
||||
}
|
||||
island = getIslands().getIsland(getWorld(), targetUUID);
|
||||
if (island == null) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
|
||||
if (args.size() == 1) {
|
||||
// We want to get the rank of the player on the island he is part of.
|
||||
// So we have to make sure that this player has an island
|
||||
if (!getIslands().hasIsland(getWorld(), targetUUID) && !getIslands().inTeam(getWorld(), targetUUID)) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
|
||||
island = getIslands().getIsland(getWorld(), targetUUID);
|
||||
} else {
|
||||
// We want to get the rank of the player on the island of the owner we specify.
|
||||
// So we have to make sure that the island owner actually owns an island
|
||||
ownerUUID = getPlayers().getUUID(args.get(1));
|
||||
if (ownerUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(1));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!getPlugin().getIslands().hasIsland(getWorld(), ownerUUID)) {
|
||||
user.sendMessage("general.errors.player-is-not-owner", TextVariables.NAME, args.get(1));
|
||||
return false;
|
||||
}
|
||||
|
||||
island = getIslands().getIsland(getWorld(), ownerUUID);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -64,9 +87,9 @@ public class AdminGetrankCommand extends CompositeCommand {
|
||||
RanksManager rm = getPlugin().getRanksManager();
|
||||
User target = User.getInstance(targetUUID);
|
||||
int currentRank = island.getRank(target);
|
||||
user.sendMessage("commands.admin.getrank.rank-is", TextVariables.RANK, user.getTranslation(rm.getRank(currentRank)));
|
||||
user.sendMessage("commands.admin.getrank.rank-is", TextVariables.RANK, user.getTranslation(rm.getRank(currentRank)),
|
||||
TextVariables.NAME, getPlayers().getName(island.getOwner()));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,7 +98,7 @@ public class AdminGetrankCommand extends CompositeCommand {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
String lastArg = args.get(args.size() - 1);
|
||||
List<String> options = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ public class AdminSetrankCommand extends CompositeCommand {
|
||||
}
|
||||
|
||||
if (!getPlugin().getIslands().hasIsland(getWorld(), ownerUUID)) {
|
||||
user.sendMessage("commands.admin.setrank.name-not-owner", TextVariables.NAME, args.get(2));
|
||||
user.sendMessage("general.errors.player-is-not-owner", TextVariables.NAME, args.get(2));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ general:
|
||||
already-have-island: "&c You already have an island!"
|
||||
no-safe-location-found: "&c Could not find a safe spot to teleport you to on the island."
|
||||
not-owner: "&c You are not the owner of the island!"
|
||||
player-is-not-owner: "&b [name] &c is not the owner of an island!"
|
||||
not-in-team: "&c That player is not in your team!"
|
||||
offline-player: "&c That player is offline or doesn't exist."
|
||||
unknown-player: "&c [name] is an unknown player!"
|
||||
@ -223,16 +224,15 @@ commands:
|
||||
description: "teleport to a player's island"
|
||||
manual: "&c No safe warp found! Manually tp near to &b [location] &c and check it out"
|
||||
getrank:
|
||||
parameters: "<player>"
|
||||
description: "get a player's rank on their island"
|
||||
rank-is: "&a Rank is [rank] on their island."
|
||||
parameters: "<player> [island owner]"
|
||||
description: "get a player's rank on their island or the island of the owner"
|
||||
rank-is: "&a Rank is &b [rank] &a on &b [name]&a 's island."
|
||||
setrank:
|
||||
parameters: "<player> <rank> [island owner]"
|
||||
description: "set a player's rank on their island or the island of the owner"
|
||||
unknown-rank: "&c Unknown rank!"
|
||||
not-possible: "&c Rank must be higher than visitor."
|
||||
rank-set: "&a Rank set from &b [from] &a to &b [to] &a on &b [name]&a 's island."
|
||||
name-not-owner: "&b [name] &c is not the owner of an island."
|
||||
setspawn:
|
||||
description: "set an island as spawn for this world"
|
||||
already-spawn: "&c This island is already a spawn!"
|
||||
|
@ -179,6 +179,7 @@ public class AdminGetrankCommandTest {
|
||||
when(pm.getUUID(any())).thenReturn(targetUUID);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
||||
when(user.getTranslation(anyString())).thenReturn("member");
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
assertTrue(c.canExecute(user, "", Collections.singletonList("tastybento")));
|
||||
}
|
||||
|
||||
@ -192,10 +193,14 @@ public class AdminGetrankCommandTest {
|
||||
testCanExecuteKnownPlayerHasIslandSuccess();
|
||||
when(island.getRank(any())).thenReturn(RanksManager.SUB_OWNER_RANK);
|
||||
when(user.getTranslation(any())).thenReturn("sub-owner", "sub-owner");
|
||||
when(island.getOwner()).thenReturn(targetUUID);
|
||||
when(pm.getName(targetUUID)).thenReturn("tastybento");
|
||||
assertTrue(c.execute(user, "", Collections.singletonList("tastybento")));
|
||||
verify(user).sendMessage(eq("commands.admin.getrank.rank-is"),
|
||||
eq("[rank]"),
|
||||
eq("sub-owner"));
|
||||
eq("sub-owner"),
|
||||
eq("[name]"),
|
||||
eq("tastybento"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user