From ad53ecf8b8fd3b3da90b44c95dbf02948ed549ad Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Mon, 27 Jun 2016 22:15:23 +0200 Subject: [PATCH] Better Woodtype recognition Fixes #126 Wood type not recognized on big barrels in 1.9 --- pom.xml | 2 +- src/com/dre/brewery/Barrel.java | 110 ++++++++++++++++++-------------- src/com/dre/brewery/Brew.java | 2 +- src/com/dre/brewery/P.java | 1 + 4 files changed, 64 insertions(+), 51 deletions(-) diff --git a/pom.xml b/pom.xml index 5be0748..81e8f53 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ org.bukkit bukkit - 1.9.4-R0.1-SNAPSHOT + 1.10.2-R0.1-SNAPSHOT provided diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index 3491cbb..ae73bb1 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -18,6 +18,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.material.MaterialData; import org.bukkit.material.Stairs; import org.bukkit.material.Tree; +import org.bukkit.material.Wood; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; @@ -623,61 +624,72 @@ public class Barrel implements InventoryHolder { // woodtype of the block the spigot is attached to public byte getWood() { - int direction = getDirection(this.spigot);// 1=x+ 2=x- 3=z+ 4=z- Block wood; - if (direction == 0) { - return 0; - } else if (direction == 1) { - wood = this.spigot.getRelative(1, 0, 0); - } else if (direction == 2) { - wood = this.spigot.getRelative(-1, 0, 0); - } else if (direction == 3) { - wood = this.spigot.getRelative(0, 0, 1); - } else { - wood = this.spigot.getRelative(0, 0, -1); - } - if (wood.getType() == Material.WOOD) { - MaterialData data = wood.getState().getData(); - if (data instanceof Tree) { - TreeSpecies woodType = ((Tree) data).getSpecies(); - if (woodType == TreeSpecies.GENERIC){ - return 2; - } else if (woodType == TreeSpecies.REDWOOD) { - return 4; - } else if (woodType == TreeSpecies.BIRCH) { - return 1; - } else if (woodType == TreeSpecies.JUNGLE) { - return 3; - } else if (woodType == TreeSpecies.ACACIA) { - return 5; - } else if (woodType == TreeSpecies.DARK_OAK) { - return 6; - } - } - } - if (wood.getType() == Material.WOOD_STAIRS) { - return 2; - } - if (wood.getType() == Material.SPRUCE_WOOD_STAIRS) { - return 4; - } - if (wood.getType() == Material.BIRCH_WOOD_STAIRS) { - return 1; - } - if (wood.getType() == Material.JUNGLE_WOOD_STAIRS) { - return 3; + 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 { - if (wood.getType() == Material.ACACIA_STAIRS) { - return 5; + switch (wood.getType()) { + case WOOD: + MaterialData data = wood.getState().getData(); + TreeSpecies woodType; + if (data instanceof Tree) { + woodType = ((Tree) data).getSpecies(); + } else if (data instanceof Wood) { + woodType = ((Wood) data).getSpecies(); + } else { + return 0; + } + + switch (woodType) { + case GENERIC: + return 2; + case REDWOOD: + return 4; + case BIRCH: + return 1; + case JUNGLE: + return 3; + case ACACIA: + return 5; + case DARK_OAK: + return 6; + default: + return 0; + } + + case WOOD_STAIRS: + return 2; + case SPRUCE_WOOD_STAIRS: + return 4; + case BIRCH_WOOD_STAIRS: + return 1; + case JUNGLE_WOOD_STAIRS: + return 3; + case ACACIA_STAIRS: + return 5; + case DARK_OAK_STAIRS: + return 6; + default: + return 0; } - if (wood.getType() == Material.DARK_OAK_STAIRS) { - return 6; - } - } catch (NoSuchFieldError e) { + + } catch (NoSuchFieldError | NoClassDefFoundError e) { + // Using older minecraft versions some fields and classes do not exist return 0; } - return 0; } // returns the Sign of a large barrel, the spigot if there is none diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 403c4d1..a90e575 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -681,7 +681,7 @@ public class Brew { BLACK(8, PotionType.WEAKNESS), RED(9, PotionType.STRENGTH), GREY(10, PotionType.SLOWNESS), - WATER(11, PotionType.WATER_BREATHING), + WATER(11, P.use1_9 ? PotionType.WATER_BREATHING : null), DARK_RED(12, PotionType.INSTANT_DAMAGE), BRIGHT_GREY(14, PotionType.INVISIBILITY); diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index eaa69e0..59a959d 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -143,6 +143,7 @@ public class P extends JavaPlugin { Brew.potions.clear(); Wakeup.wakeups.clear(); Words.words.clear(); + Words.ignoreText.clear(); this.log(this.getDescription().getName() + " disabled!"); }