From a721f61a389f0948dae5ed92234d788a67c1c331 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 28 Nov 2022 22:57:12 +0100 Subject: [PATCH] Update command framework methods --- .../commands/SchematicCommand.java | 34 ++++++++++++------- .../commands/SchematicCommandUtils.java | 9 ++--- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index fc55c29..d347a21 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -572,7 +572,7 @@ public class SchematicCommand extends SWCommand { } @Register("check") - public void checkCommand(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, SchematicType type) { + public void checkCommand(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, CheckSchemType type) { try { check(player, new SchematicData(node).load(), type, node.getName(), false); } catch (IOException e) { @@ -581,7 +581,7 @@ public class SchematicCommand extends SWCommand { } @Register(value = {"check", "clipboard"}) - public void checkClipboardCommand(Player player, SchematicType type) { + public void checkClipboardCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) { try { check(player, WorldEdit.getInstance().getSessionManager().get(new BukkitPlayer(player)).getClipboard().getClipboard(), type, "clipboard", false); } catch (EmptyClipboardException e) { @@ -590,7 +590,7 @@ public class SchematicCommand extends SWCommand { } @Register(value = {"check", "selection"}) - public void checkSelectionCommand(Player player, SchematicType type) { + public void checkSelectionCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) { try { Clipboard clipboard = new BlockArrayClipboard(WorldEdit.getInstance().getSessionManager().get(new BukkitPlayer(player)).getSelection(new BukkitWorld(player.getWorld()))); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(player.getWorld()), -1); @@ -606,7 +606,7 @@ public class SchematicCommand extends SWCommand { } @Register("fix") - public void fixSchematicCommand(Player player, SchematicType type) { + public void fixSchematicCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) { if(Core.getVersion() < 15) { SchematicSystem.MESSAGE.send("COMMAND_FIX_WRONG_VERSION", player); return; @@ -618,20 +618,15 @@ public class SchematicCommand extends SWCommand { SchematicSystem.MESSAGE.send("COMMAND_CHECK_CLIPBOARD_EMPTY", player); return; } - CheckSchemType checkSchemType = CheckSchemType.get(type); - if (checkSchemType == null) { - SchematicSystem.MESSAGE.send("UTIL_CHECK_TYPE_NOT_FOUND", player, type.name()); - return; - } - AutoCheckerResult result = AutoChecker.check(clipboard, checkSchemType); + AutoCheckerResult result = AutoChecker.check(clipboard, type); if(result.isOk()) { SchematicSystem.MESSAGE.send("COMMAND_FIX_OK", player); return; } try { - clipboard = impl.fixClipboard(clipboard, result, checkSchemType); + clipboard = impl.fixClipboard(clipboard, result, type); WorldEdit.getInstance().getSessionManager().get(new BukkitPlayer(player)).setClipboard(new ClipboardHolder(clipboard)); - AutoCheckerResult after = AutoChecker.check(clipboard, checkSchemType); + AutoCheckerResult after = AutoChecker.check(clipboard, type); if(after.isOk()) { SchematicSystem.MESSAGE.send("COMMAND_FIX_DONE", player); } else { @@ -770,6 +765,21 @@ public class SchematicCommand extends SWCommand { }; } + @ClassMapper(value = CheckSchemType.class, local = true) + public TypeMapper checkSchemTypeTypeMapper() { + return new TypeMapper() { + @Override + public Collection tabCompletes(CommandSender commandSender, String[] strings, String s) { + return SchematicType.values().stream().filter(type -> CheckSchemType.get(type) != null).map(SchematicType::name).collect(Collectors.toList()); + } + + @Override + public CheckSchemType map(CommandSender commandSender, String[] previousArguments, String s) { + return SchematicType.values().stream().filter(type -> type.name().equalsIgnoreCase(s)).map(CheckSchemType::get).findAny().orElse(null); + } + }; + } + @Mapper(value = "searchMapper", local = true) public TypeMapper searchTypeMapper() { return new TypeMapper() { diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index d731abd..de38e56 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -305,13 +305,8 @@ public class SchematicCommandUtils { } } - public static void check(Player player, Clipboard clipboard, SchematicType type, String schemName, boolean gui) { - CheckSchemType checkSchemType = CheckSchemType.get(type); - if(checkSchemType == null) { - SchematicSystem.MESSAGE.send("UTIL_CHECK_TYPE_NOT_FOUND", player, type.name()); - return; - } - AutoCheckerResult result = AutoChecker.check(clipboard, checkSchemType); + public static void check(Player player, Clipboard clipboard, CheckSchemType type, String schemName, boolean gui) { + AutoCheckerResult result = AutoChecker.check(clipboard, type); if(!result.isOk()) { result.sendErrorMessage(player, schemName); } else {