13
0

WIP: Add SchemSearch #146

Entwurf
Chaoscaot möchte 2 Commits von schemsearch nach master mergen
3 geänderte Dateien mit 69 neuen und 1 gelöschten Zeilen
Nur Änderungen aus Commit 2b0e7b3487 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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

Datei anzeigen

@ -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

Datei anzeigen

@ -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<String, AbstractTypeMapper<CommandSender, ?>> 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<String> searchTypeMapper() {
return new TypeMapper<String>() {
@ -162,4 +185,34 @@ public class SearchPart extends SWCommand {
}
};
}
@ClassMapper(SearchParameter.class)
public TypeMapper<SearchParameter> searchParameterTypeMapper() {
return new TypeMapper<SearchParameter>() {
@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<String> 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<RequestSchematicSearchPacket.RequestSchematicSearchPacketBuilder> builder;
@Getter
private final String flag;
@Getter
private final String longFlag;
}
}