From 3da19a7ff041f3bc70f6250d51b4c1dfe090e9a5 Mon Sep 17 00:00:00 2001 From: JOO200 Date: Thu, 30 Jul 2020 19:22:17 +0200 Subject: [PATCH] Added world option to block turtle egg trampling --- .../worldguard/bukkit/BukkitWorldConfiguration.java | 3 +++ .../bukkit/listener/WorldGuardEntityListener.java | 12 +++++++----- .../bukkit/listener/WorldGuardPlayerListener.java | 8 ++++++-- .../sk89q/worldguard/config/WorldConfiguration.java | 2 ++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java index be9df07c..1a65e556 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java @@ -240,6 +240,9 @@ public void loadConfiguration() { disableCreatureCropTrampling = getBoolean("crops.disable-creature-trampling", false); disablePlayerCropTrampling = getBoolean("crops.disable-player-trampling", false); + disableCreatureTurtleEggTrampling = getBoolean("turtle-egg.disable-crature-trampling", false); + disablePlayerTurtleEggTrampling = getBoolean("turtle-egg.disable-player-trampling", false); + disallowedLightningBlocks = new HashSet<>(convertLegacyBlocks(getStringList("weather.prevent-lightning-strike-blocks", null))); preventLightningFire = getBoolean("weather.disable-lightning-strike-fire", false); disableThunder = getBoolean("weather.disable-thunderstorm", false); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java index 412124a0..75e4187d 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java @@ -121,11 +121,13 @@ public void onEntityInteract(EntityInteractEvent event) { ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld())); - if (block.getType() == Material.FARMLAND) { - if (/* entity instanceof Creature && // catch for any entity (not thrown for players) */ - wcfg.disableCreatureCropTrampling) { - event.setCancelled(true); - } + if (block.getType() == Material.FARMLAND && wcfg.disableCreatureCropTrampling) { + event.setCancelled(true); + return; + } + if (block.getType() == Material.TURTLE_EGG && wcfg.disableCreatureTurtleEggTrampling) { + event.setCancelled(true); + return; } } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java index baa2a9ec..3c3aa2d9 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java @@ -314,13 +314,17 @@ private void handlePhysicalInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); Block block = event.getClickedBlock(); //not actually clicked but whatever - //int type = block.getTypeId(); + Material type = block.getType(); World world = player.getWorld(); ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(world)); - if (block.getType() == Material.FARMLAND && wcfg.disablePlayerCropTrampling) { + if (type == Material.FARMLAND && wcfg.disablePlayerCropTrampling) { + event.setCancelled(true); + return; + } + if (type == Material.TURTLE_EGG && wcfg.disablePlayerTurtleEggTrampling) { event.setCancelled(true); return; } diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java b/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java index 28f7e72b..8da024dd 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java @@ -135,6 +135,8 @@ public abstract class WorldConfiguration { public boolean removeInfiniteStacks; public boolean disableCreatureCropTrampling; public boolean disablePlayerCropTrampling; + public boolean disableCreatureTurtleEggTrampling; + public boolean disablePlayerTurtleEggTrampling; public boolean preventLightningFire; public Set disallowedLightningBlocks; public boolean disableThunder;