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