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
@@ -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;
}