Dieser Commit ist enthalten in:
Ursprung
bbe7edc55a
Commit
f94ed415a4
@ -22,11 +22,12 @@ package de.steamwar.bausystem.features.autodust;
|
|||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.SWUtils;
|
import de.steamwar.bausystem.SWUtils;
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
import de.steamwar.bausystem.configplayer.Config;
|
||||||
|
import de.steamwar.bausystem.region.Color;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -38,7 +39,7 @@ import java.util.regex.Pattern;
|
|||||||
public class AutoDustCommand extends SWCommand implements Listener {
|
public class AutoDustCommand extends SWCommand implements Listener {
|
||||||
|
|
||||||
private static final Pattern COLORED_BLOCK_REGEX = Pattern.compile(
|
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");
|
super("autodust", "dust");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register()
|
@Register
|
||||||
public void genericCommand(Player p) {
|
public void genericCommand(Player p) {
|
||||||
boolean autoDust = Config.getInstance().get(p).getPlainValueOrDefault("autodust", false);
|
boolean autoDust = Config.getInstance().get(p).getPlainValueOrDefault("autodust", false);
|
||||||
Config.getInstance().get(p).put("autodust", !autoDust);
|
Config.getInstance().get(p).put("autodust", !autoDust);
|
||||||
@ -62,17 +63,31 @@ public class AutoDustCommand extends SWCommand implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(BlockPlaceEvent event) {
|
public void onPlayerInteract(BlockPlaceEvent event) {
|
||||||
final Player p = event.getPlayer();
|
Player p = event.getPlayer();
|
||||||
|
|
||||||
if(!Config.getInstance().get(p).getPlainValueOrDefault("autodust", false)) return;
|
if(!Config.getInstance().get(p).getPlainValueOrDefault("autodust", false)) return;
|
||||||
|
|
||||||
Block placedOn = event.getBlockPlaced();
|
Block placed = event.getBlockPlaced();
|
||||||
Location dustLocation = placedOn.getLocation().add(0,1,0);
|
if (!placed.getType().isBlock() || !placed.getType().isSolid()) {
|
||||||
Material materialOnDustLocation = dustLocation.getBlock().getType();
|
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) ||
|
Block above = placed.getRelative(BlockFace.UP);
|
||||||
COLORED_BLOCK_REGEX.matcher(placedOn.getTranslationKey()).matches()) return;
|
if (!above.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
p.getWorld().setBlockData(dustLocation,Material.REDSTONE_WIRE.createBlockData());
|
above.setType(Material.REDSTONE_WIRE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren