From 7aafe88ead627b1c999e9f05dbd2152bbc7ae21c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 9 Jan 2022 21:22:14 +0100 Subject: [PATCH 1/4] Update SchematicCommand.schemSearch --- .../commands/SchematicCommand.java | 82 ++++++++++++++++++- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 2e5ee0f..79b8d16 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -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> 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>) 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 nodes = SchematicNode.filterSchems(user.getId(), node -> node.getName().contains(query)); + int userId = user.getId(); + List> predicates = new ArrayList<>(); + List 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) { + 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++; + } + + List nodes = SchematicNode.filterSchems(userId, node -> { + for (Predicate 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 searchTypeMapper() { + return new TypeMapper() { + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + return s; + } + + @Override + public List 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 list = new ArrayList<>(searchMapper.keySet()); + list.add(s); + return list; + } + return mapper.tabCompletes(commandSender, strings, s); + } + return Collections.singletonList(s); + } + }; + } + enum Extend { AUSFAHREN, NORMAL From 604e683362be7e84d2fab1dad33a8b72d9516f4d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 11 Jan 2022 17:57:07 +0100 Subject: [PATCH 2/4] Fix stuff --- .../commands/SchematicCommand.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 79b8d16..0f2bb22 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -47,9 +47,9 @@ import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*; public class SchematicCommand extends SWCommand { - Map> searchMapper = new HashMap<>(); + 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))); Class clazz = Material.class; @@ -278,10 +278,19 @@ public class SchematicCommand extends SWCommand { int finalI = i; switch (current) { case "-type": - predicates.add(node -> node.getSchemtype().name().equals(query[finalI + 1])); + predicates.add(node -> node.getSchemtype().name().equalsIgnoreCase(query[finalI + 1])); break; case "-item": - predicates.add(node -> node.getItem().equals(query[finalI + 1])); + predicates.add(node -> node.getItem().equalsIgnoreCase(query[finalI + 1])); + break; + case "-owner": + try { + SteamwarUser steamwarUser = SteamwarUser.get(query[finalI + 1]); + predicates.add(node -> node.getOwner() == steamwarUser.getId()); + } catch (Exception e) { + player.sendMessage(SchematicSystem.PREFIX + "§cDer Spieler §e" + query[finalI + 1] + " §cexistiert nicht"); + return; + } } i++; } @@ -650,6 +659,9 @@ public class SchematicCommand extends SWCommand { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + if (strings.length == 0) { + return Collections.singletonList(s); + } String last = strings[strings.length - 1]; if (searchMapper.containsKey(last)) { TypeMapper mapper = searchMapper.get(last); From 6f93130fe693ccabfbc5baf942ca281a5222dfae Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 11 Jan 2022 21:58:02 +0100 Subject: [PATCH 3/4] Fix SchematicCommand --- .../schematicsystem/commands/SchematicCommand.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 0f2bb22..a2a33f5 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -284,13 +284,12 @@ public class SchematicCommand extends SWCommand { predicates.add(node -> node.getItem().equalsIgnoreCase(query[finalI + 1])); break; case "-owner": - try { - SteamwarUser steamwarUser = SteamwarUser.get(query[finalI + 1]); - predicates.add(node -> node.getOwner() == steamwarUser.getId()); - } catch (Exception e) { + SteamwarUser steamwarUser = SteamwarUser.get(query[finalI + 1]); + if (steamwarUser == null) { player.sendMessage(SchematicSystem.PREFIX + "§cDer Spieler §e" + query[finalI + 1] + " §cexistiert nicht"); return; } + predicates.add(node -> node.getOwner() == steamwarUser.getId()); } i++; } @@ -660,7 +659,10 @@ public class SchematicCommand extends SWCommand { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { if (strings.length == 0) { - return Collections.singletonList(s); + List list = new ArrayList<>(); + list.add(s); + list.addAll(searchMapper.keySet()); + return list; } String last = strings[strings.length - 1]; if (searchMapper.containsKey(last)) { From 769538bef36b03df8c99acc2878d2208eec7c0bd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 15 Jan 2022 11:33:03 +0100 Subject: [PATCH 4/4] Fix SchematicCommand --- .../schematicsystem/commands/SchematicCommand.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index a2a33f5..0b9cc05 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -293,9 +293,10 @@ public class SchematicCommand extends SWCommand { } i++; } + } else { + predicates.add(node -> node.getName().contains(current)); + nameList.add(current); } - predicates.add(node -> node.getName().contains(current)); - nameList.add(current); i++; } @@ -674,7 +675,9 @@ public class SchematicCommand extends SWCommand { } return mapper.tabCompletes(commandSender, strings, s); } - return Collections.singletonList(s); + List list = new ArrayList<>(searchMapper.keySet()); + list.add(s); + return list; } }; }