🟩 implemented AuctionPlayerBanEvent

Took 35 seconds
This commit is contained in:
Kiran Hart 2024-10-31 12:30:05 -04:00
parent ba9793835a
commit e81ee728ca
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
2 changed files with 40 additions and 1 deletions

View File

@ -1,4 +1,32 @@
package ca.tweetzy.auctionhouse.api.event; 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;
}
} }

View File

@ -3,10 +3,12 @@ package ca.tweetzy.auctionhouse.model.manager;
import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.ban.Ban; import ca.tweetzy.auctionhouse.api.ban.Ban;
import ca.tweetzy.auctionhouse.api.ban.BanType; 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.manager.KeyValueManager;
import ca.tweetzy.auctionhouse.api.sync.SynchronizeResult; import ca.tweetzy.auctionhouse.api.sync.SynchronizeResult;
import ca.tweetzy.auctionhouse.impl.AuctionBan; import ca.tweetzy.auctionhouse.impl.AuctionBan;
import lombok.NonNull; import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -61,9 +63,18 @@ public final class BanManager extends KeyValueManager<UUID, Ban> {
public void registerBan(@NonNull final Ban ban, final Consumer<Boolean> created) { public void registerBan(@NonNull final Ban ban, final Consumer<Boolean> created) {
if (this.managerContent.containsKey(ban.getId())) return; if (this.managerContent.containsKey(ban.getId())) return;
final AuctionPlayerBanEvent banPlayerEvent = new AuctionPlayerBanEvent(ban);
if (banPlayerEvent.isCancelled()) {
created.accept(false);
return;
}
ban.store(storedBan -> { ban.store(storedBan -> {
if (storedBan != null) { if (storedBan != null) {
add(storedBan.getId(), storedBan); add(storedBan.getId(), storedBan);
// call event
AuctionHouse.newChain().sync(() -> Bukkit.getPluginManager().callEvent(banPlayerEvent)).execute();
if (created != null) if (created != null)
created.accept(true); created.accept(true);
} else { } else {