SteamWar/BauSystem2.0
Archiviert
12
0

Add TypeMask
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-09-13 17:48:14 +02:00
Ursprung 71e51654ce
Commit d96441e31d
6 geänderte Dateien mit 370 neuen und 150 gelöschten Zeilen

Datei anzeigen

@ -25,7 +25,7 @@ public enum LinkageType {
COMMAND("$.setMessage(de.steamwar.bausystem.BauSystem.MESSAGE)", "de.steamwar.command.SWCommand"), COMMAND("$.setMessage(de.steamwar.bausystem.BauSystem.MESSAGE)", "de.steamwar.command.SWCommand"),
ENABLE_LINK("$.enable()", null, "de.steamwar.bausystem.linkage.Enable"), ENABLE_LINK("$.enable()", null, "de.steamwar.bausystem.linkage.Enable"),
DISABLE_LINK("$.disable()", null, "de.steamwar.bausystem.linkage.Disable"), DISABLE_LINK("$.disable()", null, "de.steamwar.bausystem.linkage.Disable"),
PLAIN(), PLAIN("$", null),
LISTENER(), // Is handled internally from LinkageProcessor LISTENER(), // Is handled internally from LinkageProcessor
UNLINK_LISTENER("org.bukkit.event.HandlerList.unregisterAll($)", null, "org.bukkit.event.Listener"), UNLINK_LISTENER("org.bukkit.event.HandlerList.unregisterAll($)", null, "org.bukkit.event.Listener"),

Datei anzeigen

@ -0,0 +1,33 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 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.worldedit;
import com.sk89q.worldedit.WorldEdit;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
@Linked(LinkageType.PLAIN)
public class Parser {
{
WorldEdit worldEdit = WorldEdit.getInstance();
worldEdit.getMaskFactory().register(new TypeMaskParser(worldEdit));
}
}

Datei anzeigen

@ -0,0 +1,222 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 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.worldedit;
import lombok.AllArgsConstructor;
import org.bukkit.Material;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import static org.bukkit.Material.*;
@AllArgsConstructor
public enum Type {
IRON(IRON_BLOCK, null, null, null, null, null, null, IRON_BARS, IRON_DOOR, IRON_TRAPDOOR, null, HEAVY_WEIGHTED_PRESSURE_PLATE, null, null, null, null),
WARPED(WARPED_PLANKS, WARPED_SLAB, WARPED_STAIRS, WARPED_STEM, STRIPPED_WARPED_STEM, WARPED_HYPHAE, STRIPPED_WARPED_HYPHAE, WARPED_FENCE, WARPED_DOOR, WARPED_TRAPDOOR, WARPED_FENCE_GATE, WARPED_PRESSURE_PLATE, WARPED_BUTTON, WARPED_SIGN, WARPED_WALL_SIGN, WARPED_WART_BLOCK),
CRIMSON(CRIMSON_PLANKS, CRIMSON_SLAB, CRIMSON_STAIRS, CRIMSON_STEM, STRIPPED_CRIMSON_STEM, CRIMSON_HYPHAE, STRIPPED_CRIMSON_HYPHAE, CRIMSON_FENCE, CRIMSON_DOOR, CRIMSON_TRAPDOOR, CRIMSON_FENCE_GATE, CRIMSON_PRESSURE_PLATE, CRIMSON_BUTTON, CRIMSON_SIGN, CRIMSON_WALL_SIGN, NETHER_WART_BLOCK),
MANGROVE(MANGROVE_PLANKS, MANGROVE_SLAB, MANGROVE_STAIRS, MANGROVE_LOG, STRIPPED_MANGROVE_LOG, MANGROVE_WOOD, STRIPPED_MANGROVE_WOOD, MANGROVE_FENCE, MANGROVE_DOOR, MANGROVE_TRAPDOOR, MANGROVE_FENCE_GATE, MANGROVE_PRESSURE_PLATE, MANGROVE_BUTTON, MANGROVE_SIGN, MANGROVE_WALL_SIGN, MANGROVE_LEAVES),
DARK_OAK(DARK_OAK_PLANKS, DARK_OAK_SLAB, DARK_OAK_STAIRS, DARK_OAK_LOG, STRIPPED_DARK_OAK_LOG, DARK_OAK_WOOD, STRIPPED_DARK_OAK_WOOD, DARK_OAK_FENCE, DARK_OAK_DOOR, DARK_OAK_TRAPDOOR, DARK_OAK_FENCE_GATE, DARK_OAK_PRESSURE_PLATE, DARK_OAK_BUTTON, DARK_OAK_SIGN, DARK_OAK_WALL_SIGN, DARK_OAK_LEAVES),
ACACIA(ACACIA_PLANKS, ACACIA_SLAB, ACACIA_STAIRS, ACACIA_LOG, STRIPPED_ACACIA_LOG, ACACIA_WOOD, STRIPPED_ACACIA_WOOD, ACACIA_FENCE, ACACIA_DOOR, ACACIA_TRAPDOOR, ACACIA_FENCE_GATE, ACACIA_PRESSURE_PLATE, ACACIA_BUTTON, ACACIA_SIGN, ACACIA_WALL_SIGN, ACACIA_LEAVES),
JUNGLE(JUNGLE_PLANKS, JUNGLE_SLAB, JUNGLE_STAIRS, JUNGLE_LOG, STRIPPED_JUNGLE_LOG, JUNGLE_WOOD, STRIPPED_JUNGLE_WOOD, JUNGLE_FENCE, JUNGLE_DOOR, JUNGLE_TRAPDOOR, JUNGLE_FENCE_GATE, JUNGLE_PRESSURE_PLATE, JUNGLE_BUTTON, JUNGLE_SIGN, JUNGLE_WALL_SIGN, JUNGLE_LEAVES),
BIRCH(BIRCH_PLANKS, BIRCH_SLAB, BIRCH_STAIRS, BIRCH_LOG, STRIPPED_BIRCH_LOG, BIRCH_WOOD, STRIPPED_BIRCH_WOOD, BIRCH_FENCE, BIRCH_DOOR, BIRCH_TRAPDOOR, BIRCH_FENCE_GATE, BIRCH_PRESSURE_PLATE, BIRCH_BUTTON, BIRCH_SIGN, BIRCH_WALL_SIGN, BIRCH_LEAVES),
SPRUCE(SPRUCE_PLANKS, SPRUCE_SLAB, SPRUCE_STAIRS, SPRUCE_LOG, STRIPPED_SPRUCE_LOG, SPRUCE_WOOD, STRIPPED_SPRUCE_WOOD, SPRUCE_FENCE, SPRUCE_DOOR, SPRUCE_TRAPDOOR, SPRUCE_FENCE_GATE, SPRUCE_PRESSURE_PLATE, SPRUCE_BUTTON, SPRUCE_SIGN, SPRUCE_WALL_SIGN, SPRUCE_LEAVES),
OAK(OAK_PLANKS, OAK_SLAB, OAK_STAIRS, OAK_LOG, STRIPPED_OAK_LOG, OAK_WOOD, STRIPPED_OAK_WOOD, OAK_FENCE, OAK_DOOR, OAK_TRAPDOOR, OAK_FENCE_GATE, OAK_PRESSURE_PLATE, OAK_BUTTON, OAK_SIGN, OAK_WALL_SIGN, OAK_LEAVES),
STONE(Material.STONE, STONE_SLAB, STONE_STAIRS, null, null, null, null, null, null, null, null, STONE_PRESSURE_PLATE, STONE_BUTTON, null, null, null),
COBBLE(COBBLESTONE, COBBLESTONE_SLAB, COBBLESTONE_STAIRS, COBBLESTONE_WALL),
DEEPSLATE_COBBLE(COBBLED_DEEPSLATE, COBBLED_DEEPSLATE_SLAB, COBBLED_DEEPSLATE_STAIRS, COBBLED_DEEPSLATE_WALL),
DEEPSLATE_POLISHED(POLISHED_DEEPSLATE, POLISHED_DEEPSLATE_SLAB, POLISHED_DEEPSLATE_STAIRS, POLISHED_DEEPSLATE_WALL),
DEEPSLATE_BRICKS(Material.DEEPSLATE_BRICKS, DEEPSLATE_BRICK_SLAB, DEEPSLATE_BRICK_STAIRS, DEEPSLATE_BRICK_WALL),
DEEPSLATE_TILES(Material.DEEPSLATE_TILES, DEEPSLATE_TILE_SLAB, DEEPSLATE_TILE_STAIRS, DEEPSLATE_TILE_WALL),
BLACKSTONE(Material.BLACKSTONE, BLACKSTONE_SLAB, BLACKSTONE_STAIRS, BLACKSTONE_WALL),
BLACKSTONE_POLISHED(POLISHED_BLACKSTONE, POLISHED_BLACKSTONE_SLAB, POLISHED_BLACKSTONE_STAIRS, CHISELED_POLISHED_BLACKSTONE, null, null, null, POLISHED_BLACKSTONE_WALL, null, null, null, POLISHED_BLACKSTONE_PRESSURE_PLATE, POLISHED_BLACKSTONE_BUTTON, null, null, null),
BLACKSTONE_BRICKS(POLISHED_BLACKSTONE_BRICKS, POLISHED_BLACKSTONE_BRICK_SLAB, POLISHED_BLACKSTONE_BRICK_STAIRS, POLISHED_BLACKSTONE_BRICK_WALL),
ANDESITE(Material.ANDESITE, ANDESITE_SLAB, ANDESITE_STAIRS, ANDESITE_WALL),
ANDESITE_POLISHED(POLISHED_ANDESITE, POLISHED_ANDESITE_SLAB, POLISHED_ANDESITE_STAIRS, null),
DIORITE(Material.DIORITE, DIORITE_SLAB, DIORITE_STAIRS, DIORITE_WALL),
DIORITE_POLISHED(POLISHED_DIORITE, POLISHED_DIORITE_SLAB, POLISHED_DIORITE_STAIRS, null),
GRANITE(Material.GRANITE, GRANITE_SLAB, GRANITE_STAIRS, GRANITE_WALL),
GRANITE_POLISHED(POLISHED_GRANITE, POLISHED_GRANITE_SLAB, POLISHED_GRANITE_STAIRS, null),
COBBLE_MOSSY(MOSSY_COBBLESTONE, MOSSY_COBBLESTONE_SLAB, MOSSY_COBBLESTONE_STAIRS, MOSSY_COBBLESTONE_WALL),
STONE_BRICKS_MOSSY(MOSSY_STONE_BRICKS, MOSSY_STONE_BRICK_SLAB, MOSSY_STONE_BRICK_STAIRS, MOSSY_STONE_BRICK_WALL),
MUD_BRICKS(Material.MUD_BRICKS, MUD_BRICK_SLAB, MUD_BRICK_STAIRS, MUD_BRICK_WALL),
SANDSTONE(Material.SANDSTONE, SANDSTONE_SLAB, SANDSTONE_STAIRS, CUT_SANDSTONE, CHISELED_SANDSTONE, SAND, SANDSTONE_WALL),
SANDSTONE_SMOOTH(SMOOTH_SANDSTONE, SMOOTH_SANDSTONE_SLAB, SMOOTH_SANDSTONE_STAIRS, CUT_SANDSTONE, CHISELED_SANDSTONE, SAND, null),
RED_SANDSTONE(Material.RED_SANDSTONE, RED_SANDSTONE_SLAB, RED_SANDSTONE_STAIRS, CUT_RED_SANDSTONE, CHISELED_RED_SANDSTONE, RED_SAND, RED_SANDSTONE_WALL),
RED_SANDSTONE_SMOOTH(SMOOTH_RED_SANDSTONE, SMOOTH_RED_SANDSTONE_SLAB, SMOOTH_RED_SANDSTONE_STAIRS, CUT_RED_SANDSTONE, CHISELED_RED_SANDSTONE, RED_SAND, null),
SMOOTHSTONE(Material.SMOOTH_STONE, SMOOTH_STONE_SLAB, null, null),
CUT_COPPER(WAXED_CUT_COPPER, WAXED_CUT_COPPER_SLAB, WAXED_CUT_COPPER_STAIRS, null),
EXPOSED_CUT_COPPER(WAXED_EXPOSED_CUT_COPPER, WAXED_EXPOSED_CUT_COPPER_SLAB, WAXED_EXPOSED_CUT_COPPER_STAIRS, null),
WEATHERED_CUT_COPPER(WAXED_WEATHERED_CUT_COPPER, WAXED_WEATHERED_CUT_COPPER_SLAB, WAXED_WEATHERED_CUT_COPPER_STAIRS, null),
OXIDIZED_CUT_COPPER(WAXED_OXIDIZED_CUT_COPPER, WAXED_OXIDIZED_CUT_COPPER_SLAB, WAXED_OXIDIZED_CUT_COPPER_STAIRS, null),
END_STONE_BRICKS(Material.END_STONE_BRICKS, END_STONE_BRICK_SLAB, END_STONE_BRICK_STAIRS, END_STONE_BRICK_WALL),
PURPUR(PURPUR_BLOCK, PURPUR_SLAB, PURPUR_STAIRS, PURPUR_PILLAR, null, null, null),
RED_NETHER_BRICKS(Material.RED_NETHER_BRICKS, RED_NETHER_BRICK_SLAB, RED_NETHER_BRICK_STAIRS, RED_NETHER_BRICK_WALL),
NETHER_BRICKS_WITH_WALL(NETHER_BRICKS, NETHER_BRICK_SLAB, NETHER_BRICK_STAIRS, CHISELED_NETHER_BRICKS, null, null, NETHER_BRICK_WALL),
NETHER_BRICKS_WITH_FENCE(NETHER_BRICKS, NETHER_BRICK_SLAB, NETHER_BRICK_STAIRS, NETHER_BRICK_FENCE),
BASALT(Material.BASALT, null, null, POLISHED_BASALT, SMOOTH_BASALT, null, null),
PRISMARINE_DARK(DARK_PRISMARINE, DARK_PRISMARINE_SLAB, DARK_PRISMARINE_STAIRS, null),
PRISMARINE(Material.PRISMARINE, PRISMARINE_SLAB, PRISMARINE_STAIRS, PRISMARINE_WALL),
PRISMARINE_BRICKS(Material.PRISMARINE_BRICKS, PRISMARINE_BRICK_SLAB, PRISMARINE_BRICK_STAIRS, null),
QUARTZ_SMOOTH(SMOOTH_QUARTZ, SMOOTH_QUARTZ_SLAB, SMOOTH_QUARTZ_STAIRS, QUARTZ_PILLAR, QUARTZ_BRICKS, CHISELED_QUARTZ_BLOCK, null),
QUARTZ(Material.QUARTZ_BLOCK, QUARTZ_SLAB, QUARTZ_STAIRS, QUARTZ_PILLAR, QUARTZ_BRICKS, CHISELED_QUARTZ_BLOCK, null),
STONE_BRICKS(Material.STONE_BRICKS, STONE_BRICK_SLAB, STONE_BRICK_STAIRS, CHISELED_STONE_BRICKS, null, CRACKED_STONE_BRICKS, STONE_BRICK_WALL),
BRICKS(Material.BRICKS, BRICK_SLAB, BRICK_STAIRS, BRICK_WALL);
Type(Material base, Material slab, Material stairs, Material fence) {
this.base = base;
this.slab = slab;
this.stairs = stairs;
this.fence = fence;
}
Type(Material base, Material slab, Material stairs, Material log, Material strippedLog, Material allSided, Material fence) {
this.base = base;
this.slab = slab;
this.stairs = stairs;
this.log = log;
this.strippedLog = strippedLog;
this.allSided = allSided;
this.fence = fence;
}
private Material base;
private Material slab;
private Material stairs;
private Material log;
private Material strippedLog;
private Material allSided;
private Material strippedAllSided;
private Material fence;
private Material doors;
private Material trapdoors;
private Material fenceGates;
private Material pressurePlates;
private Material button;
private Material signs;
private Material wallSigns;
private Material leaves;
public Set<String> replacements() {
Set<String> replacements = new HashSet<>();
replacements.add(base.name());
if (slab != null) {
replacements.add(slab.name());
}
if (stairs != null) {
replacements.add(stairs.name());
}
if (log != null) {
replacements.add(log.name());
}
if (strippedLog != null) {
replacements.add(strippedLog.name());
}
if (allSided != null) {
replacements.add(allSided.name());
}
if (strippedAllSided != null) {
replacements.add(strippedAllSided.name());
}
if (fence != null) {
replacements.add(fence.name());
}
if (doors != null) {
replacements.add(doors.name());
}
if (trapdoors != null) {
replacements.add(trapdoors.name());
}
if (fenceGates != null) {
replacements.add(fenceGates.name());
}
if (pressurePlates != null) {
replacements.add(pressurePlates.name());
}
if (button != null) {
replacements.add(button.name());
}
if (signs != null) {
replacements.add(signs.name());
}
if (wallSigns != null) {
replacements.add(wallSigns.name());
}
if (leaves != null) {
replacements.add(leaves.name());
}
return replacements;
}
public Map<String, String> replacements(Type from) {
Map<String, String> replacements = new HashMap<>();
if (base != null && from.base != null) {
replacements.put("minecraft:" + from.base.name().toLowerCase(), "minecraft:" + base.name().toLowerCase());
}
if (slab != null && from.slab != null) {
replacements.put("minecraft:" + from.slab.name().toLowerCase(), "minecraft:" + slab.name().toLowerCase());
}
if (stairs != null && from.stairs != null) {
replacements.put("minecraft:" + from.stairs.name().toLowerCase(), "minecraft:" + stairs.name().toLowerCase());
}
if (log != null && from.log != null) {
replacements.put("minecraft:" + from.log.name().toLowerCase(), "minecraft:" + log.name().toLowerCase());
}
if (strippedLog != null && from.strippedLog != null) {
replacements.put("minecraft:" + from.strippedLog.name().toLowerCase(), "minecraft:" + strippedLog.name().toLowerCase());
}
if (allSided != null && from.allSided != null) {
replacements.put("minecraft:" + from.allSided.name().toLowerCase(), "minecraft:" + allSided.name().toLowerCase());
}
if (strippedAllSided != null && from.strippedAllSided != null) {
replacements.put("minecraft:" + from.strippedAllSided.name().toLowerCase(), "minecraft:" + strippedAllSided.name().toLowerCase());
}
if (fence != null && from.fence != null) {
replacements.put("minecraft:" + from.fence.name().toLowerCase(), "minecraft:" + fence.name().toLowerCase());
}
if (doors != null && from.doors != null) {
replacements.put("minecraft:" + from.doors.name().toLowerCase(), "minecraft:" + doors.name().toLowerCase());
}
if (trapdoors != null && from.trapdoors != null) {
replacements.put("minecraft:" + from.trapdoors.name().toLowerCase(), "minecraft:" + trapdoors.name().toLowerCase());
}
if (fenceGates != null && from.fenceGates != null) {
replacements.put("minecraft:" + from.fenceGates.name().toLowerCase(), "minecraft:" + fenceGates.name().toLowerCase());
}
if (pressurePlates != null && from.pressurePlates != null) {
replacements.put("minecraft:" + from.pressurePlates.name().toLowerCase(), "minecraft:" + pressurePlates.name().toLowerCase());
}
if (button != null && from.button != null) {
replacements.put("minecraft:" + from.button.name().toLowerCase(), "minecraft:" + button.name().toLowerCase());
}
if (signs != null && from.signs != null) {
replacements.put("minecraft:" + from.signs.name().toLowerCase(), "minecraft:" + signs.name().toLowerCase());
}
if (wallSigns != null && from.wallSigns != null) {
replacements.put("minecraft:" + from.wallSigns.name().toLowerCase(), "minecraft:" + wallSigns.name().toLowerCase());
}
if (leaves != null && from.leaves != null) {
replacements.put("minecraft:" + from.leaves.name().toLowerCase(), "minecraft:" + leaves.name().toLowerCase());
}
return replacements;
}
}

Datei anzeigen

@ -0,0 +1,50 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 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.worldedit;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Mask2D;
import com.sk89q.worldedit.math.BlockVector3;
import javax.annotation.Nullable;
import java.util.Set;
class TypeMask implements Mask {
private Set<String> toReplace;
private Extent extent;
public TypeMask(Type type, Extent extent) {
toReplace = type.replacements();
this.extent = extent;
}
@Override
public boolean test(BlockVector3 blockVector3) {
return toReplace.contains(extent.getBlock(blockVector3).getBlockType().getId());
}
@Nullable
@Override
public Mask2D toMask2D() {
return null;
}
}

Datei anzeigen

@ -0,0 +1,63 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 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.worldedit;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.InputParser;
import java.util.Arrays;
import java.util.stream.Stream;
public class TypeMaskParser extends InputParser<Mask> {
public TypeMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public Stream<String> getSuggestions(String input) {
if ("#tr".startsWith(input)) {
return Stream.of("#tr");
}
if (input.startsWith("#tr[")) {
if (input.endsWith("]")) {
return Stream.empty();
}
return Arrays.stream(Type.values()).map(Type::name).map(s -> "#tr[" + s.toLowerCase() + "]");
}
return Stream.empty();
}
@Override
public Mask parseFromInput(String s, ParserContext parserContext) throws InputParseException {
if (!s.startsWith("#tr[")) throw new InputParseException("Invalid pattern");
if (!s.endsWith("]")) throw new InputParseException("Invalid pattern");
String type = s.substring(4, s.length() - 1);
try {
Type parsedType = Type.valueOf(type.toUpperCase());
return new TypeMask(parsedType, parserContext.getExtent());
} catch (IllegalArgumentException e) {
throw new InputParseException("Invalid type");
}
}
}

Datei anzeigen

@ -34,9 +34,7 @@ import de.steamwar.bausystem.shared.Pair;
import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.bausystem.utils.WorldEditUtils;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.Fence; import org.bukkit.block.data.type.Fence;
@ -44,14 +42,9 @@ import org.bukkit.block.data.type.Wall;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Arrays; import java.util.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.bukkit.Material.*;
@Linked(value = LinkageType.COMMAND) @Linked(value = LinkageType.COMMAND)
@MinVersion(18) @MinVersion(18)
public class TypeReplaceCommand extends SWCommand { public class TypeReplaceCommand extends SWCommand {
@ -138,145 +131,4 @@ public class TypeReplaceCommand extends SWCommand {
} }
}; };
} }
@AllArgsConstructor
private enum Type {
IRON(IRON_BLOCK, null, null, null, null, null, null, IRON_BARS, IRON_DOOR, IRON_TRAPDOOR, null, HEAVY_WEIGHTED_PRESSURE_PLATE, null, null, null, null),
WARPED(WARPED_PLANKS, WARPED_SLAB, WARPED_STAIRS, WARPED_STEM, STRIPPED_WARPED_STEM, WARPED_HYPHAE, STRIPPED_WARPED_HYPHAE, WARPED_FENCE, WARPED_DOOR, WARPED_TRAPDOOR, WARPED_FENCE_GATE, WARPED_PRESSURE_PLATE, WARPED_BUTTON, WARPED_SIGN, WARPED_WALL_SIGN, WARPED_WART_BLOCK),
CRIMSON(CRIMSON_PLANKS, CRIMSON_SLAB, CRIMSON_STAIRS, CRIMSON_STEM, STRIPPED_CRIMSON_STEM, CRIMSON_HYPHAE, STRIPPED_CRIMSON_HYPHAE, CRIMSON_FENCE, CRIMSON_DOOR, CRIMSON_TRAPDOOR, CRIMSON_FENCE_GATE, CRIMSON_PRESSURE_PLATE, CRIMSON_BUTTON, CRIMSON_SIGN, CRIMSON_WALL_SIGN, NETHER_WART_BLOCK),
MANGROVE(MANGROVE_PLANKS, MANGROVE_SLAB, MANGROVE_STAIRS, MANGROVE_LOG, STRIPPED_MANGROVE_LOG, MANGROVE_WOOD, STRIPPED_MANGROVE_WOOD, MANGROVE_FENCE, MANGROVE_DOOR, MANGROVE_TRAPDOOR, MANGROVE_FENCE_GATE, MANGROVE_PRESSURE_PLATE, MANGROVE_BUTTON, MANGROVE_SIGN, MANGROVE_WALL_SIGN, MANGROVE_LEAVES),
DARK_OAK(DARK_OAK_PLANKS, DARK_OAK_SLAB, DARK_OAK_STAIRS, DARK_OAK_LOG, STRIPPED_DARK_OAK_LOG, DARK_OAK_WOOD, STRIPPED_DARK_OAK_WOOD, DARK_OAK_FENCE, DARK_OAK_DOOR, DARK_OAK_TRAPDOOR, DARK_OAK_FENCE_GATE, DARK_OAK_PRESSURE_PLATE, DARK_OAK_BUTTON, DARK_OAK_SIGN, DARK_OAK_WALL_SIGN, DARK_OAK_LEAVES),
ACACIA(ACACIA_PLANKS, ACACIA_SLAB, ACACIA_STAIRS, ACACIA_LOG, STRIPPED_ACACIA_LOG, ACACIA_WOOD, STRIPPED_ACACIA_WOOD, ACACIA_FENCE, ACACIA_DOOR, ACACIA_TRAPDOOR, ACACIA_FENCE_GATE, ACACIA_PRESSURE_PLATE, ACACIA_BUTTON, ACACIA_SIGN, ACACIA_WALL_SIGN, ACACIA_LEAVES),
JUNGLE(JUNGLE_PLANKS, JUNGLE_SLAB, JUNGLE_STAIRS, JUNGLE_LOG, STRIPPED_JUNGLE_LOG, JUNGLE_WOOD, STRIPPED_JUNGLE_WOOD, JUNGLE_FENCE, JUNGLE_DOOR, JUNGLE_TRAPDOOR, JUNGLE_FENCE_GATE, JUNGLE_PRESSURE_PLATE, JUNGLE_BUTTON, JUNGLE_SIGN, JUNGLE_WALL_SIGN, JUNGLE_LEAVES),
BIRCH(BIRCH_PLANKS, BIRCH_SLAB, BIRCH_STAIRS, BIRCH_LOG, STRIPPED_BIRCH_LOG, BIRCH_WOOD, STRIPPED_BIRCH_WOOD, BIRCH_FENCE, BIRCH_DOOR, BIRCH_TRAPDOOR, BIRCH_FENCE_GATE, BIRCH_PRESSURE_PLATE, BIRCH_BUTTON, BIRCH_SIGN, BIRCH_WALL_SIGN, BIRCH_LEAVES),
SPRUCE(SPRUCE_PLANKS, SPRUCE_SLAB, SPRUCE_STAIRS, SPRUCE_LOG, STRIPPED_SPRUCE_LOG, SPRUCE_WOOD, STRIPPED_SPRUCE_WOOD, SPRUCE_FENCE, SPRUCE_DOOR, SPRUCE_TRAPDOOR, SPRUCE_FENCE_GATE, SPRUCE_PRESSURE_PLATE, SPRUCE_BUTTON, SPRUCE_SIGN, SPRUCE_WALL_SIGN, SPRUCE_LEAVES),
OAK(OAK_PLANKS, OAK_SLAB, OAK_STAIRS, OAK_LOG, STRIPPED_OAK_LOG, OAK_WOOD, STRIPPED_OAK_WOOD, OAK_FENCE, OAK_DOOR, OAK_TRAPDOOR, OAK_FENCE_GATE, OAK_PRESSURE_PLATE, OAK_BUTTON, OAK_SIGN, OAK_WALL_SIGN, OAK_LEAVES),
STONE(Material.STONE, STONE_SLAB, STONE_STAIRS, null, null, null, null, null, null, null, null, STONE_PRESSURE_PLATE, STONE_BUTTON, null, null, null),
COBBLE(COBBLESTONE, COBBLESTONE_SLAB, COBBLESTONE_STAIRS, COBBLESTONE_WALL),
DEEPSLATE_COBBLE(COBBLED_DEEPSLATE, COBBLED_DEEPSLATE_SLAB, COBBLED_DEEPSLATE_STAIRS, COBBLED_DEEPSLATE_WALL),
DEEPSLATE_POLISHED(POLISHED_DEEPSLATE, POLISHED_DEEPSLATE_SLAB, POLISHED_DEEPSLATE_STAIRS, POLISHED_DEEPSLATE_WALL),
DEEPSLATE_BRICKS(Material.DEEPSLATE_BRICKS, DEEPSLATE_BRICK_SLAB, DEEPSLATE_BRICK_STAIRS, DEEPSLATE_BRICK_WALL),
DEEPSLATE_TILES(Material.DEEPSLATE_TILES, DEEPSLATE_TILE_SLAB, DEEPSLATE_TILE_STAIRS, DEEPSLATE_TILE_WALL),
BLACKSTONE(Material.BLACKSTONE, BLACKSTONE_SLAB, BLACKSTONE_STAIRS, BLACKSTONE_WALL),
BLACKSTONE_POLISHED(POLISHED_BLACKSTONE, POLISHED_BLACKSTONE_SLAB, POLISHED_BLACKSTONE_STAIRS, CHISELED_POLISHED_BLACKSTONE, null, null, null, POLISHED_BLACKSTONE_WALL, null, null, null, POLISHED_BLACKSTONE_PRESSURE_PLATE, POLISHED_BLACKSTONE_BUTTON, null, null, null),
BLACKSTONE_BRICKS(POLISHED_BLACKSTONE_BRICKS, POLISHED_BLACKSTONE_BRICK_SLAB, POLISHED_BLACKSTONE_BRICK_STAIRS, POLISHED_BLACKSTONE_BRICK_WALL),
ANDESITE(Material.ANDESITE, ANDESITE_SLAB, ANDESITE_STAIRS, ANDESITE_WALL),
ANDESITE_POLISHED(POLISHED_ANDESITE, POLISHED_ANDESITE_SLAB, POLISHED_ANDESITE_STAIRS, null),
DIORITE(Material.DIORITE, DIORITE_SLAB, DIORITE_STAIRS, DIORITE_WALL),
DIORITE_POLISHED(POLISHED_DIORITE, POLISHED_DIORITE_SLAB, POLISHED_DIORITE_STAIRS, null),
GRANITE(Material.GRANITE, GRANITE_SLAB, GRANITE_STAIRS, GRANITE_WALL),
GRANITE_POLISHED(POLISHED_GRANITE, POLISHED_GRANITE_SLAB, POLISHED_GRANITE_STAIRS, null),
COBBLE_MOSSY(MOSSY_COBBLESTONE, MOSSY_COBBLESTONE_SLAB, MOSSY_COBBLESTONE_STAIRS, MOSSY_COBBLESTONE_WALL),
STONE_BRICKS_MOSSY(MOSSY_STONE_BRICKS, MOSSY_STONE_BRICK_SLAB, MOSSY_STONE_BRICK_STAIRS, MOSSY_STONE_BRICK_WALL),
MUD_BRICKS(Material.MUD_BRICKS, MUD_BRICK_SLAB, MUD_BRICK_STAIRS, MUD_BRICK_WALL),
SANDSTONE(Material.SANDSTONE, SANDSTONE_SLAB, SANDSTONE_STAIRS, CUT_SANDSTONE, CHISELED_SANDSTONE, SAND, SANDSTONE_WALL),
SANDSTONE_SMOOTH(SMOOTH_SANDSTONE, SMOOTH_SANDSTONE_SLAB, SMOOTH_SANDSTONE_STAIRS, CUT_SANDSTONE, CHISELED_SANDSTONE, SAND, null),
RED_SANDSTONE(Material.RED_SANDSTONE, RED_SANDSTONE_SLAB, RED_SANDSTONE_STAIRS, CUT_RED_SANDSTONE, CHISELED_RED_SANDSTONE, RED_SAND, RED_SANDSTONE_WALL),
RED_SANDSTONE_SMOOTH(SMOOTH_RED_SANDSTONE, SMOOTH_RED_SANDSTONE_SLAB, SMOOTH_RED_SANDSTONE_STAIRS, CUT_RED_SANDSTONE, CHISELED_RED_SANDSTONE, RED_SAND, null),
SMOOTHSTONE(Material.SMOOTH_STONE, SMOOTH_STONE_SLAB, null, null),
CUT_COPPER(WAXED_CUT_COPPER, WAXED_CUT_COPPER_SLAB, WAXED_CUT_COPPER_STAIRS, null),
EXPOSED_CUT_COPPER(WAXED_EXPOSED_CUT_COPPER, WAXED_EXPOSED_CUT_COPPER_SLAB, WAXED_EXPOSED_CUT_COPPER_STAIRS, null),
WEATHERED_CUT_COPPER(WAXED_WEATHERED_CUT_COPPER, WAXED_WEATHERED_CUT_COPPER_SLAB, WAXED_WEATHERED_CUT_COPPER_STAIRS, null),
OXIDIZED_CUT_COPPER(WAXED_OXIDIZED_CUT_COPPER, WAXED_OXIDIZED_CUT_COPPER_SLAB, WAXED_OXIDIZED_CUT_COPPER_STAIRS, null),
END_STONE_BRICKS(Material.END_STONE_BRICKS, END_STONE_BRICK_SLAB, END_STONE_BRICK_STAIRS, END_STONE_BRICK_WALL),
PURPUR(PURPUR_BLOCK, PURPUR_SLAB, PURPUR_STAIRS, PURPUR_PILLAR, null, null, null),
RED_NETHER_BRICKS(Material.RED_NETHER_BRICKS, RED_NETHER_BRICK_SLAB, RED_NETHER_BRICK_STAIRS, RED_NETHER_BRICK_WALL),
NETHER_BRICKS_WITH_WALL(NETHER_BRICKS, NETHER_BRICK_SLAB, NETHER_BRICK_STAIRS, CHISELED_NETHER_BRICKS, null, null, NETHER_BRICK_WALL),
NETHER_BRICKS_WITH_FENCE(NETHER_BRICKS, NETHER_BRICK_SLAB, NETHER_BRICK_STAIRS, NETHER_BRICK_FENCE),
BASALT(Material.BASALT, null, null, POLISHED_BASALT, SMOOTH_BASALT, null, null),
PRISMARINE_DARK(DARK_PRISMARINE, DARK_PRISMARINE_SLAB, DARK_PRISMARINE_STAIRS, null),
PRISMARINE(Material.PRISMARINE, PRISMARINE_SLAB, PRISMARINE_STAIRS, PRISMARINE_WALL),
PRISMARINE_BRICKS(Material.PRISMARINE_BRICKS, PRISMARINE_BRICK_SLAB, PRISMARINE_BRICK_STAIRS, null),
QUARTZ_SMOOTH(SMOOTH_QUARTZ, SMOOTH_QUARTZ_SLAB, SMOOTH_QUARTZ_STAIRS, QUARTZ_PILLAR, QUARTZ_BRICKS, CHISELED_QUARTZ_BLOCK, null),
QUARTZ(Material.QUARTZ_BLOCK, QUARTZ_SLAB, QUARTZ_STAIRS, QUARTZ_PILLAR, QUARTZ_BRICKS, CHISELED_QUARTZ_BLOCK, null),
STONE_BRICKS(Material.STONE_BRICKS, STONE_BRICK_SLAB, STONE_BRICK_STAIRS, CHISELED_STONE_BRICKS, null, CRACKED_STONE_BRICKS, STONE_BRICK_WALL),
BRICKS(Material.BRICKS, BRICK_SLAB, BRICK_STAIRS, BRICK_WALL);
Type(Material base, Material slab, Material stairs, Material fence) {
this.base = base;
this.slab = slab;
this.stairs = stairs;
this.fence = fence;
}
Type(Material base, Material slab, Material stairs, Material log, Material strippedLog, Material allSided, Material fence) {
this.base = base;
this.slab = slab;
this.stairs = stairs;
this.log = log;
this.strippedLog = strippedLog;
this.allSided = allSided;
this.fence = fence;
}
private Material base;
private Material slab;
private Material stairs;
private Material log;
private Material strippedLog;
private Material allSided;
private Material strippedAllSided;
private Material fence;
private Material doors;
private Material trapdoors;
private Material fenceGates;
private Material pressurePlates;
private Material button;
private Material signs;
private Material wallSigns;
private Material leaves;
private Map<String, String> replacements(Type from) {
Map<String, String> replacements = new HashMap<>();
if (base != null && from.base != null) {
replacements.put("minecraft:" + from.base.name().toLowerCase(), "minecraft:" + base.name().toLowerCase());
}
if (slab != null && from.slab != null) {
replacements.put("minecraft:" + from.slab.name().toLowerCase(), "minecraft:" + slab.name().toLowerCase());
}
if (stairs != null && from.stairs != null) {
replacements.put("minecraft:" + from.stairs.name().toLowerCase(), "minecraft:" + stairs.name().toLowerCase());
}
if (log != null && from.log != null) {
replacements.put("minecraft:" + from.log.name().toLowerCase(), "minecraft:" + log.name().toLowerCase());
}
if (strippedLog != null && from.strippedLog != null) {
replacements.put("minecraft:" + from.strippedLog.name().toLowerCase(), "minecraft:" + strippedLog.name().toLowerCase());
}
if (allSided != null && from.allSided != null) {
replacements.put("minecraft:" + from.allSided.name().toLowerCase(), "minecraft:" + allSided.name().toLowerCase());
}
if (strippedAllSided != null && from.strippedAllSided != null) {
replacements.put("minecraft:" + from.strippedAllSided.name().toLowerCase(), "minecraft:" + strippedAllSided.name().toLowerCase());
}
if (fence != null && from.fence != null) {
replacements.put("minecraft:" + from.fence.name().toLowerCase(), "minecraft:" + fence.name().toLowerCase());
}
if (doors != null && from.doors != null) {
replacements.put("minecraft:" + from.doors.name().toLowerCase(), "minecraft:" + doors.name().toLowerCase());
}
if (trapdoors != null && from.trapdoors != null) {
replacements.put("minecraft:" + from.trapdoors.name().toLowerCase(), "minecraft:" + trapdoors.name().toLowerCase());
}
if (fenceGates != null && from.fenceGates != null) {
replacements.put("minecraft:" + from.fenceGates.name().toLowerCase(), "minecraft:" + fenceGates.name().toLowerCase());
}
if (pressurePlates != null && from.pressurePlates != null) {
replacements.put("minecraft:" + from.pressurePlates.name().toLowerCase(), "minecraft:" + pressurePlates.name().toLowerCase());
}
if (button != null && from.button != null) {
replacements.put("minecraft:" + from.button.name().toLowerCase(), "minecraft:" + button.name().toLowerCase());
}
if (signs != null && from.signs != null) {
replacements.put("minecraft:" + from.signs.name().toLowerCase(), "minecraft:" + signs.name().toLowerCase());
}
if (wallSigns != null && from.wallSigns != null) {
replacements.put("minecraft:" + from.wallSigns.name().toLowerCase(), "minecraft:" + wallSigns.name().toLowerCase());
}
if (leaves != null && from.leaves != null) {
replacements.put("minecraft:" + from.leaves.name().toLowerCase(), "minecraft:" + leaves.name().toLowerCase());
}
return replacements;
}
}
} }