From 54b955c1f53b8cf14efda78e88b7a2108fb3a250 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 5 Aug 2022 20:48:06 +0200 Subject: [PATCH] Update SignEdit Signed-off-by: yoyosource --- .../bausystem/features/world/SignEdit.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEdit.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEdit.java index ea97e452..46567a4f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEdit.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEdit.java @@ -34,6 +34,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; @Linked(LinkageType.LISTENER) @@ -56,15 +57,22 @@ public class SignEdit implements Listener { @EventHandler public void editSign(PlayerInteractEvent event) { - if (event.getAction() != Action.RIGHT_CLICK_BLOCK || - !event.getClickedBlock().getType().name().contains("SIGN") || - !event.getPlayer().isSneaking() || - (event.getItem() != null && event.getItem().getType() != Material.AIR)) - return; + if (!event.getPlayer().isSneaking()) return; + if (!event.getClickedBlock().getType().name().contains("SIGN")) return; - event.setCancelled(true); - Player player = event.getPlayer(); - Sign sign = (org.bukkit.block.Sign) event.getClickedBlock().getState(); + if (event.getAction() == Action.RIGHT_CLICK_BLOCK && (event.getItem() == null || event.getItem().getType() == Material.AIR)) { + event.setCancelled(true); + edit(event.getPlayer(), event.getClickedBlock()); + } else if (event.getAction() == Action.LEFT_CLICK_BLOCK) { + event.setCancelled(true); + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + edit(event.getPlayer(), event.getClickedBlock()); + }, 1); + } + } + + private void edit(Player player, Block block) { + Sign sign = (org.bukkit.block.Sign) block.getState(); String[] lines = sign.getLines(); for (int i = 0; i < lines.length; i++) { sign.setLine(i, lines[i].replace('ยง', '&')); @@ -72,7 +80,7 @@ public class SignEdit implements Listener { sign.update(); Object openSignObject = Reflection.newInstance(openSign); - blockPositionFieldAccessor.set(openSignObject, getPosition.invoke(event.getClickedBlock())); + blockPositionFieldAccessor.set(openSignObject, getPosition.invoke(block)); TinyProtocol.instance.sendPacket(player, openSignObject); }