From e7e714f8ee644012c292dda0298af4829ab1120e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Dec 2022 20:00:06 +0100 Subject: [PATCH] Hotfix RedstoneWireAttribute and RepeaterAttribute Signed-off-by: yoyosource --- .../attributescopy/AttributesCopyCommand.java | 3 +++ ...ener.java => AttributesPlaceListener.java} | 26 ++++++++++++------- .../impl/type/RedstoneWireAttribute.java | 5 +--- .../impl/type/RepeaterAttribute.java | 11 +++++--- 4 files changed, 28 insertions(+), 17 deletions(-) rename BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/{AttributesCopyListener.java => AttributesPlaceListener.java} (69%) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyCommand.java index 3355ae62..9e00c6b7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyCommand.java @@ -96,6 +96,9 @@ public class AttributesCopyCommand extends SWCommand { if (itemStack.getType() == Material.DRAGON_HEAD && block.getType() == Material.DRAGON_WALL_HEAD) return true; if (itemStack.getType() == Material.SKELETON_SKULL && block.getType() == Material.SKELETON_WALL_SKULL) return true; if (itemStack.getType() == Material.WITHER_SKELETON_SKULL && block.getType() == Material.WITHER_SKELETON_WALL_SKULL) return true; + if (itemStack.getType() == Material.TORCH && block.getType() == Material.WALL_TORCH) return true; + if (itemStack.getType() == Material.SOUL_TORCH && block.getType() == Material.SOUL_WALL_TORCH) return true; + if (itemStack.getType().name().contains("_BANNER") && block.getType().name().contains("_WALL_BANNER")) return true; return false; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java similarity index 69% rename from BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyListener.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java index 93ecf857..810597d2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java @@ -19,8 +19,11 @@ package de.steamwar.bausystem.features.attributescopy; +import de.steamwar.bausystem.BauSystem; import de.steamwar.linkage.Linked; import de.steamwar.linkage.MinVersion; +import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.event.EventHandler; @@ -37,7 +40,7 @@ import static de.steamwar.bausystem.features.attributescopy.AttributesCopyComman @Linked @MinVersion(18) -public class AttributesCopyListener implements Listener { +public class AttributesPlaceListener implements Listener { @EventHandler public void onBlockPlace(BlockPlaceEvent event) { @@ -49,14 +52,19 @@ public class AttributesCopyListener implements Listener { if (strings == null) return; if (strings.isEmpty()) return; if (!strings.get(0).equals("§eAttributes§8:")) return; - Set attributesToPaste = new HashSet<>(strings); - Block block = event.getBlock(); - BlockData blockData = block.getBlockData(); - for (BlockAttribute blockAttribute : blockAttributeList) { - if (blockAttribute.type().isInstance(blockData)) { - blockAttribute.paste(attributesToPaste, blockData); + Material type = event.getBlock().getType(); + event.setCancelled(true); + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + event.getBlock().setType(type, false); + Set attributesToPaste = new HashSet<>(strings); + Block block = event.getBlock(); + BlockData blockData = block.getBlockData(); + for (BlockAttribute blockAttribute : blockAttributeList) { + if (blockAttribute.type().isInstance(blockData)) { + blockAttribute.paste(attributesToPaste, blockData); + } } - } - block.setBlockData(blockData, false); + block.setBlockData(blockData, false); + }, 1); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RedstoneWireAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RedstoneWireAttribute.java index 63463c9b..a3049f2b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RedstoneWireAttribute.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RedstoneWireAttribute.java @@ -40,10 +40,7 @@ public class RedstoneWireAttribute implements BlockAttribute { @Override public void copy(List attributes, RedstoneWire blockData) { for (BlockFace blockFace : blockData.getAllowedFaces()) { - RedstoneWire.Connection connection = blockData.getFace(blockFace); - if (connection != RedstoneWire.Connection.NONE) { - attributes.add(attribute + blockFace.name().toLowerCase() + " " + connection.name().toLowerCase()); - } + attributes.add(attribute + blockFace.name().toLowerCase() + " " + blockData.getFace(blockFace).name().toLowerCase()); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RepeaterAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RepeaterAttribute.java index b7639b96..1f25d655 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RepeaterAttribute.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RepeaterAttribute.java @@ -29,7 +29,8 @@ import java.util.Set; @Linked public class RepeaterAttribute implements BlockAttribute { - private String attribute = "§8-§7 delay "; + private String attribute1 = "§8-§7 delay "; + private String attribute2 = "§8-§7 locked"; @Override public Class type() { @@ -38,16 +39,18 @@ public class RepeaterAttribute implements BlockAttribute { @Override public void copy(List attributes, Repeater blockData) { - attributes.add(attribute + blockData.getDelay()); + attributes.add(attribute1 + blockData.getDelay()); + if (blockData.isLocked()) attributes.add(attribute2); } @Override public void paste(Set attributes, Repeater blockData) { attributes.stream() - .filter(s -> s.startsWith(attribute)) - .map(s -> s.replace(attribute, "")) + .filter(s -> s.startsWith(attribute1)) + .map(s -> s.replace(attribute1, "")) .map(Integer::parseInt) .findFirst() .ifPresent(blockData::setDelay); + blockData.setLocked(attributes.contains(attribute2)); } }