Skip to content

Commit

Permalink
Feature : Add cancellable IslandKickEvent ! (#1641)
Browse files Browse the repository at this point in the history
* feat(event) : add IslandKickEvent cancellable !

* fix cancelled var !
  • Loading branch information
NewZAZ committed Mar 24, 2023
1 parent 1f4fd00 commit 15d487b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Expand Up @@ -2,15 +2,18 @@

import com.bgsoftware.superiorskyblock.api.island.Island;
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
import org.bukkit.event.Cancellable;

/**
* IslandKickEvent is called when a player is kicked from his island.
*/
public class IslandKickEvent extends IslandEvent {
public class IslandKickEvent extends IslandEvent implements Cancellable {

private final SuperiorPlayer superiorPlayer;
private final SuperiorPlayer targetPlayer;

private boolean cancelled = false;

/**
* The constructor of the event.
*
Expand Down Expand Up @@ -38,4 +41,13 @@ public SuperiorPlayer getTarget() {
return targetPlayer;
}

@Override
public boolean isCancelled() {
return cancelled;
}

@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}
Expand Up @@ -369,10 +369,8 @@ public boolean callIslandJoinEvent(SuperiorPlayer superiorPlayer, Island island,
return callEvent(() -> new IslandJoinEvent(superiorPlayer, island, cause), "islandjoinevent");
}

public void callIslandKickEvent(SuperiorPlayer superiorPlayer, SuperiorPlayer targetPlayer, Island island) {
if (!plugin.getSettings().getDisabledEvents().contains("islandkickevent")) {
callEvent(new IslandKickEvent(superiorPlayer, targetPlayer, island));
}
public boolean callIslandKickEvent(SuperiorPlayer superiorPlayer, SuperiorPlayer targetPlayer, Island island) {
return callEvent(() -> new IslandKickEvent(superiorPlayer, targetPlayer, island), "islandkickevent");
}

public boolean callIslandLeaveEvent(SuperiorPlayer superiorPlayer, Island island,
Expand Down
Expand Up @@ -218,7 +218,8 @@ public static void handleKickPlayer(SuperiorPlayer caller, Island island, Superi
}

public static void handleKickPlayer(SuperiorPlayer caller, String callerName, Island island, SuperiorPlayer target) {
plugin.getEventsBus().callIslandKickEvent(caller, target, island);
if(!plugin.getEventsBus().callIslandKickEvent(caller, target, island))
return;

island.kickMember(target);

Expand Down

0 comments on commit 15d487b

Please sign in to comment.