Listener for Barrel breaking -> LWC Support

This commit is contained in:
Sn0wStorm
2014-04-08 16:11:20 +02:00
parent 3155bbab63
commit 1c6fe6cc33
19 changed files with 790 additions and 227 deletions
+5 -2
View File
@@ -30,7 +30,7 @@ enableLoginDisallow: true
enableKickOnOverdrink: true enableKickOnOverdrink: true
# If the Player vomits on high drunkeness (drops item defined below) [true] # If the Player vomits on high drunkeness (drops item defined below) [true]
# The item can not be collected and stays on the ground until it despawns. (Warning: May be collected after Server restart, or through a hopper) # The item can not be collected and stays on the ground until it despawns. (Warning: May be collected after Server restart!)
enablePuke: true enablePuke: true
# Item that is dropped multiple times uncollectable when puking [SOUL_SAND] # Item that is dropped multiple times uncollectable when puking [SOUL_SAND]
@@ -48,11 +48,14 @@ hangoverDays: 7
colorInBarrels: true colorInBarrels: true
colorInBrewer: false colorInBrewer: false
# If a Large Barrel can be opened by clicking on any of its blocks, not just Spigot or Sign. This is always true for Small Barrels. [true]
openLargeBarrelEverywhere: true
# Autosave interval in minutes [3] # Autosave interval in minutes [3]
autosave: 3 autosave: 3
# Config Version # Config Version
version: '1.1' version: '1.2'
# -- Recipes for Potions -- # -- Recipes for Potions --
+2 -1
View File
@@ -1,7 +1,8 @@
name: Brewery name: Brewery
version: 1.1 version: 1.2
main: com.dre.brewery.P main: com.dre.brewery.P
authors: [Milan Albrecht, Frank Baumann] authors: [Milan Albrecht, Frank Baumann]
softdepend: [LWC]
commands: commands:
brewery: brewery:
description: Command for Administration description: Command for Administration
+18 -1
View File
@@ -4,7 +4,7 @@
<groupId>com.dre</groupId> <groupId>com.dre</groupId>
<artifactId>brewery</artifactId> <artifactId>brewery</artifactId>
<version>1.1.1</version> <version>1.2</version>
<name>Brewery</name> <name>Brewery</name>
<build> <build>
@@ -85,6 +85,15 @@
</snapshots> </snapshots>
</repository> </repository>
<repository>
<id>lwc-repo</id>
<url>http://repo.sacredlabyrinth.net:8081/artifactory/repo/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository> <repository>
<id>Plugin Metrics</id> <id>Plugin Metrics</id>
<url>http://repo.mcstats.org/content/repositories/public</url> <url>http://repo.mcstats.org/content/repositories/public</url>
@@ -116,6 +125,14 @@
<type>jar</type> <type>jar</type>
</dependency> </dependency>
<dependency>
<groupId>com.griefcraft</groupId>
<artifactId>LWC</artifactId>
<version>4.3.1</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency> <dependency>
<groupId>org.mcstats</groupId> <groupId>org.mcstats</groupId>
<artifactId>metrics</artifactId> <artifactId>metrics</artifactId>
+4 -3
View File
@@ -10,8 +10,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import com.dre.brewery.BIngredients;
public class BCauldron { public class BCauldron {
public static CopyOnWriteArrayList<BCauldron> bcauldrons = new CopyOnWriteArrayList<BCauldron>(); public static CopyOnWriteArrayList<BCauldron> bcauldrons = new CopyOnWriteArrayList<BCauldron>();
@@ -87,6 +85,7 @@ public class BCauldron {
} }
// fills players bottle with cooked brew // fills players bottle with cooked brew
@SuppressWarnings("deprecation")
public static boolean fill(Player player, Block block) { public static boolean fill(Player player, Block block) {
BCauldron bcauldron = get(block); BCauldron bcauldron = get(block);
if (bcauldron != null) { if (bcauldron != null) {
@@ -128,11 +127,13 @@ public class BCauldron {
// reset to normal cauldron // reset to normal cauldron
public static void remove(Block block) { public static void remove(Block block) {
if (block.getData() != 0) {
BCauldron bcauldron = get(block); BCauldron bcauldron = get(block);
if (bcauldron != null) { if (bcauldron != null) {
bcauldrons.remove(bcauldron); bcauldrons.remove(bcauldron);
} }
} }
}
// unloads cauldrons that are in a unloading world // unloads cauldrons that are in a unloading world
// as they were written to file just before, this is safe to do // as they were written to file just before, this is safe to do
@@ -151,7 +152,7 @@ public class BCauldron {
int id = 0; int id = 0;
for (BCauldron cauldron : bcauldrons) { for (BCauldron cauldron : bcauldrons) {
String worldName = cauldron.block.getWorld().getName(); String worldName = cauldron.block.getWorld().getName();
String prefix = null; String prefix;
if (worldName.startsWith("DXL_")) { if (worldName.startsWith("DXL_")) {
prefix = P.p.getDxlName(worldName) + "." + id; prefix = P.p.getDxlName(worldName) + "." + id;
+6 -9
View File
@@ -10,9 +10,6 @@ import org.bukkit.Material;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import com.dre.brewery.BRecipe;
import com.dre.brewery.Brew;
public class BIngredients { public class BIngredients {
public static ArrayList<Material> possibleIngredients = new ArrayList<Material>(); public static ArrayList<Material> possibleIngredients = new ArrayList<Material>();
public static ArrayList<BRecipe> recipes = new ArrayList<BRecipe>(); public static ArrayList<BRecipe> recipes = new ArrayList<BRecipe>();
@@ -121,10 +118,10 @@ public class BIngredients {
// correct one... // correct one...
public BRecipe getBestRecipe(float wood, float time, boolean distilled) { public BRecipe getBestRecipe(float wood, float time, boolean distilled) {
float quality = 0; float quality = 0;
int ingredientQuality = 0; int ingredientQuality;
int cookingQuality = 0; int cookingQuality;
int woodQuality = 0; int woodQuality;
int ageQuality = 0; int ageQuality;
BRecipe bestRecipe = null; BRecipe bestRecipe = null;
for (BRecipe recipe : recipes) { for (BRecipe recipe : recipes) {
ingredientQuality = getIngredientQuality(recipe); ingredientQuality = getIngredientQuality(recipe);
@@ -204,7 +201,7 @@ public class BIngredients {
// no recipe is near them // no recipe is near them
public int getIngredientQuality(BRecipe recipe) { public int getIngredientQuality(BRecipe recipe) {
float quality = 10; float quality = 10;
int count = 0; int count;
int badStuff = 0; int badStuff = 0;
if (recipe.isMissingIngredients(ingredients)) { if (recipe.isMissingIngredients(ingredients)) {
// when ingredients are not complete // when ingredients are not complete
@@ -278,7 +275,7 @@ public class BIngredients {
// returns the quality regarding the ageing time conditioning given Recipe // returns the quality regarding the ageing time conditioning given Recipe
public int getAgeQuality(BRecipe recipe, float time) { public int getAgeQuality(BRecipe recipe, float time) {
int quality = 10 - (int) Math.round(Math.abs(time - recipe.getAge()) * ((float) recipe.getDifficulty() / 2)); int quality = 10 - Math.round(Math.abs(time - recipe.getAge()) * ((float) recipe.getDifficulty() / 2));
if (quality > 0) { if (quality > 0) {
return quality; return quality;
-2
View File
@@ -15,8 +15,6 @@ import org.bukkit.Location;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import com.dre.brewery.Brew;
public class BPlayer { public class BPlayer {
public static Map<String, BPlayer> players = new HashMap<String, BPlayer>();// Players name and BPlayer public static Map<String, BPlayer> players = new HashMap<String, BPlayer>();// Players name and BPlayer
private static Map<Player, Integer> pTasks = new HashMap<Player, Integer>();// Player and count private static Map<Player, Integer> pTasks = new HashMap<Player, Integer>();// Player and count
+3 -12
View File
@@ -113,24 +113,15 @@ public class BRecipe {
} }
public boolean isCookingOnly() { public boolean isCookingOnly() {
if (age == 0 && distillruns == 0) { return age == 0 && distillruns == 0;
return true;
}
return false;
} }
public boolean needsDistilling() { public boolean needsDistilling() {
if (distillruns == 0) { return distillruns != 0;
return false;
}
return true;
} }
public boolean needsToAge() { public boolean needsToAge() {
if (age == 0) { return age != 0;
return false;
}
return true;
} }
// true if given map misses an ingredient // true if given map misses an ingredient
+357 -81
View File
@@ -1,74 +1,146 @@
package com.dre.brewery; package com.dre.brewery;
import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.Map; import java.util.Map;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
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.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.Plugin;
import com.dre.brewery.integration.LWCBarrel;
import com.dre.brewery.integration.WGBarrel;
import org.apache.commons.lang.ArrayUtils;
public class Barrel { public class Barrel {
public static CopyOnWriteArrayList<Barrel> barrels = new CopyOnWriteArrayList<Barrel>(); public static CopyOnWriteArrayList<Barrel> barrels = new CopyOnWriteArrayList<Barrel>();
// private CopyOnWriteArrayList<Brew> brews = new
// CopyOnWriteArrayList<Brew>();
private Block spigot; private Block spigot;
private int[] woodsloc = null; // location of wood Blocks
private int[] stairsloc = null; // location of stair Blocks
private byte signoffset;
private boolean checked = false;
private Inventory inventory; private Inventory inventory;
private float time; private float time;
public Barrel(Block spigot) { public Barrel(Block spigot, byte signoffset) {
this.spigot = spigot; this.spigot = spigot;
this.signoffset = signoffset;
} }
// load from file // load from file
public Barrel(Block spigot, Map<String, Object> items, float time) { public Barrel(Block spigot, byte sign, String[] st, String[] wo, Map<String, Object> items, float time) {
this.spigot = spigot; this.spigot = spigot;
this.signoffset = sign;
if (isLarge()) { if (isLarge()) {
this.inventory = org.bukkit.Bukkit.createInventory(null, 27, P.p.languageReader.get("Etc_Barrel")); this.inventory = org.bukkit.Bukkit.createInventory(null, 27, P.p.languageReader.get("Etc_Barrel"));
} else { } else {
this.inventory = org.bukkit.Bukkit.createInventory(null, 9, P.p.languageReader.get("Etc_Barrel")); this.inventory = org.bukkit.Bukkit.createInventory(null, 9, P.p.languageReader.get("Etc_Barrel"));
} }
if (items != null) {
for (String slot : items.keySet()) { for (String slot : items.keySet()) {
if (items.get(slot) instanceof ItemStack) { if (items.get(slot) instanceof ItemStack) {
this.inventory.setItem(P.p.parseInt(slot), (ItemStack) items.get(slot)); this.inventory.setItem(P.p.parseInt(slot), (ItemStack) items.get(slot));
} }
} }
}
this.time = time; this.time = time;
barrels.add(this);
int i = 0;
if (wo.length > 1) {
woodsloc = new int[wo.length];
for (String wos : wo) {
woodsloc[i] = P.p.parseInt(wos);
i++;
}
i = 0;
}
if (st.length > 1) {
stairsloc = new int[st.length];
for (String sts : st) {
stairsloc[i] = P.p.parseInt(sts);
i++;
}
} }
// load from file (without inventory) if (woodsloc == null && stairsloc == null) {
public Barrel(Block spigot, float time) { Block broken = getBrokenBlock(true);
this.spigot = spigot; if (broken != null) {
if (isLarge()) { remove(broken);
this.inventory = org.bukkit.Bukkit.createInventory(null, 27, P.p.languageReader.get("Etc_Barrel")); return;
} else {
this.inventory = org.bukkit.Bukkit.createInventory(null, 9, P.p.languageReader.get("Etc_Barrel"));
} }
this.time = time; }
barrels.add(this); barrels.add(this);
} }
public static void onUpdate() { public static void onUpdate() {
Block broken; Block broken;
for (Barrel barrel : barrels) { for (Barrel barrel : barrels) {
broken = getBrokenBlock(barrel.spigot); if (!barrel.checked) {
// remove the barrel if it was destroyed broken = barrel.getBrokenBlock(false);
if (broken != null) { if (broken != null) {
// remove the barrel if it was destroyed
barrel.remove(broken); barrel.remove(broken);
continue;
} else { } else {
// Dont check this barrel again, its enough to check it once after every restart
// as now this is only the backup if we dont register the barrel breaking, as sample
// when removing it with some world editor
barrel.checked = true;
}
}
// Minecraft day is 20 min, so add 1/20 to the time every minute // Minecraft day is 20 min, so add 1/20 to the time every minute
barrel.time += 1.0 / 20.0; barrel.time += (1.0 / 20.0);
}
}
public boolean hasPermsOpen(Player player, PlayerInteractEvent event) {
Plugin plugin = P.p.getServer().getPluginManager().getPlugin("WorldGuard");
if (plugin != null) {
if (!WGBarrel.checkAccess(player, spigot, plugin)) {
return false;
}
}
if (event != null) {
plugin = P.p.getServer().getPluginManager().getPlugin("LWC");
if (plugin != null) {
// If the Clicked Block was the Sign, LWC already knows and we dont need to do anything here
if (!isSign(event.getClickedBlock())) {
Block sign = getSignOfSpigot();
// If the Barrel does not have a Sign, it cannot be locked
if (!sign.equals(event.getClickedBlock())) {
return LWCBarrel.checkAccess(player, sign, event, plugin);
}
} }
} }
} }
return true;
}
public boolean hasPermsDestroy(Player player) {
if (P.p.hasLWC) {
return LWCBarrel.checkDestroy(player, this);
}
return true;
}
// player opens the barrel // player opens the barrel
@SuppressWarnings("deprecation")
public void open(Player player) { public void open(Player player) {
if (inventory == null) { if (inventory == null) {
if (isLarge()) { if (isLarge()) {
@@ -104,23 +176,162 @@ public class Barrel {
player.openInventory(inventory); player.openInventory(inventory);
} }
public static Barrel get(Block spigot) { // Returns true if this Block is part of this Barrel
// convert spigot if neccessary public boolean hasBlock(Block block) {
spigot = getSpigotOfSign(spigot); if (block != null) {
for (Barrel barrel : barrels) { if (block.getType().equals(Material.WOOD)) {
if (barrel.spigot.equals(spigot)) { if (hasWoodBlock(block)) {
return true;
}
} else if (isStairs(block.getType())) {
if (hasStairsBlock(block)) {
return true;
}
}
}
return false;
}
public boolean hasWoodBlock(Block block) {
if (woodsloc != null) {
if (spigot.getWorld() != null && spigot.getWorld().equals(block.getWorld())) {
if (woodsloc.length > 2) {
int x = block.getX();
if (Math.abs(x - woodsloc[0]) < 10) {
for (int i = 0; i < woodsloc.length - 2; i += 3) {
if (woodsloc[i] == x) {
if (woodsloc[i + 1] == block.getY()) {
if (woodsloc[i + 2] == block.getZ()) {
return true;
}
}
}
}
}
}
}
}
return false;
}
public boolean hasStairsBlock(Block block) {
if (stairsloc != null) {
if (spigot.getWorld() != null && spigot.getWorld().equals(block.getWorld())) {
if (stairsloc.length > 2) {
int x = block.getX();
if (Math.abs(x - stairsloc[0]) < 10) {
for (int i = 0; i < stairsloc.length - 2; i += 3) {
if (stairsloc[i] == x) {
if (stairsloc[i + 1] == block.getY()) {
if (stairsloc[i + 2] == block.getZ()) {
return true;
}
}
}
}
}
}
}
}
return false;
}
// Returns true if the Offset of the clicked Sign matches the Barrel.
// This prevents adding another sign to the barrel and clicking that.
public boolean isSignOfBarrel(byte offset) {
return offset == 0 || signoffset == 0 || signoffset == offset;
}
// Get the Barrel by Block, null if that block is not part of a barrel
public static Barrel get(Block block) {
if (block != null) {
switch (block.getType()) {
case FENCE:
case NETHER_FENCE:
case SIGN:
case WALL_SIGN:
Barrel barrel = getBySpigot(block);
if (barrel != null) {
return barrel; return barrel;
} }
return null;
case WOOD:
case WOOD_STAIRS:
case ACACIA_STAIRS:
case BIRCH_WOOD_STAIRS:
case DARK_OAK_STAIRS:
case JUNGLE_WOOD_STAIRS:
case SPRUCE_WOOD_STAIRS:
Barrel barrel2 = getByWood(block);
if (barrel2 != null) {
return barrel2;
}
}
}
return null;
}
// Get the Barrel by Sign or Spigot (Fastest)
public static Barrel getBySpigot(Block sign) {
// convert spigot if neccessary
Block spigot = getSpigotOfSign(sign);
byte signoffset = 0;
if (!spigot.equals(sign)) {
signoffset = (byte) (sign.getY() - spigot.getY());
}
for (Barrel barrel : barrels) {
if (barrel.isSignOfBarrel(signoffset)) {
if (barrel.spigot.equals(spigot)) {
if (barrel.signoffset == 0 && signoffset != 0) {
// Barrel has no signOffset even though we clicked a sign, may be old
barrel.signoffset = signoffset;
}
return barrel;
}
}
}
return null;
}
// Get the barrel by its corpus (Wood Planks, Stairs)
public static Barrel getByWood(Block wood) {
if (wood.getType().equals(Material.WOOD)) {
for (Barrel barrel : barrels) {
if (barrel.hasWoodBlock(wood)) {
return barrel;
}
}
} else if (isStairs(wood.getType())) {
for (Barrel barrel : Barrel.barrels) {
if (barrel.hasStairsBlock(wood)) {
return barrel;
}
}
} }
return null; return null;
} }
// creates a new Barrel out of a sign // creates a new Barrel out of a sign
public static boolean create(Block spigot) { public static boolean create(Block sign) {
spigot = getSpigotOfSign(spigot); Block spigot = getSpigotOfSign(sign);
if (getBrokenBlock(spigot) == null) {
if (get(spigot) == null) { byte signoffset = 0;
barrels.add(new Barrel(spigot)); if (!spigot.equals(sign)) {
signoffset = (byte) (sign.getY() - spigot.getY());
}
Barrel barrel = getBySpigot(spigot);
if (barrel == null) {
barrel = new Barrel(spigot, signoffset);
if (barrel.getBrokenBlock(true) == null) {
barrels.add(barrel);
return true;
}
} else {
if (barrel.signoffset == 0 && signoffset != 0) {
barrel.signoffset = signoffset;
return true; return true;
} }
} }
@@ -155,6 +366,7 @@ public class Barrel {
} }
} }
} }
barrels.remove(this); barrels.remove(this);
} }
@@ -167,6 +379,11 @@ public class Barrel {
} }
} }
// If the Sign of a Large Barrel gets destroyed, set signOffset to 0
public void destroySign() {
signoffset = 0;
}
// Saves all data // Saves all data
public static void save(ConfigurationSection config, ConfigurationSection oldData) { public static void save(ConfigurationSection config, ConfigurationSection oldData) {
P.p.createWorldSections(config); P.p.createWorldSections(config);
@@ -176,7 +393,7 @@ public class Barrel {
for (Barrel barrel : barrels) { for (Barrel barrel : barrels) {
String worldName = barrel.spigot.getWorld().getName(); String worldName = barrel.spigot.getWorld().getName();
String prefix = null; String prefix;
if (worldName.startsWith("DXL_")) { if (worldName.startsWith("DXL_")) {
prefix = P.p.getDxlName(worldName) + "." + id; prefix = P.p.getDxlName(worldName) + "." + id;
@@ -187,9 +404,27 @@ public class Barrel {
// block: x/y/z // block: x/y/z
config.set(prefix + ".spigot", barrel.spigot.getX() + "/" + barrel.spigot.getY() + "/" + barrel.spigot.getZ()); config.set(prefix + ".spigot", barrel.spigot.getX() + "/" + barrel.spigot.getY() + "/" + barrel.spigot.getZ());
if (barrel.signoffset != 0) {
config.set(prefix + ".sign", barrel.signoffset);
}
if (barrel.stairsloc != null && barrel.stairsloc.length > 0) {
StringBuilder st = new StringBuilder();
for (int i : barrel.stairsloc) {
st.append(i).append(",");
}
config.set(prefix + ".st", st.substring(0, st.length() - 1));
}
if (barrel.woodsloc != null && barrel.woodsloc.length > 0) {
StringBuilder wo = new StringBuilder();
for (int i : barrel.woodsloc) {
wo.append(i).append(",");
}
config.set(prefix + ".wo", wo.substring(0, wo.length() - 1));
}
if (barrel.inventory != null) { if (barrel.inventory != null) {
int slot = 0; int slot = 0;
ItemStack item = null; ItemStack item;
ConfigurationSection invConfig = null; ConfigurationSection invConfig = null;
while (slot < barrel.inventory.getSize()) { while (slot < barrel.inventory.getSize()) {
item = barrel.inventory.getItem(slot); item = barrel.inventory.getItem(slot);
@@ -223,14 +458,15 @@ public class Barrel {
} }
// direction of the barrel from the spigot // direction of the barrel from the spigot
@SuppressWarnings("deprecation")
public static int getDirection(Block spigot) { public static int getDirection(Block spigot) {
int direction = 0;// 1=x+ 2=x- 3=z+ 4=z- int direction = 0;// 1=x+ 2=x- 3=z+ 4=z-
int typeId = spigot.getRelative(0, 0, 1).getTypeId(); int typeId = spigot.getRelative(0, 0, 1).getTypeId();
if (typeId == 5 || typeId == 53 || typeId == 134 || typeId == 135 || typeId == 136) { if (typeId == 5 || isStairs(typeId)) {
direction = 3; direction = 3;
} }
typeId = spigot.getRelative(0, 0, -1).getTypeId(); typeId = spigot.getRelative(0, 0, -1).getTypeId();
if (typeId == 5 || typeId == 53 || typeId == 134 || typeId == 135 || typeId == 136) { if (typeId == 5 || isStairs(typeId)) {
if (direction == 0) { if (direction == 0) {
direction = 4; direction = 4;
} else { } else {
@@ -238,7 +474,7 @@ public class Barrel {
} }
} }
typeId = spigot.getRelative(1, 0, 0).getTypeId(); typeId = spigot.getRelative(1, 0, 0).getTypeId();
if (typeId == 5 || typeId == 53 || typeId == 134 || typeId == 135 || typeId == 136) { if (typeId == 5 || isStairs(typeId)) {
if (direction == 0) { if (direction == 0) {
direction = 1; direction = 1;
} else { } else {
@@ -246,7 +482,7 @@ public class Barrel {
} }
} }
typeId = spigot.getRelative(-1, 0, 0).getTypeId(); typeId = spigot.getRelative(-1, 0, 0).getTypeId();
if (typeId == 5 || typeId == 53 || typeId == 134 || typeId == 135 || typeId == 136) { if (typeId == 5 || isStairs(typeId)) {
if (direction == 0) { if (direction == 0) {
direction = 2; direction = 2;
} else { } else {
@@ -258,24 +494,20 @@ public class Barrel {
// is this a Large barrel? // is this a Large barrel?
public boolean isLarge() { public boolean isLarge() {
if (spigot.getTypeId() == 63 || spigot.getTypeId() == 68) { return !isSign(spigot);
return false;
}
return true;
} }
// true for small barrels // true for small barrels
@SuppressWarnings("deprecation")
public static boolean isSign(Block spigot) { public static boolean isSign(Block spigot) {
if (spigot.getTypeId() == 63 || spigot.getTypeId() == 68) { return spigot.getTypeId() == 63 || spigot.getTypeId() == 68;
return true;
}
return false;
} }
// woodtype of the block the spigot is attached to // woodtype of the block the spigot is attached to
@SuppressWarnings("deprecation")
public byte getWood() { public byte getWood() {
int direction = getDirection(this.spigot);// 1=x+ 2=x- 3=z+ 4=z- int direction = getDirection(this.spigot);// 1=x+ 2=x- 3=z+ 4=z-
Block wood = null; Block wood;
if (direction == 0) { if (direction == 0) {
return 0; return 0;
} else if (direction == 1) { } else if (direction == 1) {
@@ -314,45 +546,75 @@ public class Barrel {
return 0; return 0;
} }
// returns the Sign of a large barrel, the spigot if there is none
public Block getSignOfSpigot() {
if (signoffset != 0) {
if (isSign(spigot)) {
return spigot;
}
if (isSign(spigot.getRelative(0, signoffset, 0))) {
return spigot.getRelative(0, signoffset, 0);
} else {
signoffset = 0;
}
}
return spigot;
}
// returns the fence above/below a block, itself if there is none // returns the fence above/below a block, itself if there is none
@SuppressWarnings("deprecation")
public static Block getSpigotOfSign(Block block) { public static Block getSpigotOfSign(Block block) {
int y = -2; int y = -2;
while (y <= 1) { while (y <= 1) {
// Fence and Netherfence // Fence and Netherfence
if (block.getRelative(0, y, 0).getTypeId() == 85 || block.getRelative(0, y, 0).getTypeId() == 113) { Block relative = block.getRelative(0, y, 0);
return (block.getRelative(0, y, 0)); if (relative.getTypeId() == 85 || relative.getTypeId() == 113) {
return (relative);
} }
y++; y++;
} }
return block; return block;
} }
// returns null if Barrel is correctly placed; the block that is missing @SuppressWarnings("deprecation")
// when not public static boolean isStairs(Material mat) {
return isStairs(mat.getId());
}
public static boolean isStairs(int id) {
return id == 53 || id == 134 || id == 135 || id == 136 || id == 163 || id == 164;
}
// returns null if Barrel is correctly placed; the block that is missing when not
// the barrel needs to be formed correctly // the barrel needs to be formed correctly
public static Block getBrokenBlock(Block spigot) { // flag force to also check if chunk is not loaded
if (spigot.getChunk().isLoaded()) { public Block getBrokenBlock(boolean force) {
if (force || spigot.getChunk().isLoaded()) {
spigot = getSpigotOfSign(spigot); spigot = getSpigotOfSign(spigot);
if (isSign(spigot)) { if (isSign(spigot)) {
return checkSBarrel(spigot); return checkSBarrel();
} else { } else {
return checkLBarrel(spigot); return checkLBarrel();
} }
} }
return null; return null;
} }
public static Block checkSBarrel(Block spigot) { @SuppressWarnings("deprecation")
public Block checkSBarrel() {
int direction = getDirection(spigot);// 1=x+ 2=x- 3=z+ 4=z- int direction = getDirection(spigot);// 1=x+ 2=x- 3=z+ 4=z-
if (direction == 0) { if (direction == 0) {
return spigot; return spigot;
} }
int startX = 0; int startX;
int startZ = 0; int startZ;
int endX; int endX;
int endZ; int endZ;
ArrayList<Integer> stairs = new ArrayList<Integer>();
if (direction == 1) { if (direction == 1) {
startX = 1; startX = 1;
endX = startX + 1; endX = startX + 1;
@@ -382,17 +644,20 @@ public class Barrel {
while (y <= 1) { while (y <= 1) {
while (x <= endX) { while (x <= endX) {
while (z <= endZ) { while (z <= endZ) {
typeId = spigot.getRelative(x, y, z).getTypeId(); Block block = spigot.getRelative(x, y, z);
typeId = block.getTypeId();
if (typeId == 53 || typeId == 134 || typeId == 135 || typeId == 136) { if (isStairs(typeId)) {
if (y == 0) { if (y == 0) {
// stairs have to be upside down // stairs have to be upside down
if (spigot.getRelative(x, y, z).getData() < 4) { if (block.getData() < 4) {
return spigot.getRelative(x, y, z); return block;
} }
} }
stairs.add(block.getX());
stairs.add(block.getY());
stairs.add(block.getZ());
z++; z++;
continue;
} else { } else {
return spigot.getRelative(x, y, z); return spigot.getRelative(x, y, z);
} }
@@ -404,20 +669,24 @@ public class Barrel {
x = startX; x = startX;
y++; y++;
} }
stairsloc = ArrayUtils.toPrimitive(stairs.toArray(new Integer[stairs.size()]));
return null; return null;
} }
public static Block checkLBarrel(Block spigot) { @SuppressWarnings("deprecation")
public Block checkLBarrel() {
int direction = getDirection(spigot);// 1=x+ 2=x- 3=z+ 4=z- int direction = getDirection(spigot);// 1=x+ 2=x- 3=z+ 4=z-
if (direction == 0) { if (direction == 0) {
return spigot; return spigot;
} }
int startX = 0; int startX;
int startZ = 0; int startZ;
int endX; int endX;
int endZ; int endZ;
ArrayList<Integer> stairs = new ArrayList<Integer>();
ArrayList<Integer> woods = new ArrayList<Integer>();
if (direction == 1) { if (direction == 1) {
startX = 1; startX = 1;
endX = startX + 3; endX = startX + 3;
@@ -447,37 +716,42 @@ public class Barrel {
while (y <= 2) { while (y <= 2) {
while (x <= endX) { while (x <= endX) {
while (z <= endZ) { while (z <= endZ) {
typeId = spigot.getRelative(x, y, z).getTypeId(); Block block = spigot.getRelative(x, y, z);
typeId = block.getTypeId();
if (direction == 1 || direction == 2) { if (direction == 1 || direction == 2) {
if (y == 1 && z == 0) { if (y == 1 && z == 0) {
if (x == -2 || x == -3 || x == 2 || x == 3) { if (x == -1 || x == -4 || x == 1 || x == 4) {
woods.add(block.getX());
woods.add(block.getY());
woods.add(block.getZ());
}
z++; z++;
continue; continue;
} else if (x == -1 || x == -4 || x == 1 || x == 4) {
if (typeId != 0) {
z++;
continue;
}
}
} }
} else { } else {
if (y == 1 && x == 0) { if (y == 1 && x == 0) {
if (z == -2 || z == -3 || z == 2 || z == 3) { if (z == -1 || z == -4 || z == 1 || z == 4) {
z++; woods.add(block.getX());
continue; woods.add(block.getY());
} else if (z == -1 || z == -4 || z == 1 || z == 4) { woods.add(block.getZ());
if (typeId != 0) { }
z++; z++;
continue; continue;
} }
} }
} if (typeId == 5 || isStairs(typeId)) {
} if (typeId == 5) {
if (typeId == 5 || typeId == 53 || typeId == 134 || typeId == 135 || typeId == 136) { woods.add(block.getX());
z++; woods.add(block.getY());
continue; woods.add(block.getZ());
} else { } else {
return spigot.getRelative(x, y, z); stairs.add(block.getX());
stairs.add(block.getY());
stairs.add(block.getZ());
}
z++;
} else {
return block;
} }
} }
z = startZ; z = startZ;
@@ -487,8 +761,10 @@ public class Barrel {
x = startX; x = startX;
y++; y++;
} }
return null; stairsloc = ArrayUtils.toPrimitive(stairs.toArray(new Integer[stairs.size()]));
woodsloc = ArrayUtils.toPrimitive(woods.toArray(new Integer[woods.size()]));
return null;
} }
} }
+2 -7
View File
@@ -12,8 +12,6 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.inventory.BrewerInventory; import org.bukkit.inventory.BrewerInventory;
import com.dre.brewery.BIngredients;
public class Brew { public class Brew {
// represents the liquid in the brewed Potions // represents the liquid in the brewed Potions
@@ -222,7 +220,7 @@ public class Brew {
} else { } else {
quality /= 2; quality /= 2;
} }
return (int) Math.round(quality); return Math.round(quality);
} }
public int getQuality() { public int getQuality() {
@@ -529,10 +527,7 @@ public class Brew {
// True if the PotionMeta has colored Lore // True if the PotionMeta has colored Lore
public static Boolean hasColorLore(PotionMeta meta) { public static Boolean hasColorLore(PotionMeta meta) {
if (meta.hasLore()) { return meta.hasLore() && !meta.getLore().get(1).startsWith(P.p.color("&7"));
return !meta.getLore().get(1).startsWith(P.p.color("&7"));
}
return false;
} }
// gets the Color that represents a quality in Lore // gets the Color that represents a quality in Lore
+90 -24
View File
@@ -47,7 +47,7 @@ public class ConfigUpdater {
public void saveConfig() { public void saveConfig() {
StringBuilder stringBuilder = new StringBuilder(""); StringBuilder stringBuilder = new StringBuilder("");
for (String line : config) { for (String line : config) {
stringBuilder.append(line + "\n"); stringBuilder.append(line).append("\n");
} }
String configString = stringBuilder.toString().trim(); String configString = stringBuilder.toString().trim();
@@ -87,24 +87,35 @@ public class ConfigUpdater {
lang = "de"; lang = "de";
} }
} }
if (fromVersion.equals("0.5") || fromVersion.equals("1.0")) { if (fromVersion.equals("0.5") || fromVersion.equals("1.0")) {
if (lang.equals("de")) { if (lang.equals("de")) {
update05de(); update05de();
} else { } else {
update10en(); update10en();
} }
fromVersion = "1.1";
}
if (fromVersion.equals("1.1") || fromVersion.equals("1.1.1")) {
if (lang.equals("de")) {
update11de();
} else { } else {
update11en();
}
fromVersion = "1.2";
}
if (!fromVersion.equals("1.2")) {
P.p.log(P.p.languageReader.get("Error_ConfigUpdate", fromVersion)); P.p.log(P.p.languageReader.get("Error_ConfigUpdate", fromVersion));
return; return;
} }
saveConfig(); saveConfig();
} }
// Updates de from 0.5 to 1.1 // Update the Version String
private void update05de() { private void updateVersion(String to) {
// Update version String
int index = indexOfStart("version"); int index = indexOfStart("version");
String line = "version: '1.1'"; String line = "version: '" + to + "'";
if (index != -1) { if (index != -1) {
setLine(index, line); setLine(index, line);
} else { } else {
@@ -118,9 +129,14 @@ public class ConfigUpdater {
addLines(index, line); addLines(index, line);
} }
} }
}
// Updates de from 0.5 to 1.1
private void update05de() {
updateVersion("1.1");
// Default language to de // Default language to de
index = indexOfStart("language: en"); int index = indexOfStart("language: en");
if (index != -1) { if (index != -1) {
setLine(index, "language: de"); setLine(index, "language: de");
P.p.language = "de"; P.p.language = "de";
@@ -164,7 +180,7 @@ public class ConfigUpdater {
} }
// Add some new separators for overview // Add some new separators for overview
line = "# -- Verschiedene Einstellungen --"; String line = "# -- Verschiedene Einstellungen --";
index = indexOfStart("# Verschiedene Einstellungen"); index = indexOfStart("# Verschiedene Einstellungen");
if (index != -1) { if (index != -1) {
setLine(index, line); setLine(index, line);
@@ -180,21 +196,7 @@ public class ConfigUpdater {
// Updates en from 1.0 to 1.1 // Updates en from 1.0 to 1.1
private void update10en() { private void update10en() {
// Update version String // Update version String
int index = indexOfStart("version"); updateVersion("1.1");
String line = "version: '1.1'";
if (index != -1) {
setLine(index, line);
} else {
index = indexOfStart("# Config Version");
if (index == -1) {
index = indexOfStart("autosave");
}
if (index == -1) {
appendLines(line);
} else {
addLines(index, line);
}
}
// Add the new entries for the Word Distortion above the words section // Add the new entries for the Word Distortion above the words section
String[] entries = { String[] entries = {
@@ -217,7 +219,7 @@ public class ConfigUpdater {
"- '[,]'", "- '[,]'",
"" ""
}; };
index = indexOfStart("# words"); int index = indexOfStart("# words");
if (index == -1) { if (index == -1) {
index = indexOfStart("# Will be processed"); index = indexOfStart("# Will be processed");
} }
@@ -234,7 +236,7 @@ public class ConfigUpdater {
} }
// Add some new separators for overview // Add some new separators for overview
line = "# -- Settings --"; String line = "# -- Settings --";
index = indexOfStart("# Settings"); index = indexOfStart("# Settings");
if (index != -1) { if (index != -1) {
setLine(index, line); setLine(index, line);
@@ -247,4 +249,68 @@ public class ConfigUpdater {
} }
} }
// Updates de from 1.1 to 1.2
private void update11de() {
updateVersion("1.2");
int index = indexOfStart("# Das Item kann nicht aufgesammelt werden");
if (index != -1) {
setLine(index, "# Das Item kann nicht aufgesammelt werden und bleibt bis zum Despawnen liegen. (Achtung: Kann nach Serverrestart aufgesammelt werden!)");
}
// Add the BarrelAccess Setting
String[] lines = {
"# Ob große Fässer an jedem Block geöffnet werden können, nicht nur an Zapfhahn und Schild. Bei kleinen Fässern geht dies immer. [true]",
"openLargeBarrelEverywhere: true",
""
};
index = indexOfStart("colorInBrewer") + 2;
if (index == 1) {
index = indexOfStart("colorInBarrels") + 2;
}
if (index == 1) {
index = indexOfStart("# Autosave");
}
if (index == -1) {
index = indexOfStart("language") + 2;
}
if (index == 1) {
addLines(3, lines);
} else {
addLines(index, lines);
}
}
// Updates en from 1.1 to 1.2
private void update11en() {
updateVersion("1.2");
int index = indexOfStart("# The item can not be collected");
if (index != -1) {
setLine(index, "# The item can not be collected and stays on the ground until it despawns. (Warning: Can be collected after Server restart!)");
}
// Add the BarrelAccess Setting
String[] lines = {
"# If a Large Barrel can be opened by clicking on any of its blocks, not just Spigot or Sign. This is always true for Small Barrels. [true]",
"openLargeBarrelEverywhere: true",
""
};
index = indexOfStart("colorInBrewer") + 2;
if (index == 1) {
index = indexOfStart("colorInBarrels") + 2;
}
if (index == 1) {
index = indexOfStart("# Autosave");
}
if (index == -1) {
index = indexOfStart("language") + 2;
}
if (index == 1) {
addLines(3, lines);
} else {
addLines(index, lines);
}
}
} }
+72 -5
View File
@@ -8,6 +8,7 @@ import java.util.HashMap;
import java.io.IOException; import java.io.IOException;
import java.io.File; import java.io.File;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@@ -32,6 +33,9 @@ public class P extends JavaPlugin {
public static int lastSave = 1; public static int lastSave = 1;
public static int autosave = 3; public static int autosave = 3;
// Third Party Enabled
public boolean hasLWC;
// Listeners // Listeners
public BlockListener blockListener; public BlockListener blockListener;
public PlayerListener playerListener; public PlayerListener playerListener;
@@ -47,15 +51,15 @@ public class P extends JavaPlugin {
public void onEnable() { public void onEnable() {
p = this; p = this;
// Check Third Party
hasLWC = getServer().getPluginManager().isPluginEnabled("LWC");
readConfig(); readConfig();
readData(); readData();
// Setup Metrics // Setup Metrics
setupMetrics(); setupMetrics();
// Load LanguageReader
languageReader = new LanguageReader(new File(p.getDataFolder(), "languages/" + language + ".yml"));
// Listeners // Listeners
blockListener = new BlockListener(); blockListener = new BlockListener();
playerListener = new PlayerListener(); playerListener = new PlayerListener();
@@ -170,6 +174,9 @@ public class P extends JavaPlugin {
// Set the Language // Set the Language
language = config.getString("language", "en"); language = config.getString("language", "en");
// Load LanguageReader
languageReader = new LanguageReader(new File(p.getDataFolder(), "languages/" + language + ".yml"));
// Check if config is the newest version // Check if config is the newest version
String version = config.getString("version", null); String version = config.getString("version", null);
if (version != null) { if (version != null) {
@@ -193,6 +200,7 @@ public class P extends JavaPlugin {
BPlayer.homeType = config.getString("homeType", null); BPlayer.homeType = config.getString("homeType", null);
Brew.colorInBarrels = config.getBoolean("colorInBarrels", false); Brew.colorInBarrels = config.getBoolean("colorInBarrels", false);
Brew.colorInBrewer = config.getBoolean("colorInBrewer", false); Brew.colorInBrewer = config.getBoolean("colorInBrewer", false);
PlayerListener.openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false);
Words.log = config.getBoolean("logRealChat", false); Words.log = config.getBoolean("logRealChat", false);
Words.commands = config.getStringList("distortCommands"); Words.commands = config.getStringList("distortCommands");
Words.doSigns = config.getBoolean("distortSignText", false); Words.doSigns = config.getBoolean("distortSignText", false);
@@ -390,12 +398,15 @@ public class P extends JavaPlugin {
ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv"); ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
Block block = world.getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2])); Block block = world.getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
float time = (float) section.getDouble(barrel + ".time", 0.0); float time = (float) section.getDouble(barrel + ".time", 0.0);
byte sign = (byte) section.getInt(barrel + ".sign", 0);
String[] st = section.getString(barrel + ".st", "").split(",");
String[] wo = section.getString(barrel + ".wo", "").split(",");
if (invSection != null) { if (invSection != null) {
new Barrel(block, invSection.getValues(true), time); new Barrel(block, sign, st, wo, invSection.getValues(true), time);
} else { } else {
// Barrel has no inventory // Barrel has no inventory
new Barrel(block, time); new Barrel(block, sign, st, wo, null, time);
} }
} else { } else {
@@ -561,6 +572,62 @@ public class P extends JavaPlugin {
} }
} }
// Returns true if the Block can be destroyed by the Player
public boolean blockDestroy(Block block, Player player) {
switch (block.getType()) {
case CAULDRON:
// will only remove when existing
BCauldron.remove(block);
return true;
case FENCE:
case NETHER_FENCE:
// remove barrel and throw potions on the ground
Barrel barrel = Barrel.getBySpigot(block);
if (barrel != null) {
if (barrel.hasPermsDestroy(player)) {
barrel.remove(null);
return true;
} else {
return false;
}
}
return true;
case SIGN:
case WALL_SIGN:
// remove small Barrels
Barrel barrel2 = Barrel.getBySpigot(block);
if (barrel2 != null) {
if (!barrel2.isLarge()) {
if (barrel2.hasPermsDestroy(player)) {
barrel2.remove(null);
return true;
} else {
return false;
}
} else {
barrel2.destroySign();
}
}
return true;
case WOOD:
case WOOD_STAIRS:
case ACACIA_STAIRS:
case BIRCH_WOOD_STAIRS:
case DARK_OAK_STAIRS:
case JUNGLE_WOOD_STAIRS:
case SPRUCE_WOOD_STAIRS:
Barrel barrel3 = Barrel.getByWood(block);
if (barrel3 != null) {
if (barrel3.hasPermsDestroy(player)) {
barrel3.remove(block);
} else {
return false;
}
}
}
return true;
}
public String color(String msg) { public String color(String msg) {
if (msg != null) { if (msg != null) {
msg = ChatColor.translateAlternateColorCodes('&', msg); msg = ChatColor.translateAlternateColorCodes('&', msg);
+1 -1
View File
@@ -241,7 +241,7 @@ public class Wakeup {
} }
String worldName = wakeup.loc.getWorld().getName(); String worldName = wakeup.loc.getWorld().getName();
String prefix = null; String prefix;
if (worldName.startsWith("DXL_")) { if (worldName.startsWith("DXL_")) {
prefix = p.getDxlName(worldName) + "." + id; prefix = p.getDxlName(worldName) + "." + id;
+2 -4
View File
@@ -11,8 +11,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.block.SignChangeEvent;
import com.dre.brewery.BPlayer;
public class Words { public class Words {
// represends Words and letters, that are replaced in drunk players messages // represends Words and letters, that are replaced in drunk players messages
@@ -231,7 +229,7 @@ public class Words {
// remove all "from" and split "words" there // remove all "from" and split "words" there
String[] splitted = words.split(from); String[] splitted = words.split(from);
int index = 0; int index = 0;
String part = null; String part;
// if there are occurences of "from" // if there are occurences of "from"
if (splitted.length > 1) { if (splitted.length > 1) {
@@ -272,7 +270,7 @@ public class Words {
boolean isBefore = !match; boolean isBefore = !match;
if (pre != null) { if (pre != null) {
for (String pr : pre) { for (String pr : pre) {
if (match == true) { if (match) {
// if one is correct, it is enough // if one is correct, it is enough
if (part.endsWith(pr) == match) { if (part.endsWith(pr) == match) {
isBefore = true; isBefore = true;
@@ -0,0 +1,96 @@
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.P;
import com.griefcraft.listeners.LWCPlayerListener;
import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Flag;
import com.griefcraft.model.Protection;
import com.griefcraft.scripting.event.LWCProtectionDestroyEvent;
public class LWCBarrel {
public static boolean checkDestroy(Player player, Barrel barrel) {
LWC lwc = LWC.getInstance();
Block sign = barrel.getSignOfSpigot();
//if (!Boolean.parseBoolean(lwc.resolveProtectionConfiguration(sign, "ignoreBlockDestruction"))) {
Protection protection = lwc.findProtection(sign);
if (protection != null) {
boolean canAccess = lwc.canAccessProtection(player, protection);
boolean canAdmin = lwc.canAdminProtection(player, protection);
try {
LWCProtectionDestroyEvent evt = new LWCProtectionDestroyEvent(player, protection, LWCProtectionDestroyEvent.Method.BLOCK_DESTRUCTION, canAccess, canAdmin);
lwc.getModuleLoader().dispatchEvent(evt);
if (evt.isCancelled()) {
return false;
}
} catch (Exception e) {
lwc.sendLocale(player, "protection.internalerror", "id", "BLOCK_BREAK");
P.p.errorLog("Failed to dispatch LWCProtectionDestroyEvent");
e.printStackTrace();
return false;
}
}
//}
return true;
}
public static boolean checkAccess(Player player, Block sign, PlayerInteractEvent event, Plugin plugin) {
LWC lwc = LWC.getInstance();
// Disallow Chest Access with these permissions
if (!lwc.hasPermission(player, "lwc.protect") && lwc.hasPermission(player, "lwc.deny") && !lwc.isAdmin(player) && !lwc.isMod(player)) {
lwc.sendLocale(player, "protection.interact.error.blocked");
return false;
}
// We just fake a BlockInteractEvent on the Sign for LWC, it handles it nicely. Otherwise we could copy LWCs listener in here...
PlayerInteractEvent lwcEvent = new PlayerInteractEvent(player, event.getAction(), event.getItem(), sign, event.getBlockFace());
for (RegisteredListener listener : HandlerList.getRegisteredListeners(plugin)) {
if (listener.getListener() instanceof LWCPlayerListener) {
try {
listener.callEvent(lwcEvent);
if (lwcEvent.isCancelled()) {
return false;
}
} catch (EventException e) {
lwc.sendLocale(player, "protection.internalerror", "id", "PLAYER_INTERACT");
P.p.errorLog("Block Interact could not be passed to LWC");
e.printStackTrace();
return false;
}
}
}
return true;
}
// Returns true if the block that exploded should not be removed
public static boolean blockExplosion(Barrel barrel, Block block) {
Protection protection = LWC.getInstance().findProtection(barrel.getSignOfSpigot());
if (protection == null) {
barrel.remove(block);
return false;
}
if (protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS)) {
protection.remove();
barrel.remove(block);
return false;
}
return true;
}
}
@@ -0,0 +1,31 @@
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.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
public class WGBarrel {
public static boolean checkAccess(Player player, Block spigot, Plugin plugin) {
WorldGuardPlugin wg = (WorldGuardPlugin) plugin;
if (!wg.getGlobalRegionManager().hasBypass(player, player.getWorld())) {
ApplicableRegionSet region = wg.getRegionManager(player.getWorld()).getApplicableRegions(spigot.getLocation());
if (region != null) {
LocalPlayer localPlayer = wg.wrapPlayer(player);
if (!region.allows(DefaultFlag.CHEST_ACCESS, localPlayer)) {
if (!region.canBuild(localPlayer)) {
P.p.msg(player, P.p.languageReader.get("Error_NoBarrelAccess"));
return false;
}
}
}
}
return true;
}
}
@@ -1,14 +1,14 @@
package com.dre.brewery.listeners; package com.dre.brewery.listeners;
import org.bukkit.block.Block;
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.BlockPistonExtendEvent;
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 org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.Material;
import org.bukkit.block.Block;
import com.dre.brewery.BCauldron;
import com.dre.brewery.Barrel; import com.dre.brewery.Barrel;
import com.dre.brewery.BPlayer; import com.dre.brewery.BPlayer;
import com.dre.brewery.Words; import com.dre.brewery.Words;
@@ -27,7 +27,7 @@ public class BlockListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onSignChangeLow(SignChangeEvent event) { public void onSignChangeLow(SignChangeEvent event) {
if (Words.doSigns) { if (Words.doSigns) {
if (BPlayer.players.containsKey(event.getPlayer().getName())) { if (BPlayer.players.containsKey(event.getPlayer().getName())) {
@@ -36,29 +36,31 @@ public class BlockListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock(); if (!P.p.blockDestroy(event.getBlock(), event.getPlayer())) {
// remove cauldron event.setCancelled(true);
if (block.getType() == Material.CAULDRON) {
if (block.getData() != 0) {
// will only remove when existing
BCauldron.remove(block);
} }
// remove barrel and throw potions on the ground
} else if (block.getType() == Material.FENCE || block.getType() == Material.NETHER_FENCE) {
Barrel barrel = Barrel.get(block);
if (barrel != null) {
barrel.remove(null);
} }
// remove small Barrels
} else if (block.getType() == Material.SIGN || block.getType() == Material.WALL_SIGN) { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
Barrel barrel = Barrel.get(block); public void onPistonRetract(BlockPistonRetractEvent event) {
if (barrel != null) { if (event.isSticky()) {
if (!barrel.isLarge()) { Block block = event.getRetractLocation().getBlock();
barrel.remove(null);
if (Barrel.get(block) != null) {
event.setCancelled(true);
} }
} }
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPistonExtend(BlockPistonExtendEvent event) {
for (Block block : event.getBlocks()) {
if (Barrel.get(block) != null) {
event.setCancelled(true);
return;
}
}
} }
} }
@@ -1,15 +1,22 @@
package com.dre.brewery.listeners; package com.dre.brewery.listeners;
import java.util.ListIterator;
import org.bukkit.block.Block;
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.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ItemDespawnEvent; import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.dre.brewery.Barrel;
import com.dre.brewery.Brew; import com.dre.brewery.Brew;
import com.dre.brewery.P;
import com.dre.brewery.integration.LWCBarrel;
public class EntityListener implements Listener { public class EntityListener implements Listener {
@@ -35,4 +42,25 @@ public class EntityListener implements Listener {
} }
} }
// --- Barrel Breaking ---
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onExplode(EntityExplodeEvent event) {
ListIterator<Block> iter = event.blockList().listIterator();
Barrel barrel = null;
while (iter.hasNext()) {
Block block = iter.next();
if (barrel == null || !barrel.hasBlock(block)) {
barrel = Barrel.get(block);
}
if (barrel != null) {
if (P.p.hasLWC) {
if (LWCBarrel.blockExplosion(barrel, block)) {
iter.remove();
}
}
}
}
}
} }
@@ -1,6 +1,5 @@
package com.dre.brewery.listeners; package com.dre.brewery.listeners;
import org.bukkit.entity.Item;
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;
@@ -87,9 +86,7 @@ public class InventoryListener implements Listener {
// block the pickup of items where getPickupDelay is > 1000 (puke) // block the pickup of items where getPickupDelay is > 1000 (puke)
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onInventoryPickupItem(InventoryPickupItemEvent event){ public void onInventoryPickupItem(InventoryPickupItemEvent event){
Item item = event.getItem(); if (event.getItem().getPickupDelay() > 1000) {
if (item.getPickupDelay() > 1000) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@@ -17,7 +17,6 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.plugin.Plugin;
import com.dre.brewery.BCauldron; import com.dre.brewery.BCauldron;
import com.dre.brewery.BIngredients; import com.dre.brewery.BIngredients;
@@ -27,12 +26,12 @@ import com.dre.brewery.BPlayer;
import com.dre.brewery.Words; import com.dre.brewery.Words;
import com.dre.brewery.Wakeup; import com.dre.brewery.Wakeup;
import com.dre.brewery.P; import com.dre.brewery.P;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
public static boolean openEverywhere;
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
Block clickedBlock = event.getClickedBlock(); Block clickedBlock = event.getClickedBlock();
@@ -41,9 +40,10 @@ public class PlayerListener implements Listener {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (!player.isSneaking()) { if (!player.isSneaking()) {
if (clickedBlock.getType() == Material.CAULDRON) { Material type = clickedBlock.getType();
if (clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.FIRE || clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA if (type == Material.CAULDRON) {
|| clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.LAVA) { Block down = clickedBlock.getRelative(BlockFace.DOWN);
if (down.getType() == Material.FIRE || down.getType() == Material.STATIONARY_LAVA || down.getType() == Material.LAVA) {
Material materialInHand = event.getMaterial(); Material materialInHand = event.getMaterial();
ItemStack item = event.getItem(); ItemStack item = event.getItem();
@@ -90,38 +90,37 @@ public class PlayerListener implements Listener {
} else { } else {
event.setCancelled(true); event.setCancelled(true);
} }
}
// access a barrel
} else if (clickedBlock.getType() == Material.FENCE || clickedBlock.getType() == Material.NETHER_FENCE || clickedBlock.getType() == Material.SIGN
|| clickedBlock.getType() == Material.WALL_SIGN) {
Barrel barrel = Barrel.get(clickedBlock);
if (barrel != null) {
event.setCancelled(true);
Plugin plugin = P.p.getServer().getPluginManager().getPlugin("WorldGuard");
if (plugin != null && plugin instanceof WorldGuardPlugin) {
WorldGuardPlugin wg = (WorldGuardPlugin) plugin;
if (!wg.getGlobalRegionManager().hasBypass(player, player.getWorld())) {
ApplicableRegionSet region = wg.getRegionManager(player.getWorld()).getApplicableRegions(clickedBlock.getLocation());
if (region != null) {
LocalPlayer localPlayer = wg.wrapPlayer(player);
if (!region.allows(DefaultFlag.CHEST_ACCESS, localPlayer)) {
if (!region.canBuild(localPlayer)) {
P.p.msg(player, P.p.languageReader.get("Error_NoBarrelAccess"));
return; return;
} }
} }
// Access a Barrel
Barrel barrel = null;
if (type == Material.WOOD) {
if (openEverywhere) {
barrel = Barrel.get(clickedBlock);
}
} else if (Barrel.isStairs(type)) {
for (Barrel barrel2 : Barrel.barrels) {
if (barrel2.hasStairsBlock(clickedBlock)) {
if (openEverywhere || !barrel2.isLarge()) {
barrel = barrel2;
}
break;
} }
} }
} else if (type == Material.FENCE || type == Material.NETHER_FENCE || type == Material.SIGN || type == Material.WALL_SIGN) {
barrel = Barrel.getBySpigot(clickedBlock);
} }
Block broken = Barrel.getBrokenBlock(clickedBlock);
// barrel is built correctly if (barrel != null) {
if (broken == null) { event.setCancelled(true);
if (!barrel.hasPermsOpen(player, event)) {
return;
}
barrel.open(player); barrel.open(player);
} else {
barrel.remove(broken);
}
}
} }
} }
} }