diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java index dfe69d8e..2509c16c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java @@ -29,6 +29,9 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import java.util.HashSet; +import java.util.Set; + @Linked(LinkageType.LISTENER) public class WorldEditListener implements Listener { @@ -43,12 +46,20 @@ public class WorldEditListener implements Listener { } } + public static void addOtherCommand(String s) { + commands.add(s); + } + + private static final Set commands = new HashSet<>(); private static final String[] shortcutCommands = {"//1", "//2", "//90", "//-90", "//180", "//p", "//c", "//flopy", "//floppy", "//flopyp", "//floppyp", "//u", "//r"}; private boolean isWorldEditCommand(String command) { for (String shortcut : shortcutCommands) { if (command.startsWith(shortcut)) return true; } + for (String s : commands) { + if (command.startsWith(s)) return true; + } return FlatteningWrapper.impl.isWorldEditCommand(command); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java index eaca541b..29a99e34 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java @@ -26,13 +26,12 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.features.world.WorldEditListener; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeValidator; import lombok.SneakyThrows; import org.bukkit.Material; import org.bukkit.World; @@ -42,7 +41,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; @Linked(LinkageType.COMMAND) public class ColorReplaceCommand extends SWCommand { @@ -53,6 +51,8 @@ public class ColorReplaceCommand extends SWCommand { private Set types = new HashSet<>(); { + WorldEditListener.addOtherCommand("//colorreplace"); + WorldEditListener.addOtherCommand("//cr"); for (Material value : Material.values()) { if (value.name().startsWith("WHITE_")) { types.add(value.name().substring(6)); @@ -62,7 +62,7 @@ public class ColorReplaceCommand extends SWCommand { @Register(description = "COLORREPLACE_HELP") @SneakyThrows - public void genericCommand(@Validator Player player, Color from, Color to) { + public void genericCommand(Player player, Color from, Color to) { if (from == to) { BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(0)})); return; @@ -83,15 +83,4 @@ public class ColorReplaceCommand extends SWCommand { editSession.flushSession(); BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(affected)})); } - - @ClassValidator(Player.class) - public TypeValidator playerValidator() { - return (commandSender, player, messageSender) -> { - if (Permission.WORLDEDIT.hasPermission(player)) { - return true; - } - messageSender.send("COLORREPLACE_NO_PERMS"); - return false; - }; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java index 66894668..33979648 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java @@ -26,19 +26,17 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.features.world.WorldEditListener; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.MinVersion; import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeValidator; import lombok.AllArgsConstructor; import lombok.SneakyThrows; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.BlockFace; -import org.bukkit.block.Sign; import org.bukkit.block.data.type.Fence; import org.bukkit.block.data.type.Wall; import org.bukkit.entity.Player; @@ -56,9 +54,14 @@ public class TypeReplaceCommand extends SWCommand { super("/typereplace", "/tr"); } + { + WorldEditListener.addOtherCommand("//typereplace"); + WorldEditListener.addOtherCommand("//tr"); + } + @Register(description = "TYPEREPLACE_HELP") @SneakyThrows - public void genericCommand(@Validator Player player, Type from, Type to) { + public void genericCommand(Player player, Type from, Type to) { if (from == to) { BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(0)})); return; @@ -94,17 +97,6 @@ public class TypeReplaceCommand extends SWCommand { BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(affected)})); } - @ClassValidator(Player.class) - public TypeValidator playerValidator() { - return (commandSender, player, messageSender) -> { - if (Permission.WORLDEDIT.hasPermission(player)) { - return true; - } - messageSender.send("TYPEREPLACE_NO_PERMS"); - return false; - }; - } - @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),