diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionPlayerBanEvent.java b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionPlayerBanEvent.java index 04bd227..52f240b 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionPlayerBanEvent.java +++ b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionPlayerBanEvent.java @@ -1,4 +1,32 @@ package ca.tweetzy.auctionhouse.api.event; -public final class AuctionPlayerBanEvent { +import ca.tweetzy.auctionhouse.api.ban.Ban; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public final class AuctionPlayerBanEvent extends Event implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + + @Setter @Getter + private boolean cancelled; + + @Getter + private final Ban ban; + + public AuctionPlayerBanEvent(@NonNull final Ban ban) { + this.ban = ban; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/model/manager/BanManager.java b/src/main/java/ca/tweetzy/auctionhouse/model/manager/BanManager.java index c272cd6..466ffe0 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/model/manager/BanManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/model/manager/BanManager.java @@ -3,10 +3,12 @@ package ca.tweetzy.auctionhouse.model.manager; import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.api.ban.Ban; import ca.tweetzy.auctionhouse.api.ban.BanType; +import ca.tweetzy.auctionhouse.api.event.AuctionPlayerBanEvent; import ca.tweetzy.auctionhouse.api.manager.KeyValueManager; import ca.tweetzy.auctionhouse.api.sync.SynchronizeResult; import ca.tweetzy.auctionhouse.impl.AuctionBan; import lombok.NonNull; +import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -61,9 +63,18 @@ public final class BanManager extends KeyValueManager { public void registerBan(@NonNull final Ban ban, final Consumer created) { if (this.managerContent.containsKey(ban.getId())) return; + final AuctionPlayerBanEvent banPlayerEvent = new AuctionPlayerBanEvent(ban); + if (banPlayerEvent.isCancelled()) { + created.accept(false); + return; + } + ban.store(storedBan -> { if (storedBan != null) { add(storedBan.getId(), storedBan); + // call event + AuctionHouse.newChain().sync(() -> Bukkit.getPluginManager().callEvent(banPlayerEvent)).execute(); + if (created != null) created.accept(true); } else {