mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 19:25:12 +01:00
Fire TeamLeave and TeamKick events earlier so they can be canceled.
This commit is contained in:
parent
c9a7804921
commit
ed85dce1b2
@ -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())
|
||||
|
@ -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())
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user