Skip to content

Commit

Permalink
Makes podzol yield podzol when broken if coarse dirt tilling is denied
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Mar 21, 2019
1 parent 68a52c7 commit 99e9ad6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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));
}
}
}
6 changes: 3 additions & 3 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 99e9ad6

Please sign in to comment.