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
@@ -9,6 +9,9 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* The Brewery Config was reloaded
*/
public class ConfigLoadEvent extends Event {
private static final HandlerList handlers = new HandlerList();
@@ -39,4 +42,9 @@ public class ConfigLoadEvent extends Event {
public HandlerList getHandlers() {
return handlers;
}
// Required by Bukkit
public static HandlerList getHandlerList() {
return handlers;
}
}
@@ -11,8 +11,10 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/*
/**
* Player adding an ingredient to a cauldron
* Always one item added at a time
* If needed use the caudrons add method to manually add more Items
@@ -51,36 +53,55 @@ public class IngedientAddEvent extends PlayerEvent implements Cancellable {
return rItem;
}
// Get the item currently being added to the cauldron by the player
// Can be changed directly (mutable) or with the setter Method
// The amount is ignored and always one added
/**
* Get the item currently being added to the cauldron by the player
* Can be changed directly (mutable) or with the setter Method
* The amount is ignored and always one added
*
* @return The item being added
*/
public ItemStack getIngredient() {
return ingredient;
}
// Set the ingredient added to the cauldron to something else
// Will always be accepted, even when not in a recipe or the cooked list
// The amount is ignored and always one added
// This also recalculates the recipeItem!
/**
* Set the ingredient added to the cauldron to something else
* Will always be accepted, even when not in a recipe or the cooked lis
* The amount is ignored and always one added
* This also recalculates the recipeItem!
*
* @param ingredient The item to add instead
*/
public void setIngredient(ItemStack ingredient) {
this.ingredient = ingredient;
// The Ingredient has been changed. Recalculate RecipeItem!
rItem = RecipeItem.getMatchingRecipeItem(ingredient, true);
}
// If the amount of the item in the players hand should be decreased
// Default true
/**
* If the amount of the item in the players hand should be decreased
* Default true
*/
public boolean willTakeItem() {
return takeItem;
}
// Set if the amount of the item in the players hand should be decreased
/**
* Set if the amount of the item in the players hand should be decreased
*
* @param takeItem if the item amount in the hand should be decreased
*/
public void setTakeItem(boolean takeItem) {
this.takeItem = takeItem;
}
// Get the BlockData of the Cauldron
// May be null if the Cauldron does not exist anymore
/**
* Get the BlockData of the Cauldron
* May be null if the Cauldron does not exist anymore
*
* @return The BlockData of the cauldron
*/
@Nullable
public Levelled getCauldronData() {
BlockData data = block.getBlockData();
if (data instanceof Levelled) {
@@ -89,9 +110,13 @@ public class IngedientAddEvent extends PlayerEvent implements Cancellable {
return null;
}
// Get the Water Fill level of the Cauldron
// 0 = empty, 1 = something in, 2 = full
// Can use BCauldron.EMPTY, BCauldron.SOME, BCauldron.FULL
/**
* Get the water fill level of the Cauldron
* 0 = empty, 1 = something in, 2 = full
* Can use BCauldron.EMPTY, BCauldron.SOME, BCauldron.FULL
*
* @return The fill level as a byte 0-2
*/
public byte getFillLevel() {
return LegacyUtil.getFillLevel(block);
}
@@ -101,16 +126,21 @@ public class IngedientAddEvent extends PlayerEvent implements Cancellable {
return cancelled;
}
/**
* If the event is cancelled, no item will be added or taken from the player
*/
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
// Required by Bukkit
public static HandlerList getHandlerList() {
return handlers;
}
@@ -1,54 +0,0 @@
package com.dre.brewery.api.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.potion.PotionEffect;
import java.util.List;
/*
* Called when the Alcohol in the Player demands its toll
* These effects are applied regularly to the Player depending on his alcohol level
* By default it is just one Confusion effect
* Can be changed or cancelled
*/
public class PlayerAlcEffectEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private List<PotionEffect> effects;
private boolean cancelled;
public PlayerAlcEffectEvent(Player who, List<PotionEffect> effects) {
super(who);
this.effects = effects;
}
public List<PotionEffect> getEffects() {
return effects;
}
public void setEffects(List<PotionEffect> effects) {
this.effects = effects;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}
@@ -0,0 +1,95 @@
package com.dre.brewery.api.events;
import com.dre.brewery.BPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
/**
* The Player writes something in Chat or on a Sign and his words are distorted.
*
* This Event may be Async if the Chat Event is Async!
*/
public class PlayerChatDistortEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Player player;
private final BPlayer bPlayer;
private final String prevMsg;
private String distortMsg;
private boolean cancelled;
public PlayerChatDistortEvent(boolean async, Player player, BPlayer bPlayer, String prevMsg, String distortMsg) {
super(async);
this.player = player;
this.bPlayer = bPlayer;
this.prevMsg = prevMsg;
this.distortMsg = distortMsg;
}
@NotNull
public Player getPlayer() {
return player;
}
@NotNull
public BPlayer getbPlayer() {
return bPlayer;
}
/**
* @return The Message the Player had actually written
*/
@NotNull
public String getWrittenMessage() {
return prevMsg;
}
/**
* @return The message after it was distorted
*/
@NotNull
public String getDistortedMessage() {
return distortMsg;
}
/**
* @return The drunkeness of the player that is writing the message
*/
public int getDrunkeness() {
return bPlayer.getDrunkeness();
}
/**
* Set the Message that the player will say instead of what he wrote
*/
public void setDistortedMessage(String distortMsg) {
this.distortMsg = Objects.requireNonNull(distortMsg);
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
// Required by Bukkit
public static HandlerList getHandlerList() {
return handlers;
}
}
@@ -1,52 +0,0 @@
package com.dre.brewery.api.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.potion.PotionEffect;
import java.util.List;
/*
* Called when the Effects of a Brew are applied to the player (drinking the Brew)
* These depend on alcohol and quality of the brew
* Can be changed or cancelled
*/
public class PlayerDrinkEffectEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private List<PotionEffect> effects;
private boolean cancelled;
public PlayerDrinkEffectEvent(Player who, List<PotionEffect> effects) {
super(who);
this.effects = effects;
}
public List<PotionEffect> getEffects() {
return effects;
}
public void setEffects(List<PotionEffect> effects) {
this.effects = effects;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}
@@ -0,0 +1,94 @@
package com.dre.brewery.api.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* A List of effects is applied to the player.
* This happens for various reasons like Alcohol level, Brew quality, Brew effects, etc.
* Can be changed or cancelled
*/
public class PlayerEffectEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final EffectType effectType;
private List<PotionEffect> effects;
private boolean cancelled;
public PlayerEffectEvent(Player who, EffectType effectType, List<PotionEffect> effects) {
super(who);
this.effectType = effectType;
this.effects = effects;
}
/**
* @return The effects being applied. Effects can be added or removed from this list.
*/
public List<PotionEffect> getEffects() {
return effects;
}
public void setEffects(List<PotionEffect> effects) {
this.effects = effects;
}
/**
* @return What type of effects are applied, sie EffectType
*/
public EffectType getEffectType() {
return effectType;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
// Required by Bukkit
public static HandlerList getHandlerList() {
return handlers;
}
public enum EffectType {
/**
* The Alcohol level demands its toll.
* Regularly applied depending on the players alcohol level
* By default it is just one Confusion effect
*/
ALCOHOL,
/**
* Effects of a Brew are applied to the player (drinking the Brew)
* These depend on alcohol and quality of the brew
*/
DRINK,
/**
* When drinking a Brew with low Quality, these effects are applied
*/
QUALITY,
/**
* When logging in after drinking, Hangover Effects are applied
*/
HANGOVER
}
}
@@ -5,8 +5,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
/*
/**
* The player pukes (throws puke items to the ground)
* Those items can never be picked up and despawn after the time set in the config
* Number of items to drop can be changed with count
@@ -23,10 +24,16 @@ public class PlayerPukeEvent extends PlayerEvent implements Cancellable {
this.count = count;
}
/**
* @return The Amount of items being dropped this time
*/
public int getCount() {
return count;
}
/**
* @param count Set the amount of items being dropped this time
*/
public void setCount(int count) {
this.count = count;
}
@@ -48,11 +55,13 @@ public class PlayerPukeEvent extends PlayerEvent implements Cancellable {
this.cancelled = cancelled;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
// Required by Bukkit
public static HandlerList getHandlerList() {
return handlers;
}
@@ -6,8 +6,9 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
/*
/**
* The Players movement is hindered because of drunkeness
* Called each time before pushing the Player with the Vector push 10 times
* The Push Vector can be changed or multiplied
@@ -30,12 +31,23 @@ public class PlayerPushEvent extends PlayerEvent implements Cancellable {
// The Vector in which direction and magnitude the player is Pushed
// Can be changed directly or through setPush
/**
* Get the Vector in which direction and magnitude the player is pushed
* Can be changed directly or through setPush
*
* @return The current push vector
*/
public Vector getPush() {
return push;
}
// Set the Push vector, can not be null
public void setPush(Vector push) {
/**
* Set the Push vector
*
* @param push The new push vector, not null
*/
public void setPush(@NotNull Vector push) {
if (push == null) {
throw new NullPointerException("Push Vector is null");
}
@@ -52,11 +64,13 @@ public class PlayerPushEvent extends PlayerEvent implements Cancellable {
this.cancelled = cancelled;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
// Required by Bukkit
public static HandlerList getHandlerList() {
return handlers;
}
@@ -5,8 +5,9 @@ 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;
/*
/**
* A Player opens a Barrel by rightclicking it
* The PlayerInteractEvent on the Barrel may be cancelled. In that case this never gets called
* Can be cancelled to silently deny opening the Barrel
@@ -23,8 +24,10 @@ public class BarrelAccessEvent extends BarrelEvent implements Cancellable {
this.clickedBlock = clickedBlock;
}
// Gets the Block that was actually clicked.
// For access Permissions getSpigot() should be used
/**
* Gets the Block that was actually clicked.
* For access Permissions getSpigot() should be used
*/
public Block getClickedBlock() {
return clickedBlock;
}
@@ -43,11 +46,13 @@ public class BarrelAccessEvent extends BarrelEvent implements Cancellable {
return player;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
// Required by Bukkit
public static HandlerList getHandlerList() {
return handlers;
}
@@ -4,8 +4,9 @@ import com.dre.brewery.Barrel;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/*
/**
* Called when a Barrel is created by a Player by placing a Sign
* Cancelling this will silently fail the Barrel creation
*/
@@ -33,11 +34,13 @@ public class BarrelCreateEvent extends BarrelEvent implements Cancellable {
this.cancelled = cancelled;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
// Required by Bukkit
public static HandlerList getHandlerList() {
return handlers;
}
@@ -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
}
}
@@ -3,7 +3,6 @@ package com.dre.brewery.api.events.barrel;
import com.dre.brewery.Barrel;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.Inventory;
public abstract class BarrelEvent extends Event {
@@ -21,6 +20,9 @@ public abstract class BarrelEvent extends Event {
return barrel.getInventory();
}
/**
* @return The Spigot Block of the Barrel, usually Sign or a Fence
*/
public Block getSpigot() {
return barrel.getSpigot();
}
@@ -2,32 +2,39 @@ package com.dre.brewery.api.events.barrel;
import com.dre.brewery.Barrel;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/*
* A Barrel is being removed. There may have been a BarrelDestroyEvent before
/**
* A Barrel is being removed. There may have been a BarrelDestroyEvent before this
* If not, Worldedit, other Plugins etc may be the cause for unexpected removal
*/
public class BarrelRemoveEvent extends BarrelEvent {
private static final HandlerList handlers = new HandlerList();
private boolean itemsDrop = true;
private boolean dropItems;
public BarrelRemoveEvent(Barrel barrel) {
public BarrelRemoveEvent(Barrel barrel, boolean dropItems) {
super(barrel);
this.dropItems = dropItems;
}
public boolean willItemsDrop() {
return itemsDrop;
public boolean willDropItems() {
return dropItems;
}
public void setShouldItemsDrop(boolean itemsDrop) {
this.itemsDrop = itemsDrop;
/**
* @param dropItems Should the Items contained in this Barrel drop to the ground?
*/
public void setShouldDropItems(boolean dropItems) {
this.dropItems = dropItems;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
// Required by Bukkit
public static HandlerList getHandlerList() {
return handlers;
}
@@ -6,8 +6,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
/*
/**
* A Player Drinks a Brew
* The amount of alcohol and quality that will be added to the player can be get/set here
* If cancelled the drinking will fail silently
@@ -65,11 +66,13 @@ public class BrewDrinkEvent extends BrewEvent implements Cancellable {
this.cancelled = cancelled;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
// Required by Bukkit
public static HandlerList getHandlerList() {
return handlers;
}
@@ -8,7 +8,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.jetbrains.annotations.NotNull;
/*
/**
* A Brew has been created or modified
* Usually happens on Filling from cauldron, distilling and aging.
* Modifications to the Brew or the PotionMeta can be done now
@@ -40,7 +40,7 @@ public class BrewModifyEvent extends BrewEvent implements Cancellable {
return cancelled;
}
/*
/**
* Setting the Event cancelled cancels all modificatons to the brew.
* Modifications to the Brew or ItemMeta will not be applied
*/
@@ -55,6 +55,7 @@ public class BrewModifyEvent extends BrewEvent implements Cancellable {
return handlers;
}
// Required by Bukkit
public static HandlerList getHandlerList() {
return handlers;
}