From 6db04f872b7f5e9939f5df2f21bdf70bb8442302 Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 14 Mar 2024 18:16:09 -0700 Subject: [PATCH] Fix promote and demote #2322 --- .../island/team/IslandTeamPromoteCommand.java | 13 +++++++++++-- src/main/resources/locales/en-US.yml | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamPromoteCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamPromoteCommand.java index eab48723a..e35e8aeea 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamPromoteCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamPromoteCommand.java @@ -15,6 +15,9 @@ import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.util.Util; +/** + * Handle promotion and demotion + */ public class IslandTeamPromoteCommand extends CompositeCommand { private User target; @@ -45,7 +48,7 @@ public class IslandTeamPromoteCommand extends CompositeCommand { showHelp(this, user); return false; } - + // Check if the user has a team if (!getIslands().inTeam(getWorld(), user.getUniqueId())) { user.sendMessage("general.errors.no-team"); return false; @@ -65,6 +68,11 @@ public class IslandTeamPromoteCommand extends CompositeCommand { user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0)); return false; } + // Check that target is a member of this island + if (!island.getMemberSet().contains(target.getUniqueId())) { + user.sendMessage("commands.island.team.promote.errors.must-be-member"); + return false; + } // Check if the user is not trying to promote/ demote himself if (target.equals(user)) { if (this.getLabel().equals("promote")) { @@ -100,7 +108,8 @@ public class IslandTeamPromoteCommand extends CompositeCommand { if (this.getLabel().equals("promote")) { int nextRank = RanksManager.getInstance().getRankUpValue(currentRank); // Stop short of owner - if (nextRank != RanksManager.OWNER_RANK && nextRank > currentRank) { + if (nextRank < RanksManager.OWNER_RANK && currentRank >= RanksManager.MEMBER_RANK + && nextRank > currentRank) { island.setRank(target, nextRank); String rankName = user.getTranslation(RanksManager.getInstance().getRank(nextRank)); user.sendMessage("commands.island.team.promote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName, TextVariables.DISPLAY_NAME, target.getDisplayName()); diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 2bbbd78bb..61af1f1a1 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -786,6 +786,7 @@ commands: errors: cant-demote-yourself: '&c You can''t demote yourself!' cant-demote: '&c You can''t demote higher ranks!' + must-be-member: '&c Player must be an island member!' failure: '&c Player cannot be demoted any further!' success: '&a Demoted [name] to [rank]' promote: @@ -794,6 +795,7 @@ commands: errors: cant-promote-yourself: '&c You can''t promote yourself!' cant-promote: '&c You can''t promote above your rank!' + must-be-member: '&c Player must be an island member!' failure: '&c Player cannot be promoted any further!' success: '&a Promoted [name] to [rank]' setowner: