|
|
|
@ -0,0 +1,93 @@
|
|
|
|
|
/*
|
|
|
|
|
* This file is a part of the SteamWar software.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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.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;
|
|
|
|
|
import org.bukkit.event.block.BlockPlaceEvent;
|
|
|
|
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
@Linked
|
|
|
|
|
public class AutoDustCommand extends SWCommand implements Listener {
|
|
|
|
|
|
|
|
|
|
private static final Pattern COLORED_BLOCK_REGEX = Pattern.compile(
|
|
|
|
|
"^(\\w+?)_(wool|stained_glass|concrete_powder|concrete|glazed_terracotta|terracotta)$"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AutoDustCommand() {
|
|
|
|
|
super("autodust", "dust");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Register
|
|
|
|
|
public void genericCommand(Player p) {
|
|
|
|
|
boolean autoDust = Config.getInstance().get(p).getPlainValueOrDefault("autodust", false);
|
|
|
|
|
Config.getInstance().get(p).put("autodust", !autoDust);
|
|
|
|
|
|
|
|
|
|
if(!autoDust) {
|
|
|
|
|
BauSystem.MESSAGE.send("AUTODUST_ENABLE",p);
|
|
|
|
|
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("AUTODUST_ENABLE", p));
|
|
|
|
|
}else {
|
|
|
|
|
BauSystem.MESSAGE.send("AUTODUST_DISABLE",p);
|
|
|
|
|
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("AUTODUST_DISABLE", p));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
|
public void onPlayerInteract(BlockPlaceEvent event) {
|
|
|
|
|
Player p = event.getPlayer();
|
|
|
|
|
|
|
|
|
|
if(!Config.getInstance().get(p).getPlainValueOrDefault("autodust", false)) return;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Block above = placed.getRelative(BlockFace.UP);
|
|
|
|
|
if (!above.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
above.setType(Material.REDSTONE_WIRE);
|
|
|
|
|
}
|
|
|
|
|
}
|