mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-23 11:45:32 +01:00
Started api and events
This commit is contained in:
parent
49fb0e3d82
commit
519c4821d9
@ -4,6 +4,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
|
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.block.data.Levelled;
|
import org.bukkit.block.data.Levelled;
|
||||||
|
import com.dre.brewery.api.events.IngedientAddEvent;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -12,16 +13,15 @@ import org.bukkit.Effect;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
public class BCauldron {
|
public class BCauldron {
|
||||||
public static CopyOnWriteArrayList<BCauldron> bcauldrons = new CopyOnWriteArrayList<>();
|
public static CopyOnWriteArrayList<BCauldron> bcauldrons = new CopyOnWriteArrayList<>(); // TODO find best Collection
|
||||||
|
|
||||||
private BIngredients ingredients = new BIngredients();
|
private BIngredients ingredients = new BIngredients();
|
||||||
private Block block;
|
private final Block block;
|
||||||
private int state = 1;
|
private int state = 1;
|
||||||
private boolean someRemoved = false;
|
private boolean someRemoved = false;
|
||||||
|
|
||||||
public BCauldron(Block block, ItemStack ingredient) {
|
public BCauldron(Block block) {
|
||||||
this.block = block;
|
this.block = block;
|
||||||
add(ingredient);
|
|
||||||
bcauldrons.add(this);
|
bcauldrons.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,8 @@ public class BCauldron {
|
|||||||
|
|
||||||
// add an ingredient to the cauldron
|
// add an ingredient to the cauldron
|
||||||
public void add(ItemStack ingredient) {
|
public void add(ItemStack ingredient) {
|
||||||
if (someRemoved) {
|
if (ingredient == null || ingredient.getType() == Material.AIR) return;
|
||||||
|
if (someRemoved) { // TODO no need to clone
|
||||||
ingredients = ingredients.clone();
|
ingredients = ingredients.clone();
|
||||||
someRemoved = false;
|
someRemoved = false;
|
||||||
}
|
}
|
||||||
@ -70,16 +71,22 @@ public class BCauldron {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get cauldron from block and add given ingredient
|
// get cauldron from block and add given ingredient
|
||||||
public static boolean ingredientAdd(Block block, ItemStack ingredient) {
|
// Calls the IngredientAddEvent and may be cancelled or changed
|
||||||
|
public static boolean ingredientAdd(Block block, ItemStack ingredient, Player player) {
|
||||||
// if not empty
|
// if not empty
|
||||||
if (LegacyUtil.getFillLevel(block) != 0) {
|
if (LegacyUtil.getFillLevel(block) != 0) {
|
||||||
BCauldron bcauldron = get(block);
|
BCauldron bcauldron = get(block);
|
||||||
if (bcauldron != null) {
|
if (bcauldron == null) {
|
||||||
bcauldron.add(ingredient);
|
bcauldron = new BCauldron(block);
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
IngedientAddEvent event = new IngedientAddEvent(player, block, bcauldron, ingredient);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
bcauldron.add(event.getIngredient());
|
||||||
|
return event.shouldTakeItem();
|
||||||
} else {
|
} else {
|
||||||
new BCauldron(block, ingredient);
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -161,13 +168,15 @@ public class BCauldron {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// reset to normal cauldron
|
// reset to normal cauldron
|
||||||
public static void remove(Block block) {
|
public static boolean remove(Block block) {
|
||||||
if (LegacyUtil.getFillLevel(block) != 0) {
|
if (LegacyUtil.getFillLevel(block) != 0) {
|
||||||
BCauldron bcauldron = get(block);
|
BCauldron bcauldron = get(block);
|
||||||
if (bcauldron != null) {
|
if (bcauldron != null) {
|
||||||
bcauldrons.remove(bcauldron);
|
bcauldrons.remove(bcauldron);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// unloads cauldrons that are in a unloading world
|
// unloads cauldrons that are in a unloading world
|
||||||
|
@ -2,6 +2,7 @@ package com.dre.brewery;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
public class BEffect {
|
public class BEffect {
|
||||||
@ -81,19 +82,26 @@ public class BEffect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apply(int quality, Player player) {
|
public PotionEffect generateEffect(int quality) {
|
||||||
int duration = calcDuration(quality);
|
int duration = calcDuration(quality);
|
||||||
int lvl = calcLvl(quality);
|
int lvl = calcLvl(quality);
|
||||||
|
|
||||||
if (lvl < 1 || (duration < 1 && !type.isInstant())) {
|
if (lvl < 1 || (duration < 1 && !type.isInstant())) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
duration *= 20;
|
duration *= 20;
|
||||||
if (!P.use1_14) {
|
if (!P.use1_14) {
|
||||||
duration /= type.getDurationModifier();
|
duration /= type.getDurationModifier();
|
||||||
}
|
}
|
||||||
Util.reapplyPotionEffect(player, type.createEffect(duration, lvl - 1), true);
|
return type.createEffect(duration, lvl - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apply(int quality, Player player) {
|
||||||
|
PotionEffect effect = generateEffect(quality);
|
||||||
|
if (effect != null) {
|
||||||
|
Util.reapplyPotionEffect(player, effect, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int calcDuration(float quality) {
|
public int calcDuration(float quality) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.dre.brewery;
|
package com.dre.brewery;
|
||||||
|
|
||||||
|
import com.dre.brewery.api.events.brew.BrewModifyEvent;
|
||||||
import com.dre.brewery.lore.BrewLore;
|
import com.dre.brewery.lore.BrewLore;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@ -120,6 +121,11 @@ public class BIngredients {
|
|||||||
cookedName = P.p.languageReader.get("Brew_Undefined");
|
cookedName = P.p.languageReader.get("Brew_Undefined");
|
||||||
Brew.PotionColor.CYAN.colorBrew(potionMeta, potion, true);
|
Brew.PotionColor.CYAN.colorBrew(potionMeta, potion, true);
|
||||||
}
|
}
|
||||||
|
BrewModifyEvent modifyEvent = new BrewModifyEvent(brew, BrewModifyEvent.Type.FILL);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(modifyEvent);
|
||||||
|
if (modifyEvent.isCancelled()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
potionMeta.setDisplayName(P.p.color("&f" + cookedName));
|
potionMeta.setDisplayName(P.p.color("&f" + cookedName));
|
||||||
if (!P.use1_14) {
|
if (!P.use1_14) {
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package com.dre.brewery;
|
package com.dre.brewery;
|
||||||
|
|
||||||
|
import com.dre.brewery.api.events.PlayerAlcEffectEvent;
|
||||||
|
import com.dre.brewery.api.events.PlayerDrinkEffectEvent;
|
||||||
|
import com.dre.brewery.api.events.PlayerPukeEvent;
|
||||||
|
import com.dre.brewery.api.events.PlayerPushEvent;
|
||||||
|
import com.dre.brewery.api.events.brew.BrewDrinkEvent;
|
||||||
import org.apache.commons.lang.mutable.MutableInt;
|
import org.apache.commons.lang.mutable.MutableInt;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -10,13 +15,20 @@ import org.bukkit.entity.Item;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BPlayer {
|
public class BPlayer {
|
||||||
private static Map<String, BPlayer> players = new HashMap<>();// Players name/uuid and BPlayer
|
private static Map<String, BPlayer> players = new HashMap<>();// Players name/uuid and BPlayer
|
||||||
@ -124,9 +136,10 @@ public class BPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
for (Map.Entry<String, BPlayer> entry : players.entrySet()) {
|
for (Iterator<Map.Entry<String, BPlayer>> iterator = players.entrySet().iterator(); iterator.hasNext(); ) {
|
||||||
|
Map.Entry<String, BPlayer> entry = iterator.next();
|
||||||
if (entry.getValue() == this) {
|
if (entry.getValue() == this) {
|
||||||
players.remove(entry.getKey());
|
iterator.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,32 +150,46 @@ public class BPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Drink a brew and apply effects, etc.
|
// Drink a brew and apply effects, etc.
|
||||||
public static void drink(Brew brew, Player player) {
|
public static boolean drink(Brew brew, Player player) {
|
||||||
int brewAlc = brew.calcAlcohol();
|
|
||||||
if (brewAlc == 0) {
|
|
||||||
//no alcohol so we dont need to add a BPlayer
|
|
||||||
addBrewEffects(brew, player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BPlayer bPlayer = get(player);
|
BPlayer bPlayer = get(player);
|
||||||
if (bPlayer == null) {
|
if (bPlayer == null) {
|
||||||
bPlayer = addPlayer(player);
|
bPlayer = addPlayer(player);
|
||||||
}
|
}
|
||||||
|
BrewDrinkEvent drinkEvent = new BrewDrinkEvent(brew, player, bPlayer);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(drinkEvent);
|
||||||
|
if (drinkEvent.isCancelled()) {
|
||||||
|
if (bPlayer.drunkeness <= 0) {
|
||||||
|
bPlayer.remove();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int brewAlc = drinkEvent.getAddedAlcohol();
|
||||||
|
int quality = drinkEvent.getQuality();
|
||||||
|
List<PotionEffect> effects = getBrewEffects(brew.getEffects(), quality);
|
||||||
|
|
||||||
|
if (brewAlc < 1) {
|
||||||
|
//no alcohol so we dont need to add a BPlayer
|
||||||
|
applyDrinkEffects(effects, player);
|
||||||
|
if (bPlayer.drunkeness <= 0) {
|
||||||
|
bPlayer.remove();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
effects.addAll(getQualityEffects(drinkEvent.getQuality(), brewAlc));
|
||||||
bPlayer.drunkeness += brewAlc;
|
bPlayer.drunkeness += brewAlc;
|
||||||
if (brew.getQuality() > 0) {
|
if (quality > 0) {
|
||||||
bPlayer.quality += brew.getQuality() * brewAlc;
|
bPlayer.quality += quality * brewAlc;
|
||||||
} else {
|
} else {
|
||||||
bPlayer.quality += brewAlc;
|
bPlayer.quality += brewAlc;
|
||||||
}
|
}
|
||||||
|
applyDrinkEffects(effects, player);
|
||||||
|
|
||||||
if (bPlayer.drunkeness <= 100) {
|
if (bPlayer.drunkeness > 100) {
|
||||||
|
|
||||||
addBrewEffects(brew, player);
|
|
||||||
addQualityEffects(brew.getQuality(), brewAlc, player);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
bPlayer.drinkCap(player);
|
bPlayer.drinkCap(player);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Player has drunken too much
|
// Player has drunken too much
|
||||||
@ -244,6 +271,13 @@ public class BPlayer {
|
|||||||
push.setX(Math.random() - 0.5);
|
push.setX(Math.random() - 0.5);
|
||||||
push.setZ(Math.random() - 0.5);
|
push.setZ(Math.random() - 0.5);
|
||||||
}
|
}
|
||||||
|
PlayerPushEvent pushEvent = new PlayerPushEvent(player, push, this);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(pushEvent);
|
||||||
|
push = pushEvent.getPush();
|
||||||
|
if (pushEvent.isCancelled() || push.lengthSquared() <= 0) {
|
||||||
|
time = -10;
|
||||||
|
return;
|
||||||
|
}
|
||||||
player.setVelocity(push);
|
player.setVelocity(push);
|
||||||
} else if (time < 0 && time > -10) {
|
} else if (time < 0 && time > -10) {
|
||||||
// push him some more in the same direction
|
// push him some more in the same direction
|
||||||
@ -382,6 +416,12 @@ public class BPlayer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlayerPukeEvent event = new PlayerPukeEvent(player, count);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled() || event.getCount() < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (pTasks.isEmpty()) {
|
if (pTasks.isEmpty()) {
|
||||||
taskId = P.p.getServer().getScheduler().scheduleSyncRepeatingTask(P.p, new Runnable() {
|
taskId = P.p.getServer().getScheduler().scheduleSyncRepeatingTask(P.p, new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -389,7 +429,7 @@ public class BPlayer {
|
|||||||
}
|
}
|
||||||
}, 1L, 1L);
|
}, 1L, 1L);
|
||||||
}
|
}
|
||||||
pTasks.put(player, new MutableInt(count));
|
pTasks.put(player, new MutableInt(event.getCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void pukeTask() {
|
public static void pukeTask() {
|
||||||
@ -466,6 +506,18 @@ public class BPlayer {
|
|||||||
|
|
||||||
// #### Effects ####
|
// #### Effects ####
|
||||||
|
|
||||||
|
public static void applyDrinkEffects(List<PotionEffect> effects, Player player) {
|
||||||
|
PlayerDrinkEffectEvent event = new PlayerDrinkEffectEvent(player, effects);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
effects = event.getEffects();
|
||||||
|
if (event.isCancelled() || effects == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (PotionEffect effect : effects) {
|
||||||
|
Util.reapplyPotionEffect(player, effect, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void drunkEffects(Player player) {
|
public void drunkEffects(Player player) {
|
||||||
int duration = 10 - getQuality();
|
int duration = 10 - getQuality();
|
||||||
duration += drunkeness / 2;
|
duration += drunkeness / 2;
|
||||||
@ -478,10 +530,22 @@ public class BPlayer {
|
|||||||
if (!P.use1_14) {
|
if (!P.use1_14) {
|
||||||
duration *= 4;
|
duration *= 4;
|
||||||
}
|
}
|
||||||
PotionEffectType.CONFUSION.createEffect(duration, 0).apply(player);
|
List<PotionEffect> l = new ArrayList<>(1);
|
||||||
|
l.add(PotionEffectType.CONFUSION.createEffect(duration, 0));
|
||||||
|
|
||||||
|
PlayerAlcEffectEvent event = new PlayerAlcEffectEvent(player, l);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
l = event.getEffects();
|
||||||
|
if (event.isCancelled() || l == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (PotionEffect effect : l) {
|
||||||
|
effect.apply(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addQualityEffects(int quality, int brewAlc, Player player) {
|
public static List<PotionEffect> getQualityEffects(int quality, int brewAlc) {
|
||||||
|
List<PotionEffect> out = new ArrayList<>(2);
|
||||||
int duration = 7 - quality;
|
int duration = 7 - quality;
|
||||||
if (quality == 0) {
|
if (quality == 0) {
|
||||||
duration *= 125;
|
duration *= 125;
|
||||||
@ -497,7 +561,7 @@ public class BPlayer {
|
|||||||
duration *= 4;
|
duration *= 4;
|
||||||
}
|
}
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
Util.reapplyPotionEffect(player, PotionEffectType.POISON.createEffect(duration, 0), true);
|
out.add(PotionEffectType.POISON.createEffect(duration, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (brewAlc > 10) {
|
if (brewAlc > 10) {
|
||||||
@ -511,8 +575,28 @@ public class BPlayer {
|
|||||||
if (!P.use1_14) {
|
if (!P.use1_14) {
|
||||||
duration *= 4;
|
duration *= 4;
|
||||||
}
|
}
|
||||||
Util.reapplyPotionEffect(player, PotionEffectType.BLINDNESS.createEffect(duration, 0), true);
|
out.add(PotionEffectType.BLINDNESS.createEffect(duration, 0));
|
||||||
}
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addQualityEffects(int quality, int brewAlc, Player player) {
|
||||||
|
for (PotionEffect effect : getQualityEffects(quality, brewAlc)) {
|
||||||
|
Util.reapplyPotionEffect(player, effect, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<PotionEffect> getBrewEffects(List<BEffect> effects, int quality) {
|
||||||
|
List<PotionEffect> out = new ArrayList<>();
|
||||||
|
if (effects != null) {
|
||||||
|
for (BEffect effect : effects) {
|
||||||
|
PotionEffect e = effect.generateEffect(quality);
|
||||||
|
if (e != null) {
|
||||||
|
out.add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addBrewEffects(Brew brew, Player player) {
|
public static void addBrewEffects(Brew brew, Player player) {
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package com.dre.brewery;
|
package com.dre.brewery;
|
||||||
|
|
||||||
|
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BUtil {
|
public class BUtil {
|
||||||
@ -25,4 +29,72 @@ public class BUtil {
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
---- Barrel ----
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Returns true if the Block can be destroyed by the Player or something else (null)
|
||||||
|
public static boolean blockDestroy(Block block, Player player, BarrelDestroyEvent.Reason reason) {
|
||||||
|
switch (block.getType()) {
|
||||||
|
case CAULDRON:
|
||||||
|
// will only remove when existing
|
||||||
|
BCauldron.remove(block);
|
||||||
|
return true;
|
||||||
|
case FENCE:
|
||||||
|
case NETHER_FENCE:
|
||||||
|
case ACACIA_FENCE:
|
||||||
|
case BIRCH_FENCE:
|
||||||
|
case DARK_OAK_FENCE:
|
||||||
|
case IRON_FENCE:
|
||||||
|
case JUNGLE_FENCE:
|
||||||
|
case SPRUCE_FENCE:
|
||||||
|
// remove barrel and throw potions on the ground
|
||||||
|
Barrel barrel = Barrel.getBySpigot(block);
|
||||||
|
if (barrel != null) {
|
||||||
|
if (barrel.hasPermsDestroy(player, block, reason)) {
|
||||||
|
barrel.remove(null, player);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case SIGN_POST:
|
||||||
|
case WALL_SIGN:
|
||||||
|
// remove small Barrels
|
||||||
|
Barrel barrel2 = Barrel.getBySpigot(block);
|
||||||
|
if (barrel2 != null) {
|
||||||
|
if (!barrel2.isLarge()) {
|
||||||
|
if (barrel2.hasPermsDestroy(player, block, reason)) {
|
||||||
|
barrel2.remove(null, player);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
barrel2.destroySign();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case WOOD:
|
||||||
|
case WOOD_STAIRS:
|
||||||
|
case BIRCH_WOOD_STAIRS:
|
||||||
|
case JUNGLE_WOOD_STAIRS:
|
||||||
|
case SPRUCE_WOOD_STAIRS:
|
||||||
|
case ACACIA_STAIRS:
|
||||||
|
case DARK_OAK_STAIRS:
|
||||||
|
Barrel barrel3 = Barrel.getByWood(block);
|
||||||
|
if (barrel3 != null) {
|
||||||
|
if (barrel3.hasPermsDestroy(player, block, reason)) {
|
||||||
|
barrel3.remove(block, player);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package com.dre.brewery;
|
package com.dre.brewery;
|
||||||
|
|
||||||
|
import com.dre.brewery.api.events.barrel.BarrelAccessEvent;
|
||||||
|
import com.dre.brewery.api.events.barrel.BarrelCreateEvent;
|
||||||
|
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
||||||
|
import com.dre.brewery.api.events.barrel.BarrelRemoveEvent;
|
||||||
import com.dre.brewery.integration.CitadelBarrel;
|
import com.dre.brewery.integration.CitadelBarrel;
|
||||||
import com.dre.brewery.integration.GriefPreventionBarrel;
|
import com.dre.brewery.integration.GriefPreventionBarrel;
|
||||||
import com.dre.brewery.integration.LWCBarrel;
|
import com.dre.brewery.integration.LWCBarrel;
|
||||||
import com.dre.brewery.integration.LogBlockBarrel;
|
import com.dre.brewery.integration.LogBlockBarrel;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
|
||||||
import com.dre.brewery.lore.BrewLore;
|
import com.dre.brewery.lore.BrewLore;
|
||||||
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.TreeSpecies;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
@ -16,6 +21,10 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
import org.bukkit.material.MaterialData;
|
||||||
|
import org.bukkit.material.Stairs;
|
||||||
|
import org.bukkit.material.Tree;
|
||||||
|
import org.bukkit.material.Wood;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
@ -26,7 +35,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
|
|
||||||
public class Barrel implements InventoryHolder {
|
public class Barrel implements InventoryHolder {
|
||||||
|
|
||||||
public static CopyOnWriteArrayList<Barrel> barrels = new CopyOnWriteArrayList<>();
|
public static CopyOnWriteArrayList<Barrel> barrels = new CopyOnWriteArrayList<>(); // TODO find best collection
|
||||||
private static int check = 0;
|
private static int check = 0;
|
||||||
|
|
||||||
private Block spigot;
|
private Block spigot;
|
||||||
@ -47,9 +56,9 @@ public class Barrel implements InventoryHolder {
|
|||||||
this.spigot = spigot;
|
this.spigot = spigot;
|
||||||
this.signoffset = sign;
|
this.signoffset = sign;
|
||||||
if (isLarge()) {
|
if (isLarge()) {
|
||||||
this.inventory = org.bukkit.Bukkit.createInventory(this, 27, P.p.languageReader.get("Etc_Barrel"));
|
this.inventory = P.p.getServer().createInventory(this, 27, P.p.languageReader.get("Etc_Barrel"));
|
||||||
} else {
|
} else {
|
||||||
this.inventory = org.bukkit.Bukkit.createInventory(this, 9, P.p.languageReader.get("Etc_Barrel"));
|
this.inventory = P.p.getServer().createInventory(this, 9, P.p.languageReader.get("Etc_Barrel"));
|
||||||
}
|
}
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
for (String slot : items.keySet()) {
|
for (String slot : items.keySet()) {
|
||||||
@ -119,57 +128,21 @@ public class Barrel implements InventoryHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (P.p.useWG) {
|
// Call event
|
||||||
Plugin plugin = P.p.getServer().getPluginManager().getPlugin("WorldGuard");
|
BarrelAccessEvent accessEvent = new BarrelAccessEvent(this, player, event.getClickedBlock());
|
||||||
if (plugin != null) {
|
// Listened to by WGBarrelNew, WGBarrelOld, GriefPreventionBarrel (IntegrationListener)
|
||||||
try {
|
P.p.getServer().getPluginManager().callEvent(accessEvent);
|
||||||
if (!P.p.wg.checkAccess(player, spigot, plugin)) {
|
if (accessEvent.isCancelled()) {
|
||||||
|
P.p.msg(player, P.p.languageReader.get("Error_NoBarrelAccess"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
|
||||||
P.p.errorLog("Failed to Check WorldGuard for Barrel Open Permissions!");
|
|
||||||
P.p.errorLog("Brewery was tested with version 5.8, 6.1 to 7.0 of WorldGuard!");
|
|
||||||
P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
|
|
||||||
e.printStackTrace();
|
|
||||||
if (player.hasPermission("brewery.admin") || player.hasPermission("brewery.mod")) {
|
|
||||||
P.p.msg(player, "&cWorldGuard check Error, Brewery was tested with up to v7.0 of Worldguard");
|
|
||||||
P.p.msg(player, "&cSet &7useWorldGuard: false &cin the config and /brew reload");
|
|
||||||
} else {
|
|
||||||
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (P.p.useGP) {
|
|
||||||
if (P.p.getServer().getPluginManager().isPluginEnabled("GriefPrevention")) {
|
|
||||||
try {
|
|
||||||
if (!GriefPreventionBarrel.checkAccess(player, spigot)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
P.p.errorLog("Failed to Check GriefPrevention for Barrel Open Permissions!");
|
|
||||||
P.p.errorLog("Brewery was tested with GriefPrevention v14.5 - v16.9");
|
|
||||||
P.p.errorLog("Disable the GriefPrevention support in the config and do /brew reload");
|
|
||||||
e.printStackTrace();
|
|
||||||
if (player.hasPermission("brewery.admin") || player.hasPermission("brewery.mod")) {
|
|
||||||
P.p.msg(player, "&cGriefPrevention check Error, Brewery was tested with up to v16.9 of GriefPrevention");
|
|
||||||
P.p.msg(player, "&cSet &7useGriefPrevention: false &cin the config and /brew reload");
|
|
||||||
} else {
|
|
||||||
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event != null && P.p.useLWC) {
|
if (event != null && P.p.useLWC) {
|
||||||
Plugin plugin = P.p.getServer().getPluginManager().getPlugin("LWC");
|
Plugin plugin = P.p.getServer().getPluginManager().getPlugin("LWC");
|
||||||
if (plugin != null) {
|
if (plugin != null) {
|
||||||
|
|
||||||
// If the Clicked Block was the Sign, LWC already knows and we dont need to do anything here
|
// If the Clicked Block was the Sign, LWC already knows and we dont need to do anything here
|
||||||
if (!LegacyUtil.isSign(event.getClickedBlock().getType())) {
|
if (!isSign(event.getClickedBlock())) {
|
||||||
Block sign = getSignOfSpigot();
|
Block sign = getSignOfSpigot();
|
||||||
// If the Barrel does not have a Sign, it cannot be locked
|
// If the Barrel does not have a Sign, it cannot be locked
|
||||||
if (!sign.equals(event.getClickedBlock())) {
|
if (!sign.equals(event.getClickedBlock())) {
|
||||||
@ -180,60 +153,6 @@ public class Barrel implements InventoryHolder {
|
|||||||
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
|
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
|
||||||
P.p.errorLog("Disable the LWC support in the config and do /brew reload");
|
P.p.errorLog("Disable the LWC support in the config and do /brew reload");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (player.hasPermission("brewery.admin") || player.hasPermission("brewery.mod")) {
|
|
||||||
P.p.msg(player, "&cLWC check Error, Brewery was tested with up to v4.5.0 of LWC");
|
|
||||||
P.p.msg(player, "&cSet &7useLWC: false &cin the config and /brew reload");
|
|
||||||
} else {
|
|
||||||
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event != null && P.p.useCitadel) {
|
|
||||||
Plugin plugin = P.p.getServer().getPluginManager().getPlugin("Citadel");
|
|
||||||
if (plugin != null) {
|
|
||||||
try {
|
|
||||||
if (LegacyUtil.isSign(event.getClickedBlock().getType())) {
|
|
||||||
return CitadelBarrel.checkAccess(player, getSignOfSpigot());
|
|
||||||
} else {
|
|
||||||
return CitadelBarrel.checkAccess(player, spigot);
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
P.p.errorLog("Failed to Check Citadel for Container Access Permissions!");
|
|
||||||
P.p.errorLog("Brewery was tested with version 3.9.1 of Citadel!");
|
|
||||||
P.p.errorLog("Disable Citadel support in the config and do /brew reload");
|
|
||||||
e.printStackTrace();
|
|
||||||
if (player.hasPermission("brewery.admin") || player.hasPermission("brewery.mod")) {
|
|
||||||
P.p.msg(player, "&cCitadel check Error, Brewery was tested with up to v3.9.1 of Citadel");
|
|
||||||
} else {
|
|
||||||
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ask for permission to destroy barrel, remove protection if has
|
|
||||||
public boolean hasPermsDestroy(Player player) {
|
|
||||||
if (player == null) {
|
|
||||||
willDestroy();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (P.p.useLWC) {
|
|
||||||
try {
|
|
||||||
return LWCBarrel.checkDestroy(player, this);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
P.p.errorLog("Failed to Check LWC for Barrel Break Permissions!");
|
|
||||||
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
|
|
||||||
P.p.errorLog("Disable the LWC support in the config and do /brew reload");
|
|
||||||
e.printStackTrace();
|
|
||||||
if (player.hasPermission("brewery.admin") || player.hasPermission("brewery.mod")) {
|
if (player.hasPermission("brewery.admin") || player.hasPermission("brewery.mod")) {
|
||||||
P.p.msg(player, "&cLWC check Error, Brewery was tested with up to v4.5.0 of LWC");
|
P.p.msg(player, "&cLWC check Error, Brewery was tested with up to v4.5.0 of LWC");
|
||||||
P.p.msg(player, "&cSet &7useLWC: false &cin the config and /brew reload");
|
P.p.msg(player, "&cSet &7useLWC: false &cin the config and /brew reload");
|
||||||
@ -243,30 +162,28 @@ public class Barrel implements InventoryHolder {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If something other than the Player is destroying the barrel, inform protection plugins
|
// Ask for permission to destroy barrel
|
||||||
public void willDestroy() {
|
public boolean hasPermsDestroy(Player player, Block block, BarrelDestroyEvent.Reason reason) {
|
||||||
if (P.p.useLWC) {
|
// Listened to by LWCBarrel (IntegrationListener)
|
||||||
try {
|
BarrelDestroyEvent destroyEvent = new BarrelDestroyEvent(this, block, reason, player);
|
||||||
LWCBarrel.remove(this);
|
P.p.getServer().getPluginManager().callEvent(destroyEvent);
|
||||||
} catch (Throwable e) {
|
return !destroyEvent.isCancelled();
|
||||||
P.p.errorLog("Failed to Remove LWC Lock from Barrel!");
|
|
||||||
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// player opens the barrel
|
// player opens the barrel
|
||||||
public void open(Player player) {
|
public void open(Player player) {
|
||||||
if (inventory == null) {
|
if (inventory == null) {
|
||||||
if (isLarge()) {
|
if (isLarge()) {
|
||||||
inventory = org.bukkit.Bukkit.createInventory(this, 27, P.p.languageReader.get("Etc_Barrel"));
|
inventory = P.p.getServer().createInventory(this, 27, P.p.languageReader.get("Etc_Barrel"));
|
||||||
} else {
|
} else {
|
||||||
inventory = org.bukkit.Bukkit.createInventory(this, 9, P.p.languageReader.get("Etc_Barrel"));
|
inventory = P.p.getServer().createInventory(this, 9, P.p.languageReader.get("Etc_Barrel"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (time > 0) {
|
if (time > 0) {
|
||||||
@ -315,6 +232,10 @@ public class Barrel implements InventoryHolder {
|
|||||||
return spigot;
|
return spigot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
// Returns true if this Block is part of this Barrel
|
// Returns true if this Block is part of this Barrel
|
||||||
public boolean hasBlock(Block block) {
|
public boolean hasBlock(Block block) {
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
@ -457,9 +378,13 @@ public class Barrel implements InventoryHolder {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BarrelCreateEvent createEvent = new BarrelCreateEvent(barrel, player);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(createEvent);
|
||||||
|
if (!createEvent.isCancelled()) {
|
||||||
barrels.add(barrel);
|
barrels.add(barrel);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (barrel.signoffset == 0 && signoffset != 0) {
|
if (barrel.signoffset == 0 && signoffset != 0) {
|
||||||
barrel.signoffset = signoffset;
|
barrel.signoffset = signoffset;
|
||||||
@ -471,6 +396,10 @@ public class Barrel implements InventoryHolder {
|
|||||||
|
|
||||||
// removes a barrel, throwing included potions to the ground
|
// removes a barrel, throwing included potions to the ground
|
||||||
public void remove(Block broken, Player breaker) {
|
public void remove(Block broken, Player breaker) {
|
||||||
|
BarrelRemoveEvent event = new BarrelRemoveEvent(this);
|
||||||
|
// Listened to by LWCBarrel (IntegrationListener)
|
||||||
|
P.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (inventory != null) {
|
if (inventory != null) {
|
||||||
List<HumanEntity> viewers = new ArrayList(inventory.getViewers());
|
List<HumanEntity> viewers = new ArrayList(inventory.getViewers());
|
||||||
// Copy List to fix ConcModExc
|
// Copy List to fix ConcModExc
|
||||||
@ -481,13 +410,14 @@ public class Barrel implements InventoryHolder {
|
|||||||
inventory.clear();
|
inventory.clear();
|
||||||
if (P.p.useLB && breaker != null) {
|
if (P.p.useLB && breaker != null) {
|
||||||
try {
|
try {
|
||||||
LogBlockBarrel.breakBarrel(breaker, items, spigot.getLocation());
|
LogBlockBarrel.breakBarrel(breaker.getName(), items, spigot.getLocation());
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
P.p.errorLog("Failed to Log Barrel-break to LogBlock!");
|
P.p.errorLog("Failed to Log Barrel-break to LogBlock!");
|
||||||
P.p.errorLog("Brewery was tested with version 1.94 of LogBlock!");
|
P.p.errorLog("Brewery was tested with version 1.94 of LogBlock!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (event.shouldItemsDrop()) {
|
||||||
for (ItemStack item : items) {
|
for (ItemStack item : items) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
Brew brew = Brew.get(item);
|
Brew brew = Brew.get(item);
|
||||||
@ -511,6 +441,7 @@ public class Barrel implements InventoryHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
barrels.remove(this);
|
barrels.remove(this);
|
||||||
}
|
}
|
||||||
@ -638,6 +569,11 @@ public class Barrel implements InventoryHolder {
|
|||||||
|
|
||||||
// is this a Large barrel?
|
// is this a Large barrel?
|
||||||
public boolean isLarge() {
|
public boolean isLarge() {
|
||||||
|
return !isSmall();
|
||||||
|
}
|
||||||
|
|
||||||
|
// is this a Small barrel?
|
||||||
|
public boolean isSmall() {
|
||||||
return !LegacyUtil.isSign(spigot.getType());
|
return !LegacyUtil.isSign(spigot.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -889,7 +825,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.willDestroy();
|
barrel.willDestroy(); // TODO Check if still needed
|
||||||
barrel.remove(broken, null);
|
barrel.remove(broken, null);
|
||||||
} 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
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.dre.brewery;
|
package com.dre.brewery;
|
||||||
|
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
|
import com.dre.brewery.api.events.brew.BrewModifyEvent;
|
||||||
import com.dre.brewery.lore.*;
|
import com.dre.brewery.lore.*;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@ -458,6 +459,9 @@ public class Brew {
|
|||||||
// distill custom potion in given slot
|
// distill custom potion in given slot
|
||||||
public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) {
|
public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) {
|
||||||
if (immutable) return;
|
if (immutable) return;
|
||||||
|
BrewModifyEvent modifyEvent = new BrewModifyEvent(this, BrewModifyEvent.Type.DISTILL);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(modifyEvent);
|
||||||
|
if (modifyEvent.isCancelled()) return;
|
||||||
|
|
||||||
distillRuns += 1;
|
distillRuns += 1;
|
||||||
BrewLore lore = new BrewLore(this, potionMeta);
|
BrewLore lore = new BrewLore(this, potionMeta);
|
||||||
@ -512,6 +516,9 @@ public class Brew {
|
|||||||
|
|
||||||
public void age(ItemStack item, float time, byte woodType) {
|
public void age(ItemStack item, float time, byte woodType) {
|
||||||
if (immutable) return;
|
if (immutable) return;
|
||||||
|
BrewModifyEvent modifyEvent = new BrewModifyEvent(this, BrewModifyEvent.Type.AGE);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(modifyEvent);
|
||||||
|
if (modifyEvent.isCancelled()) return;
|
||||||
|
|
||||||
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||||
BrewLore lore = new BrewLore(this, potionMeta);
|
BrewLore lore = new BrewLore(this, potionMeta);
|
||||||
|
@ -5,12 +5,19 @@ import com.dre.brewery.filedata.DataSave;
|
|||||||
import com.dre.brewery.filedata.DataUpdater;
|
import com.dre.brewery.filedata.DataUpdater;
|
||||||
import com.dre.brewery.filedata.LanguageReader;
|
import com.dre.brewery.filedata.LanguageReader;
|
||||||
import com.dre.brewery.filedata.UpdateChecker;
|
import com.dre.brewery.filedata.UpdateChecker;
|
||||||
|
import com.dre.brewery.integration.IntegrationListener;
|
||||||
import com.dre.brewery.integration.LogBlockBarrel;
|
import com.dre.brewery.integration.LogBlockBarrel;
|
||||||
import com.dre.brewery.integration.WGBarrel;
|
import com.dre.brewery.integration.WGBarrel;
|
||||||
import com.dre.brewery.integration.WGBarrel7;
|
import com.dre.brewery.integration.WGBarrel7;
|
||||||
import com.dre.brewery.integration.WGBarrelNew;
|
import com.dre.brewery.integration.WGBarrelNew;
|
||||||
import com.dre.brewery.integration.WGBarrelOld;
|
import com.dre.brewery.integration.WGBarrelOld;
|
||||||
import com.dre.brewery.listeners.*;
|
import com.dre.brewery.listeners.BlockListener;
|
||||||
|
import com.dre.brewery.listeners.CauldronListener;
|
||||||
|
import com.dre.brewery.listeners.CommandListener;
|
||||||
|
import com.dre.brewery.listeners.EntityListener;
|
||||||
|
import com.dre.brewery.listeners.InventoryListener;
|
||||||
|
import com.dre.brewery.listeners.PlayerListener;
|
||||||
|
import com.dre.brewery.listeners.WorldListener;
|
||||||
import org.apache.commons.lang.math.NumberUtils;
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -31,11 +38,14 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -65,6 +75,7 @@ public class P extends JavaPlugin {
|
|||||||
public EntityListener entityListener;
|
public EntityListener entityListener;
|
||||||
public InventoryListener inventoryListener;
|
public InventoryListener inventoryListener;
|
||||||
public WorldListener worldListener;
|
public WorldListener worldListener;
|
||||||
|
public IntegrationListener integrationListener;
|
||||||
|
|
||||||
// Language
|
// Language
|
||||||
public String language;
|
public String language;
|
||||||
@ -413,6 +424,7 @@ public class P extends JavaPlugin {
|
|||||||
entityListener = new EntityListener();
|
entityListener = new EntityListener();
|
||||||
inventoryListener = new InventoryListener();
|
inventoryListener = new InventoryListener();
|
||||||
worldListener = new WorldListener();
|
worldListener = new WorldListener();
|
||||||
|
integrationListener = new IntegrationListener();
|
||||||
getCommand("Brewery").setExecutor(new CommandListener());
|
getCommand("Brewery").setExecutor(new CommandListener());
|
||||||
getCommand("Brewery").setTabCompleter(new TabListener());
|
getCommand("Brewery").setTabCompleter(new TabListener());
|
||||||
|
|
||||||
@ -421,6 +433,7 @@ public class P extends JavaPlugin {
|
|||||||
p.getServer().getPluginManager().registerEvents(entityListener, p);
|
p.getServer().getPluginManager().registerEvents(entityListener, p);
|
||||||
p.getServer().getPluginManager().registerEvents(inventoryListener, p);
|
p.getServer().getPluginManager().registerEvents(inventoryListener, p);
|
||||||
p.getServer().getPluginManager().registerEvents(worldListener, p);
|
p.getServer().getPluginManager().registerEvents(worldListener, p);
|
||||||
|
p.getServer().getPluginManager().registerEvents(integrationListener, p);
|
||||||
if (use1_9) {
|
if (use1_9) {
|
||||||
p.getServer().getPluginManager().registerEvents(new CauldronListener(), p);
|
p.getServer().getPluginManager().registerEvents(new CauldronListener(), p);
|
||||||
}
|
}
|
||||||
@ -579,6 +592,11 @@ public class P extends JavaPlugin {
|
|||||||
|
|
||||||
// Third-Party
|
// Third-Party
|
||||||
useWG = config.getBoolean("useWorldGuard", true) && getServer().getPluginManager().isPluginEnabled("WorldGuard");
|
useWG = config.getBoolean("useWorldGuard", true) && getServer().getPluginManager().isPluginEnabled("WorldGuard");
|
||||||
|
useLWC = config.getBoolean("useLWC", true) && getServer().getPluginManager().isPluginEnabled("LWC");
|
||||||
|
useGP = config.getBoolean("useGriefPrevention", true) && getServer().getPluginManager().isPluginEnabled("GriefPrevention");
|
||||||
|
useLB = config.getBoolean("useLogBlock", false) && getServer().getPluginManager().isPluginEnabled("LogBlock");
|
||||||
|
hasVault = getServer().getPluginManager().isPluginEnabled("Vault");
|
||||||
|
|
||||||
if (useWG) {
|
if (useWG) {
|
||||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldEdit");
|
Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||||
if (plugin != null) {
|
if (plugin != null) {
|
||||||
|
150
src/com/dre/brewery/api/BreweryApi.java
Normal file
150
src/com/dre/brewery/api/BreweryApi.java
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
package com.dre.brewery.api;
|
||||||
|
|
||||||
|
import com.dre.brewery.BCauldron;
|
||||||
|
import com.dre.brewery.BRecipe;
|
||||||
|
import com.dre.brewery.Barrel;
|
||||||
|
import com.dre.brewery.Brew;
|
||||||
|
import org.apache.commons.lang.NotImplementedException;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
public class BreweryApi {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convenience methods to get common objects or do common things
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove any data that this Plugin may associate with the given Block
|
||||||
|
* Currently Cauldrons and Barrels (Cauldron, Wood, Woodstairs, Fence, Sign)
|
||||||
|
* Does not remove any actual Blocks
|
||||||
|
* Returns true if anything was removed
|
||||||
|
*/
|
||||||
|
public static boolean removeAny(Block block) {
|
||||||
|
if (removeCauldron(block)) return true;
|
||||||
|
return removeBarrel(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Like removeAny() but removes data as if the given player broke the Block
|
||||||
|
* Currently only makes a difference for Logging
|
||||||
|
*/
|
||||||
|
public static boolean removeAnyByPlayer(Block block, Player player) {
|
||||||
|
if (removeCauldron(block)) return true;
|
||||||
|
return removeBarrelByPlayer(block, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// # # # # # Brew # # # # #
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a Brew from an ItemStack
|
||||||
|
* Reads the Brew data from the saved data on the item
|
||||||
|
* Checks if item is actually a Brew
|
||||||
|
* Returns null if item is not a Brew
|
||||||
|
*/
|
||||||
|
public static Brew getBrew(ItemStack item) {
|
||||||
|
return Brew.get(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a Brew from an ItemMeta
|
||||||
|
* Reads the Brew data from the saved data in the Meta
|
||||||
|
* Checks if meta has a Brew saved
|
||||||
|
* Returns null if meta is not a Brew
|
||||||
|
*/
|
||||||
|
public static Brew getBrew(ItemMeta meta) {
|
||||||
|
return Brew.get(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// # # # # # Barrel # # # # #
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a Barrel from a Block
|
||||||
|
* May be any Wood, Fence, Sign that is part of a Barrel
|
||||||
|
* Returns null if block is not part of a Barrel
|
||||||
|
*/
|
||||||
|
public static Barrel getBarrel(Block block) {
|
||||||
|
return Barrel.get(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the Inventory of a Block part of a Barrel
|
||||||
|
* May be any Wood, Fence or Sign that is part of a Barrel
|
||||||
|
* Returns null if block is not part of a Barrel
|
||||||
|
*/
|
||||||
|
public static Inventory getBarrelInventory(Block block) {
|
||||||
|
Barrel barrel = Barrel.get(block);
|
||||||
|
if (barrel != null) {
|
||||||
|
return barrel.getInventory();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove any Barrel that this Block may be Part of
|
||||||
|
* Returns true if a Barrel was removed
|
||||||
|
* Does not remove any actual Block
|
||||||
|
*/
|
||||||
|
public static boolean removeBarrel(Block block) { // TODO add dropItems flag
|
||||||
|
return removeBarrelByPlayer(block, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public static boolean removeBarrelByPlayer(Block block, Player player) {
|
||||||
|
Barrel barrel = Barrel.get(block);
|
||||||
|
if (barrel != null) {
|
||||||
|
barrel.remove(block, player);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// # # # # # Cauldron # # # # #
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a BCauldron from a Block
|
||||||
|
* Returns null if block is not a BCauldron
|
||||||
|
*/
|
||||||
|
public static BCauldron getCauldron(Block block) {
|
||||||
|
return BCauldron.get(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove any data associated with a Cauldron at that given Block
|
||||||
|
* Returns true if a Cauldron was removed
|
||||||
|
* Does not actually remove the Block
|
||||||
|
*/
|
||||||
|
public static boolean removeCauldron(Block block) {
|
||||||
|
return BCauldron.remove(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// # # # # # Recipe # # # # #
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a BRecipe by its name
|
||||||
|
* The name is the middle one of the three if three are set in the config
|
||||||
|
* Returns null if recipe with that name does not exist
|
||||||
|
*/
|
||||||
|
public static BRecipe getRecipe(String name) {
|
||||||
|
return BRecipe.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add a new recipe
|
||||||
|
* Not Implemented yet
|
||||||
|
*/
|
||||||
|
public static boolean addRecipe(BRecipe recipe) {
|
||||||
|
throw new NotImplementedException(); // TODO implement
|
||||||
|
}
|
||||||
|
}
|
103
src/com/dre/brewery/api/events/IngedientAddEvent.java
Normal file
103
src/com/dre/brewery/api/events/IngedientAddEvent.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
package com.dre.brewery.api.events;
|
||||||
|
|
||||||
|
import com.dre.brewery.BCauldron;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.material.Cauldron;
|
||||||
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public class IngedientAddEvent extends PlayerEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private final Block block;
|
||||||
|
private final BCauldron cauldron;
|
||||||
|
private ItemStack ingredient;
|
||||||
|
private boolean cancelled;
|
||||||
|
private boolean takeItem = true;
|
||||||
|
|
||||||
|
public IngedientAddEvent(Player who, Block block, BCauldron bCauldron, ItemStack ingredient) {
|
||||||
|
super(who);
|
||||||
|
this.block = block;
|
||||||
|
cauldron = bCauldron;
|
||||||
|
this.ingredient = ingredient.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block getBlock() {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BCauldron getCauldron() {
|
||||||
|
return cauldron;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the item currently being added to the cauldron by the player
|
||||||
|
// Can be changed directly or with the setter
|
||||||
|
// The amount is ignored and always one 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
|
||||||
|
public void setIngredient(ItemStack ingredient) {
|
||||||
|
this.ingredient = ingredient;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the amount of the item in the players hand should be decreased
|
||||||
|
// Default true
|
||||||
|
public boolean shouldTakeItem() {
|
||||||
|
return takeItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set if the amount of the item in the players hand should be decreased
|
||||||
|
public void setTakeItem(boolean takeItem) {
|
||||||
|
this.takeItem = takeItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the MaterialData of the Cauldron
|
||||||
|
// May be null if the Cauldron does not exist anymore
|
||||||
|
public Cauldron getCauldronData() {
|
||||||
|
BlockState state = block.getState();
|
||||||
|
if (state != null) {
|
||||||
|
MaterialData data = state.getData();
|
||||||
|
if (data instanceof Cauldron) {
|
||||||
|
return ((Cauldron) state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0 = empty, 1 = something in, 2 = full
|
||||||
|
public int getFillLevel() {
|
||||||
|
return BCauldron.getFillLevel(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
54
src/com/dre/brewery/api/events/PlayerAlcEffectEvent.java
Normal file
54
src/com/dre/brewery/api/events/PlayerAlcEffectEvent.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
src/com/dre/brewery/api/events/PlayerDrinkEffectEvent.java
Normal file
52
src/com/dre/brewery/api/events/PlayerDrinkEffectEvent.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
60
src/com/dre/brewery/api/events/PlayerPukeEvent.java
Normal file
60
src/com/dre/brewery/api/events/PlayerPukeEvent.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
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.HandlerList;
|
||||||
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public class PlayerPukeEvent extends PlayerEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private int count;
|
||||||
|
private boolean cancelled;
|
||||||
|
private BPlayer bPlayer;
|
||||||
|
|
||||||
|
|
||||||
|
public PlayerPukeEvent(Player who, int count) {
|
||||||
|
super(who);
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCount(int count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BPlayer getBPlayer() {
|
||||||
|
if (bPlayer == null) {
|
||||||
|
bPlayer = BPlayer.get(player);
|
||||||
|
}
|
||||||
|
return bPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
64
src/com/dre/brewery/api/events/PlayerPushEvent.java
Normal file
64
src/com/dre/brewery/api/events/PlayerPushEvent.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
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.HandlerList;
|
||||||
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public class PlayerPushEvent extends PlayerEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private final BPlayer bPlayer;
|
||||||
|
private Vector push;
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
public PlayerPushEvent(Player who, Vector push, BPlayer bPlayer) {
|
||||||
|
super(who);
|
||||||
|
this.push = push;
|
||||||
|
this.bPlayer = bPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BPlayer getbPlayer() {
|
||||||
|
return bPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The Vector in which direction and magnitude the player is Pushed
|
||||||
|
// Can be changed directly or through setPush
|
||||||
|
public Vector getPush() {
|
||||||
|
return push;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the Push vector, can not be null
|
||||||
|
public void setPush(Vector push) {
|
||||||
|
if (push == null) {
|
||||||
|
throw new NullPointerException("Push Vector is null");
|
||||||
|
}
|
||||||
|
this.push = push;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
54
src/com/dre/brewery/api/events/barrel/BarrelAccessEvent.java
Normal file
54
src/com/dre/brewery/api/events/barrel/BarrelAccessEvent.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package com.dre.brewery.api.events.barrel;
|
||||||
|
|
||||||
|
import com.dre.brewery.Barrel;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public class BarrelAccessEvent extends BarrelEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private final Player player;
|
||||||
|
private final Block clickedBlock;
|
||||||
|
private boolean isCancelled;
|
||||||
|
|
||||||
|
public BarrelAccessEvent(Barrel barrel, Player player, Block clickedBlock) {
|
||||||
|
super(barrel);
|
||||||
|
this.player = player;
|
||||||
|
this.clickedBlock = clickedBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets the Block that was actually clicked.
|
||||||
|
// For access Permissions getSpigot() should be used
|
||||||
|
public Block getClickedBlock() {
|
||||||
|
return clickedBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return isCancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
isCancelled = cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
44
src/com/dre/brewery/api/events/barrel/BarrelCreateEvent.java
Normal file
44
src/com/dre/brewery/api/events/barrel/BarrelCreateEvent.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package com.dre.brewery.api.events.barrel;
|
||||||
|
|
||||||
|
import com.dre.brewery.Barrel;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called when a Barrel is created by a Player by placing a Sign
|
||||||
|
* Cancelling this will silently fail the Barrel creation
|
||||||
|
*/
|
||||||
|
public class BarrelCreateEvent extends BarrelEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private final Player player;
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
public BarrelCreateEvent(Barrel barrel, Player player) {
|
||||||
|
super(barrel);
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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,71 @@
|
|||||||
|
package com.dre.brewery.api.events.barrel;
|
||||||
|
|
||||||
|
import com.dre.brewery.Barrel;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public class BarrelDestroyEvent extends BarrelEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private final Block broken;
|
||||||
|
private final Reason reason;
|
||||||
|
private final Player player;
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
public BarrelDestroyEvent(Barrel barrel, Block broken, Reason reason, Player player) {
|
||||||
|
super(barrel);
|
||||||
|
this.broken = broken;
|
||||||
|
this.player = player;
|
||||||
|
this.reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block getBroken() {
|
||||||
|
return broken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Reason getReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPlayer() {
|
||||||
|
return player != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MAY BE NULL if no Player is involved
|
||||||
|
public Player getPlayerOptional() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
27
src/com/dre/brewery/api/events/barrel/BarrelEvent.java
Normal file
27
src/com/dre/brewery/api/events/barrel/BarrelEvent.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
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 {
|
||||||
|
protected final Barrel barrel;
|
||||||
|
|
||||||
|
public BarrelEvent(Barrel barrel) {
|
||||||
|
this.barrel = barrel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Barrel getBarrel() {
|
||||||
|
return barrel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return barrel.getInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block getSpigot() {
|
||||||
|
return barrel.getSpigot();
|
||||||
|
}
|
||||||
|
}
|
34
src/com/dre/brewery/api/events/barrel/BarrelRemoveEvent.java
Normal file
34
src/com/dre/brewery/api/events/barrel/BarrelRemoveEvent.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package com.dre.brewery.api.events.barrel;
|
||||||
|
|
||||||
|
import com.dre.brewery.Barrel;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A Barrel is being removed. There may have been a BarrelDestroyEvent before
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
public BarrelRemoveEvent(Barrel barrel) {
|
||||||
|
super(barrel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldItemsDrop() {
|
||||||
|
return itemsDrop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShouldItemsDrop(boolean itemsDrop) {
|
||||||
|
this.itemsDrop = itemsDrop;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
79
src/com/dre/brewery/api/events/brew/BrewDrinkEvent.java
Normal file
79
src/com/dre/brewery/api/events/brew/BrewDrinkEvent.java
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package com.dre.brewery.api.events.brew;
|
||||||
|
|
||||||
|
import com.dre.brewery.BEffect;
|
||||||
|
import com.dre.brewery.BPlayer;
|
||||||
|
import com.dre.brewery.Brew;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public class BrewDrinkEvent extends BrewEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private final Player player;
|
||||||
|
private final BPlayer bPlayer;
|
||||||
|
private int alc;
|
||||||
|
private int quality;
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
public BrewDrinkEvent(Brew brew, Player player, BPlayer bPlayer) {
|
||||||
|
super(brew);
|
||||||
|
this.player = player;
|
||||||
|
this.bPlayer = bPlayer;
|
||||||
|
alc = brew.calcAlcohol();
|
||||||
|
quality = brew.getQuality();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BPlayer getbPlayer() {
|
||||||
|
return bPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAddedAlcohol() {
|
||||||
|
return alc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddedAlcohol(int alc) {
|
||||||
|
this.alc = alc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getQuality() {
|
||||||
|
return quality;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuality(int quality) {
|
||||||
|
if (quality > 10 || quality < 0) {
|
||||||
|
throw new IllegalArgumentException("Quality must be in range from 0 to 10");
|
||||||
|
}
|
||||||
|
this.quality = quality;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
17
src/com/dre/brewery/api/events/brew/BrewEvent.java
Normal file
17
src/com/dre/brewery/api/events/brew/BrewEvent.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.dre.brewery.api.events.brew;
|
||||||
|
|
||||||
|
import com.dre.brewery.Brew;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public abstract class BrewEvent extends Event {
|
||||||
|
protected final Brew brew;
|
||||||
|
|
||||||
|
public BrewEvent(Brew brew) {
|
||||||
|
this.brew = brew;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Brew getBrew() {
|
||||||
|
return brew;
|
||||||
|
}
|
||||||
|
}
|
53
src/com/dre/brewery/api/events/brew/BrewModifyEvent.java
Normal file
53
src/com/dre/brewery/api/events/brew/BrewModifyEvent.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package com.dre.brewery.api.events.brew;
|
||||||
|
|
||||||
|
import com.dre.brewery.Brew;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A Brew is created or modified
|
||||||
|
* Usually happens on Filling from cauldron, distilling and aging.
|
||||||
|
*/
|
||||||
|
public class BrewModifyEvent extends BrewEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private final Type type;
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
public BrewModifyEvent(Brew brew, Type type) {
|
||||||
|
super(brew);
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
//CREATE, // A new Brew is created with arbitrary ways, like the create command
|
||||||
|
FILL, // Filled from a Cauldron into a new Brew
|
||||||
|
DISTILL, // Distilled in the Brewing stand
|
||||||
|
AGE, // Aged in a Barrel
|
||||||
|
UNLABEL, // Unlabeling Brew with command
|
||||||
|
STATIC, // Making Brew static with command
|
||||||
|
UNKNOWN // Unknown modification, unused
|
||||||
|
}
|
||||||
|
}
|
@ -1,18 +1,19 @@
|
|||||||
package com.dre.brewery.integration;
|
package com.dre.brewery.integration;
|
||||||
|
|
||||||
import com.dre.brewery.P;
|
import com.dre.brewery.P;
|
||||||
|
import com.dre.brewery.api.events.barrel.BarrelAccessEvent;
|
||||||
import me.ryanhamshire.GriefPrevention.Claim;
|
import me.ryanhamshire.GriefPrevention.Claim;
|
||||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||||
import me.ryanhamshire.GriefPrevention.PlayerData;
|
import me.ryanhamshire.GriefPrevention.PlayerData;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class GriefPreventionBarrel {
|
public class GriefPreventionBarrel {
|
||||||
|
|
||||||
static P brewery = P.p;
|
private static P brewery = P.p;
|
||||||
static GriefPrevention griefPrevention = GriefPrevention.instance;
|
|
||||||
|
|
||||||
public static boolean checkAccess(Player player, Block sign) {
|
public static boolean checkAccess(BarrelAccessEvent event) {
|
||||||
|
GriefPrevention griefPrevention = GriefPrevention.instance;
|
||||||
|
Player player = event.getPlayer();
|
||||||
PlayerData playerData = griefPrevention.dataStore.getPlayerData(player.getUniqueId());
|
PlayerData playerData = griefPrevention.dataStore.getPlayerData(player.getUniqueId());
|
||||||
|
|
||||||
if (!griefPrevention.claimsEnabledForWorld(player.getWorld()) || playerData.ignoreClaims || !griefPrevention.config_claims_preventTheft) {
|
if (!griefPrevention.claimsEnabledForWorld(player.getWorld()) || playerData.ignoreClaims || !griefPrevention.config_claims_preventTheft) {
|
||||||
@ -21,12 +22,11 @@ public class GriefPreventionBarrel {
|
|||||||
|
|
||||||
// block container use during pvp combat
|
// block container use during pvp combat
|
||||||
if (playerData.inPvpCombat()) {
|
if (playerData.inPvpCombat()) {
|
||||||
brewery.msg(player, brewery.languageReader.get("Error_NoBarrelAccess"));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check permissions for the claim the Barrel is in
|
// check permissions for the claim the Barrel is in
|
||||||
Claim claim = griefPrevention.dataStore.getClaimAt(sign.getLocation(), false, playerData.lastClaim);
|
Claim claim = griefPrevention.dataStore.getClaimAt(event.getSpigot().getLocation(), false, playerData.lastClaim);
|
||||||
if (claim != null) {
|
if (claim != null) {
|
||||||
playerData.lastClaim = claim;
|
playerData.lastClaim = claim;
|
||||||
String noContainersReason = claim.allowContainers(player);
|
String noContainersReason = claim.allowContainers(player);
|
||||||
|
122
src/com/dre/brewery/integration/IntegrationListener.java
Normal file
122
src/com/dre/brewery/integration/IntegrationListener.java
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
package com.dre.brewery.integration;
|
||||||
|
|
||||||
|
import com.dre.brewery.Barrel;
|
||||||
|
import com.dre.brewery.P;
|
||||||
|
import com.dre.brewery.api.events.barrel.BarrelAccessEvent;
|
||||||
|
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
||||||
|
import com.dre.brewery.api.events.barrel.BarrelRemoveEvent;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class IntegrationListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
|
public void onBarrelAccessLowest(BarrelAccessEvent event) {
|
||||||
|
if (P.p.useWG) {
|
||||||
|
Plugin plugin = P.p.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||||
|
if (plugin != null) {
|
||||||
|
try {
|
||||||
|
if (!P.p.wg.checkAccess(event.getPlayer(), event.getSpigot(), plugin)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
P.p.errorLog("Failed to Check WorldGuard for Barrel Open Permissions!");
|
||||||
|
P.p.errorLog("Brewery was tested with version 5.8 to 6.1 of WorldGuard!");
|
||||||
|
P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
|
||||||
|
e.printStackTrace();
|
||||||
|
P.p.msg(event.getPlayer(), "&cError opening Barrel, please report to an Admin!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
|
public void onBarrelAccess(BarrelAccessEvent event) {
|
||||||
|
if (P.p.useGP) {
|
||||||
|
if (P.p.getServer().getPluginManager().isPluginEnabled("GriefPrevention")) {
|
||||||
|
try {
|
||||||
|
if (!GriefPreventionBarrel.checkAccess(event)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
P.p.errorLog("Failed to Check GriefPrevention for Barrel Open Permissions!");
|
||||||
|
P.p.errorLog("Brewery was tested with GriefPrevention 14.5.4");
|
||||||
|
P.p.errorLog("Disable the GriefPrevention support in the config and do /brew reload");
|
||||||
|
e.printStackTrace();
|
||||||
|
P.p.msg(event.getPlayer(), "&cError opening Barrel, please report to an Admin!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
|
||||||
|
public void onBarrelDestroy(BarrelDestroyEvent event) {
|
||||||
|
if (!P.p.useLWC) return;
|
||||||
|
|
||||||
|
if (event.hasPlayer()) {
|
||||||
|
try {
|
||||||
|
if (LWCBarrel.denyDestroy(event.getPlayerOptional(), event.getBarrel())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
P.p.errorLog("Failed to Check LWC for Barrel Break Permissions!");
|
||||||
|
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
|
||||||
|
P.p.errorLog("Disable the LWC support in the config and do /brew reload");
|
||||||
|
e.printStackTrace();
|
||||||
|
P.p.msg(event.getPlayerOptional(), "&cError breaking Barrel, please report to an Admin!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
if (event.getReason() == BarrelDestroyEvent.Reason.EXPLODED) {
|
||||||
|
if (LWCBarrel.denyExplosion(event.getBarrel())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (LWCBarrel.denyDestroyOther(event.getBarrel())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
P.p.errorLog("Failed to Check LWC on Barrel Destruction!");
|
||||||
|
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
|
||||||
|
P.p.errorLog("Disable the LWC support in the config and do /brew reload");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBarrelRemove(BarrelRemoveEvent event) {
|
||||||
|
if (!P.p.useLWC) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
LWCBarrel.remove(event.getBarrel());
|
||||||
|
} catch (Throwable e) {
|
||||||
|
P.p.errorLog("Failed to Remove LWC Lock from Barrel!");
|
||||||
|
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClose(InventoryCloseEvent event) {
|
||||||
|
if (P.p.useLB) {
|
||||||
|
if (event.getInventory().getHolder() instanceof Barrel) {
|
||||||
|
try {
|
||||||
|
LogBlockBarrel.closeBarrel(event.getPlayer(), event.getInventory());
|
||||||
|
} catch (Exception e) {
|
||||||
|
P.p.errorLog("Failed to Log Barrel to LogBlock!");
|
||||||
|
P.p.errorLog("Brewery was tested with version 1.94 of LogBlock!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,5 @@
|
|||||||
package com.dre.brewery.integration;
|
package com.dre.brewery.integration;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventException;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
|
||||||
|
|
||||||
import com.dre.brewery.Barrel;
|
import com.dre.brewery.Barrel;
|
||||||
import com.dre.brewery.P;
|
import com.dre.brewery.P;
|
||||||
import com.griefcraft.listeners.LWCPlayerListener;
|
import com.griefcraft.listeners.LWCPlayerListener;
|
||||||
@ -15,11 +7,18 @@ import com.griefcraft.lwc.LWC;
|
|||||||
import com.griefcraft.model.Flag;
|
import com.griefcraft.model.Flag;
|
||||||
import com.griefcraft.model.Protection;
|
import com.griefcraft.model.Protection;
|
||||||
import com.griefcraft.scripting.event.LWCProtectionDestroyEvent;
|
import com.griefcraft.scripting.event.LWCProtectionDestroyEvent;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventException;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.RegisteredListener;
|
||||||
|
|
||||||
public class LWCBarrel {
|
public class LWCBarrel {
|
||||||
|
|
||||||
|
|
||||||
public static boolean checkDestroy(Player player, Barrel barrel) {
|
public static boolean denyDestroy(Player player, Barrel barrel) {
|
||||||
LWC lwc = LWC.getInstance();
|
LWC lwc = LWC.getInstance();
|
||||||
Block sign = barrel.getSignOfSpigot();
|
Block sign = barrel.getSignOfSpigot();
|
||||||
//if (!Boolean.parseBoolean(lwc.resolveProtectionConfiguration(sign, "ignoreBlockDestruction"))) {
|
//if (!Boolean.parseBoolean(lwc.resolveProtectionConfiguration(sign, "ignoreBlockDestruction"))) {
|
||||||
@ -33,18 +32,18 @@ public class LWCBarrel {
|
|||||||
lwc.getModuleLoader().dispatchEvent(evt);
|
lwc.getModuleLoader().dispatchEvent(evt);
|
||||||
|
|
||||||
if (evt.isCancelled()) {
|
if (evt.isCancelled()) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
lwc.sendLocale(player, "protection.internalerror", "id", "BLOCK_BREAK");
|
lwc.sendLocale(player, "protection.internalerror", "id", "BLOCK_BREAK");
|
||||||
P.p.errorLog("Failed to dispatch LWCProtectionDestroyEvent");
|
P.p.errorLog("Failed to dispatch LWCProtectionDestroyEvent");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkAccess(Player player, Block sign, PlayerInteractEvent event, Plugin plugin) {
|
public static boolean checkAccess(Player player, Block sign, PlayerInteractEvent event, Plugin plugin) {
|
||||||
@ -86,19 +85,14 @@ public class LWCBarrel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the block that exploded should not be removed
|
// Returns true if the block that exploded should not be removed
|
||||||
public static boolean blockExplosion(Barrel barrel, Block block) {
|
public static boolean denyExplosion(Barrel barrel) {
|
||||||
Protection protection = LWC.getInstance().findProtection(barrel.getSignOfSpigot());
|
Protection protection = LWC.getInstance().findProtection(barrel.getSignOfSpigot());
|
||||||
|
|
||||||
if (protection == null) {
|
return protection != null && !protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS);
|
||||||
barrel.remove(block, null);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS)) {
|
// Returns true if the block that was destroyed should not be removed
|
||||||
protection.remove();
|
public static boolean denyDestroyOther(Barrel barrel) {
|
||||||
barrel.remove(block, null);
|
return LWC.getInstance().findProtection(barrel.getSignOfSpigot()) != null;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package com.dre.brewery.integration;
|
package com.dre.brewery.integration;
|
||||||
|
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import com.dre.brewery.P;
|
|
||||||
import com.sk89q.worldguard.bukkit.RegionQuery;
|
import com.sk89q.worldguard.bukkit.RegionQuery;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.bukkit.permission.RegionPermissionModel;
|
import com.sk89q.worldguard.bukkit.permission.RegionPermissionModel;
|
||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class WGBarrelNew implements WGBarrel {
|
public class WGBarrelNew implements WGBarrel {
|
||||||
|
|
||||||
@ -21,12 +19,8 @@ public class WGBarrelNew implements WGBarrel {
|
|||||||
|
|
||||||
RegionQuery query = wg.getRegionContainer().createQuery();
|
RegionQuery query = wg.getRegionContainer().createQuery();
|
||||||
|
|
||||||
if (!query.testBuild(spigot.getLocation(), player, DefaultFlag.USE, DefaultFlag.CHEST_ACCESS)) {
|
return query.testBuild(spigot.getLocation(), player, DefaultFlag.USE, DefaultFlag.CHEST_ACCESS);
|
||||||
P.p.msg(player, P.p.languageReader.get("Error_NoBarrelAccess"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,6 @@ public class WGBarrelOld implements WGBarrel {
|
|||||||
|
|
||||||
if (!(Boolean) allows.invoke(region, DefaultFlag.CHEST_ACCESS, localPlayer)) {
|
if (!(Boolean) allows.invoke(region, DefaultFlag.CHEST_ACCESS, localPlayer)) {
|
||||||
if (!(Boolean) canBuild.invoke(region, localPlayer)) {
|
if (!(Boolean) canBuild.invoke(region, localPlayer)) {
|
||||||
P.p.msg(player, P.p.languageReader.get("Error_NoBarrelAccess"));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
package com.dre.brewery.listeners;
|
package com.dre.brewery.listeners;
|
||||||
|
|
||||||
|
import com.dre.brewery.BPlayer;
|
||||||
|
import com.dre.brewery.BUtil;
|
||||||
|
import com.dre.brewery.Barrel;
|
||||||
|
import com.dre.brewery.P;
|
||||||
|
import com.dre.brewery.Words;
|
||||||
|
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockBurnEvent;
|
import org.bukkit.event.block.BlockBurnEvent;
|
||||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
|
||||||
|
|
||||||
import com.dre.brewery.Barrel;
|
|
||||||
import com.dre.brewery.BPlayer;
|
|
||||||
import com.dre.brewery.Words;
|
|
||||||
import com.dre.brewery.P;
|
|
||||||
|
|
||||||
public class BlockListener implements Listener {
|
public class BlockListener implements Listener {
|
||||||
|
|
||||||
@ -45,14 +46,14 @@ public class BlockListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
if (!P.p.blockDestroy(event.getBlock(), event.getPlayer())) {
|
if (!BUtil.blockDestroy(event.getBlock(), event.getPlayer(), BarrelDestroyEvent.Reason.PLAYER)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onBlockBurn(BlockBurnEvent event) {
|
public void onBlockBurn(BlockBurnEvent event) {
|
||||||
P.p.blockDestroy(event.getBlock(), null);
|
BUtil.blockDestroy(event.getBlock(), null, BarrelDestroyEvent.Reason.BURNED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import com.dre.brewery.Util;
|
import com.dre.brewery.Util;
|
||||||
|
import com.dre.brewery.api.events.brew.BrewModifyEvent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@ -484,6 +485,11 @@ public class CommandListener implements CommandExecutor {
|
|||||||
if (hand != null) {
|
if (hand != null) {
|
||||||
Brew brew = Brew.get(hand);
|
Brew brew = Brew.get(hand);
|
||||||
if (brew != null) {
|
if (brew != null) {
|
||||||
|
BrewModifyEvent modifyEvent = new BrewModifyEvent(brew, BrewModifyEvent.Type.STATIC);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(modifyEvent);
|
||||||
|
if (modifyEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (brew.isStatic()) {
|
if (brew.isStatic()) {
|
||||||
if (!brew.isPersistent()) {
|
if (!brew.isPersistent()) {
|
||||||
brew.setStatic(false, hand);
|
brew.setStatic(false, hand);
|
||||||
@ -516,6 +522,11 @@ public class CommandListener implements CommandExecutor {
|
|||||||
if (hand != null) {
|
if (hand != null) {
|
||||||
Brew brew = Brew.get(hand);
|
Brew brew = Brew.get(hand);
|
||||||
if (brew != null) {
|
if (brew != null) {
|
||||||
|
BrewModifyEvent modifyEvent = new BrewModifyEvent(brew, BrewModifyEvent.Type.UNLABEL);
|
||||||
|
P.p.getServer().getPluginManager().callEvent(modifyEvent);
|
||||||
|
if (modifyEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
brew.unLabel(hand);
|
brew.unLabel(hand);
|
||||||
brew.touch();
|
brew.touch();
|
||||||
brew.save(hand);
|
brew.save(hand);
|
||||||
|
@ -1,25 +1,26 @@
|
|||||||
package com.dre.brewery.listeners;
|
package com.dre.brewery.listeners;
|
||||||
|
|
||||||
import java.util.ListIterator;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
||||||
import org.bukkit.event.entity.ItemDespawnEvent;
|
|
||||||
import org.bukkit.event.entity.EntityCombustEvent;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Item;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import com.dre.brewery.Barrel;
|
import com.dre.brewery.Barrel;
|
||||||
import com.dre.brewery.Brew;
|
import com.dre.brewery.Brew;
|
||||||
import com.dre.brewery.P;
|
import com.dre.brewery.P;
|
||||||
import com.dre.brewery.integration.LWCBarrel;
|
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
|
import org.bukkit.event.entity.EntityCombustEvent;
|
||||||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
import org.bukkit.event.entity.ItemDespawnEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class EntityListener implements Listener {
|
public class EntityListener implements Listener {
|
||||||
|
|
||||||
@ -50,29 +51,31 @@ public class EntityListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onExplode(EntityExplodeEvent event) {
|
public void onExplode(EntityExplodeEvent event) {
|
||||||
ListIterator<Block> iter = event.blockList().listIterator();
|
ListIterator<Block> iter = event.blockList().listIterator();
|
||||||
Barrel barrel = null;
|
if (!iter.hasNext()) return;
|
||||||
boolean removedBarrel = false;
|
Set<BarrelDestroyEvent> breakEvents = new HashSet<>(6);
|
||||||
while (iter.hasNext()) {
|
Block block;
|
||||||
Block block = iter.next();
|
blocks: while (iter.hasNext()) {
|
||||||
if (barrel == null || !barrel.hasBlock(block)) {
|
block = iter.next();
|
||||||
barrel = Barrel.get(block);
|
if (!breakEvents.isEmpty()) {
|
||||||
removedBarrel = false;
|
for (BarrelDestroyEvent breakEvent : breakEvents) {
|
||||||
|
if (breakEvent.getBarrel().hasBlock(block)) {
|
||||||
|
if (breakEvent.isCancelled()) {
|
||||||
|
iter.remove();
|
||||||
}
|
}
|
||||||
if (!removedBarrel) {
|
continue blocks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Barrel barrel = Barrel.get(block);
|
||||||
if (barrel != null) {
|
if (barrel != null) {
|
||||||
if (P.p.useLWC) {
|
BarrelDestroyEvent breakEvent = new BarrelDestroyEvent(barrel, block, BarrelDestroyEvent.Reason.EXPLODED, null);
|
||||||
try {
|
// Listened to by LWCBarrel (IntegrationListener)
|
||||||
if (LWCBarrel.blockExplosion(barrel, block)) {
|
P.p.getServer().getPluginManager().callEvent(breakEvent);
|
||||||
|
breakEvents.add(breakEvent);
|
||||||
|
if (breakEvent.isCancelled()) {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
} else {
|
} else {
|
||||||
removedBarrel = true;
|
barrel.remove(block, null);
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
P.p.errorLog("Failed to Check LWC on Barrel Explosion!");
|
|
||||||
e.printStackTrace();
|
|
||||||
removedBarrel = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ import com.dre.brewery.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.MCBarrel;
|
import com.dre.brewery.MCBarrel;
|
||||||
import com.dre.brewery.P;
|
|
||||||
import com.dre.brewery.integration.LogBlockBarrel;
|
import com.dre.brewery.integration.LogBlockBarrel;
|
||||||
|
import com.dre.brewery.P;
|
||||||
import com.dre.brewery.lore.BrewLore;
|
import com.dre.brewery.lore.BrewLore;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
package com.dre.brewery.listeners;
|
package com.dre.brewery.listeners;
|
||||||
|
|
||||||
import com.dre.brewery.*;
|
import com.dre.brewery.BCauldron;
|
||||||
|
import com.dre.brewery.BIngredients;
|
||||||
|
import com.dre.brewery.BPlayer;
|
||||||
|
import com.dre.brewery.Barrel;
|
||||||
|
import com.dre.brewery.Brew;
|
||||||
|
import com.dre.brewery.P;
|
||||||
|
import com.dre.brewery.Wakeup;
|
||||||
|
import com.dre.brewery.Words;
|
||||||
import com.dre.brewery.filedata.UpdateChecker;
|
import com.dre.brewery.filedata.UpdateChecker;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -118,7 +125,7 @@ public class PlayerListener implements Listener {
|
|||||||
if (BIngredients.possibleIngredients.contains(materialInHand)) {
|
if (BIngredients.possibleIngredients.contains(materialInHand)) {
|
||||||
|
|
||||||
if (player.hasPermission("brewery.cauldron.insert")) {
|
if (player.hasPermission("brewery.cauldron.insert")) {
|
||||||
if (BCauldron.ingredientAdd(clickedBlock, item)) {
|
if (BCauldron.ingredientAdd(clickedBlock, item, player)) {
|
||||||
boolean isBucket = item.getType().equals(Material.WATER_BUCKET)
|
boolean isBucket = item.getType().equals(Material.WATER_BUCKET)
|
||||||
|| item.getType().equals(Material.LAVA_BUCKET)
|
|| item.getType().equals(Material.LAVA_BUCKET)
|
||||||
|| item.getType().equals(Material.MILK_BUCKET);
|
|| item.getType().equals(Material.MILK_BUCKET);
|
||||||
@ -256,7 +263,10 @@ public class PlayerListener implements Listener {
|
|||||||
if (item.getType() == Material.POTION) {
|
if (item.getType() == Material.POTION) {
|
||||||
Brew brew = Brew.get(item);
|
Brew brew = Brew.get(item);
|
||||||
if (brew != null) {
|
if (brew != null) {
|
||||||
BPlayer.drink(brew, player);
|
if (!BPlayer.drink(brew, player)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
/*if (player.getGameMode() != org.bukkit.GameMode.CREATIVE) {
|
/*if (player.getGameMode() != org.bukkit.GameMode.CREATIVE) {
|
||||||
brew.remove(item);
|
brew.remove(item);
|
||||||
}*/
|
}*/
|
||||||
|
Loading…
Reference in New Issue
Block a user