From f94ed415a400b5959b25f07532b17e81efa81541 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 14 Oct 2023 13:47:59 +0200 Subject: [PATCH] Fix AutoDustCommand --- .../features/autodust/AutoDustCommand.java | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autodust/AutoDustCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autodust/AutoDustCommand.java index 5849a7e4..2df01e9a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/autodust/AutoDustCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autodust/AutoDustCommand.java @@ -22,11 +22,12 @@ package de.steamwar.bausystem.features.autodust; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.configplayer.Config; +import de.steamwar.bausystem.region.Color; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -38,7 +39,7 @@ import java.util.regex.Pattern; public class AutoDustCommand extends SWCommand implements Listener { private static final Pattern COLORED_BLOCK_REGEX = Pattern.compile( - "^minecraft:(\\w+?)_(wool|stained_glass|concrete_powder|concrete|glazed_terracotta|terracotta)$" + "^(\\w+?)_(wool|stained_glass|concrete_powder|concrete|glazed_terracotta|terracotta)$" ); @@ -46,7 +47,7 @@ public class AutoDustCommand extends SWCommand implements Listener { super("autodust", "dust"); } - @Register() + @Register public void genericCommand(Player p) { boolean autoDust = Config.getInstance().get(p).getPlainValueOrDefault("autodust", false); Config.getInstance().get(p).put("autodust", !autoDust); @@ -62,17 +63,31 @@ public class AutoDustCommand extends SWCommand implements Listener { @EventHandler public void onPlayerInteract(BlockPlaceEvent event) { - final Player p = event.getPlayer(); + Player p = event.getPlayer(); if(!Config.getInstance().get(p).getPlainValueOrDefault("autodust", false)) return; - Block placedOn = event.getBlockPlaced(); - Location dustLocation = placedOn.getLocation().add(0,1,0); - Material materialOnDustLocation = dustLocation.getBlock().getType(); + Block placed = event.getBlockPlaced(); + if (!placed.getType().isBlock() || !placed.getType().isSolid()) { + return; + } + String type = placed.getType().name(); + boolean isColored = false; + for (Color color : Color.values()) { + if (type.startsWith(color.name() + "_")) { + isColored = true; + break; + } + } + if (!isColored) { + return; + } - if(materialOnDustLocation.equals(Material.AIR) || - COLORED_BLOCK_REGEX.matcher(placedOn.getTranslationKey()).matches()) return; + Block above = placed.getRelative(BlockFace.UP); + if (!above.isEmpty()) { + return; + } - p.getWorld().setBlockData(dustLocation,Material.REDSTONE_WIRE.createBlockData()); + above.setType(Material.REDSTONE_WIRE); } }