From 0e9d0d36c9cc96379b6e77d6254a2603ecc577dc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 19 May 2022 16:38:10 +0200 Subject: [PATCH] Fix SmartPlace Signed-off-by: yoyosource --- .../smartplace/SmartPlaceListener.java | 19 ++++++++-------- .../behaviour/BlockPlaceBehaviour.java | 2 +- .../behaviour/BlockRotatingBehaviour.java | 22 +++++++------------ 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index b63abbb0..0a4bd246 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -46,24 +46,23 @@ public class SmartPlaceListener implements Listener { @EventHandler public void onBlockPlace(BlockPlaceEvent event) { - if (event.getPlayer().isSneaking() && Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) { - SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED; - for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) { - if (smartPlaceBehaviour.getType() == SmartPlaceBehaviour.SmartPlaceType.PLACE) { - smartPlaceBehaviour.place(event); - } - if (smartPlaceResult == SmartPlaceBehaviour.SmartPlaceResult.APPLIED) { - break; - } + if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return; + SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED; + for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) { + if (smartPlaceBehaviour.getType() == SmartPlaceBehaviour.SmartPlaceType.PLACE) { + smartPlaceResult = smartPlaceBehaviour.place(event); + } + if (smartPlaceResult == SmartPlaceBehaviour.SmartPlaceResult.APPLIED) { + break; } } } @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return; - if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return; for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) { SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockPlaceBehaviour.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockPlaceBehaviour.java index 5474561c..68830598 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockPlaceBehaviour.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockPlaceBehaviour.java @@ -39,7 +39,7 @@ public class BlockPlaceBehaviour implements SmartPlaceBehaviour { @Override public SmartPlaceResult place(BlockPlaceEvent event) { - if (event.getBlockAgainst().getType().isInteractable()) { + if (!event.getPlayer().isSneaking()) { return SmartPlaceResult.IGNORED; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockRotatingBehaviour.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockRotatingBehaviour.java index 29071148..e0b3dbbc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockRotatingBehaviour.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockRotatingBehaviour.java @@ -43,26 +43,20 @@ public class BlockRotatingBehaviour implements SmartPlaceBehaviour { @Override public SmartPlaceResult interact(PlayerInteractEvent event) { - if (event.getClickedBlock().getType() == event.getMaterial() || event.getMaterial() == Material.HOPPER) { - if (!(event.getClickedBlock().getState() instanceof InventoryHolder)) { - return SmartPlaceResult.IGNORED; - } - } else { - BlockData blockData = event.getMaterial().createBlockData(); - if (blockData instanceof Directional) { - return SmartPlaceResult.IGNORED; - } - if (blockData instanceof Rotatable) { - return SmartPlaceResult.IGNORED; - } + if (!(event.getClickedBlock().getState() instanceof InventoryHolder)) { + return SmartPlaceResult.IGNORED; + } + + BlockData blockData = event.getMaterial().createBlockData(); + if (!(blockData instanceof Directional) && !(blockData instanceof Rotatable)) { + return SmartPlaceResult.IGNORED; } - // TODO: Fix block setting event.setUseInteractedBlock(Event.Result.DENY); World world = event.getPlayer().getWorld(); Block block = world.getBlockAt(event.getClickedBlock().getX() + event.getBlockFace().getModX(), event.getClickedBlock().getY() + event.getBlockFace().getModY(), event.getClickedBlock().getZ() + event.getBlockFace().getModZ()); block.setType(event.getMaterial()); - BlockData blockData = event.getItem().getType().createBlockData(); + blockData = event.getItem().getType().createBlockData(); BlockFace blockFace = event.getBlockFace(); if (block.getType() == Material.HOPPER || block.getType() == Material.OBSERVER) { blockFace = blockFace.getOppositeFace();