From 9f21314818a55ab21d778930828f0d77f8e84ac1 Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 25 Mar 2022 23:29:14 +0200 Subject: [PATCH] Improve team kick command (#1957) The kick command has an unnecessary owner check. As command should be configurable by island owners, then limiting it to an owner is wrong. Add a code that allows kicking only lower-ranked players. Add message that shows who kicked from the island. Add message that shows that rank does not allow to kick. --- .../island/team/IslandTeamKickCommand.java | 16 +++++++++++----- src/main/resources/locales/en-US.yml | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommand.java index 2aab070fa..e89bc3594 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommand.java @@ -42,10 +42,6 @@ public class IslandTeamKickCommand extends ConfirmableCommand { user.sendMessage("general.errors.no-team"); return false; } - if (!user.getUniqueId().equals(getOwner(getWorld(), user))) { - user.sendMessage("general.errors.not-owner"); - return false; - } // Check rank to use command Island island = getIslands().getIsland(getWorld(), user); int rank = Objects.requireNonNull(island).getRank(user); @@ -72,6 +68,14 @@ public class IslandTeamKickCommand extends ConfirmableCommand { user.sendMessage("general.errors.not-in-team"); return false; } + + int targetRank = Objects.requireNonNull(island).getRank(user); + if (rank <= targetRank) { + user.sendMessage("commands.island.team.kick.cannot-kick-rank", + TextVariables.NAME, getPlayers().getName(targetUUID)); + return false; + } + if (!getSettings().isKickConfirmation()) { kick(user, targetUUID); return true; @@ -93,7 +97,9 @@ public class IslandTeamKickCommand extends ConfirmableCommand { if (event.isCancelled()) { return; } - target.sendMessage("commands.island.team.kick.owner-kicked", TextVariables.GAMEMODE, getAddon().getDescription().getName()); + target.sendMessage("commands.island.team.kick.player-kicked", + TextVariables.GAMEMODE, getAddon().getDescription().getName(), + TextVariables.NAME, user.getName()); getIslands().removePlayer(getWorld(), targetUUID); // Clean the target player diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 2da92e94e..51c28f0c9 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -652,8 +652,9 @@ commands: kick: description: "remove a member from your island" parameters: "" - owner-kicked: "&c The owner kicked you from the island in [gamemode]!" + player-kicked: "&c The [name] kicked you from the island in [gamemode]!" cannot-kick: "&c You cannot kick yourself!" + cannot-kick-rank: "&c Your rank does not allow to kick [name]!" success: "&b [name] &a has been kicked from your island." demote: description: "demote a player on your island down a rank"