Update SchematicCommand.schemSearch #104
@ -20,6 +20,7 @@
|
||||
package de.steamwar.schematicsystem.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.SWCommandUtils;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.inventory.SchematicSelector;
|
||||
@ -36,6 +37,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -44,6 +47,16 @@ import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*;
|
||||
|
||||
public class SchematicCommand extends SWCommand {
|
||||
|
||||
Map<String, TypeMapper<?>> searchMapper = new HashMap<>();
|
||||
|
||||
{
|
||||
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)));
|
||||
Class<?> clazz = Material.class;
|
||||
searchMapper.put("-item", SWCommandUtils.createEnumMapper((Class<Enum<?>>) clazz));
|
||||
searchMapper.put("-public", null);
|
||||
}
|
||||
|
||||
public SchematicCommand() {
|
||||
super("schematic", Bukkit.getPluginManager().getPlugin("Teamserver") == null ? new String[] {"schem", "/schem", "/schematic"} : new String[]{"schem"});
|
||||
}
|
||||
@ -248,13 +261,51 @@ public class SchematicCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register("search")
|
||||
public void schemSearch(Player player, String query) {
|
||||
public void schemSearch(Player player, @Mapper("searchMapper") String... query) {
|
||||
SteamwarUser user = getUser(player);
|
||||
List<SchematicNode> nodes = SchematicNode.filterSchems(user.getId(), node -> node.getName().contains(query));
|
||||
int userId = user.getId();
|
||||
List<Predicate<SchematicNode>> predicates = new ArrayList<>();
|
||||
List<String> nameList = new ArrayList<>();
|
||||
int i = 0;
|
||||
while (i < query.length) {
|
||||
String current = query[i];
|
||||
if (searchMapper.containsKey(current)) {
|
||||
if (searchMapper.get(current) == null) {
|
||||
if (current.equals("-public")) {
|
||||
userId = 0;
|
||||
}
|
||||
} else if (i + 1 < query.length) {
|
||||
int finalI = i;
|
||||
switch (current) {
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
|
||||
case "-type":
|
||||
predicates.add(node -> node.getSchemtype().name().equals(query[finalI + 1]));
|
||||
break;
|
||||
case "-item":
|
||||
predicates.add(node -> node.getItem().equals(query[finalI + 1]));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
predicates.add(node -> node.getName().contains(current));
|
||||
nameList.add(current);
|
||||
i++;
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Chaoscaot
hat
Diese Exception wird nicht fliegen, da wenn der Spieler nicht existiert, von der SteamwarUser.get() einfach null zurück gegeben wird Diese Exception wird nicht fliegen, da wenn der Spieler nicht existiert, von der SteamwarUser.get() einfach null zurück gegeben wird
YoyoNow
hat
Naja doch schon so irgendwie, aber nicht mehr hier. Änder ich. Naja doch schon so irgendwie, aber nicht mehr hier. Änder ich.
|
||||
}
|
||||
|
||||
List<SchematicNode> nodes = SchematicNode.filterSchems(userId, node -> {
|
||||
for (Predicate<SchematicNode> predicate : predicates) {
|
||||
if (!predicate.test(node)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)");
|
||||
nodes.forEach(node -> {
|
||||
String br = node.generateBreadcrumbs(user);
|
||||
TextComponent schematics = new TextComponent("§7" + br.replace(query, "§e§l" + query + "§7"));
|
||||
for (String s : nameList) {
|
||||
br = br.replace(s, "§e§l" + s + "§8");
|
||||
}
|
||||
TextComponent schematics = new TextComponent("§7" + br);
|
||||
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create()));
|
||||
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + br));
|
||||
|
||||
@ -589,6 +640,31 @@ public class SchematicCommand extends SWCommand {
|
||||
};
|
||||
}
|
||||
|
||||
@Mapper(value = "searchMapper", local = true)
|
||||
public TypeMapper<String> searchTypeMapper() {
|
||||
return new TypeMapper<String>() {
|
||||
@Override
|
||||
public String map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
|
||||
String last = strings[strings.length - 1];
|
||||
if (searchMapper.containsKey(last)) {
|
||||
TypeMapper<?> mapper = searchMapper.get(last);
|
||||
if (mapper == null) {
|
||||
List<String> list = new ArrayList<>(searchMapper.keySet());
|
||||
list.add(s);
|
||||
return list;
|
||||
}
|
||||
return mapper.tabCompletes(commandSender, strings, s);
|
||||
}
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
enum Extend {
|
||||
AUSFAHREN,
|
||||
NORMAL
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Hier wird die -owner Flag nicht genutzt.