Call the TeamSetownerEvent before making the change in AdminTeamSetownerCommand

Fixes https://github.com/BentoBoxWorld/BentoBox/issues/1349
Also call one of the two "RankChange" event before the change (not doing the latter was a bug, actually).
This commit is contained in:
Florian CUNY 2020-05-13 16:17:06 +02:00
parent feab01cde8
commit 783a68a757

View File

@ -55,11 +55,7 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
// 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);
@ -72,6 +68,7 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
.build();
// Call the rank change event for the new island owner
// We need to call it BEFORE the actual change, in order to retain the player's previous rank.
IslandEvent.builder()
.island(island)
.involvedPlayer(targetUUID)
@ -80,7 +77,12 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
.rankChange(island.getRank(target), RanksManager.OWNER_RANK)
.build();
// Make new owner
getIslands().setOwner(getWorld(), user, targetUUID);
user.sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, args.get(0));
// Call the rank change event for the old island owner
// We need to call it AFTER the actual change.
IslandEvent.builder()
.island(island)
.involvedPlayer(previousOwnerUUID)
@ -88,6 +90,7 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(RanksManager.OWNER_RANK, island.getRank(previousOwner))
.build();
return true;
}
}