Dieser Commit ist enthalten in:
Ursprung
f82d5815ee
Commit
6d09635a38
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.configplayer.Config;
|
||||
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.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Linked
|
||||
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)$"
|
||||
);
|
||||
|
||||
|
||||
public AutoDustCommand() {
|
||||
super("autodust", "dust");
|
||||
}
|
||||
|
||||
@Register(description = "autodust_help")
|
||||
public void genericCommand(@Validator Player p) {
|
||||
boolean autoDust = Config.getInstance().get(p).getPlainValueOrDefault("autodust", false);
|
||||
Config.getInstance().get(p).put("smartPlace", !autoDust);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(BlockPlaceEvent event) {
|
||||
final 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();
|
||||
|
||||
if(materialOnDustLocation.equals(Material.AIR) || !isColoredBlock(placedOn)) return;
|
||||
|
||||
p.getWorld().setBlockData(dustLocation,Material.REDSTONE_WIRE.createBlockData());
|
||||
}
|
||||
|
||||
public boolean isColoredBlock(Block block) {
|
||||
Matcher matcher = COLORED_BLOCK_REGEX.matcher(block.getTranslationKey());
|
||||
return matcher.matches();
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren