mirror of
https://github.com/kiranhart/Auction-House.git
synced 2024-11-21 05:15:11 +01:00
🟩 implemented AuctionPlayerBanEvent
Took 35 seconds
This commit is contained in:
parent
ba9793835a
commit
e81ee728ca
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<UUID, Ban> {
|
||||
public void registerBan(@NonNull final Ban ban, final Consumer<Boolean> 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user