From 2e9209841a294f2281e79f2a8084557a514cfa15 Mon Sep 17 00:00:00 2001 From: Tristan van den Elzen Date: Sun, 3 Oct 2021 16:27:13 +0200 Subject: [PATCH] Fixed interaction with Brewery cauldrons Cauldrons for making brews in the Brewery plugin can now take ExoticGarden fruits again. Regular cauldrons will not be interactable, preventing fruit placement and bush duplication exploit. When brewery is not installed `isBreweryCauldron()` returns false causing it not to be interactable, as expected. --- pom.xml | 7 ++++ .../exoticgarden/items/ExoticGardenFruit.java | 38 +++++++++++++------ src/main/resources/plugin.yml | 5 ++- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 791b07c8..2294f343 100644 --- a/pom.xml +++ b/pom.xml @@ -135,5 +135,12 @@ 2.2.1 compile + + + com.github.DieReicheErethons + Brewery + 3.1 + provided + diff --git a/src/main/java/io/github/thebusybiscuit/exoticgarden/items/ExoticGardenFruit.java b/src/main/java/io/github/thebusybiscuit/exoticgarden/items/ExoticGardenFruit.java index 07e44d9b..0992788e 100644 --- a/src/main/java/io/github/thebusybiscuit/exoticgarden/items/ExoticGardenFruit.java +++ b/src/main/java/io/github/thebusybiscuit/exoticgarden/items/ExoticGardenFruit.java @@ -5,9 +5,12 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import com.dre.brewery.BCauldron; +import com.dre.brewery.utility.LegacyUtil; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -42,29 +45,30 @@ public boolean useVanillaBlockBreaking() { @Override public ItemUseHandler getItemHandler() { return e -> { - Optional block = e.getClickedBlock(); + Optional optionalBlock = e.getClickedBlock(); - if (block.isPresent()) { - Material material = block.get().getType(); + if (optionalBlock.isPresent()) { + Block block = optionalBlock.get(); // Cancel the Block placement if the Player sneaks or the Block is not interactable - if (e.getPlayer().isSneaking() || !isInteractable(material)) { + if (e.getPlayer().isSneaking() || !isInteractable(block)) { e.cancel(); } else { return; } - } - - if (edible && e.getPlayer().getFoodLevel() < 20) { - restoreHunger(e.getPlayer()); - ItemUtils.consumeItem(e.getItem(), false); + } else { + if (edible && e.getPlayer().getFoodLevel() < 20) { + restoreHunger(e.getPlayer()); + ItemUtils.consumeItem(e.getItem(), false); + } } }; } - private boolean isInteractable(@Nonnull Material material) { + private boolean isInteractable(@Nonnull Block block) { // We cannot rely on Material#isInteractable() sadly // as it would allow the placement of this block on strange items like stairs... + Material material = block.getType(); switch (material) { case ANVIL: case BREWING_STAND: @@ -73,11 +77,21 @@ private boolean isInteractable(@Nonnull Material material) { case HOPPER: case TRAPPED_CHEST: case ENDER_CHEST: - case CAULDRON: case SHULKER_BOX: return true; default: - return material.name().equals("BARREL") || material.name().endsWith("_SHULKER_BOX"); + return material.name().equals("BARREL") || + material.name().endsWith("_SHULKER_BOX") || + isBreweryCauldron(block); + } + } + + private boolean isBreweryCauldron(@Nonnull Block block) { + try { + return LegacyUtil.isWaterCauldron(block.getType()) && + LegacyUtil.isCauldronHeatsource(block.getRelative(BlockFace.DOWN)); + } catch (NoClassDefFoundError e) { + return false; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 44598ce6..4f65d66c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -8,4 +8,7 @@ api-version: '1.13' main: io.github.thebusybiscuit.exoticgarden.ExoticGarden depend: -- Slimefun \ No newline at end of file +- Slimefun + +softdepend: +- Brewery \ No newline at end of file