Call a RankChange event for the old island owner in Setowner commands

Fixes https://github.com/BentoBoxWorld/BentoBox/issues/1342
This commit is contained in:
Florian CUNY 2020-05-09 11:39:17 +02:00
parent 937052d378
commit de124ab182
2 changed files with 29 additions and 2 deletions

View File

@ -46,22 +46,32 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
user.sendMessage("general.errors.not-in-team");
return false;
}
if (getIslands().getOwner(getWorld(), targetUUID).equals(targetUUID)) {
UUID previousOwnerUUID = getIslands().getOwner(getWorld(), targetUUID);
if (targetUUID.equals(previousOwnerUUID)) {
user.sendMessage("commands.admin.team.setowner.already-owner", TextVariables.NAME, args.get(0));
return false;
}
// Get the User corresponding to the current owner
User previousOwner = User.getInstance(previousOwnerUUID);
// Make new owner
User target = User.getInstance(targetUUID);
getIslands().setOwner(getWorld(), user, targetUUID);
user.sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, args.get(0));
// Fire event so add-ons know
Island island = getIslands().getIsland(getWorld(), targetUUID);
// Call the setowner event
TeamEvent.builder()
.island(island)
.reason(TeamEvent.Reason.SETOWNER)
.involvedPlayer(targetUUID)
.admin(true)
.build();
// Call the rank change event for the new island owner
IslandEvent.builder()
.island(island)
.involvedPlayer(targetUUID)
@ -69,6 +79,15 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(island.getRank(target), RanksManager.OWNER_RANK)
.build();
// Call the rank change event for the old island owner
IslandEvent.builder()
.island(island)
.involvedPlayer(previousOwnerUUID)
.admin(true)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(RanksManager.OWNER_RANK, island.getRank(previousOwner))
.build();
return true;
}
}

View File

@ -73,6 +73,7 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
return false;
}
getIslands().setOwner(getWorld(), user, targetUUID);
// Call the event for the new owner
IslandEvent.builder()
.island(island)
.involvedPlayer(targetUUID)
@ -80,11 +81,18 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(island.getRank(User.getInstance(targetUUID)), RanksManager.OWNER_RANK)
.build();
// Call the event for the previous owner
IslandEvent.builder()
.island(island)
.involvedPlayer(playerUUID)
.admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(RanksManager.OWNER_RANK, island.getRank(user))
.build();
getIslands().save(island);
return true;
}
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
List<String> options = new ArrayList<>();