Fire TeamLeave and TeamKick events earlier so they can be canceled.

This commit is contained in:
tastybento 2021-02-20 11:13:55 -08:00
parent c9a7804921
commit ed85dce1b2
3 changed files with 27 additions and 13 deletions

View File

@ -11,6 +11,7 @@ import org.bukkit.OfflinePlayer;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
@ -82,19 +83,23 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
private void kick(User user, UUID targetUUID) {
User target = User.getInstance(targetUUID);
target.sendMessage("commands.island.team.kick.owner-kicked", TextVariables.GAMEMODE, getAddon().getDescription().getName());
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
// Fire event
IslandBaseEvent event = TeamEvent.builder()
.island(oldIsland)
.reason(TeamEvent.Reason.KICK)
.involvedPlayer(targetUUID)
.build();
if (event.isCancelled()) {
return;
}
target.sendMessage("commands.island.team.kick.owner-kicked", TextVariables.GAMEMODE, getAddon().getDescription().getName());
getIslands().removePlayer(getWorld(), targetUUID);
// Clean the target player
getPlayers().cleanLeavingPlayer(getWorld(), target, true);
user.sendMessage("commands.island.team.kick.success", TextVariables.NAME, target.getName());
// Fire event
TeamEvent.builder()
.island(oldIsland)
.reason(TeamEvent.Reason.KICK)
.involvedPlayer(targetUUID)
.build();
IslandEvent.builder()
.island(oldIsland)
.involvedPlayer(user.getUniqueId())

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
@ -66,6 +67,15 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
private void leave(User user) {
Island island = getIslands().getIsland(getWorld(), user);
// Fire event
IslandBaseEvent event = TeamEvent.builder()
.island(island)
.reason(TeamEvent.Reason.LEAVE)
.involvedPlayer(user.getUniqueId())
.build();
if (event.isCancelled()) {
return;
}
UUID ownerUUID = getIslands().getOwner(getWorld(), user.getUniqueId());
if (ownerUUID != null) {
User.getInstance(ownerUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName());
@ -87,12 +97,6 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
showResets(user);
}
user.sendMessage("commands.island.team.leave.success");
// Fire event
TeamEvent.builder()
.island(island)
.reason(TeamEvent.Reason.LEAVE)
.involvedPlayer(user.getUniqueId())
.build();
IslandEvent.builder()
.island(island)
.involvedPlayer(user.getUniqueId())

View File

@ -8,6 +8,11 @@ import org.bukkit.event.HandlerList;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
/**
* Fired when player leaves an island.
* @author tastybento
*
*/
public class TeamLeaveEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();