From 99e9ad6ac8dca9cc9eea6a35ac80401fa76b1821 Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 20 Mar 2019 23:38:02 -0700 Subject: [PATCH] Makes podzol yield podzol when broken if coarse dirt tilling is denied https://github.com/BentoBoxWorld/BentoBox/issues/613 --- .../CoarseDirtTillingListener.java | 50 +++++++++++++------ src/main/resources/locales/en-US.yml | 6 +-- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/CoarseDirtTillingListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/CoarseDirtTillingListener.java index e2ecc2ce1..6204eb365 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/CoarseDirtTillingListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/CoarseDirtTillingListener.java @@ -1,10 +1,13 @@ package world.bentobox.bentobox.listeners.flags.worldsettings; +import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; import world.bentobox.bentobox.api.flags.FlagListener; import world.bentobox.bentobox.api.localization.TextVariables; @@ -21,22 +24,39 @@ public void onTillingCoarseDirt(PlayerInteractEvent e) { if (e.getClickedBlock().getType().equals(Material.COARSE_DIRT)) { switch (e.getItem().getType()) { - case WOODEN_HOE: - case STONE_HOE: - case IRON_HOE: - case GOLDEN_HOE: - case DIAMOND_HOE: - if (e.getClickedBlock().getType().equals(Material.COARSE_DIRT) - && getIWM().inWorld(e.getClickedBlock().getWorld()) - && !Flags.COARSE_DIRT_TILLING.isSetForWorld(e.getClickedBlock().getWorld())) { - e.setCancelled(true); - User user = User.getInstance(e.getPlayer()); - user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(Flags.COARSE_DIRT_TILLING.getHintReference())); - } - break; - default: - break; + case WOODEN_HOE: + case STONE_HOE: + case IRON_HOE: + case GOLDEN_HOE: + case DIAMOND_HOE: + if (e.getClickedBlock().getType().equals(Material.COARSE_DIRT) + && getIWM().inWorld(e.getClickedBlock().getWorld()) + && !Flags.COARSE_DIRT_TILLING.isSetForWorld(e.getClickedBlock().getWorld())) { + e.setCancelled(true); + User user = User.getInstance(e.getPlayer()); + user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(Flags.COARSE_DIRT_TILLING.getHintReference())); + } + break; + default: + break; } } } + + /** + * If podzol is mined when coarse dirt tilling is not allowed, then it'll just drop podzol and not dirt + * This prevents an exploit where growing big spruce trees can turn gravel into podzol. + * https://github.com/BentoBoxWorld/BentoBox/issues/613 + * @param e - event + */ + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void onBreakingPodzol(BlockBreakEvent e) { + if (!e.getPlayer().getGameMode().equals(GameMode.CREATIVE) + && e.getBlock().getType().equals(Material.PODZOL) + && getIWM().inWorld(e.getBlock().getWorld()) + && !Flags.COARSE_DIRT_TILLING.isSetForWorld(e.getBlock().getWorld())) { + e.getBlock().setType(Material.AIR); + e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(Material.PODZOL)); + } + } } diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 87044e46e..6a5a4e48d 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -527,9 +527,9 @@ protection: name: "Clean Super Flat" COARSE_DIRT_TILLING: description: |- - &aToggle tilling the - &acoarse dirt to - &aobtain dirt + &aToggle tilling coarse + &adirt and breaking podzol + &ato obtain dirt name: "Coarse dirt tilling" hint: "No coarse dirt tilling" COLLECT_LAVA: