From 2b0e7b34872be765053990994348b6d756725715 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 12 Apr 2023 02:18:09 +0200 Subject: [PATCH 1/2] Add SchemSearch --- .../src/SchematicSystem.properties | 8 +++ .../src/SchematicSystem_de.properties | 7 +++ .../schematiccommand/parts/SearchPart.java | 55 ++++++++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/SchematicSystem_Core/src/SchematicSystem.properties b/SchematicSystem_Core/src/SchematicSystem.properties index 60acc26..fab73ac 100644 --- a/SchematicSystem_Core/src/SchematicSystem.properties +++ b/SchematicSystem_Core/src/SchematicSystem.properties @@ -162,6 +162,14 @@ COMMAND_FIX_MANUAL=manually fix COMMAND_FIX_ERROR=§cError while fixing the schematic, please contact a developer COMMAND_FIX_WRONG_VERSION=§cThis feature is only available for version 1.15 and greater +COMMAND_MATCH_HELP_HEAD=§7---===(§eSchematic Match§7)===--- +COMMAND_MATCH_HELP_0=§7Schematic Match allows you to search for a pattern in your schematics +COMMAND_MATCH_HELP_1=§7The search is done by a simple pattern, which must be a schematic in your schematic list +COMMAND_MATCH_HELP_2=§7Parameters: +COMMAND_MATCH_HELP_3=§8• §e-d §8(§e-ignoreData§8): §7Ignore block data values, just search for the block type +COMMAND_MATCH_HELP_4=§8• §e-a §8(§e-airAsAny§8): §7Air blocks in the pattern are ignored +COMMAND_MATCH_HELP_5=§8• §e-A §8(§e-ignoreAir§8): §7Air blocks in the schematic are ignored + HELP_HEADER=§e§lSchematicSystem §8§lHelp HELP_VIEW=Find & Load HELP_VIEW_HOVER=Search or download schematics diff --git a/SchematicSystem_Core/src/SchematicSystem_de.properties b/SchematicSystem_Core/src/SchematicSystem_de.properties index e135cc4..0462038 100644 --- a/SchematicSystem_Core/src/SchematicSystem_de.properties +++ b/SchematicSystem_Core/src/SchematicSystem_de.properties @@ -147,6 +147,13 @@ COMMAND_FIX_MANUAL=Manuel Fixen COMMAND_FIX_ERROR=§cFehler beim Fixen der Schematic, bitte kontaktiere einen Developer COMMAND_FIX_WRONG_VERSION=§cDiese Funktion ist nur für Version 1.15 und höher verfügbar +COMMAND_MATCH_HELP_0=§7Schematic Match erlaubt es dir, nach Schematics zu suchen, die mit deiner Schematic übereinstimmen +COMMAND_MATCH_HELP_1=§7Die Suche arbeitet mit einem Muster, welches eine deiner Schematics ist. +COMMAND_MATCH_HELP_2=§7Parameter: +COMMAND_MATCH_HELP_3=§8• §e-d §8(§e-ignoreData§8): §7Block-Data wird ignoriert, es wird nur nach dem Block-Typ gesucht +COMMAND_MATCH_HELP_4=§8• §e-a §8(§e-airAsAny§8): §7Luftblöcke werden im Mustern als beliebige Blöcke behandelt +COMMAND_MATCH_HELP_5=§8• §e-A §8(§e-ignoreAir§8): §7Luftblöcke werden in der durchsuchten Schematic ignoriert + HELP_HEADER=§e§lSchematicSystem §8§lHilfe HELP_VIEW=Finden & Laden HELP_VIEW_HOVER=Suche oder lade Schematics diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SearchPart.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SearchPart.java index 8187139..25cad40 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SearchPart.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SearchPart.java @@ -20,17 +20,23 @@ package de.steamwar.schematicsystem.commands.schematiccommand.parts; import de.steamwar.command.*; +import de.steamwar.network.NetworkSender; +import de.steamwar.network.packets.client.RequestSchematicSearchPacket; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils; import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.UserConfig; +import lombok.AllArgsConstructor; +import lombok.Getter; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.*; +import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -43,7 +49,6 @@ public class SearchPart extends SWCommand { private static final Map> searchMapper = new HashMap<>(); - static { searchMapper.put("-type", SWCommandUtils.createMapper(SchematicType.values().stream().map(SchematicType::name).toArray(String[]::new))); searchMapper.put("-owner", SWCommandUtils.createMapper(Function.identity(), (commandSender, s) -> Collections.singletonList(s))); @@ -130,6 +135,24 @@ public class SearchPart extends SWCommand { }).build()); } + @Register("match") + public void schematicMatchHelp(Player player) { + SchematicSystem.MESSAGE.sendPrefixless("COMMAND_MATCH_HELP_HEAD", player); + for (int i = 0; i < 6; i++) { + SchematicSystem.MESSAGE.sendPrefixless("COMMAND_MATCH_HELP_" + i, player); + } + } + + @Register("match") + public void schematicMatch(Player player, SchematicNode node, SearchParameter... parameter) { + SteamwarUser user = getUser(player); + RequestSchematicSearchPacket.RequestSchematicSearchPacketBuilder builder = RequestSchematicSearchPacket.builder().schematicId(node.getId()).playerId(user.getId()); + for (SearchParameter searchParameter : parameter) { + searchParameter.builder.accept(builder); + } + NetworkSender.send(builder.build()); + } + @Mapper(value = "searchMapper", local = true) public TypeMapper searchTypeMapper() { return new TypeMapper() { @@ -162,4 +185,34 @@ public class SearchPart extends SWCommand { } }; } + + @ClassMapper(SearchParameter.class) + public TypeMapper searchParameterTypeMapper() { + return new TypeMapper() { + @Override + public SearchParameter map(CommandSender commandSender, String[] previousArguments, String s) { + return Arrays.stream(SearchParameter.values()).filter(searchParameter -> searchParameter.getFlag().equals(s) || searchParameter.getLongFlag().equalsIgnoreCase(s)).findFirst().orElse(null); + } + + @Override + public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + return Arrays.stream(SearchParameter.values()).flatMap(parameter -> Arrays.stream(new String[] {parameter.getFlag(), parameter.getLongFlag()})).collect(Collectors.toList()); + } + }; + } + + @AllArgsConstructor + private enum SearchParameter { + AIR_AS_ANY(requestSchematicSearchPacketBuilder -> requestSchematicSearchPacketBuilder.airAsAny(true),"-a", "-airAsAny"), + IGNORE_AIR(requestSchematicSearchPacketBuilder -> requestSchematicSearchPacketBuilder.ignoreAir(true), "-A", "-ignoreAir"), + IGNORE_BLOCK_DATA(requestSchematicSearchPacketBuilder -> requestSchematicSearchPacketBuilder.ignoreBlockData(true), "-d", "-ignoreData"); + + private final Consumer builder; + @Getter + private final String flag; + @Getter + private final String longFlag; + } + + } -- 2.39.5 From 2bccde3ba672213e073ff012dfa606d80ffaf657 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 13 Apr 2023 16:17:52 +0200 Subject: [PATCH 2/2] Add to Help --- SchematicSystem_Core/src/SchematicSystem.properties | 1 + .../commands/schematiccommand/SchematicCommandHelp.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/SchematicSystem_Core/src/SchematicSystem.properties b/SchematicSystem_Core/src/SchematicSystem.properties index fab73ac..8d0b949 100644 --- a/SchematicSystem_Core/src/SchematicSystem.properties +++ b/SchematicSystem_Core/src/SchematicSystem.properties @@ -181,6 +181,7 @@ HELP_VIEW_5=§8/§7schem §eload §8[§7schematic§8] - §7Loads a schematic HELP_VIEW_6=§8/§7schem §edownload §8[§7schematic§8] - §7Gives you a download link (valid for 1 min) HELP_VIEW_7=§8/§7download §8- §7Gives you a download link for your current clipboard (valid for 1 min) HELP_VIEW_8=§8/§7schem §echeck §8[§7schematic§8|§7selection§8|§7clipboard§8] [§7schematictype§8] - §7Checks the schematic for errors +HELP_VIEW_9=§8/§7schem §ematch §8[§7schematic§8] - §7Searches for a pattern in your schematics HELP_EDIT=Save & Edit HELP_EDIT_HOVER=Modification of schematics and folders HELP_EDIT_1=§8/§7schem §esave §8[§7schematic§8] - §7Saves your clipboard as a schematic diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandHelp.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandHelp.java index 1cb0ebd..3f35d04 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandHelp.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandHelp.java @@ -57,7 +57,8 @@ public class SchematicCommandHelp { "HELP_VIEW_5", "HELP_VIEW_6", "HELP_VIEW_7", - "HELP_VIEW_8" + "HELP_VIEW_8", + "HELP_VIEW_9" }), BEARBEITUNG("HELP_EDIT", "HELP_EDIT_HOVER", new String[]{ "HELP_EDIT_1", -- 2.39.5