SteamWar/BauSystem2.0
Archiviert
12
0

Fix AutoDustCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2023-10-14 13:47:59 +02:00
Ursprung bbe7edc55a
Commit f94ed415a4

Datei anzeigen

@ -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);
}
}