Skip to content

Commit

Permalink
Feature : Add cancellable IslandBanEvent (#1368)
Browse files Browse the repository at this point in the history
* 🎨 Add IslandBanEvent cancellable !

* Fix error ❌

* 🎨 Optimize line when event call !

* 🎨 Change format of calling event !
  • Loading branch information
NewZAZ committed Sep 23, 2022
1 parent e2ff574 commit fdc9876
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;

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

private final SuperiorPlayer superiorPlayer;
private final SuperiorPlayer targetPlayer;

private boolean cancelled;

/**
* 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 @@ -67,10 +67,8 @@ public boolean callBlockUnstackEvent(Block block, Player player, int originalAmo
"blockunstackevent");
}

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

public EventResult<String> callIslandBankDepositEvent(SuperiorPlayer superiorPlayer, Island island, BigDecimal amount) {
Expand Down
Expand Up @@ -257,7 +257,8 @@ public static boolean checkBanRestrictions(SuperiorPlayer superiorPlayer, Island
}

public static void handleBanPlayer(SuperiorPlayer caller, Island island, SuperiorPlayer target) {
plugin.getEventsBus().callIslandBanEvent(caller, target, island);
if (plugin.getEventsBus().callIslandBanEvent(caller, target, island))
return;

island.banMember(target, caller);

Expand Down

0 comments on commit fdc9876

Please sign in to comment.