From d1e73f9d2a2bf92a7a4e38d9626c8b8af6ea8dab Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 24 Sep 2023 16:24:21 +0200 Subject: [PATCH] Fix IngameListener.onPlayerInteract --- .../towerrun/listener/IngameListener.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/de/steamwar/towerrun/listener/IngameListener.java b/src/de/steamwar/towerrun/listener/IngameListener.java index fed8446..84a2ee4 100644 --- a/src/de/steamwar/towerrun/listener/IngameListener.java +++ b/src/de/steamwar/towerrun/listener/IngameListener.java @@ -33,7 +33,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPhysicsEvent; -import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.ItemSpawnEvent; @@ -136,16 +135,14 @@ public class IngameListener extends GameStateBukkitListener { } @EventHandler - public void onBlockPlace(BlockPlaceEvent event) { - if (event.getBlockPlaced().getType() == Material.LEVER) { - event.setCancelled(true); - if (event.getBlockAgainst().getType() == Material.IRON_DOOR) { - event.setCancelled(false); - event.getBlockPlaced().breakNaturally(); - event.getBlockAgainst().breakNaturally(); - event.getItemInHand().setType(Material.AIR); - } - } + public void onPlayerInteract(PlayerInteractEvent event) { + if (!event.hasItem()) return; + if (event.getItem().getType() != Material.LEVER) return; + event.setCancelled(true); + if (!event.hasBlock()) return; + if (event.getClickedBlock().getType() != Material.IRON_DOOR) return; + event.getPlayer().getInventory().setItemInMainHand(null); + event.getClickedBlock().breakNaturally(); } @EventHandler