mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 06:38:56 +00:00
Added more API and features for Events
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package com.dre.brewery;
|
package com.dre.brewery;
|
||||||
|
|
||||||
import com.dre.brewery.api.events.PlayerAlcEffectEvent;
|
import com.dre.brewery.api.events.PlayerEffectEvent;
|
||||||
import com.dre.brewery.api.events.PlayerDrinkEffectEvent;
|
|
||||||
import com.dre.brewery.api.events.PlayerPukeEvent;
|
import com.dre.brewery.api.events.PlayerPukeEvent;
|
||||||
import com.dre.brewery.api.events.PlayerPushEvent;
|
import com.dre.brewery.api.events.PlayerPushEvent;
|
||||||
import com.dre.brewery.api.events.brew.BrewDrinkEvent;
|
import com.dre.brewery.api.events.brew.BrewDrinkEvent;
|
||||||
@@ -160,21 +159,21 @@ public class BPlayer {
|
|||||||
|
|
||||||
if (brewAlc < 1) {
|
if (brewAlc < 1) {
|
||||||
//no alcohol so we dont need to add a BPlayer
|
//no alcohol so we dont need to add a BPlayer
|
||||||
applyDrinkEffects(effects, player);
|
applyEffects(effects, player, PlayerEffectEvent.EffectType.DRINK);
|
||||||
if (bPlayer.drunkeness <= 0) {
|
if (bPlayer.drunkeness <= 0) {
|
||||||
bPlayer.remove();
|
bPlayer.remove();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
effects.addAll(getQualityEffects(drinkEvent.getQuality(), brewAlc));
|
|
||||||
bPlayer.drunkeness += brewAlc;
|
bPlayer.drunkeness += brewAlc;
|
||||||
if (quality > 0) {
|
if (quality > 0) {
|
||||||
bPlayer.quality += quality * brewAlc;
|
bPlayer.quality += quality * brewAlc;
|
||||||
} else {
|
} else {
|
||||||
bPlayer.quality += brewAlc;
|
bPlayer.quality += brewAlc;
|
||||||
}
|
}
|
||||||
applyDrinkEffects(effects, player);
|
applyEffects(effects, player, PlayerEffectEvent.EffectType.DRINK);
|
||||||
|
applyEffects(getQualityEffects(drinkEvent.getQuality(), brewAlc), player, PlayerEffectEvent.EffectType.QUALITY);
|
||||||
|
|
||||||
if (bPlayer.drunkeness > 100) {
|
if (bPlayer.drunkeness > 100) {
|
||||||
bPlayer.drinkCap(player);
|
bPlayer.drinkCap(player);
|
||||||
@@ -490,8 +489,8 @@ public class BPlayer {
|
|||||||
|
|
||||||
// #### Effects ####
|
// #### Effects ####
|
||||||
|
|
||||||
public static void applyDrinkEffects(List<PotionEffect> effects, Player player) {
|
public static void applyEffects(List<PotionEffect> effects, Player player, PlayerEffectEvent.EffectType effectType) {
|
||||||
PlayerDrinkEffectEvent event = new PlayerDrinkEffectEvent(player, effects);
|
PlayerEffectEvent event = new PlayerEffectEvent(player, effectType, effects);
|
||||||
P.p.getServer().getPluginManager().callEvent(event);
|
P.p.getServer().getPluginManager().callEvent(event);
|
||||||
effects = event.getEffects();
|
effects = event.getEffects();
|
||||||
if (event.isCancelled() || effects == null) {
|
if (event.isCancelled() || effects == null) {
|
||||||
@@ -517,7 +516,7 @@ public class BPlayer {
|
|||||||
List<PotionEffect> l = new ArrayList<>(1);
|
List<PotionEffect> l = new ArrayList<>(1);
|
||||||
l.add(PotionEffectType.CONFUSION.createEffect(duration, 0));
|
l.add(PotionEffectType.CONFUSION.createEffect(duration, 0));
|
||||||
|
|
||||||
PlayerAlcEffectEvent event = new PlayerAlcEffectEvent(player, l);
|
PlayerEffectEvent event = new PlayerEffectEvent(player, PlayerEffectEvent.EffectType.ALCOHOL, l);
|
||||||
P.p.getServer().getPluginManager().callEvent(event);
|
P.p.getServer().getPluginManager().callEvent(event);
|
||||||
l = event.getEffects();
|
l = event.getEffects();
|
||||||
if (event.isCancelled() || l == null) {
|
if (event.isCancelled() || l == null) {
|
||||||
@@ -565,7 +564,14 @@ public class BPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void addQualityEffects(int quality, int brewAlc, Player player) {
|
public static void addQualityEffects(int quality, int brewAlc, Player player) {
|
||||||
for (PotionEffect effect : getQualityEffects(quality, brewAlc)) {
|
List<PotionEffect> list = getQualityEffects(quality, brewAlc);
|
||||||
|
PlayerEffectEvent event = new PlayerEffectEvent(player, PlayerEffectEvent.EffectType.QUALITY, list);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
list = event.getEffects();
|
||||||
|
if (event.isCancelled() || list == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (PotionEffect effect : list) {
|
||||||
BUtil.reapplyPotionEffect(player, effect, true);
|
BUtil.reapplyPotionEffect(player, effect, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -599,8 +605,19 @@ public class BPlayer {
|
|||||||
}
|
}
|
||||||
int amplifier = getHangoverQuality() / 3;
|
int amplifier = getHangoverQuality() / 3;
|
||||||
|
|
||||||
BUtil.reapplyPotionEffect(player, PotionEffectType.SLOW.createEffect(duration, amplifier), true);
|
List<PotionEffect> list = new ArrayList<>(2);
|
||||||
BUtil.reapplyPotionEffect(player, PotionEffectType.HUNGER.createEffect(duration, amplifier), true);
|
list.add(PotionEffectType.SLOW.createEffect(duration, amplifier));
|
||||||
|
list.add(PotionEffectType.HUNGER.createEffect(duration, amplifier));
|
||||||
|
|
||||||
|
PlayerEffectEvent event = new PlayerEffectEvent(player, PlayerEffectEvent.EffectType.HANGOVER, list);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
list = event.getEffects();
|
||||||
|
if (event.isCancelled() || list == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (PotionEffect effect : list) {
|
||||||
|
BUtil.reapplyPotionEffect(player, effect, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -325,9 +325,15 @@ public class Barrel implements InventoryHolder {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// removes a barrel, throwing included potions to the ground
|
/**
|
||||||
public void remove(Block broken, Player breaker) {
|
* Removes a barrel, throwing included potions to the ground
|
||||||
BarrelRemoveEvent event = new BarrelRemoveEvent(this);
|
*
|
||||||
|
* @param broken The Block that was broken
|
||||||
|
* @param breaker The Player that broke it, or null if not known
|
||||||
|
* @param dropItems If the items in the barrels inventory should drop to the ground
|
||||||
|
*/
|
||||||
|
public void remove(@Nullable Block broken, @Nullable Player breaker, boolean dropItems) {
|
||||||
|
BarrelRemoveEvent event = new BarrelRemoveEvent(this, dropItems);
|
||||||
// Listened to by LWCBarrel (IntegrationListener)
|
// Listened to by LWCBarrel (IntegrationListener)
|
||||||
P.p.getServer().getPluginManager().callEvent(event);
|
P.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
@@ -348,7 +354,7 @@ public class Barrel implements InventoryHolder {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.willItemsDrop()) {
|
if (event.willDropItems()) {
|
||||||
for (ItemStack item : items) {
|
for (ItemStack item : items) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
Brew brew = Brew.get(item);
|
Brew brew = Brew.get(item);
|
||||||
@@ -480,7 +486,7 @@ public class Barrel implements InventoryHolder {
|
|||||||
P.p.debugLog("Barrel at " + broken.getWorld().getName() + "/" + broken.getX() + "/" + broken.getY() + "/" + broken.getZ()
|
P.p.debugLog("Barrel at " + broken.getWorld().getName() + "/" + broken.getX() + "/" + broken.getY() + "/" + broken.getZ()
|
||||||
+ " has been destroyed unexpectedly, contents will drop");
|
+ " has been destroyed unexpectedly, contents will drop");
|
||||||
// remove the barrel if it was destroyed
|
// remove the barrel if it was destroyed
|
||||||
barrel.remove(broken, null);
|
barrel.remove(broken, null, true);
|
||||||
} else {
|
} else {
|
||||||
// Dont check this barrel again, its enough to check it once after every restart
|
// Dont check this barrel again, its enough to check it once after every restart
|
||||||
// as now this is only the backup if we dont register the barrel breaking, as sample
|
// as now this is only the backup if we dont register the barrel breaking, as sample
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class BarrelBody {
|
|||||||
// This will only be done in those extreme cases.
|
// This will only be done in those extreme cases.
|
||||||
Block broken = getBrokenBlock(true);
|
Block broken = getBrokenBlock(true);
|
||||||
if (broken != null) {
|
if (broken != null) {
|
||||||
barrel.remove(broken, null);
|
barrel.remove(broken, null, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.bounds = bounds;
|
this.bounds = bounds;
|
||||||
@@ -150,6 +150,9 @@ public class BarrelBody {
|
|||||||
*/
|
*/
|
||||||
public boolean hasBlock(Block block) {
|
public boolean hasBlock(Block block) {
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
|
if (spigot.equals(block)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (spigot.getWorld().equals(block.getWorld())) {
|
if (spigot.getWorld().equals(block.getWorld())) {
|
||||||
return bounds != null && bounds.contains(block.getX(), block.getY(), block.getZ());
|
return bounds != null && bounds.contains(block.getX(), block.getY(), block.getZ());
|
||||||
}
|
}
|
||||||
|
|||||||
+123
-33
@@ -7,6 +7,7 @@ import com.dre.brewery.lore.*;
|
|||||||
import com.dre.brewery.recipe.BEffect;
|
import com.dre.brewery.recipe.BEffect;
|
||||||
import com.dre.brewery.recipe.BRecipe;
|
import com.dre.brewery.recipe.BRecipe;
|
||||||
import com.dre.brewery.recipe.PotionColor;
|
import com.dre.brewery.recipe.PotionColor;
|
||||||
|
import com.dre.brewery.utility.BUtil;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.inventory.BrewerInventory;
|
import org.bukkit.inventory.BrewerInventory;
|
||||||
@@ -25,9 +26,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Brew {
|
/**
|
||||||
// represents the liquid in the brewed Potions
|
* Represents the liquid in the brewed Potions
|
||||||
|
*/
|
||||||
|
public class Brew implements Cloneable {
|
||||||
public static final byte SAVE_VER = 1;
|
public static final byte SAVE_VER = 1;
|
||||||
private static long saveSeed;
|
private static long saveSeed;
|
||||||
private static List<Long> prevSaveSeeds = new ArrayList<>(); // Save Seeds that have been used in the past, stored to decode brews made at that time
|
private static List<Long> prevSaveSeeds = new ArrayList<>(); // Save Seeds that have been used in the past, stored to decode brews made at that time
|
||||||
@@ -47,12 +51,17 @@ public class Brew {
|
|||||||
private int lastUpdate; // last update in hours after install time
|
private int lastUpdate; // last update in hours after install time
|
||||||
private boolean needsSave; // There was a change that has not yet been saved
|
private boolean needsSave; // There was a change that has not yet been saved
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A new Brew with only ingredients
|
||||||
|
*/
|
||||||
public Brew(BIngredients ingredients) {
|
public Brew(BIngredients ingredients) {
|
||||||
this.ingredients = ingredients;
|
this.ingredients = ingredients;
|
||||||
touch();
|
touch();
|
||||||
}
|
}
|
||||||
|
|
||||||
// quality already set
|
/**
|
||||||
|
* A Brew with quality, alc and recipe already set
|
||||||
|
*/
|
||||||
public Brew(int quality, int alc, BRecipe recipe, BIngredients ingredients) {
|
public Brew(int quality, int alc, BRecipe recipe, BIngredients ingredients) {
|
||||||
this.ingredients = ingredients;
|
this.ingredients = ingredients;
|
||||||
this.quality = quality;
|
this.quality = quality;
|
||||||
@@ -61,7 +70,9 @@ public class Brew {
|
|||||||
touch();
|
touch();
|
||||||
}
|
}
|
||||||
|
|
||||||
// loading with all values set
|
/**
|
||||||
|
* Loading a Brew with all values set
|
||||||
|
*/
|
||||||
public Brew(BIngredients ingredients, int quality, int alc, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean immutable, int lastUpdate) {
|
public Brew(BIngredients ingredients, int quality, int alc, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean immutable, int lastUpdate) {
|
||||||
this.ingredients = ingredients;
|
this.ingredients = ingredients;
|
||||||
this.quality = quality;
|
this.quality = quality;
|
||||||
@@ -79,7 +90,12 @@ public class Brew {
|
|||||||
private Brew() {
|
private Brew() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a Brew by ItemMeta
|
/**
|
||||||
|
* returns a Brew by ItemMeta
|
||||||
|
*
|
||||||
|
* @param meta The meta to get the brew from
|
||||||
|
* @return The Brew if meta is a brew, null if not
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Brew get(ItemMeta meta) {
|
public static Brew get(ItemMeta meta) {
|
||||||
if (!P.useNBT && !meta.hasLore()) return null;
|
if (!P.useNBT && !meta.hasLore()) return null;
|
||||||
@@ -93,7 +109,12 @@ public class Brew {
|
|||||||
return brew;
|
return brew;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a Brew by ItemStack
|
/**
|
||||||
|
* returns a Brew by ItemStack
|
||||||
|
*
|
||||||
|
* @param item The Item to get the brew from
|
||||||
|
* @return The Brew if item is a brew, null if not
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Brew get(ItemStack item) {
|
public static Brew get(ItemStack item) {
|
||||||
if (item.getType() != Material.POTION) return null;
|
if (item.getType() != Material.POTION) return null;
|
||||||
@@ -197,7 +218,9 @@ public class Brew {
|
|||||||
return uid;
|
return uid;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
//returns the recipe with the given name, recalculates if not found
|
/**
|
||||||
|
* returns the recipe with the given name, recalculates if not found
|
||||||
|
*/
|
||||||
public boolean setRecipeFromString(String name) {
|
public boolean setRecipeFromString(String name) {
|
||||||
currentRecipe = null;
|
currentRecipe = null;
|
||||||
if (name != null && !name.equals("")) {
|
if (name != null && !name.equals("")) {
|
||||||
@@ -256,20 +279,21 @@ public class Brew {
|
|||||||
persistent == brew.persistent &&
|
persistent == brew.persistent &&
|
||||||
immutable == brew.immutable &&
|
immutable == brew.immutable &&
|
||||||
ingredients.equals(brew.ingredients) &&
|
ingredients.equals(brew.ingredients) &&
|
||||||
(currentRecipe != null ? currentRecipe.equals(brew.currentRecipe) : brew.currentRecipe == null);
|
(Objects.equals(currentRecipe, brew.currentRecipe));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clones this instance
|
/**
|
||||||
|
* Clones this instance
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Brew clone() throws CloneNotSupportedException {
|
public Brew clone() {
|
||||||
super.clone();
|
try {
|
||||||
Brew brew = new Brew(quality, alc, currentRecipe, ingredients);
|
Brew brew = (Brew) super.clone();
|
||||||
brew.distillRuns = distillRuns;
|
brew.ingredients = ingredients.copy();
|
||||||
brew.ageTime = ageTime;
|
return brew;
|
||||||
brew.unlabeled = unlabeled;
|
} catch (CloneNotSupportedException e) {
|
||||||
brew.persistent = persistent;
|
throw new InternalError(e);
|
||||||
brew.immutable = immutable;
|
}
|
||||||
return brew;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -295,7 +319,9 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
// calculate alcohol from recipe
|
/**
|
||||||
|
* calculate alcohol from recipe
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
public int calcAlcohol() {
|
public int calcAlcohol() {
|
||||||
if (quality == 0) {
|
if (quality == 0) {
|
||||||
@@ -338,7 +364,9 @@ public class Brew {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculating quality
|
/**
|
||||||
|
* calculating quality
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
public int calcQuality() {
|
public int calcQuality() {
|
||||||
// calculate quality from all of the factors
|
// calculate quality from all of the factors
|
||||||
@@ -373,7 +401,11 @@ public class Brew {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set unlabeled to true to hide the numbers in Lore
|
/**
|
||||||
|
* Set unlabeled to true to hide the numbers in Lore
|
||||||
|
*
|
||||||
|
* @param item The Item this Brew is on
|
||||||
|
*/
|
||||||
public void unLabel(ItemStack item) {
|
public void unLabel(ItemStack item) {
|
||||||
unlabeled = true;
|
unlabeled = true;
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
@@ -392,7 +424,9 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do some regular updates
|
/**
|
||||||
|
* Do some regular updates
|
||||||
|
*/
|
||||||
public void touch() {
|
public void touch() {
|
||||||
lastUpdate = (int) ((double) (System.currentTimeMillis() - installTime) / 3600000D);
|
lastUpdate = (int) ((double) (System.currentTimeMillis() - installTime) / 3600000D);
|
||||||
}
|
}
|
||||||
@@ -470,7 +504,9 @@ public class Brew {
|
|||||||
this.needsSave = needsSave;
|
this.needsSave = needsSave;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the Static flag, so potion is unchangeable
|
/**
|
||||||
|
* Set the Static flag, so potion is unchangeable
|
||||||
|
*/
|
||||||
public void setStatic(boolean immutable, ItemStack potion) {
|
public void setStatic(boolean immutable, ItemStack potion) {
|
||||||
this.immutable = immutable;
|
this.immutable = immutable;
|
||||||
if (currentRecipe != null && canDistill()) {
|
if (currentRecipe != null && canDistill()) {
|
||||||
@@ -488,7 +524,12 @@ public class Brew {
|
|||||||
|
|
||||||
// Distilling section ---------------
|
// Distilling section ---------------
|
||||||
|
|
||||||
// distill all custom potions in the brewer
|
/**
|
||||||
|
* distill all custom potions in the brewer
|
||||||
|
*
|
||||||
|
* @param inv The Inventory of the Distiller
|
||||||
|
* @param contents The Brews in the 3 slots of the Inventory
|
||||||
|
*/
|
||||||
public static void distillAll(BrewerInventory inv, Brew[] contents) {
|
public static void distillAll(BrewerInventory inv, Brew[] contents) {
|
||||||
for (int slot = 0; slot < 3; slot++) {
|
for (int slot = 0; slot < 3; slot++) {
|
||||||
if (contents[slot] != null) {
|
if (contents[slot] != null) {
|
||||||
@@ -499,7 +540,12 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// distill custom potion in given slot
|
/**
|
||||||
|
* distill custom potion in a distiller slot
|
||||||
|
*
|
||||||
|
* @param slotItem The item in the slot
|
||||||
|
* @param potionMeta The meta of the item
|
||||||
|
*/
|
||||||
public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) {
|
public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) {
|
||||||
if (immutable) return;
|
if (immutable) return;
|
||||||
|
|
||||||
@@ -626,7 +672,9 @@ public class Brew {
|
|||||||
item.setItemMeta(potionMeta);
|
item.setItemMeta(potionMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slowly shift the wood of the Brew to the new Type
|
/**
|
||||||
|
* Slowly shift the wood of the Brew to the new Type
|
||||||
|
*/
|
||||||
public void woodShift(float time, byte to) {
|
public void woodShift(float time, byte to) {
|
||||||
float factor = 1;
|
float factor = 1;
|
||||||
if (ageTime > 5) {
|
if (ageTime > 5) {
|
||||||
@@ -703,6 +751,35 @@ public class Brew {
|
|||||||
return potion;
|
return potion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performant way of checking if this item is a Brew
|
||||||
|
* Does not give any guarantees that get() will return notnull for this item, i.e. if it is a brew but the data is corrupt
|
||||||
|
*
|
||||||
|
* @param item The Item to check
|
||||||
|
* @return True if the item is a brew
|
||||||
|
*/
|
||||||
|
public static boolean isBrew(ItemStack item) {
|
||||||
|
if (item == null || item.getType() != Material.POTION) return false;
|
||||||
|
if (!item.hasItemMeta()) return false;
|
||||||
|
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
assert meta != null;
|
||||||
|
if (!P.useNBT && !meta.hasLore()) return false;
|
||||||
|
|
||||||
|
if (P.useNBT) {
|
||||||
|
// Check for Data on PersistentDataContainer
|
||||||
|
if (NBTLoadStream.hasDataInMeta(meta)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If either NBT is not supported or no data was found in NBT, try finding data in lore
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
// Find the Data Identifier in Lore
|
||||||
|
return BUtil.indexOfStart(meta.getLore(), LoreLoadStream.IDENTIFIER) > -1;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static Brew load(ItemMeta meta) {
|
private static Brew load(ItemMeta meta) {
|
||||||
InputStream itemLoadStream = null;
|
InputStream itemLoadStream = null;
|
||||||
if (P.useNBT) {
|
if (P.useNBT) {
|
||||||
@@ -795,7 +872,10 @@ public class Brew {
|
|||||||
setRecipeFromString(recipe);
|
setRecipeFromString(recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save brew data into meta: lore/nbt
|
/**
|
||||||
|
* Save brew data into meta: lore/nbt
|
||||||
|
* Should be called after any changes made to the brew
|
||||||
|
*/
|
||||||
public void save(ItemMeta meta) {
|
public void save(ItemMeta meta) {
|
||||||
OutputStream itemSaveStream;
|
OutputStream itemSaveStream;
|
||||||
if (P.useNBT) {
|
if (P.useNBT) {
|
||||||
@@ -819,8 +899,12 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save brew data into the meta/lore of the specified item
|
/**
|
||||||
// The meta on the item changes, so to make further changes to the meta, item.getItemMeta() has to be called again after this
|
* Save brew data into the meta/lore of the specified item
|
||||||
|
* The meta on the item changes, so to make further changes to the meta, item.getItemMeta() has to be called again after this
|
||||||
|
*
|
||||||
|
* @param item The item to save this brew into
|
||||||
|
*/
|
||||||
public void save(ItemStack item) {
|
public void save(ItemStack item) {
|
||||||
ItemMeta meta;
|
ItemMeta meta;
|
||||||
if (!item.hasItemMeta()) {
|
if (!item.hasItemMeta()) {
|
||||||
@@ -899,7 +983,9 @@ public class Brew {
|
|||||||
return legacyPotions.isEmpty();
|
return legacyPotions.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load potion data from data file for backwards compatibility
|
/**
|
||||||
|
* Load potion data from data file for backwards compatibility
|
||||||
|
*/
|
||||||
public static void loadLegacy(BIngredients ingredients, int uid, int quality, int alc, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat, int lastUpdate) {
|
public static void loadLegacy(BIngredients ingredients, int uid, int quality, int alc, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat, int lastUpdate) {
|
||||||
Brew brew = new Brew(ingredients, quality, alc, distillRuns, ageTime, wood, recipe, unlabeled, stat, lastUpdate);
|
Brew brew = new Brew(ingredients, quality, alc, distillRuns, ageTime, wood, recipe, unlabeled, stat, lastUpdate);
|
||||||
brew.persistent = persistent;
|
brew.persistent = persistent;
|
||||||
@@ -910,7 +996,9 @@ public class Brew {
|
|||||||
legacyPotions.put(uid, brew);
|
legacyPotions.put(uid, brew);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove legacy potiondata for an item
|
/**
|
||||||
|
* remove legacy potiondata for an item
|
||||||
|
*/
|
||||||
public static void removeLegacy(ItemStack item) {
|
public static void removeLegacy(ItemStack item) {
|
||||||
if (legacyPotions.isEmpty()) return;
|
if (legacyPotions.isEmpty()) return;
|
||||||
if (!item.hasItemMeta()) return;
|
if (!item.hasItemMeta()) return;
|
||||||
@@ -936,8 +1024,10 @@ public class Brew {
|
|||||||
item.setItemMeta(potionMeta);
|
item.setItemMeta(potionMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Saves all data
|
/**
|
||||||
// Legacy method to save to data file
|
* Saves all data
|
||||||
|
* Legacy method to save to data file
|
||||||
|
*/
|
||||||
public static void saveLegacy(ConfigurationSection config) {
|
public static void saveLegacy(ConfigurationSection config) {
|
||||||
for (Map.Entry<Integer, Brew> entry : legacyPotions.entrySet()) {
|
for (Map.Entry<Integer, Brew> entry : legacyPotions.entrySet()) {
|
||||||
int uid = entry.getKey();
|
int uid = entry.getKey();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.dre.brewery;
|
package com.dre.brewery;
|
||||||
|
|
||||||
|
import com.dre.brewery.api.events.PlayerChatDistortEvent;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
@@ -79,9 +80,15 @@ public class DistortChat {
|
|||||||
P.p.log(P.p.languageReader.get("Player_TriedToSay", name, chat));
|
P.p.log(P.p.languageReader.get("Player_TriedToSay", name, chat));
|
||||||
}
|
}
|
||||||
String message = chat.substring(command.length() + 1);
|
String message = chat.substring(command.length() + 1);
|
||||||
message = distortMessage(message, bPlayer.getDrunkeness());
|
String distorted = distortMessage(message, bPlayer.getDrunkeness());
|
||||||
|
PlayerChatDistortEvent call = new PlayerChatDistortEvent(event.isAsynchronous(), event.getPlayer(), bPlayer, message, distorted);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(call);
|
||||||
|
if (call.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
distorted = call.getDistortedMessage();
|
||||||
|
|
||||||
event.setMessage(chat.substring(0, command.length() + 1) + message);
|
event.setMessage(chat.substring(0, command.length() + 1) + distorted);
|
||||||
waitPlayers.put(name, System.currentTimeMillis());
|
waitPlayers.put(name, System.currentTimeMillis());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -101,12 +108,17 @@ public class DistortChat {
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
for (String message : event.getLines()) {
|
for (String message : event.getLines()) {
|
||||||
if (message.length() > 1) {
|
if (message.length() > 1) {
|
||||||
message = distortMessage(message, bPlayer.getDrunkeness());
|
String distorted = distortMessage(message, bPlayer.getDrunkeness());
|
||||||
|
PlayerChatDistortEvent call = new PlayerChatDistortEvent(event.isAsynchronous(), event.getPlayer(), bPlayer, message, distorted);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(call);
|
||||||
|
if (!call.isCancelled()) {
|
||||||
|
distorted = call.getDistortedMessage();
|
||||||
|
|
||||||
if (message.length() > 15) {
|
if (distorted.length() > 15) {
|
||||||
message = message.substring(0, 14);
|
distorted = distorted.substring(0, 14);
|
||||||
|
}
|
||||||
|
event.setLine(index, distorted);
|
||||||
}
|
}
|
||||||
event.setLine(index, message);
|
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
@@ -123,7 +135,16 @@ public class DistortChat {
|
|||||||
if (log) {
|
if (log) {
|
||||||
P.p.log(P.p.languageReader.get("Player_TriedToSay", event.getPlayer().getName(), message));
|
P.p.log(P.p.languageReader.get("Player_TriedToSay", event.getPlayer().getName(), message));
|
||||||
}
|
}
|
||||||
event.setMessage(distortMessage(message, bPlayer.getDrunkeness()));
|
|
||||||
|
String distorted = distortMessage(message, bPlayer.getDrunkeness());
|
||||||
|
PlayerChatDistortEvent call = new PlayerChatDistortEvent(event.isAsynchronous(), event.getPlayer(), bPlayer, message, distorted);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(call);
|
||||||
|
if (call.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
distorted = call.getDistortedMessage();
|
||||||
|
|
||||||
|
event.setMessage(distorted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -514,6 +514,10 @@ public class P extends JavaPlugin {
|
|||||||
BConfig.reloader = null;
|
BConfig.reloader = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public P getInstance() {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
// Utility
|
// Utility
|
||||||
|
|
||||||
public void msg(CommandSender sender, String msg) {
|
public void msg(CommandSender sender, String msg) {
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package com.dre.brewery.api;
|
package com.dre.brewery.api;
|
||||||
|
|
||||||
import com.dre.brewery.BCauldron;
|
import com.dre.brewery.BCauldron;
|
||||||
|
import com.dre.brewery.BPlayer;
|
||||||
|
import com.dre.brewery.filedata.BConfig;
|
||||||
import com.dre.brewery.recipe.BCauldronRecipe;
|
import com.dre.brewery.recipe.BCauldronRecipe;
|
||||||
import com.dre.brewery.recipe.BRecipe;
|
import com.dre.brewery.recipe.BRecipe;
|
||||||
import com.dre.brewery.Barrel;
|
import com.dre.brewery.Barrel;
|
||||||
import com.dre.brewery.Brew;
|
import com.dre.brewery.Brew;
|
||||||
|
import com.dre.brewery.utility.Tuple;
|
||||||
import org.apache.commons.lang.NotImplementedException;
|
import org.apache.commons.lang.NotImplementedException;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -28,7 +31,7 @@ public class BreweryApi {
|
|||||||
*/
|
*/
|
||||||
public static boolean removeAny(Block block) {
|
public static boolean removeAny(Block block) {
|
||||||
if (removeCauldron(block)) return true;
|
if (removeCauldron(block)) return true;
|
||||||
return removeBarrel(block);
|
return removeBarrel(block, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +40,59 @@ public class BreweryApi {
|
|||||||
*/
|
*/
|
||||||
public static boolean removeAnyByPlayer(Block block, Player player) {
|
public static boolean removeAnyByPlayer(Block block, Player player) {
|
||||||
if (removeCauldron(block)) return true;
|
if (removeCauldron(block)) return true;
|
||||||
return removeBarrelByPlayer(block, player);
|
return removeBarrelByPlayer(block, player, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// # # # # # # # # # # # #
|
||||||
|
// # # # # # Player # # # # #
|
||||||
|
// # # # # # # # # # # # #
|
||||||
|
|
||||||
|
public static BPlayer getBPlayer(Player player) {
|
||||||
|
return BPlayer.get(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Players drunkeness state
|
||||||
|
*
|
||||||
|
* @param player The Player to set the drunkeness on
|
||||||
|
* @param drunkeness The amount of drunkeness 0-100 to apply to the player
|
||||||
|
* @param quality The Quality 1-10 the drunkeness of the player should have
|
||||||
|
* zero Quality keeps the players current quality
|
||||||
|
*/
|
||||||
|
public static void setPlayerDrunk(Player player, int drunkeness, int quality) {
|
||||||
|
if (drunkeness < 0) {
|
||||||
|
throw new IllegalArgumentException("Drunkeness can not be <0");
|
||||||
|
}
|
||||||
|
if (quality > 10) {
|
||||||
|
throw new IllegalArgumentException("Quality can not be >10");
|
||||||
|
}
|
||||||
|
BPlayer bPlayer = BPlayer.get(player);
|
||||||
|
if (bPlayer == null && player != null) {
|
||||||
|
if (drunkeness == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bPlayer = BPlayer.addPlayer(player);
|
||||||
|
}
|
||||||
|
if (bPlayer == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drunkeness == 0) {
|
||||||
|
bPlayer.remove();
|
||||||
|
} else {
|
||||||
|
bPlayer.setData(drunkeness, quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drunkeness > 100) {
|
||||||
|
if (player != null) {
|
||||||
|
bPlayer.drinkCap(player);
|
||||||
|
} else {
|
||||||
|
if (!BConfig.overdrinkKick) {
|
||||||
|
bPlayer.setData(100, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -67,6 +122,24 @@ public class BreweryApi {
|
|||||||
return Brew.get(meta);
|
return Brew.get(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performant way to check if an item is a brew.
|
||||||
|
* Does not give any guarantees that getBrew() will return notnull for this item, i.e. if it is a brew but couldn't be loaded
|
||||||
|
*/
|
||||||
|
public static boolean isBrew(ItemStack item) {
|
||||||
|
return Brew.isBrew(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a Brew from the given Recipe
|
||||||
|
*
|
||||||
|
* @param recipe The Recipe to create a brew from
|
||||||
|
* @return The Brew that was created. Can use brew.createItem() to get an ItemStack
|
||||||
|
*/
|
||||||
|
public static Brew createBrew(BRecipe recipe, int quality) {
|
||||||
|
return recipe.createBrew(quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// # # # # # # # # # # # #
|
// # # # # # # # # # # # #
|
||||||
// # # # # # Barrel # # # # #
|
// # # # # # Barrel # # # # #
|
||||||
@@ -98,22 +171,29 @@ public class BreweryApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove any Barrel that this Block may be Part of
|
* Remove any Barrel that this Block may be Part of
|
||||||
* Returns true if a Barrel was removed
|
|
||||||
* Does not remove any actual Block
|
* Does not remove any actual Block
|
||||||
|
*
|
||||||
|
* @param block The Block thats part of the barrel, potions will drop there
|
||||||
|
* @param dropItems If the items in the barrels inventory should drop to the ground
|
||||||
|
* @return True if a Barrel was removed
|
||||||
*/
|
*/
|
||||||
public static boolean removeBarrel(Block block) { // TODO add dropItems flag
|
public static boolean removeBarrel(Block block, boolean dropItems) {
|
||||||
return removeBarrelByPlayer(block, null);
|
return removeBarrelByPlayer(block, null, dropItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove any Barrel that this Block may be Part of, as if broken by the Player
|
* Remove any Barrel that this Block may be Part of, as if broken by the Player
|
||||||
* Returns true if a Barrel was removed
|
|
||||||
* Does not remove any actual Block from the World
|
* Does not remove any actual Block from the World
|
||||||
|
*
|
||||||
|
* @param block The Block thats part of the barrel, potions will drop there
|
||||||
|
* @param player The Player that broke the Block
|
||||||
|
* @param dropItems If the items in the barrels inventory should drop to the ground
|
||||||
|
* @return True if a Barrel was removed
|
||||||
*/
|
*/
|
||||||
public static boolean removeBarrelByPlayer(Block block, Player player) {
|
public static boolean removeBarrelByPlayer(Block block, Player player, boolean dropItems) {
|
||||||
Barrel barrel = Barrel.get(block);
|
Barrel barrel = Barrel.get(block);
|
||||||
if (barrel != null) {
|
if (barrel != null) {
|
||||||
barrel.remove(block, player);
|
barrel.remove(block, player, dropItems);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -170,7 +250,7 @@ public class BreweryApi {
|
|||||||
public static void addRecipe(BRecipe recipe, boolean saveForever) {
|
public static void addRecipe(BRecipe recipe, boolean saveForever) {
|
||||||
//recipe.setSaveInData(saveForever);
|
//recipe.setSaveInData(saveForever);
|
||||||
if (saveForever) {
|
if (saveForever) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException("SaveForever is not implemented yet");
|
||||||
}
|
}
|
||||||
BRecipe.getAddedRecipes().add(recipe);
|
BRecipe.getAddedRecipes().add(recipe);
|
||||||
recipe.updateAcceptedLists();
|
recipe.updateAcceptedLists();
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Brewery Config was reloaded
|
||||||
|
*/
|
||||||
public class ConfigLoadEvent extends Event {
|
public class ConfigLoadEvent extends Event {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
@@ -39,4 +42,9 @@ public class ConfigLoadEvent extends Event {
|
|||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
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.HandlerList;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Player adding an ingredient to a cauldron
|
* Player adding an ingredient to a cauldron
|
||||||
* Always one item added at a time
|
* Always one item added at a time
|
||||||
* If needed use the caudrons add method to manually add more Items
|
* 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;
|
return rItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the item currently being added to the cauldron by the player
|
/**
|
||||||
// Can be changed directly (mutable) or with the setter Method
|
* Get the item currently being added to the cauldron by the player
|
||||||
// The amount is ignored and always one added
|
* 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() {
|
public ItemStack getIngredient() {
|
||||||
return ingredient;
|
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
|
* Set the ingredient added to the cauldron to something else
|
||||||
// The amount is ignored and always one added
|
* Will always be accepted, even when not in a recipe or the cooked lis
|
||||||
// This also recalculates the recipeItem!
|
* 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) {
|
public void setIngredient(ItemStack ingredient) {
|
||||||
this.ingredient = ingredient;
|
this.ingredient = ingredient;
|
||||||
// The Ingredient has been changed. Recalculate RecipeItem!
|
// The Ingredient has been changed. Recalculate RecipeItem!
|
||||||
rItem = RecipeItem.getMatchingRecipeItem(ingredient, true);
|
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() {
|
public boolean willTakeItem() {
|
||||||
return takeItem;
|
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) {
|
public void setTakeItem(boolean takeItem) {
|
||||||
this.takeItem = 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() {
|
public Levelled getCauldronData() {
|
||||||
BlockData data = block.getBlockData();
|
BlockData data = block.getBlockData();
|
||||||
if (data instanceof Levelled) {
|
if (data instanceof Levelled) {
|
||||||
@@ -89,9 +110,13 @@ public class IngedientAddEvent extends PlayerEvent implements Cancellable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Water Fill level of the Cauldron
|
/**
|
||||||
// 0 = empty, 1 = something in, 2 = full
|
* Get the water fill level of the Cauldron
|
||||||
// Can use BCauldron.EMPTY, BCauldron.SOME, BCauldron.FULL
|
* 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() {
|
public byte getFillLevel() {
|
||||||
return LegacyUtil.getFillLevel(block);
|
return LegacyUtil.getFillLevel(block);
|
||||||
}
|
}
|
||||||
@@ -101,16 +126,21 @@ public class IngedientAddEvent extends PlayerEvent implements Cancellable {
|
|||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the event is cancelled, no item will be added or taken from the player
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancelled) {
|
public void setCancelled(boolean cancelled) {
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Required by Bukkit
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
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.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* The player pukes (throws puke items to the ground)
|
* 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
|
* 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
|
* Number of items to drop can be changed with count
|
||||||
@@ -23,10 +24,16 @@ public class PlayerPukeEvent extends PlayerEvent implements Cancellable {
|
|||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The Amount of items being dropped this time
|
||||||
|
*/
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param count Set the amount of items being dropped this time
|
||||||
|
*/
|
||||||
public void setCount(int count) {
|
public void setCount(int count) {
|
||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
@@ -48,11 +55,13 @@ public class PlayerPukeEvent extends PlayerEvent implements Cancellable {
|
|||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Required by Bukkit
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import org.bukkit.event.Cancellable;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* The Players movement is hindered because of drunkeness
|
* The Players movement is hindered because of drunkeness
|
||||||
* Called each time before pushing the Player with the Vector push 10 times
|
* Called each time before pushing the Player with the Vector push 10 times
|
||||||
* The Push Vector can be changed or multiplied
|
* 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
|
// The Vector in which direction and magnitude the player is Pushed
|
||||||
// Can be changed directly or through setPush
|
// 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() {
|
public Vector getPush() {
|
||||||
return push;
|
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) {
|
if (push == null) {
|
||||||
throw new NullPointerException("Push Vector is null");
|
throw new NullPointerException("Push Vector is null");
|
||||||
}
|
}
|
||||||
@@ -52,11 +64,13 @@ public class PlayerPushEvent extends PlayerEvent implements Cancellable {
|
|||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Required by Bukkit
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* A Player opens a Barrel by rightclicking it
|
* A Player opens a Barrel by rightclicking it
|
||||||
* The PlayerInteractEvent on the Barrel may be cancelled. In that case this never gets called
|
* The PlayerInteractEvent on the Barrel may be cancelled. In that case this never gets called
|
||||||
* Can be cancelled to silently deny opening the Barrel
|
* Can be cancelled to silently deny opening the Barrel
|
||||||
@@ -23,8 +24,10 @@ public class BarrelAccessEvent extends BarrelEvent implements Cancellable {
|
|||||||
this.clickedBlock = clickedBlock;
|
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() {
|
public Block getClickedBlock() {
|
||||||
return clickedBlock;
|
return clickedBlock;
|
||||||
}
|
}
|
||||||
@@ -43,11 +46,13 @@ public class BarrelAccessEvent extends BarrelEvent implements Cancellable {
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Required by Bukkit
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import com.dre.brewery.Barrel;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Called when a Barrel is created by a Player by placing a Sign
|
* Called when a Barrel is created by a Player by placing a Sign
|
||||||
* Cancelling this will silently fail the Barrel creation
|
* Cancelling this will silently fail the Barrel creation
|
||||||
*/
|
*/
|
||||||
@@ -33,11 +34,13 @@ public class BarrelCreateEvent extends BarrelEvent implements Cancellable {
|
|||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Required by Bukkit
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,14 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
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 Barrel is being destroyed by something, may not be by a Player
|
||||||
* A BarrelRemoveEvent will be called after this, if this is not cancelled
|
* 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
|
* 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 {
|
public class BarrelDestroyEvent extends BarrelEvent implements Cancellable {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
@@ -30,42 +33,79 @@ public class BarrelDestroyEvent extends BarrelEvent implements Cancellable {
|
|||||||
return cancelled;
|
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
|
@Override
|
||||||
public void setCancelled(boolean cancelled) {
|
public void setCancelled(boolean cancelled) {
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The Block of the Barrel that was broken
|
||||||
|
*/
|
||||||
public Block getBroken() {
|
public Block getBroken() {
|
||||||
return broken;
|
return broken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The Reason of destruction of this barrel, see Reason
|
||||||
|
*/
|
||||||
public Reason getReason() {
|
public Reason getReason() {
|
||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a Player was recorded destroying the barrel
|
||||||
|
*/
|
||||||
public boolean hasPlayer() {
|
public boolean hasPlayer() {
|
||||||
return player != null;
|
return player != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MAY BE NULL if no Player is involved
|
/**
|
||||||
|
* @return The Player, Null if no Player is involved
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
public Player getPlayerOptional() {
|
public Player getPlayerOptional() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Required by Bukkit
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Reason {
|
public enum Reason {
|
||||||
PLAYER, // A Player Broke the Barrel
|
/**
|
||||||
BROKEN, // A Block was broken by something
|
* A Player Broke the Barrel
|
||||||
BURNED, // A Block burned away
|
*/
|
||||||
EXPLODED, // The Barrel exploded somehow
|
PLAYER,
|
||||||
UNKNOWN // The Barrel was broken somehow else
|
|
||||||
|
/**
|
||||||
|
* 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 com.dre.brewery.Barrel;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
public abstract class BarrelEvent extends Event {
|
public abstract class BarrelEvent extends Event {
|
||||||
@@ -21,6 +20,9 @@ public abstract class BarrelEvent extends Event {
|
|||||||
return barrel.getInventory();
|
return barrel.getInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The Spigot Block of the Barrel, usually Sign or a Fence
|
||||||
|
*/
|
||||||
public Block getSpigot() {
|
public Block getSpigot() {
|
||||||
return barrel.getSpigot();
|
return barrel.getSpigot();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,32 +2,39 @@ package com.dre.brewery.api.events.barrel;
|
|||||||
|
|
||||||
import com.dre.brewery.Barrel;
|
import com.dre.brewery.Barrel;
|
||||||
import org.bukkit.event.HandlerList;
|
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
|
* If not, Worldedit, other Plugins etc may be the cause for unexpected removal
|
||||||
*/
|
*/
|
||||||
public class BarrelRemoveEvent extends BarrelEvent {
|
public class BarrelRemoveEvent extends BarrelEvent {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
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);
|
super(barrel);
|
||||||
|
this.dropItems = dropItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean willItemsDrop() {
|
public boolean willDropItems() {
|
||||||
return itemsDrop;
|
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
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Required by Bukkit
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* A Player Drinks a Brew
|
* A Player Drinks a Brew
|
||||||
* The amount of alcohol and quality that will be added to the player can be get/set here
|
* 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
|
* If cancelled the drinking will fail silently
|
||||||
@@ -65,11 +66,13 @@ public class BrewDrinkEvent extends BrewEvent implements Cancellable {
|
|||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Required by Bukkit
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* A Brew has been created or modified
|
* A Brew has been created or modified
|
||||||
* Usually happens on Filling from cauldron, distilling and aging.
|
* Usually happens on Filling from cauldron, distilling and aging.
|
||||||
* Modifications to the Brew or the PotionMeta can be done now
|
* Modifications to the Brew or the PotionMeta can be done now
|
||||||
@@ -40,7 +40,7 @@ public class BrewModifyEvent extends BrewEvent implements Cancellable {
|
|||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Setting the Event cancelled cancels all modificatons to the brew.
|
* Setting the Event cancelled cancels all modificatons to the brew.
|
||||||
* Modifications to the Brew or ItemMeta will not be applied
|
* Modifications to the Brew or ItemMeta will not be applied
|
||||||
*/
|
*/
|
||||||
@@ -55,6 +55,7 @@ public class BrewModifyEvent extends BrewEvent implements Cancellable {
|
|||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Required by Bukkit
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,9 @@ public class BlockListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onBlockBurn(BlockBurnEvent event) {
|
public void onBlockBurn(BlockBurnEvent event) {
|
||||||
BUtil.blockDestroy(event.getBlock(), null, BarrelDestroyEvent.Reason.BURNED);
|
if (!BUtil.blockDestroy(event.getBlock(), null, BarrelDestroyEvent.Reason.BURNED)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import java.util.ListIterator;
|
|||||||
|
|
||||||
public class EntityListener implements Listener {
|
public class EntityListener implements Listener {
|
||||||
|
|
||||||
// Remove the Potion from Brew when it despawns
|
// Legacy Brew removal
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onItemDespawn(ItemDespawnEvent event) {
|
public void onItemDespawn(ItemDespawnEvent event) {
|
||||||
if (Brew.noLegacy()) return;
|
if (Brew.noLegacy()) return;
|
||||||
@@ -77,7 +77,7 @@ public class EntityListener implements Listener {
|
|||||||
if (breakEvent.isCancelled()) {
|
if (breakEvent.isCancelled()) {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
} else {
|
} else {
|
||||||
barrel.remove(block, null);
|
barrel.remove(block, null, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package com.dre.brewery.listeners;
|
package com.dre.brewery.listeners;
|
||||||
|
|
||||||
import com.dre.brewery.*;
|
import com.dre.brewery.BDistiller;
|
||||||
|
import com.dre.brewery.Barrel;
|
||||||
|
import com.dre.brewery.Brew;
|
||||||
|
import com.dre.brewery.MCBarrel;
|
||||||
|
import com.dre.brewery.P;
|
||||||
import com.dre.brewery.filedata.BConfig;
|
import com.dre.brewery.filedata.BConfig;
|
||||||
import com.dre.brewery.lore.BrewLore;
|
import com.dre.brewery.lore.BrewLore;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|||||||
@@ -9,13 +9,14 @@ import java.io.ByteArrayInputStream;
|
|||||||
|
|
||||||
public class NBTLoadStream extends ByteArrayInputStream {
|
public class NBTLoadStream extends ByteArrayInputStream {
|
||||||
private static final String TAG = "brewdata";
|
private static final String TAG = "brewdata";
|
||||||
|
private static final NamespacedKey KEY = new NamespacedKey(P.p, TAG);
|
||||||
|
|
||||||
public NBTLoadStream(ItemMeta meta) {
|
public NBTLoadStream(ItemMeta meta) {
|
||||||
super(getNBTBytes(meta));
|
super(getNBTBytes(meta));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] getNBTBytes(ItemMeta meta) {
|
private static byte[] getNBTBytes(ItemMeta meta) {
|
||||||
byte[] bytes = LegacyUtil.readBytesItem(meta, new NamespacedKey(P.p, TAG));
|
byte[] bytes = LegacyUtil.readBytesItem(meta, KEY);
|
||||||
if (bytes == null) {
|
if (bytes == null) {
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
@@ -25,4 +26,8 @@ public class NBTLoadStream extends ByteArrayInputStream {
|
|||||||
public boolean hasData() {
|
public boolean hasData() {
|
||||||
return count > 0;
|
return count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasDataInMeta(ItemMeta meta) {
|
||||||
|
return LegacyUtil.hasBytesItem(meta, KEY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class NBTSaveStream extends ByteArrayOutputStream {
|
public class NBTSaveStream extends ByteArrayOutputStream {
|
||||||
private static final String TAG = "brewdata";
|
private static final String TAG = "brewdata";
|
||||||
|
private static final NamespacedKey KEY = new NamespacedKey(P.p, TAG);
|
||||||
|
|
||||||
private final ItemMeta meta;
|
private final ItemMeta meta;
|
||||||
|
|
||||||
public NBTSaveStream(ItemMeta meta) {
|
public NBTSaveStream(ItemMeta meta) {
|
||||||
@@ -21,6 +23,6 @@ public class NBTSaveStream extends ByteArrayOutputStream {
|
|||||||
public void flush() throws IOException {
|
public void flush() throws IOException {
|
||||||
super.flush();
|
super.flush();
|
||||||
if (size() <= 0) return;
|
if (size() <= 0) return;
|
||||||
LegacyUtil.writeBytesItem(toByteArray(), meta, new NamespacedKey(P.p, TAG));
|
LegacyUtil.writeBytesItem(toByteArray(), meta, KEY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ public class BUtil {
|
|||||||
Barrel barrel = Barrel.getBySpigot(block);
|
Barrel barrel = Barrel.getBySpigot(block);
|
||||||
if (barrel != null) {
|
if (barrel != null) {
|
||||||
if (barrel.hasPermsDestroy(player, block, reason)) {
|
if (barrel.hasPermsDestroy(player, block, reason)) {
|
||||||
barrel.remove(null, player);
|
barrel.remove(null, player, true);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@@ -183,7 +183,7 @@ public class BUtil {
|
|||||||
if (barrel2 != null) {
|
if (barrel2 != null) {
|
||||||
if (!barrel2.isLarge()) {
|
if (!barrel2.isLarge()) {
|
||||||
if (barrel2.hasPermsDestroy(player, block, reason)) {
|
if (barrel2.hasPermsDestroy(player, block, reason)) {
|
||||||
barrel2.remove(null, player);
|
barrel2.remove(null, player, true);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@@ -198,7 +198,7 @@ public class BUtil {
|
|||||||
Barrel barrel3 = Barrel.getByWood(block);
|
Barrel barrel3 = Barrel.getByWood(block);
|
||||||
if (barrel3 != null) {
|
if (barrel3 != null) {
|
||||||
if (barrel3.hasPermsDestroy(player, block, reason)) {
|
if (barrel3.hasPermsDestroy(player, block, reason)) {
|
||||||
barrel3.remove(block, player);
|
barrel3.remove(block, player, true);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,4 +291,13 @@ public class LegacyUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public static boolean hasBytesItem(ItemMeta meta, NamespacedKey key) {
|
||||||
|
if (NewNbtVer) {
|
||||||
|
return meta.getPersistentDataContainer().has(key, org.bukkit.persistence.PersistentDataType.BYTE_ARRAY);
|
||||||
|
} else {
|
||||||
|
return meta.getCustomTagContainer().hasCustomTag(key, org.bukkit.inventory.meta.tags.ItemTagType.BYTE_ARRAY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user