Merge pull request #2323 from BentoBoxWorld/team_fixes

Fix promote and demote #2322
This commit is contained in:
tastybento 2024-03-14 21:13:21 -07:00 committed by GitHub
commit b45c842c2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -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());

View File

@ -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: