Added more API and features for Events

This commit is contained in:
Sn0wStorm
2019-11-13 22:07:22 +01:00
parent 48a15a0e82
commit 3332354846
29 changed files with 672 additions and 224 deletions
@@ -5,11 +5,14 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/*
/**
* A Barrel is being destroyed by something, may not be by a Player
* A BarrelRemoveEvent will be called after this, if this is not cancelled
* Use the BarrelRemoveEvent to monitor any and all barrels being removed in a non cancellable way
* Cancelling the Event will stop the barrel from being destroyed
*/
public class BarrelDestroyEvent extends BarrelEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
@@ -30,42 +33,79 @@ public class BarrelDestroyEvent extends BarrelEvent implements Cancellable {
return cancelled;
}
/**
* Cancelling the Event will stop the barrel from being destroyed.
* Any Blocks that are part of the barrel will not be destroyed
*/
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
/**
* @return The Block of the Barrel that was broken
*/
public Block getBroken() {
return broken;
}
/**
* @return The Reason of destruction of this barrel, see Reason
*/
public Reason getReason() {
return reason;
}
/**
* If a Player was recorded destroying the barrel
*/
public boolean hasPlayer() {
return player != null;
}
// MAY BE NULL if no Player is involved
/**
* @return The Player, Null if no Player is involved
*/
@Nullable
public Player getPlayerOptional() {
return player;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
// Required by Bukkit
public static HandlerList getHandlerList() {
return handlers;
}
public enum Reason {
PLAYER, // A Player Broke the Barrel
BROKEN, // A Block was broken by something
BURNED, // A Block burned away
EXPLODED, // The Barrel exploded somehow
UNKNOWN // The Barrel was broken somehow else
/**
* A Player Broke the Barrel
*/
PLAYER,
/**
* A Block was broken by something
*/
BROKEN,
/**
* A Block burned away
*/
BURNED,
/**
* The Barrel exploded somehow
*/
EXPLODED,
/**
* The Barrel was broken somehow else
*/
UNKNOWN
}
}