mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-02-14 00:51:21 +01:00
Refractor Barrel
This commit is contained in:
parent
7c0dcefb1b
commit
7d177a3d9f
@ -186,7 +186,7 @@ public class BUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
barrel2.destroySign();
|
barrel2.getBody().destroySign();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -5,10 +5,9 @@ import com.dre.brewery.api.events.barrel.BarrelCreateEvent;
|
|||||||
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
import com.dre.brewery.api.events.barrel.BarrelDestroyEvent;
|
||||||
import com.dre.brewery.api.events.barrel.BarrelRemoveEvent;
|
import com.dre.brewery.api.events.barrel.BarrelRemoveEvent;
|
||||||
import com.dre.brewery.filedata.BConfig;
|
import com.dre.brewery.filedata.BConfig;
|
||||||
import com.dre.brewery.integration.LWCBarrel;
|
|
||||||
import com.dre.brewery.integration.LogBlockBarrel;
|
import com.dre.brewery.integration.LogBlockBarrel;
|
||||||
import com.dre.brewery.lore.BrewLore;
|
import com.dre.brewery.lore.BrewLore;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.SoundCategory;
|
import org.bukkit.SoundCategory;
|
||||||
@ -21,7 +20,6 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -34,23 +32,20 @@ public class Barrel implements InventoryHolder {
|
|||||||
public static CopyOnWriteArrayList<Barrel> barrels = new CopyOnWriteArrayList<>(); // TODO find best collection
|
public static CopyOnWriteArrayList<Barrel> barrels = new CopyOnWriteArrayList<>(); // TODO find best collection
|
||||||
private static int check = 0;
|
private static int check = 0;
|
||||||
|
|
||||||
private Block spigot;
|
private final Block spigot;
|
||||||
private int[] woodsloc = null; // location of wood Blocks
|
private final BarrelBody body; // The Blocks that make up a Barrel in the World
|
||||||
private int[] stairsloc = null; // location of stair Blocks
|
private boolean checked; // Checked by the random BarrelCheck routine
|
||||||
private byte signoffset;
|
|
||||||
private boolean checked;
|
|
||||||
private Inventory inventory;
|
private Inventory inventory;
|
||||||
private float time;
|
private float time;
|
||||||
|
|
||||||
public Barrel(Block spigot, byte signoffset) {
|
public Barrel(Block spigot, byte signoffset) {
|
||||||
this.spigot = spigot;
|
this.spigot = spigot;
|
||||||
this.signoffset = signoffset;
|
body = new BarrelBody(this, signoffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// load from file
|
// load from file
|
||||||
public Barrel(Block spigot, byte sign, String[] st, String[] wo, 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 = P.p.getServer().createInventory(this, 27, P.p.languageReader.get("Etc_Barrel"));
|
this.inventory = P.p.getServer().createInventory(this, 27, P.p.languageReader.get("Etc_Barrel"));
|
||||||
} else {
|
} else {
|
||||||
@ -65,34 +60,7 @@ public class Barrel implements InventoryHolder {
|
|||||||
}
|
}
|
||||||
this.time = time;
|
this.time = time;
|
||||||
|
|
||||||
int i = 0;
|
body = new BarrelBody(this, sign, st, wo);
|
||||||
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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (woodsloc == null && stairsloc == null) {
|
|
||||||
// If loading from old data, or block locations are missing, regenerate them
|
|
||||||
// This will only be done in those extreme cases.
|
|
||||||
Block broken = getBrokenBlock(true);
|
|
||||||
if (broken != null) {
|
|
||||||
remove(broken, null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
barrels.add(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onUpdate() {
|
public static void onUpdate() {
|
||||||
@ -158,7 +126,7 @@ public class Barrel implements InventoryHolder {
|
|||||||
if (inventory.getViewers().isEmpty()) {
|
if (inventory.getViewers().isEmpty()) {
|
||||||
// if inventory contains potions
|
// if inventory contains potions
|
||||||
if (inventory.contains(Material.POTION)) {
|
if (inventory.contains(Material.POTION)) {
|
||||||
byte wood = getWood();
|
byte wood = body.getWood();
|
||||||
long loadTime = System.nanoTime();
|
long loadTime = System.nanoTime();
|
||||||
for (ItemStack item : inventory.getContents()) {
|
for (ItemStack item : inventory.getContents()) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
@ -192,22 +160,24 @@ public class Barrel implements InventoryHolder {
|
|||||||
|
|
||||||
public void playOpeningSound() {
|
public void playOpeningSound() {
|
||||||
float randPitch = (float) (Math.random() * 0.1);
|
float randPitch = (float) (Math.random() * 0.1);
|
||||||
|
Location location = getSpigot().getLocation();
|
||||||
if (isLarge()) {
|
if (isLarge()) {
|
||||||
getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.4f, 0.55f + randPitch);
|
location.getWorld().playSound(location, Sound.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.4f, 0.55f + randPitch);
|
||||||
//getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 0.5f, 0.6f + randPitch);
|
//getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 0.5f, 0.6f + randPitch);
|
||||||
getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.BLOCK_BREWING_STAND_BREW, SoundCategory.BLOCKS, 0.4f, 0.45f + randPitch);
|
location.getWorld().playSound(location, Sound.BLOCK_BREWING_STAND_BREW, SoundCategory.BLOCKS, 0.4f, 0.45f + randPitch);
|
||||||
} else {
|
} else {
|
||||||
getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.BLOCK_BARREL_OPEN, SoundCategory.BLOCKS, 0.5f, 0.8f + randPitch);
|
location.getWorld().playSound(location, Sound.BLOCK_BARREL_OPEN, SoundCategory.BLOCKS, 0.5f, 0.8f + randPitch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playClosingSound() {
|
public void playClosingSound() {
|
||||||
float randPitch = (float) (Math.random() * 0.1);
|
float randPitch = (float) (Math.random() * 0.1);
|
||||||
|
Location location = getSpigot().getLocation();
|
||||||
if (isLarge()) {
|
if (isLarge()) {
|
||||||
getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.BLOCK_BARREL_CLOSE, SoundCategory.BLOCKS, 0.5f, 0.5f + randPitch);
|
location.getWorld().playSound(location, Sound.BLOCK_BARREL_CLOSE, SoundCategory.BLOCKS, 0.5f, 0.5f + randPitch);
|
||||||
getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 0.2f, 0.6f + randPitch);
|
location.getWorld().playSound(location, Sound.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 0.2f, 0.6f + randPitch);
|
||||||
} else {
|
} else {
|
||||||
getSpigot().getWorld().playSound(getSpigot().getLocation(), Sound.BLOCK_BARREL_CLOSE, SoundCategory.BLOCKS, 0.5f, 0.8f + randPitch);
|
location.getWorld().playSound(location, Sound.BLOCK_BARREL_CLOSE, SoundCategory.BLOCKS, 0.5f, 0.8f + randPitch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,70 +190,25 @@ public class Barrel implements InventoryHolder {
|
|||||||
return spigot;
|
return spigot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BarrelBody getBody() {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
public float getTime() {
|
public float getTime() {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if this Block is part of this Barrel
|
// Returns true if this Block is part of this Barrel
|
||||||
public boolean hasBlock(Block block) {
|
public boolean hasBlock(Block block) {
|
||||||
if (block != null) {
|
return body.hasBlock(block);
|
||||||
if (LegacyUtil.isWoodPlanks(block.getType())) {
|
|
||||||
return hasWoodBlock(block);
|
|
||||||
} else if (LegacyUtil.isWoodStairs(block.getType())) {
|
|
||||||
return hasStairsBlock(block);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasWoodBlock(Block block) {
|
public boolean hasWoodBlock(Block block) {
|
||||||
if (woodsloc != null) {
|
return body.hasWoodBlock(block);
|
||||||
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) {
|
public boolean hasStairsBlock(Block block) {
|
||||||
if (stairsloc != null) {
|
return body.hasStairsBlock(block);
|
||||||
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
|
// Get the Barrel by Block, null if that block is not part of a barrel
|
||||||
@ -303,7 +228,7 @@ public class Barrel implements InventoryHolder {
|
|||||||
// Get the Barrel by Sign or Spigot (Fastest)
|
// Get the Barrel by Sign or Spigot (Fastest)
|
||||||
public static Barrel getBySpigot(Block sign) {
|
public static Barrel getBySpigot(Block sign) {
|
||||||
// convert spigot if neccessary
|
// convert spigot if neccessary
|
||||||
Block spigot = getSpigotOfSign(sign);
|
Block spigot = BarrelBody.getSpigotOfSign(sign);
|
||||||
|
|
||||||
byte signoffset = 0;
|
byte signoffset = 0;
|
||||||
if (!spigot.equals(sign)) {
|
if (!spigot.equals(sign)) {
|
||||||
@ -311,11 +236,11 @@ public class Barrel implements InventoryHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Barrel barrel : barrels) {
|
for (Barrel barrel : barrels) {
|
||||||
if (barrel.isSignOfBarrel(signoffset)) {
|
if (barrel.body.isSignOfBarrel(signoffset)) {
|
||||||
if (barrel.spigot.equals(spigot)) {
|
if (barrel.body.equals(spigot)) {
|
||||||
if (barrel.signoffset == 0 && signoffset != 0) {
|
if (barrel.body.getSignoffset() == 0 && signoffset != 0) {
|
||||||
// Barrel has no signOffset even though we clicked a sign, may be old
|
// Barrel has no signOffset even though we clicked a sign, may be old
|
||||||
barrel.signoffset = signoffset;
|
barrel.body.setSignoffset(signoffset);
|
||||||
}
|
}
|
||||||
return barrel;
|
return barrel;
|
||||||
}
|
}
|
||||||
@ -328,13 +253,13 @@ public class Barrel implements InventoryHolder {
|
|||||||
public static Barrel getByWood(Block wood) {
|
public static Barrel getByWood(Block wood) {
|
||||||
if (LegacyUtil.isWoodPlanks(wood.getType())) {
|
if (LegacyUtil.isWoodPlanks(wood.getType())) {
|
||||||
for (Barrel barrel : barrels) {
|
for (Barrel barrel : barrels) {
|
||||||
if (barrel.hasWoodBlock(wood)) {
|
if (barrel.body.hasWoodBlock(wood)) {
|
||||||
return barrel;
|
return barrel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (LegacyUtil.isWoodStairs(wood.getType())) {
|
} else if (LegacyUtil.isWoodStairs(wood.getType())) {
|
||||||
for (Barrel barrel : Barrel.barrels) {
|
for (Barrel barrel : Barrel.barrels) {
|
||||||
if (barrel.hasStairsBlock(wood)) {
|
if (barrel.body.hasStairsBlock(wood)) {
|
||||||
return barrel;
|
return barrel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -344,7 +269,7 @@ public class Barrel implements InventoryHolder {
|
|||||||
|
|
||||||
// creates a new Barrel out of a sign
|
// creates a new Barrel out of a sign
|
||||||
public static boolean create(Block sign, Player player) {
|
public static boolean create(Block sign, Player player) {
|
||||||
Block spigot = getSpigotOfSign(sign);
|
Block spigot = BarrelBody.getSpigotOfSign(sign);
|
||||||
|
|
||||||
byte signoffset = 0;
|
byte signoffset = 0;
|
||||||
if (!spigot.equals(sign)) {
|
if (!spigot.equals(sign)) {
|
||||||
@ -354,7 +279,7 @@ public class Barrel implements InventoryHolder {
|
|||||||
Barrel barrel = getBySpigot(spigot);
|
Barrel barrel = getBySpigot(spigot);
|
||||||
if (barrel == null) {
|
if (barrel == null) {
|
||||||
barrel = new Barrel(spigot, signoffset);
|
barrel = new Barrel(spigot, signoffset);
|
||||||
if (barrel.getBrokenBlock(true) == null) {
|
if (barrel.body.getBrokenBlock(true) == null) {
|
||||||
if (LegacyUtil.isSign(spigot.getType())) {
|
if (LegacyUtil.isSign(spigot.getType())) {
|
||||||
if (!player.hasPermission("brewery.createbarrel.small")) {
|
if (!player.hasPermission("brewery.createbarrel.small")) {
|
||||||
P.p.msg(player, P.p.languageReader.get("Perms_NoSmallBarrelCreate"));
|
P.p.msg(player, P.p.languageReader.get("Perms_NoSmallBarrelCreate"));
|
||||||
@ -374,8 +299,8 @@ public class Barrel implements InventoryHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (barrel.signoffset == 0 && signoffset != 0) {
|
if (barrel.body.getSignoffset() == 0 && signoffset != 0) {
|
||||||
barrel.signoffset = signoffset;
|
barrel.body.setSignoffset(signoffset);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -411,7 +336,7 @@ public class Barrel implements InventoryHolder {
|
|||||||
Brew brew = Brew.get(item);
|
Brew brew = Brew.get(item);
|
||||||
if (brew != null) {
|
if (brew != null) {
|
||||||
// Brew before throwing
|
// Brew before throwing
|
||||||
brew.age(item, time, getWood());
|
brew.age(item, time, body.getWood());
|
||||||
PotionMeta meta = (PotionMeta) item.getItemMeta();
|
PotionMeta meta = (PotionMeta) item.getItemMeta();
|
||||||
if (BrewLore.hasColorLore(meta)) {
|
if (BrewLore.hasColorLore(meta)) {
|
||||||
BrewLore lore = new BrewLore(brew, meta);
|
BrewLore lore = new BrewLore(brew, meta);
|
||||||
@ -434,45 +359,6 @@ public class Barrel implements InventoryHolder {
|
|||||||
barrels.remove(this);
|
barrels.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the Sign of a Large Barrel gets destroyed, set signOffset to 0
|
|
||||||
public void destroySign() {
|
|
||||||
signoffset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// direction of the barrel from the spigot
|
|
||||||
public static int getDirection(Block spigot) {
|
|
||||||
int direction = 0;// 1=x+ 2=x- 3=z+ 4=z-
|
|
||||||
Material type = spigot.getRelative(0, 0, 1).getType();
|
|
||||||
if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)) {
|
|
||||||
direction = 3;
|
|
||||||
}
|
|
||||||
type = spigot.getRelative(0, 0, -1).getType();
|
|
||||||
if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)) {
|
|
||||||
if (direction == 0) {
|
|
||||||
direction = 4;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
type = spigot.getRelative(1, 0, 0).getType();
|
|
||||||
if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)) {
|
|
||||||
if (direction == 0) {
|
|
||||||
direction = 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
type = spigot.getRelative(-1, 0, 0).getType();
|
|
||||||
if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)) {
|
|
||||||
if (direction == 0) {
|
|
||||||
direction = 2;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return direction;
|
|
||||||
}
|
|
||||||
|
|
||||||
// is this a Large barrel?
|
// is this a Large barrel?
|
||||||
public boolean isLarge() {
|
public boolean isLarge() {
|
||||||
return !isSmall();
|
return !isSmall();
|
||||||
@ -483,239 +369,21 @@ public class Barrel implements InventoryHolder {
|
|||||||
return !LegacyUtil.isSign(spigot.getType());
|
return !LegacyUtil.isSign(spigot.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
// woodtype of the block the spigot is attached to
|
|
||||||
public byte getWood() {
|
|
||||||
Block wood;
|
|
||||||
switch (getDirection(spigot)) { // 1=x+ 2=x- 3=z+ 4=z-
|
|
||||||
case 0:
|
|
||||||
return 0;
|
|
||||||
case 1:
|
|
||||||
wood = spigot.getRelative(1, 0, 0);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
wood = spigot.getRelative(-1, 0, 0);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
wood = spigot.getRelative(0, 0, 1);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
wood = spigot.getRelative(0, 0, -1);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return LegacyUtil.getWoodType(wood);
|
|
||||||
} catch (NoSuchFieldError | NoClassDefFoundError noSuchFieldError) {
|
|
||||||
// Using older minecraft versions some fields and classes do not exist
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns the Sign of a large barrel, the spigot if there is none
|
// returns the Sign of a large barrel, the spigot if there is none
|
||||||
public Block getSignOfSpigot() {
|
public Block getSignOfSpigot() {
|
||||||
if (signoffset != 0) {
|
return body.getSignOfSpigot();
|
||||||
if (LegacyUtil.isSign(spigot.getType())) {
|
|
||||||
return spigot;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LegacyUtil.isSign(spigot.getRelative(0, signoffset, 0).getType())) {
|
|
||||||
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
|
||||||
public static Block getSpigotOfSign(Block block) {
|
public static Block getSpigotOfSign(Block block) {
|
||||||
|
return BarrelBody.getSpigotOfSign(block);
|
||||||
int y = -2;
|
|
||||||
while (y <= 1) {
|
|
||||||
// Fence and Netherfence
|
|
||||||
Block relative = block.getRelative(0, y, 0);
|
|
||||||
if (LegacyUtil.isFence(relative.getType())) {
|
|
||||||
return (relative);
|
|
||||||
}
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
return block;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns null if Barrel is correctly placed; the block that is missing when not
|
// 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
|
||||||
// flag force to also check if chunk is not loaded
|
// flag force to also check if chunk is not loaded
|
||||||
public Block getBrokenBlock(boolean force) {
|
public Block getBrokenBlock(boolean force) {
|
||||||
if (force || BUtil.isChunkLoaded(spigot)) {
|
return body.getBrokenBlock(force);
|
||||||
spigot = getSpigotOfSign(spigot);
|
|
||||||
if (LegacyUtil.isSign(spigot.getType())) {
|
|
||||||
return checkSBarrel();
|
|
||||||
} else {
|
|
||||||
return checkLBarrel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Block checkSBarrel() {
|
|
||||||
int direction = getDirection(spigot);// 1=x+ 2=x- 3=z+ 4=z-
|
|
||||||
if (direction == 0) {
|
|
||||||
return spigot;
|
|
||||||
}
|
|
||||||
int startX;
|
|
||||||
int startZ;
|
|
||||||
int endX;
|
|
||||||
int endZ;
|
|
||||||
|
|
||||||
ArrayList<Integer> stairs = new ArrayList<>();
|
|
||||||
|
|
||||||
if (direction == 1) {
|
|
||||||
startX = 1;
|
|
||||||
endX = startX + 1;
|
|
||||||
startZ = -1;
|
|
||||||
endZ = 0;
|
|
||||||
} else if (direction == 2) {
|
|
||||||
startX = -2;
|
|
||||||
endX = startX + 1;
|
|
||||||
startZ = 0;
|
|
||||||
endZ = 1;
|
|
||||||
} else if (direction == 3) {
|
|
||||||
startX = 0;
|
|
||||||
endX = 1;
|
|
||||||
startZ = 1;
|
|
||||||
endZ = startZ + 1;
|
|
||||||
} else {
|
|
||||||
startX = -1;
|
|
||||||
endX = 0;
|
|
||||||
startZ = -2;
|
|
||||||
endZ = startZ + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Material type;
|
|
||||||
int x = startX;
|
|
||||||
int y = 0;
|
|
||||||
int z = startZ;
|
|
||||||
while (y <= 1) {
|
|
||||||
while (x <= endX) {
|
|
||||||
while (z <= endZ) {
|
|
||||||
Block block = spigot.getRelative(x, y, z);
|
|
||||||
type = block.getType();
|
|
||||||
|
|
||||||
if (LegacyUtil.isWoodStairs(type)) {
|
|
||||||
if (y == 0) {
|
|
||||||
// stairs have to be upside down
|
|
||||||
if (!LegacyUtil.areStairsInverted(block)) {
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stairs.add(block.getX());
|
|
||||||
stairs.add(block.getY());
|
|
||||||
stairs.add(block.getZ());
|
|
||||||
z++;
|
|
||||||
} else {
|
|
||||||
return spigot.getRelative(x, y, z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
z = startZ;
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
z = startZ;
|
|
||||||
x = startX;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
stairsloc = ArrayUtils.toPrimitive(stairs.toArray(new Integer[0]));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Block checkLBarrel() {
|
|
||||||
int direction = getDirection(spigot);// 1=x+ 2=x- 3=z+ 4=z-
|
|
||||||
if (direction == 0) {
|
|
||||||
return spigot;
|
|
||||||
}
|
|
||||||
int startX;
|
|
||||||
int startZ;
|
|
||||||
int endX;
|
|
||||||
int endZ;
|
|
||||||
|
|
||||||
ArrayList<Integer> stairs = new ArrayList<>();
|
|
||||||
ArrayList<Integer> woods = new ArrayList<>();
|
|
||||||
|
|
||||||
if (direction == 1) {
|
|
||||||
startX = 1;
|
|
||||||
endX = startX + 3;
|
|
||||||
startZ = -1;
|
|
||||||
endZ = 1;
|
|
||||||
} else if (direction == 2) {
|
|
||||||
startX = -4;
|
|
||||||
endX = startX + 3;
|
|
||||||
startZ = -1;
|
|
||||||
endZ = 1;
|
|
||||||
} else if (direction == 3) {
|
|
||||||
startX = -1;
|
|
||||||
endX = 1;
|
|
||||||
startZ = 1;
|
|
||||||
endZ = startZ + 3;
|
|
||||||
} else {
|
|
||||||
startX = -1;
|
|
||||||
endX = 1;
|
|
||||||
startZ = -4;
|
|
||||||
endZ = startZ + 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
Material type;
|
|
||||||
int x = startX;
|
|
||||||
int y = 0;
|
|
||||||
int z = startZ;
|
|
||||||
while (y <= 2) {
|
|
||||||
while (x <= endX) {
|
|
||||||
while (z <= endZ) {
|
|
||||||
Block block = spigot.getRelative(x, y, z);
|
|
||||||
type = block.getType();
|
|
||||||
if (direction == 1 || direction == 2) {
|
|
||||||
if (y == 1 && z == 0) {
|
|
||||||
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 == -1 || z == -4 || z == 1 || z == 4) {
|
|
||||||
woods.add(block.getX());
|
|
||||||
woods.add(block.getY());
|
|
||||||
woods.add(block.getZ());
|
|
||||||
}
|
|
||||||
z++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)) {
|
|
||||||
if (LegacyUtil.isWoodPlanks(type)) {
|
|
||||||
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++;
|
|
||||||
} else {
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
z = startZ;
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
z = startZ;
|
|
||||||
x = startX;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
stairsloc = ArrayUtils.toPrimitive(stairs.toArray(new Integer[0]));
|
|
||||||
woodsloc = ArrayUtils.toPrimitive(woods.toArray(new Integer[0]));
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//unloads barrels that are in a unloading world
|
//unloads barrels that are in a unloading world
|
||||||
@ -731,7 +399,7 @@ public class Barrel implements InventoryHolder {
|
|||||||
public static void save(ConfigurationSection config, ConfigurationSection oldData) {
|
public static void save(ConfigurationSection config, ConfigurationSection oldData) {
|
||||||
BUtil.createWorldSections(config);
|
BUtil.createWorldSections(config);
|
||||||
|
|
||||||
if (barrels.isEmpty()) {
|
if (!barrels.isEmpty()) {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
for (Barrel barrel : barrels) {
|
for (Barrel barrel : barrels) {
|
||||||
|
|
||||||
@ -747,23 +415,8 @@ public class Barrel implements InventoryHolder {
|
|||||||
// 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) {
|
// save the body data into the section as well
|
||||||
config.set(prefix + ".sign", barrel.signoffset);
|
barrel.body.save(config, prefix);
|
||||||
}
|
|
||||||
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;
|
||||||
@ -808,7 +461,7 @@ public class Barrel implements InventoryHolder {
|
|||||||
if (check < barrels.size()) {
|
if (check < barrels.size()) {
|
||||||
Barrel barrel = barrels.get(check);
|
Barrel barrel = barrels.get(check);
|
||||||
if (!barrel.checked) {
|
if (!barrel.checked) {
|
||||||
Block broken = barrel.getBrokenBlock(false);
|
Block broken = barrel.body.getBrokenBlock(false);
|
||||||
if (broken != null) {
|
if (broken != null) {
|
||||||
P.p.debugLog("Barrel at " + broken.getWorld().getName() + "/" + broken.getX() + "/" + broken.getY() + "/" + broken.getZ()
|
P.p.debugLog("Barrel at " + broken.getWorld().getName() + "/" + broken.getX() + "/" + broken.getY() + "/" + broken.getZ()
|
||||||
+ " has been destroyed unexpectedly, contents will drop");
|
+ " has been destroyed unexpectedly, contents will drop");
|
||||||
|
453
src/com/dre/brewery/BarrelBody.java
Normal file
453
src/com/dre/brewery/BarrelBody.java
Normal file
@ -0,0 +1,453 @@
|
|||||||
|
package com.dre.brewery;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
// The Blocks that make up a Barrel in the World
|
||||||
|
public class BarrelBody {
|
||||||
|
|
||||||
|
private final Barrel barrel;
|
||||||
|
private final Block spigot;
|
||||||
|
private int[] woodsloc = null; // location of wood Blocks
|
||||||
|
private int[] stairsloc = null; // location of stair Blocks
|
||||||
|
private byte signoffset;
|
||||||
|
|
||||||
|
public BarrelBody(Barrel barrel, byte signoffset) {
|
||||||
|
this.barrel = barrel;
|
||||||
|
this.signoffset = signoffset;
|
||||||
|
spigot = barrel.getSpigot();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loading from file
|
||||||
|
public BarrelBody(Barrel barrel, byte signoffset, String[] st, String[] wo) {
|
||||||
|
this(barrel, signoffset);
|
||||||
|
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (woodsloc == null && stairsloc == null) {
|
||||||
|
// If loading from old data, or block locations are missing, regenerate them
|
||||||
|
// This will only be done in those extreme cases.
|
||||||
|
Block broken = getBrokenBlock(true);
|
||||||
|
if (broken != null) {
|
||||||
|
barrel.remove(broken, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Barrel getBarrel() {
|
||||||
|
return barrel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block getSpigot() {
|
||||||
|
return spigot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getWoodsloc() {
|
||||||
|
return woodsloc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWoodsloc(int[] woodsloc) {
|
||||||
|
this.woodsloc = woodsloc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getStairsloc() {
|
||||||
|
return stairsloc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStairsloc(int[] stairsloc) {
|
||||||
|
this.stairsloc = stairsloc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getSignoffset() {
|
||||||
|
return signoffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSignoffset(byte signoffset) {
|
||||||
|
this.signoffset = signoffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the Sign of a Large Barrel gets destroyed, set signOffset to 0
|
||||||
|
public void destroySign() {
|
||||||
|
signoffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// direction of the barrel from the spigot
|
||||||
|
public static int getDirection(Block spigot) {
|
||||||
|
int direction = 0;// 1=x+ 2=x- 3=z+ 4=z-
|
||||||
|
Material type = spigot.getRelative(0, 0, 1).getType();
|
||||||
|
if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)) {
|
||||||
|
direction = 3;
|
||||||
|
}
|
||||||
|
type = spigot.getRelative(0, 0, -1).getType();
|
||||||
|
if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)) {
|
||||||
|
if (direction == 0) {
|
||||||
|
direction = 4;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
type = spigot.getRelative(1, 0, 0).getType();
|
||||||
|
if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)) {
|
||||||
|
if (direction == 0) {
|
||||||
|
direction = 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
type = spigot.getRelative(-1, 0, 0).getType();
|
||||||
|
if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)) {
|
||||||
|
if (direction == 0) {
|
||||||
|
direction = 2;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
// is this a Large barrel?
|
||||||
|
public boolean isLarge() {
|
||||||
|
return barrel.isLarge();
|
||||||
|
}
|
||||||
|
|
||||||
|
// is this a Small barrel?
|
||||||
|
public boolean isSmall() {
|
||||||
|
return barrel.isSmall();
|
||||||
|
}
|
||||||
|
|
||||||
|
// woodtype of the block the spigot is attached to
|
||||||
|
public byte getWood() {
|
||||||
|
Block wood;
|
||||||
|
switch (getDirection(spigot)) { // 1=x+ 2=x- 3=z+ 4=z-
|
||||||
|
case 0:
|
||||||
|
return 0;
|
||||||
|
case 1:
|
||||||
|
wood = spigot.getRelative(1, 0, 0);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
wood = spigot.getRelative(-1, 0, 0);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
wood = spigot.getRelative(0, 0, 1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
wood = spigot.getRelative(0, 0, -1);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return LegacyUtil.getWoodType(wood);
|
||||||
|
} catch (NoSuchFieldError | NoClassDefFoundError noSuchFieldError) {
|
||||||
|
// Using older minecraft versions some fields and classes do not exist
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns true if this Block is part of this Barrel
|
||||||
|
public boolean hasBlock(Block block) {
|
||||||
|
if (block != null) {
|
||||||
|
if (LegacyUtil.isWoodPlanks(block.getType())) {
|
||||||
|
return hasWoodBlock(block);
|
||||||
|
} else if (LegacyUtil.isWoodStairs(block.getType())) {
|
||||||
|
return hasStairsBlock(block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the Sign of a large barrel, the spigot if there is none
|
||||||
|
public Block getSignOfSpigot() {
|
||||||
|
if (signoffset != 0) {
|
||||||
|
if (LegacyUtil.isSign(spigot.getType())) {
|
||||||
|
return spigot;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LegacyUtil.isSign(spigot.getRelative(0, signoffset, 0).getType())) {
|
||||||
|
return spigot.getRelative(0, signoffset, 0);
|
||||||
|
} else {
|
||||||
|
signoffset = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return spigot;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the fence above/below a block, itself if there is none
|
||||||
|
public static Block getSpigotOfSign(Block block) {
|
||||||
|
|
||||||
|
int y = -2;
|
||||||
|
while (y <= 1) {
|
||||||
|
// Fence and Netherfence
|
||||||
|
Block relative = block.getRelative(0, y, 0);
|
||||||
|
if (LegacyUtil.isFence(relative.getType())) {
|
||||||
|
return (relative);
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns null if Barrel is correctly placed; the block that is missing when not
|
||||||
|
// the barrel needs to be formed correctly
|
||||||
|
// flag force to also check if chunk is not loaded
|
||||||
|
public Block getBrokenBlock(boolean force) {
|
||||||
|
if (force || BUtil.isChunkLoaded(spigot)) {
|
||||||
|
//spigot = getSpigotOfSign(spigot);
|
||||||
|
if (LegacyUtil.isSign(spigot.getType())) {
|
||||||
|
return checkSBarrel();
|
||||||
|
} else {
|
||||||
|
return checkLBarrel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block checkSBarrel() {
|
||||||
|
int direction = getDirection(spigot);// 1=x+ 2=x- 3=z+ 4=z-
|
||||||
|
if (direction == 0) {
|
||||||
|
return spigot;
|
||||||
|
}
|
||||||
|
int startX;
|
||||||
|
int startZ;
|
||||||
|
int endX;
|
||||||
|
int endZ;
|
||||||
|
|
||||||
|
ArrayList<Integer> stairs = new ArrayList<>();
|
||||||
|
|
||||||
|
if (direction == 1) {
|
||||||
|
startX = 1;
|
||||||
|
endX = startX + 1;
|
||||||
|
startZ = -1;
|
||||||
|
endZ = 0;
|
||||||
|
} else if (direction == 2) {
|
||||||
|
startX = -2;
|
||||||
|
endX = startX + 1;
|
||||||
|
startZ = 0;
|
||||||
|
endZ = 1;
|
||||||
|
} else if (direction == 3) {
|
||||||
|
startX = 0;
|
||||||
|
endX = 1;
|
||||||
|
startZ = 1;
|
||||||
|
endZ = startZ + 1;
|
||||||
|
} else {
|
||||||
|
startX = -1;
|
||||||
|
endX = 0;
|
||||||
|
startZ = -2;
|
||||||
|
endZ = startZ + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material type;
|
||||||
|
int x = startX;
|
||||||
|
int y = 0;
|
||||||
|
int z = startZ;
|
||||||
|
while (y <= 1) {
|
||||||
|
while (x <= endX) {
|
||||||
|
while (z <= endZ) {
|
||||||
|
Block block = spigot.getRelative(x, y, z);
|
||||||
|
type = block.getType();
|
||||||
|
|
||||||
|
if (LegacyUtil.isWoodStairs(type)) {
|
||||||
|
if (y == 0) {
|
||||||
|
// stairs have to be upside down
|
||||||
|
if (!LegacyUtil.areStairsInverted(block)) {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stairs.add(block.getX());
|
||||||
|
stairs.add(block.getY());
|
||||||
|
stairs.add(block.getZ());
|
||||||
|
z++;
|
||||||
|
} else {
|
||||||
|
return spigot.getRelative(x, y, z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
z = startZ;
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
z = startZ;
|
||||||
|
x = startX;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
stairsloc = ArrayUtils.toPrimitive(stairs.toArray(new Integer[0]));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block checkLBarrel() {
|
||||||
|
int direction = getDirection(spigot);// 1=x+ 2=x- 3=z+ 4=z-
|
||||||
|
if (direction == 0) {
|
||||||
|
return spigot;
|
||||||
|
}
|
||||||
|
int startX;
|
||||||
|
int startZ;
|
||||||
|
int endX;
|
||||||
|
int endZ;
|
||||||
|
|
||||||
|
ArrayList<Integer> stairs = new ArrayList<>();
|
||||||
|
ArrayList<Integer> woods = new ArrayList<>();
|
||||||
|
|
||||||
|
if (direction == 1) {
|
||||||
|
startX = 1;
|
||||||
|
endX = startX + 3;
|
||||||
|
startZ = -1;
|
||||||
|
endZ = 1;
|
||||||
|
} else if (direction == 2) {
|
||||||
|
startX = -4;
|
||||||
|
endX = startX + 3;
|
||||||
|
startZ = -1;
|
||||||
|
endZ = 1;
|
||||||
|
} else if (direction == 3) {
|
||||||
|
startX = -1;
|
||||||
|
endX = 1;
|
||||||
|
startZ = 1;
|
||||||
|
endZ = startZ + 3;
|
||||||
|
} else {
|
||||||
|
startX = -1;
|
||||||
|
endX = 1;
|
||||||
|
startZ = -4;
|
||||||
|
endZ = startZ + 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material type;
|
||||||
|
int x = startX;
|
||||||
|
int y = 0;
|
||||||
|
int z = startZ;
|
||||||
|
while (y <= 2) {
|
||||||
|
while (x <= endX) {
|
||||||
|
while (z <= endZ) {
|
||||||
|
Block block = spigot.getRelative(x, y, z);
|
||||||
|
type = block.getType();
|
||||||
|
if (direction == 1 || direction == 2) {
|
||||||
|
if (y == 1 && z == 0) {
|
||||||
|
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 == -1 || z == -4 || z == 1 || z == 4) {
|
||||||
|
woods.add(block.getX());
|
||||||
|
woods.add(block.getY());
|
||||||
|
woods.add(block.getZ());
|
||||||
|
}
|
||||||
|
z++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (LegacyUtil.isWoodPlanks(type) || LegacyUtil.isWoodStairs(type)) {
|
||||||
|
if (LegacyUtil.isWoodPlanks(type)) {
|
||||||
|
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++;
|
||||||
|
} else {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
z = startZ;
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
z = startZ;
|
||||||
|
x = startX;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
stairsloc = ArrayUtils.toPrimitive(stairs.toArray(new Integer[0]));
|
||||||
|
woodsloc = ArrayUtils.toPrimitive(woods.toArray(new Integer[0]));
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(ConfigurationSection config, String prefix) {
|
||||||
|
if (signoffset != 0) {
|
||||||
|
config.set(prefix + ".sign", signoffset);
|
||||||
|
}
|
||||||
|
if (stairsloc != null && stairsloc.length > 0) {
|
||||||
|
StringBuilder st = new StringBuilder();
|
||||||
|
for (int i : stairsloc) {
|
||||||
|
st.append(i).append(",");
|
||||||
|
}
|
||||||
|
config.set(prefix + ".st", st.substring(0, st.length() - 1));
|
||||||
|
}
|
||||||
|
if (woodsloc != null && woodsloc.length > 0) {
|
||||||
|
StringBuilder wo = new StringBuilder();
|
||||||
|
for (int i : woodsloc) {
|
||||||
|
wo.append(i).append(",");
|
||||||
|
}
|
||||||
|
config.set(prefix + ".wo", wo.substring(0, wo.length() - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -211,11 +211,17 @@ public class BData {
|
|||||||
String[] st = section.getString(barrel + ".st", "").split(",");
|
String[] st = section.getString(barrel + ".st", "").split(",");
|
||||||
String[] wo = section.getString(barrel + ".wo", "").split(",");
|
String[] wo = section.getString(barrel + ".wo", "").split(",");
|
||||||
|
|
||||||
|
Barrel b;
|
||||||
if (invSection != null) {
|
if (invSection != null) {
|
||||||
new Barrel(block, sign, st, wo, invSection.getValues(true), time);
|
b = new Barrel(block, sign, st, wo, invSection.getValues(true), time);
|
||||||
} else {
|
} else {
|
||||||
// Barrel has no inventory
|
// Barrel has no inventory
|
||||||
new Barrel(block, sign, st, wo, null, time);
|
b = new Barrel(block, sign, st, wo, null, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case Barrel Block locations were missing and could not be recreated: do not add the barrel
|
||||||
|
if (b.getBody().getStairsloc() != null || b.getBody().getWoodsloc() != null) {
|
||||||
|
Barrel.barrels.add(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -76,7 +76,7 @@ public class IntegrationListener implements Listener {
|
|||||||
|
|
||||||
// If the Clicked Block was the Sign, LWC already knows and we dont need to do anything here
|
// If the Clicked Block was the Sign, LWC already knows and we dont need to do anything here
|
||||||
if (!LegacyUtil.isSign(event.getClickedBlock().getType())) {
|
if (!LegacyUtil.isSign(event.getClickedBlock().getType())) {
|
||||||
Block sign = event.getBarrel().getSignOfSpigot();
|
Block sign = event.getBarrel().getBody().getSignOfSpigot();
|
||||||
// If the Barrel does not have a Sign, it cannot be locked
|
// If the Barrel does not have a Sign, it cannot be locked
|
||||||
if (!sign.equals(event.getClickedBlock())) {
|
if (!sign.equals(event.getClickedBlock())) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
@ -24,7 +24,7 @@ public class LWCBarrel {
|
|||||||
|
|
||||||
public static boolean denyDestroy(Player player, Barrel barrel) {
|
public static boolean denyDestroy(Player player, Barrel barrel) {
|
||||||
LWC lwc = LWC.getInstance();
|
LWC lwc = LWC.getInstance();
|
||||||
Block sign = barrel.getSignOfSpigot();
|
Block sign = barrel.getBody().getSignOfSpigot();
|
||||||
//if (!Boolean.parseBoolean(lwc.resolveProtectionConfiguration(sign, "ignoreBlockDestruction"))) {
|
//if (!Boolean.parseBoolean(lwc.resolveProtectionConfiguration(sign, "ignoreBlockDestruction"))) {
|
||||||
Protection protection = lwc.findProtection(sign);
|
Protection protection = lwc.findProtection(sign);
|
||||||
if (protection != null) {
|
if (protection != null) {
|
||||||
@ -82,7 +82,7 @@ public class LWCBarrel {
|
|||||||
|
|
||||||
// If a Barrel is destroyed without player
|
// If a Barrel is destroyed without player
|
||||||
public static void remove(Barrel barrel) {
|
public static void remove(Barrel barrel) {
|
||||||
Protection protection = LWC.getInstance().findProtection(barrel.getSignOfSpigot());
|
Protection protection = LWC.getInstance().findProtection(barrel.getBody().getSignOfSpigot());
|
||||||
if (protection != null) {
|
if (protection != null) {
|
||||||
protection.remove();
|
protection.remove();
|
||||||
}
|
}
|
||||||
@ -90,13 +90,13 @@ public class LWCBarrel {
|
|||||||
|
|
||||||
// Returns true if the block that exploded should not be removed
|
// Returns true if the block that exploded should not be removed
|
||||||
public static boolean denyExplosion(Barrel barrel) {
|
public static boolean denyExplosion(Barrel barrel) {
|
||||||
Protection protection = LWC.getInstance().findProtection(barrel.getSignOfSpigot());
|
Protection protection = LWC.getInstance().findProtection(barrel.getBody().getSignOfSpigot());
|
||||||
|
|
||||||
return protection != null && !protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS);
|
return protection != null && !protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the block that was destroyed should not be removed
|
// Returns true if the block that was destroyed should not be removed
|
||||||
public static boolean denyDestroyOther(Barrel barrel) {
|
public static boolean denyDestroyOther(Barrel barrel) {
|
||||||
return LWC.getInstance().findProtection(barrel.getSignOfSpigot()) != null;
|
return LWC.getInstance().findProtection(barrel.getBody().getSignOfSpigot()) != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
} else if (LegacyUtil.isWoodStairs(type)) {
|
} else if (LegacyUtil.isWoodStairs(type)) {
|
||||||
for (Barrel barrel2 : Barrel.barrels) {
|
for (Barrel barrel2 : Barrel.barrels) {
|
||||||
if (barrel2.hasStairsBlock(clickedBlock)) {
|
if (barrel2.getBody().hasStairsBlock(clickedBlock)) {
|
||||||
if (BConfig.openEverywhere || !barrel2.isLarge()) {
|
if (BConfig.openEverywhere || !barrel2.isLarge()) {
|
||||||
barrel = barrel2;
|
barrel = barrel2;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user