mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-06-28 10:44:48 +02:00
Listener for Barrel breaking -> LWC Support
This commit is contained in:
parent
3155bbab63
commit
1c6fe6cc33
|
@ -30,7 +30,7 @@ enableLoginDisallow: true
|
|||
enableKickOnOverdrink: 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
|
||||
|
||||
# Item that is dropped multiple times uncollectable when puking [SOUL_SAND]
|
||||
|
@ -48,11 +48,14 @@ hangoverDays: 7
|
|||
colorInBarrels: true
|
||||
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: 3
|
||||
|
||||
# Config Version
|
||||
version: '1.1'
|
||||
version: '1.2'
|
||||
|
||||
|
||||
# -- Recipes for Potions --
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
name: Brewery
|
||||
version: 1.1
|
||||
version: 1.2
|
||||
main: com.dre.brewery.P
|
||||
authors: [Milan Albrecht, Frank Baumann]
|
||||
softdepend: [LWC]
|
||||
commands:
|
||||
brewery:
|
||||
description: Command for Administration
|
||||
|
|
19
pom.xml
19
pom.xml
|
@ -4,7 +4,7 @@
|
|||
|
||||
<groupId>com.dre</groupId>
|
||||
<artifactId>brewery</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<version>1.2</version>
|
||||
<name>Brewery</name>
|
||||
|
||||
<build>
|
||||
|
@ -85,6 +85,15 @@
|
|||
</snapshots>
|
||||
</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>
|
||||
<id>Plugin Metrics</id>
|
||||
<url>http://repo.mcstats.org/content/repositories/public</url>
|
||||
|
@ -116,6 +125,14 @@
|
|||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.griefcraft</groupId>
|
||||
<artifactId>LWC</artifactId>
|
||||
<version>4.3.1</version>
|
||||
<scope>compile</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mcstats</groupId>
|
||||
<artifactId>metrics</artifactId>
|
||||
|
|
|
@ -10,8 +10,6 @@ import org.bukkit.inventory.ItemStack;
|
|||
import org.bukkit.Effect;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import com.dre.brewery.BIngredients;
|
||||
|
||||
public class BCauldron {
|
||||
public static CopyOnWriteArrayList<BCauldron> bcauldrons = new CopyOnWriteArrayList<BCauldron>();
|
||||
|
||||
|
@ -87,6 +85,7 @@ public class BCauldron {
|
|||
}
|
||||
|
||||
// fills players bottle with cooked brew
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean fill(Player player, Block block) {
|
||||
BCauldron bcauldron = get(block);
|
||||
if (bcauldron != null) {
|
||||
|
@ -128,9 +127,11 @@ public class BCauldron {
|
|||
|
||||
// reset to normal cauldron
|
||||
public static void remove(Block block) {
|
||||
BCauldron bcauldron = get(block);
|
||||
if (bcauldron != null) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
if (block.getData() != 0) {
|
||||
BCauldron bcauldron = get(block);
|
||||
if (bcauldron != null) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,7 +152,7 @@ public class BCauldron {
|
|||
int id = 0;
|
||||
for (BCauldron cauldron : bcauldrons) {
|
||||
String worldName = cauldron.block.getWorld().getName();
|
||||
String prefix = null;
|
||||
String prefix;
|
||||
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
prefix = P.p.getDxlName(worldName) + "." + id;
|
||||
|
|
|
@ -10,9 +10,6 @@ import org.bukkit.Material;
|
|||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
|
||||
import com.dre.brewery.BRecipe;
|
||||
import com.dre.brewery.Brew;
|
||||
|
||||
public class BIngredients {
|
||||
public static ArrayList<Material> possibleIngredients = new ArrayList<Material>();
|
||||
public static ArrayList<BRecipe> recipes = new ArrayList<BRecipe>();
|
||||
|
@ -121,10 +118,10 @@ public class BIngredients {
|
|||
// correct one...
|
||||
public BRecipe getBestRecipe(float wood, float time, boolean distilled) {
|
||||
float quality = 0;
|
||||
int ingredientQuality = 0;
|
||||
int cookingQuality = 0;
|
||||
int woodQuality = 0;
|
||||
int ageQuality = 0;
|
||||
int ingredientQuality;
|
||||
int cookingQuality;
|
||||
int woodQuality;
|
||||
int ageQuality;
|
||||
BRecipe bestRecipe = null;
|
||||
for (BRecipe recipe : recipes) {
|
||||
ingredientQuality = getIngredientQuality(recipe);
|
||||
|
@ -204,7 +201,7 @@ public class BIngredients {
|
|||
// no recipe is near them
|
||||
public int getIngredientQuality(BRecipe recipe) {
|
||||
float quality = 10;
|
||||
int count = 0;
|
||||
int count;
|
||||
int badStuff = 0;
|
||||
if (recipe.isMissingIngredients(ingredients)) {
|
||||
// when ingredients are not complete
|
||||
|
@ -278,7 +275,7 @@ public class BIngredients {
|
|||
|
||||
// returns the quality regarding the ageing time conditioning given Recipe
|
||||
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) {
|
||||
return quality;
|
||||
|
|
|
@ -15,8 +15,6 @@ import org.bukkit.Location;
|
|||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import com.dre.brewery.Brew;
|
||||
|
||||
public class 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
|
||||
|
|
|
@ -113,24 +113,15 @@ public class BRecipe {
|
|||
}
|
||||
|
||||
public boolean isCookingOnly() {
|
||||
if (age == 0 && distillruns == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return age == 0 && distillruns == 0;
|
||||
}
|
||||
|
||||
public boolean needsDistilling() {
|
||||
if (distillruns == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return distillruns != 0;
|
||||
}
|
||||
|
||||
public boolean needsToAge() {
|
||||
if (age == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return age != 0;
|
||||
}
|
||||
|
||||
// true if given map misses an ingredient
|
||||
|
|
|
@ -1,74 +1,146 @@
|
|||
package com.dre.brewery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
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 static CopyOnWriteArrayList<Barrel> barrels = new CopyOnWriteArrayList<Barrel>();
|
||||
|
||||
// private CopyOnWriteArrayList<Brew> brews = new
|
||||
// CopyOnWriteArrayList<Brew>();
|
||||
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 float time;
|
||||
|
||||
public Barrel(Block spigot) {
|
||||
public Barrel(Block spigot, byte signoffset) {
|
||||
this.spigot = spigot;
|
||||
this.signoffset = signoffset;
|
||||
}
|
||||
|
||||
// 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.signoffset = sign;
|
||||
if (isLarge()) {
|
||||
this.inventory = org.bukkit.Bukkit.createInventory(null, 27, P.p.languageReader.get("Etc_Barrel"));
|
||||
} else {
|
||||
this.inventory = org.bukkit.Bukkit.createInventory(null, 9, P.p.languageReader.get("Etc_Barrel"));
|
||||
}
|
||||
for (String slot : items.keySet()) {
|
||||
if (items.get(slot) instanceof ItemStack) {
|
||||
this.inventory.setItem(P.p.parseInt(slot), (ItemStack) items.get(slot));
|
||||
if (items != null) {
|
||||
for (String slot : items.keySet()) {
|
||||
if (items.get(slot) instanceof ItemStack) {
|
||||
this.inventory.setItem(P.p.parseInt(slot), (ItemStack) items.get(slot));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.time = time;
|
||||
barrels.add(this);
|
||||
}
|
||||
|
||||
// load from file (without inventory)
|
||||
public Barrel(Block spigot, float time) {
|
||||
this.spigot = spigot;
|
||||
if (isLarge()) {
|
||||
this.inventory = org.bukkit.Bukkit.createInventory(null, 27, P.p.languageReader.get("Etc_Barrel"));
|
||||
} else {
|
||||
this.inventory = org.bukkit.Bukkit.createInventory(null, 9, P.p.languageReader.get("Etc_Barrel"));
|
||||
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;
|
||||
}
|
||||
this.time = time;
|
||||
if (st.length > 1) {
|
||||
stairsloc = new int[st.length];
|
||||
for (String sts : st) {
|
||||
stairsloc[i] = P.p.parseInt(sts);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (woodsloc == null && stairsloc == null) {
|
||||
Block broken = getBrokenBlock(true);
|
||||
if (broken != null) {
|
||||
remove(broken);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
barrels.add(this);
|
||||
}
|
||||
|
||||
public static void onUpdate() {
|
||||
Block broken;
|
||||
for (Barrel barrel : barrels) {
|
||||
broken = getBrokenBlock(barrel.spigot);
|
||||
// remove the barrel if it was destroyed
|
||||
if (broken != null) {
|
||||
barrel.remove(broken);
|
||||
} else {
|
||||
// Minecraft day is 20 min, so add 1/20 to the time every minute
|
||||
barrel.time += 1.0 / 20.0;
|
||||
if (!barrel.checked) {
|
||||
broken = barrel.getBrokenBlock(false);
|
||||
if (broken != null) {
|
||||
// remove the barrel if it was destroyed
|
||||
barrel.remove(broken);
|
||||
continue;
|
||||
} 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
|
||||
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
|
||||
@SuppressWarnings("deprecation")
|
||||
public void open(Player player) {
|
||||
if (inventory == null) {
|
||||
if (isLarge()) {
|
||||
|
@ -104,23 +176,162 @@ public class Barrel {
|
|||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public static Barrel get(Block spigot) {
|
||||
// Returns true if this Block is part of this Barrel
|
||||
public boolean hasBlock(Block block) {
|
||||
if (block != null) {
|
||||
if (block.getType().equals(Material.WOOD)) {
|
||||
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 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
|
||||
spigot = getSpigotOfSign(spigot);
|
||||
Block spigot = getSpigotOfSign(sign);
|
||||
|
||||
byte signoffset = 0;
|
||||
if (!spigot.equals(sign)) {
|
||||
signoffset = (byte) (sign.getY() - spigot.getY());
|
||||
}
|
||||
|
||||
for (Barrel barrel : barrels) {
|
||||
if (barrel.spigot.equals(spigot)) {
|
||||
return barrel;
|
||||
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;
|
||||
}
|
||||
|
||||
// creates a new Barrel out of a sign
|
||||
public static boolean create(Block spigot) {
|
||||
spigot = getSpigotOfSign(spigot);
|
||||
if (getBrokenBlock(spigot) == null) {
|
||||
if (get(spigot) == null) {
|
||||
barrels.add(new Barrel(spigot));
|
||||
public static boolean create(Block sign) {
|
||||
Block spigot = getSpigotOfSign(sign);
|
||||
|
||||
byte signoffset = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +366,7 @@ public class Barrel {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
public static void save(ConfigurationSection config, ConfigurationSection oldData) {
|
||||
P.p.createWorldSections(config);
|
||||
|
@ -176,7 +393,7 @@ public class Barrel {
|
|||
for (Barrel barrel : barrels) {
|
||||
|
||||
String worldName = barrel.spigot.getWorld().getName();
|
||||
String prefix = null;
|
||||
String prefix;
|
||||
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
prefix = P.p.getDxlName(worldName) + "." + id;
|
||||
|
@ -187,9 +404,27 @@ public class Barrel {
|
|||
// block: x/y/z
|
||||
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) {
|
||||
int slot = 0;
|
||||
ItemStack item = null;
|
||||
ItemStack item;
|
||||
ConfigurationSection invConfig = null;
|
||||
while (slot < barrel.inventory.getSize()) {
|
||||
item = barrel.inventory.getItem(slot);
|
||||
|
@ -223,14 +458,15 @@ public class Barrel {
|
|||
}
|
||||
|
||||
// direction of the barrel from the spigot
|
||||
@SuppressWarnings("deprecation")
|
||||
public static int getDirection(Block spigot) {
|
||||
int direction = 0;// 1=x+ 2=x- 3=z+ 4=z-
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
direction = 4;
|
||||
} else {
|
||||
|
@ -238,7 +474,7 @@ public class Barrel {
|
|||
}
|
||||
}
|
||||
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) {
|
||||
direction = 1;
|
||||
} else {
|
||||
|
@ -246,7 +482,7 @@ public class Barrel {
|
|||
}
|
||||
}
|
||||
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) {
|
||||
direction = 2;
|
||||
} else {
|
||||
|
@ -258,24 +494,20 @@ public class Barrel {
|
|||
|
||||
// is this a Large barrel?
|
||||
public boolean isLarge() {
|
||||
if (spigot.getTypeId() == 63 || spigot.getTypeId() == 68) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !isSign(spigot);
|
||||
}
|
||||
|
||||
// true for small barrels
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean isSign(Block spigot) {
|
||||
if (spigot.getTypeId() == 63 || spigot.getTypeId() == 68) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return spigot.getTypeId() == 63 || spigot.getTypeId() == 68;
|
||||
}
|
||||
|
||||
// woodtype of the block the spigot is attached to
|
||||
@SuppressWarnings("deprecation")
|
||||
public byte getWood() {
|
||||
int direction = getDirection(this.spigot);// 1=x+ 2=x- 3=z+ 4=z-
|
||||
Block wood = null;
|
||||
Block wood;
|
||||
if (direction == 0) {
|
||||
return 0;
|
||||
} else if (direction == 1) {
|
||||
|
@ -314,45 +546,75 @@ public class Barrel {
|
|||
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
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Block getSpigotOfSign(Block block) {
|
||||
|
||||
int y = -2;
|
||||
while (y <= 1) {
|
||||
// Fence and Netherfence
|
||||
if (block.getRelative(0, y, 0).getTypeId() == 85 || block.getRelative(0, y, 0).getTypeId() == 113) {
|
||||
return (block.getRelative(0, y, 0));
|
||||
Block relative = block.getRelative(0, y, 0);
|
||||
if (relative.getTypeId() == 85 || relative.getTypeId() == 113) {
|
||||
return (relative);
|
||||
}
|
||||
y++;
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
// returns null if Barrel is correctly placed; the block that is missing
|
||||
// when not
|
||||
@SuppressWarnings("deprecation")
|
||||
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
|
||||
public static Block getBrokenBlock(Block spigot) {
|
||||
if (spigot.getChunk().isLoaded()) {
|
||||
// flag force to also check if chunk is not loaded
|
||||
public Block getBrokenBlock(boolean force) {
|
||||
if (force || spigot.getChunk().isLoaded()) {
|
||||
spigot = getSpigotOfSign(spigot);
|
||||
if (isSign(spigot)) {
|
||||
return checkSBarrel(spigot);
|
||||
return checkSBarrel();
|
||||
} else {
|
||||
return checkLBarrel(spigot);
|
||||
return checkLBarrel();
|
||||
}
|
||||
}
|
||||
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-
|
||||
if (direction == 0) {
|
||||
return spigot;
|
||||
}
|
||||
int startX = 0;
|
||||
int startZ = 0;
|
||||
int startX;
|
||||
int startZ;
|
||||
int endX;
|
||||
int endZ;
|
||||
|
||||
ArrayList<Integer> stairs = new ArrayList<Integer>();
|
||||
|
||||
if (direction == 1) {
|
||||
startX = 1;
|
||||
endX = startX + 1;
|
||||
|
@ -382,17 +644,20 @@ public class Barrel {
|
|||
while (y <= 1) {
|
||||
while (x <= endX) {
|
||||
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) {
|
||||
// stairs have to be upside down
|
||||
if (spigot.getRelative(x, y, z).getData() < 4) {
|
||||
return spigot.getRelative(x, y, z);
|
||||
if (block.getData() < 4) {
|
||||
return block;
|
||||
}
|
||||
}
|
||||
stairs.add(block.getX());
|
||||
stairs.add(block.getY());
|
||||
stairs.add(block.getZ());
|
||||
z++;
|
||||
continue;
|
||||
} else {
|
||||
return spigot.getRelative(x, y, z);
|
||||
}
|
||||
|
@ -404,20 +669,24 @@ public class Barrel {
|
|||
x = startX;
|
||||
y++;
|
||||
}
|
||||
stairsloc = ArrayUtils.toPrimitive(stairs.toArray(new Integer[stairs.size()]));
|
||||
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-
|
||||
if (direction == 0) {
|
||||
return spigot;
|
||||
}
|
||||
int startX = 0;
|
||||
int startZ = 0;
|
||||
int startX;
|
||||
int startZ;
|
||||
int endX;
|
||||
int endZ;
|
||||
|
||||
ArrayList<Integer> stairs = new ArrayList<Integer>();
|
||||
ArrayList<Integer> woods = new ArrayList<Integer>();
|
||||
|
||||
if (direction == 1) {
|
||||
startX = 1;
|
||||
endX = startX + 3;
|
||||
|
@ -447,37 +716,42 @@ public class Barrel {
|
|||
while (y <= 2) {
|
||||
while (x <= endX) {
|
||||
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 (y == 1 && z == 0) {
|
||||
if (x == -2 || x == -3 || x == 2 || x == 3) {
|
||||
z++;
|
||||
continue;
|
||||
} else if (x == -1 || x == -4 || x == 1 || x == 4) {
|
||||
if (typeId != 0) {
|
||||
z++;
|
||||
continue;
|
||||
}
|
||||
if (x == -1 || x == -4 || x == 1 || x == 4) {
|
||||
woods.add(block.getX());
|
||||
woods.add(block.getY());
|
||||
woods.add(block.getZ());
|
||||
}
|
||||
z++;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (y == 1 && x == 0) {
|
||||
if (z == -2 || z == -3 || z == 2 || z == 3) {
|
||||
z++;
|
||||
continue;
|
||||
} else if (z == -1 || z == -4 || z == 1 || z == 4) {
|
||||
if (typeId != 0) {
|
||||
z++;
|
||||
continue;
|
||||
}
|
||||
if (z == -1 || z == -4 || z == 1 || z == 4) {
|
||||
woods.add(block.getX());
|
||||
woods.add(block.getY());
|
||||
woods.add(block.getZ());
|
||||
}
|
||||
z++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (typeId == 5 || typeId == 53 || typeId == 134 || typeId == 135 || typeId == 136) {
|
||||
if (typeId == 5 || isStairs(typeId)) {
|
||||
if (typeId == 5) {
|
||||
woods.add(block.getX());
|
||||
woods.add(block.getY());
|
||||
woods.add(block.getZ());
|
||||
} else {
|
||||
stairs.add(block.getX());
|
||||
stairs.add(block.getY());
|
||||
stairs.add(block.getZ());
|
||||
}
|
||||
z++;
|
||||
continue;
|
||||
} else {
|
||||
return spigot.getRelative(x, y, z);
|
||||
return block;
|
||||
}
|
||||
}
|
||||
z = startZ;
|
||||
|
@ -487,8 +761,10 @@ public class Barrel {
|
|||
x = startX;
|
||||
y++;
|
||||
}
|
||||
return null;
|
||||
stairsloc = ArrayUtils.toPrimitive(stairs.toArray(new Integer[stairs.size()]));
|
||||
woodsloc = ArrayUtils.toPrimitive(woods.toArray(new Integer[woods.size()]));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,8 +12,6 @@ import org.bukkit.potion.PotionEffect;
|
|||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.inventory.BrewerInventory;
|
||||
|
||||
import com.dre.brewery.BIngredients;
|
||||
|
||||
public class Brew {
|
||||
|
||||
// represents the liquid in the brewed Potions
|
||||
|
@ -222,7 +220,7 @@ public class Brew {
|
|||
} else {
|
||||
quality /= 2;
|
||||
}
|
||||
return (int) Math.round(quality);
|
||||
return Math.round(quality);
|
||||
}
|
||||
|
||||
public int getQuality() {
|
||||
|
@ -529,10 +527,7 @@ public class Brew {
|
|||
|
||||
// True if the PotionMeta has colored Lore
|
||||
public static Boolean hasColorLore(PotionMeta meta) {
|
||||
if (meta.hasLore()) {
|
||||
return !meta.getLore().get(1).startsWith(P.p.color("&7"));
|
||||
}
|
||||
return false;
|
||||
return meta.hasLore() && !meta.getLore().get(1).startsWith(P.p.color("&7"));
|
||||
}
|
||||
|
||||
// gets the Color that represents a quality in Lore
|
||||
|
|
|
@ -47,7 +47,7 @@ public class ConfigUpdater {
|
|||
public void saveConfig() {
|
||||
StringBuilder stringBuilder = new StringBuilder("");
|
||||
for (String line : config) {
|
||||
stringBuilder.append(line + "\n");
|
||||
stringBuilder.append(line).append("\n");
|
||||
}
|
||||
String configString = stringBuilder.toString().trim();
|
||||
|
||||
|
@ -87,24 +87,35 @@ public class ConfigUpdater {
|
|||
lang = "de";
|
||||
}
|
||||
}
|
||||
|
||||
if (fromVersion.equals("0.5") || fromVersion.equals("1.0")) {
|
||||
if (lang.equals("de")) {
|
||||
update05de();
|
||||
} else {
|
||||
update10en();
|
||||
}
|
||||
} else {
|
||||
fromVersion = "1.1";
|
||||
}
|
||||
if (fromVersion.equals("1.1") || fromVersion.equals("1.1.1")) {
|
||||
if (lang.equals("de")) {
|
||||
update11de();
|
||||
} else {
|
||||
update11en();
|
||||
}
|
||||
fromVersion = "1.2";
|
||||
}
|
||||
|
||||
if (!fromVersion.equals("1.2")) {
|
||||
P.p.log(P.p.languageReader.get("Error_ConfigUpdate", fromVersion));
|
||||
return;
|
||||
}
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
// Updates de from 0.5 to 1.1
|
||||
private void update05de() {
|
||||
// Update version String
|
||||
// Update the Version String
|
||||
private void updateVersion(String to) {
|
||||
int index = indexOfStart("version");
|
||||
String line = "version: '1.1'";
|
||||
String line = "version: '" + to + "'";
|
||||
if (index != -1) {
|
||||
setLine(index, line);
|
||||
} else {
|
||||
|
@ -118,9 +129,14 @@ public class ConfigUpdater {
|
|||
addLines(index, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Updates de from 0.5 to 1.1
|
||||
private void update05de() {
|
||||
updateVersion("1.1");
|
||||
|
||||
// Default language to de
|
||||
index = indexOfStart("language: en");
|
||||
int index = indexOfStart("language: en");
|
||||
if (index != -1) {
|
||||
setLine(index, "language: de");
|
||||
P.p.language = "de";
|
||||
|
@ -164,7 +180,7 @@ public class ConfigUpdater {
|
|||
}
|
||||
|
||||
// Add some new separators for overview
|
||||
line = "# -- Verschiedene Einstellungen --";
|
||||
String line = "# -- Verschiedene Einstellungen --";
|
||||
index = indexOfStart("# Verschiedene Einstellungen");
|
||||
if (index != -1) {
|
||||
setLine(index, line);
|
||||
|
@ -180,21 +196,7 @@ public class ConfigUpdater {
|
|||
// Updates en from 1.0 to 1.1
|
||||
private void update10en() {
|
||||
// Update version String
|
||||
int index = indexOfStart("version");
|
||||
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);
|
||||
}
|
||||
}
|
||||
updateVersion("1.1");
|
||||
|
||||
// Add the new entries for the Word Distortion above the words section
|
||||
String[] entries = {
|
||||
|
@ -217,7 +219,7 @@ public class ConfigUpdater {
|
|||
"- '[,]'",
|
||||
""
|
||||
};
|
||||
index = indexOfStart("# words");
|
||||
int index = indexOfStart("# words");
|
||||
if (index == -1) {
|
||||
index = indexOfStart("# Will be processed");
|
||||
}
|
||||
|
@ -234,7 +236,7 @@ public class ConfigUpdater {
|
|||
}
|
||||
|
||||
// Add some new separators for overview
|
||||
line = "# -- Settings --";
|
||||
String line = "# -- Settings --";
|
||||
index = indexOfStart("# Settings");
|
||||
if (index != -1) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.HashMap;
|
|||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
@ -32,6 +33,9 @@ public class P extends JavaPlugin {
|
|||
public static int lastSave = 1;
|
||||
public static int autosave = 3;
|
||||
|
||||
// Third Party Enabled
|
||||
public boolean hasLWC;
|
||||
|
||||
// Listeners
|
||||
public BlockListener blockListener;
|
||||
public PlayerListener playerListener;
|
||||
|
@ -47,14 +51,14 @@ public class P extends JavaPlugin {
|
|||
public void onEnable() {
|
||||
p = this;
|
||||
|
||||
// Check Third Party
|
||||
hasLWC = getServer().getPluginManager().isPluginEnabled("LWC");
|
||||
|
||||
readConfig();
|
||||
readData();
|
||||
|
||||
// Setup Metrics
|
||||
setupMetrics();
|
||||
|
||||
// Load LanguageReader
|
||||
languageReader = new LanguageReader(new File(p.getDataFolder(), "languages/" + language + ".yml"));
|
||||
|
||||
// Listeners
|
||||
blockListener = new BlockListener();
|
||||
|
@ -170,6 +174,9 @@ public class P extends JavaPlugin {
|
|||
// Set the Language
|
||||
language = config.getString("language", "en");
|
||||
|
||||
// Load LanguageReader
|
||||
languageReader = new LanguageReader(new File(p.getDataFolder(), "languages/" + language + ".yml"));
|
||||
|
||||
// Check if config is the newest version
|
||||
String version = config.getString("version", null);
|
||||
if (version != null) {
|
||||
|
@ -193,6 +200,7 @@ public class P extends JavaPlugin {
|
|||
BPlayer.homeType = config.getString("homeType", null);
|
||||
Brew.colorInBarrels = config.getBoolean("colorInBarrels", false);
|
||||
Brew.colorInBrewer = config.getBoolean("colorInBrewer", false);
|
||||
PlayerListener.openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false);
|
||||
Words.log = config.getBoolean("logRealChat", false);
|
||||
Words.commands = config.getStringList("distortCommands");
|
||||
Words.doSigns = config.getBoolean("distortSignText", false);
|
||||
|
@ -390,12 +398,15 @@ public class P extends JavaPlugin {
|
|||
ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
|
||||
Block block = world.getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
|
||||
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) {
|
||||
new Barrel(block, invSection.getValues(true), time);
|
||||
new Barrel(block, sign, st, wo, invSection.getValues(true), time);
|
||||
} else {
|
||||
// Barrel has no inventory
|
||||
new Barrel(block, time);
|
||||
new Barrel(block, sign, st, wo, null, time);
|
||||
}
|
||||
|
||||
} 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) {
|
||||
if (msg != null) {
|
||||
msg = ChatColor.translateAlternateColorCodes('&', msg);
|
||||
|
|
|
@ -241,7 +241,7 @@ public class Wakeup {
|
|||
}
|
||||
|
||||
String worldName = wakeup.loc.getWorld().getName();
|
||||
String prefix = null;
|
||||
String prefix;
|
||||
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
prefix = p.getDxlName(worldName) + "." + id;
|
||||
|
|
|
@ -11,8 +11,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
import com.dre.brewery.BPlayer;
|
||||
|
||||
public class Words {
|
||||
|
||||
// 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
|
||||
String[] splitted = words.split(from);
|
||||
int index = 0;
|
||||
String part = null;
|
||||
String part;
|
||||
|
||||
// if there are occurences of "from"
|
||||
if (splitted.length > 1) {
|
||||
|
@ -272,7 +270,7 @@ public class Words {
|
|||
boolean isBefore = !match;
|
||||
if (pre != null) {
|
||||
for (String pr : pre) {
|
||||
if (match == true) {
|
||||
if (match) {
|
||||
// if one is correct, it is enough
|
||||
if (part.endsWith(pr) == match) {
|
||||
isBefore = true;
|
||||
|
|
96
src/com/dre/brewery/integration/LWCBarrel.java
Normal file
96
src/com/dre/brewery/integration/LWCBarrel.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
31
src/com/dre/brewery/integration/WGBarrel.java
Normal file
31
src/com/dre/brewery/integration/WGBarrel.java
Normal file
|
@ -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;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
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.BlockBreakEvent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import com.dre.brewery.BCauldron;
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.BPlayer;
|
||||
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) {
|
||||
if (Words.doSigns) {
|
||||
if (BPlayer.players.containsKey(event.getPlayer().getName())) {
|
||||
|
@ -36,28 +36,30 @@ public class BlockListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Block block = event.getBlock();
|
||||
// remove cauldron
|
||||
if (block.getType() == Material.CAULDRON) {
|
||||
if (block.getData() != 0) {
|
||||
// will only remove when existing
|
||||
BCauldron.remove(block);
|
||||
if (!P.p.blockDestroy(event.getBlock(), event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPistonRetract(BlockPistonRetractEvent event) {
|
||||
if (event.isSticky()) {
|
||||
Block block = event.getRetractLocation().getBlock();
|
||||
|
||||
if (Barrel.get(block) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
// 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) {
|
||||
Barrel barrel = Barrel.get(block);
|
||||
if (barrel != null) {
|
||||
if (!barrel.isLarge()) {
|
||||
barrel.remove(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
import java.util.ListIterator;
|
||||
|
||||
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.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ItemDespawnEvent;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.Brew;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.integration.LWCBarrel;
|
||||
|
||||
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;
|
||||
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
@ -87,9 +86,7 @@ public class InventoryListener implements Listener {
|
|||
// block the pickup of items where getPickupDelay is > 1000 (puke)
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInventoryPickupItem(InventoryPickupItemEvent event){
|
||||
Item item = event.getItem();
|
||||
|
||||
if (item.getPickupDelay() > 1000) {
|
||||
if (event.getItem().getPickupDelay() > 1000) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.bukkit.Material;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.dre.brewery.BCauldron;
|
||||
import com.dre.brewery.BIngredients;
|
||||
|
@ -27,12 +26,12 @@ import com.dre.brewery.BPlayer;
|
|||
import com.dre.brewery.Words;
|
||||
import com.dre.brewery.Wakeup;
|
||||
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 static boolean openEverywhere;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Block clickedBlock = event.getClickedBlock();
|
||||
|
@ -41,9 +40,10 @@ public class PlayerListener implements Listener {
|
|||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Player player = event.getPlayer();
|
||||
if (!player.isSneaking()) {
|
||||
if (clickedBlock.getType() == Material.CAULDRON) {
|
||||
if (clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.FIRE || clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA
|
||||
|| clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
|
||||
Material type = clickedBlock.getType();
|
||||
if (type == Material.CAULDRON) {
|
||||
Block down = clickedBlock.getRelative(BlockFace.DOWN);
|
||||
if (down.getType() == Material.FIRE || down.getType() == Material.STATIONARY_LAVA || down.getType() == Material.LAVA) {
|
||||
Material materialInHand = event.getMaterial();
|
||||
ItemStack item = event.getItem();
|
||||
|
||||
|
@ -90,38 +90,37 @@ public class PlayerListener implements Listener {
|
|||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
Block broken = Barrel.getBrokenBlock(clickedBlock);
|
||||
// barrel is built correctly
|
||||
if (broken == null) {
|
||||
barrel.open(player);
|
||||
} else {
|
||||
barrel.remove(broken);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (type == Material.FENCE || type == Material.NETHER_FENCE || type == Material.SIGN || type == Material.WALL_SIGN) {
|
||||
barrel = Barrel.getBySpigot(clickedBlock);
|
||||
}
|
||||
|
||||
if (barrel != null) {
|
||||
event.setCancelled(true);
|
||||
|
||||
if (!barrel.hasPermsOpen(player, event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
barrel.open(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user