From 9e0f9c42dfcd67b6ba3207e48247249c346599bf Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 2 Jan 2022 21:12:20 +0100 Subject: [PATCH 1/9] Hotfix Name Length Check Signed-off-by: Chaoscaot --- .../schematicsystem/commands/SchematicCommandUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index 8b4e551..cacbd02 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -53,6 +53,10 @@ public class SchematicCommandUtils { player.sendMessage(SchematicSystem.PREFIX + "§cDeine Ordner brauchen schon einen Namen!"); return true; } + if(layer.length() > 64) { + player.sendMessage(SchematicSystem.PREFIX + "§cDer Name der Schematic ist zu lang"); + return true; + } if (layer.contains("/") || layer.contains("\\") || layer.contains("<") || From 9453e41a05d3513b2b75561b80e4e65462d6adc1 Mon Sep 17 00:00:00 2001 From: Chaos Date: Fri, 7 Jan 2022 22:42:20 +0100 Subject: [PATCH 2/9] Remove Schematic Load Logging --- .../schematicsystem/commands/SchematicCommandUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index cacbd02..469f178 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -309,7 +309,7 @@ public class SchematicCommandUtils { player.sendMessage(SchematicSystem.PREFIX + "§cEs konnte keine Daten in der Schematic gefunden werden."); } catch (Exception e) { player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic konnte nicht geladen werden."); - throw new SecurityException(e); + Bukkit.getLogger().log(Level.INFO, e.getMessage(), e); } } From 7aafe88ead627b1c999e9f05dbd2152bbc7ae21c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 9 Jan 2022 21:22:14 +0100 Subject: [PATCH 3/9] 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 4/9] 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 5/9] 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 e428a1285f891cf3917367488d7211c5fc580dc0 Mon Sep 17 00:00:00 2001 From: Chaos Date: Thu, 13 Jan 2022 22:21:59 +0100 Subject: [PATCH 6/9] Fix Saving to Schem-Ordner --- .../schematicsystem/commands/SchematicCommand.java | 11 ++++++++--- 1 file changed, 8 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..09a7c09 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -145,9 +145,14 @@ public class SchematicCommand extends SWCommand { SchematicNode currentNode = mkdirs(layers, user, 1); SchematicNode node = SchematicNode.getNodeFromPath(user, String.join("/", layers)); - if (node != null && !node.getSchemtype().writeable() && node.getOwner() != user.getId()) { - player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst diese Schematic nicht überschreiben"); - return; + if (node != null) { + if(node.isDir()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic ist ein Ordner"); + return; + } else if (!node.getSchemtype().writeable() || node.getOwner() != user.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst diese Schematic nicht überschreiben"); + return; + } } boolean newSchem = false; From 769538bef36b03df8c99acc2878d2208eec7c0bd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 15 Jan 2022 11:33:03 +0100 Subject: [PATCH 7/9] 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; } }; } From 0a2760efbd66339e5a964cac1cc154af937ce8c9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 15 Jan 2022 17:39:14 +0100 Subject: [PATCH 8/9] Hotfix SchematicCommand --- .../steamwar/schematicsystem/commands/SchematicCommand.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index db1278d..b50034f 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -316,10 +316,11 @@ public class SchematicCommand extends SWCommand { player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)"); nodes.forEach(node -> { String br = node.generateBreadcrumbs(user); + String displayName = br; for (String s : nameList) { - br = br.replace(s, "§e§l" + s + "§8"); + displayName = displayName.replace(s, "§e§l" + s + "§8"); } - TextComponent schematics = new TextComponent("§7" + br); + TextComponent schematics = new TextComponent("§7" + displayName); schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create())); schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + br)); From 1b18fe5a28788705e1fe0c9a91b3578f4e3a3b6f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Jan 2022 20:52:29 +0100 Subject: [PATCH 9/9] Hotfix SchematicCommand --- .../de/steamwar/schematicsystem/commands/SchematicCommand.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index b50034f..8e3202b 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -317,6 +317,9 @@ public class SchematicCommand extends SWCommand { nodes.forEach(node -> { String br = node.generateBreadcrumbs(user); String displayName = br; + if (!nameList.isEmpty()) { + displayName = "§8" + br; + } for (String s : nameList) { displayName = displayName.replace(s, "§e§l" + s + "§8"); }