From c22109daa9155274c1caa49aa0dd02e248ffb92b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 26 Nov 2021 16:35:30 +0100 Subject: [PATCH] Update to new SchematicSelector Signed-off-by: Chaoscaot --- .../schematicsystem/commands/GUI.java | 10 ++-- .../commands/SchematicCommand.java | 6 +-- .../commands/SchematicCommandUtils.java | 53 +++---------------- 3 files changed, 15 insertions(+), 54 deletions(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index 8183e09..4ec155e 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -26,7 +26,7 @@ import de.steamwar.inventory.SWListInv; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.*; import de.steamwar.util.SchematicSelector; -import de.steamwar.util.SchematicSelectorInjectableAdapter; +import de.steamwar.util.SchematicSelectorInjectable; import de.steamwar.util.UtilGui; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -34,8 +34,7 @@ import org.bukkit.event.inventory.ClickType; import java.util.*; -import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.getUser; -import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.invalidSchemName; +import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*; public class GUI { @@ -44,7 +43,7 @@ public class GUI { } private static void list(Player player) { - SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematic(), new SchematicSelectorInjectableAdapter() { + SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematic(), new SchematicSelectorInjectable() { @Override public void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent) { if(parent == null) { @@ -58,7 +57,8 @@ public class GUI { }, node -> { info(player, node); }); - selector.setTitle("Schematic GUI: {1}"); + selector.setSingleDirOpen(false); + selector.setTitle(player1 -> "Schematic GUI: {1}"); selector.open(); } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index b0480cf..6ce9eb8 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -384,7 +384,7 @@ public class SchematicCommand extends SWCommand { player.closeInventory(); }); inv.setItem(8, SWItem.getDye(7), (byte) 7, "§eDirekt einsenden", click -> { - node.setType(type.checkType().toDB()); + node.setSchemtype(type.checkType()); player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft"); player.closeInventory(); }); @@ -566,7 +566,7 @@ public class SchematicCommand extends SWCommand { @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return mapNode(SteamwarUser.get(0), previousArguments, s); + return SchematicNode.getNodeFromPath(SteamwarUser.get(0), s); } }; } @@ -665,7 +665,7 @@ public class SchematicCommand extends SWCommand { @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return mapNode(getUser((Player) commandSender), previousArguments, s); + return SchematicNode.getNodeFromPath(getUser((Player) commandSender), s); } }; } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index 930a85c..3431aa5 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -40,45 +40,6 @@ public class SchematicCommandUtils { private SchematicCommandUtils() { } - public static SchematicNode mapNode(SteamwarUser user, String[] previousArguments, String s) { - if (s.startsWith("/")) { - s = s.substring(1); - } - if (s.isEmpty()) { - return null; - } - if (s.contains("/")) { - String[] layers = s.split("/"); - SchematicNode currentNode = null; - for (int i = 0; i < layers.length; i++) { - int finalI = i; - List nodes; - if (currentNode == null) { - nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node -> node.getName().equals(layers[finalI])).collect(Collectors.toList()); - } else { - nodes = SchematicNode.getSchematicNodeInNode(currentNode).stream().filter(node -> node.getName().equals(layers[finalI])).collect(Collectors.toList()); - } - if (nodes.isEmpty()) { - return null; - } else { - currentNode = nodes.get(0); - if (!currentNode.isDir() && i != layers.length - 1) { - return null; - } - } - } - return currentNode; - } else { - String finalS = s; - List nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node -> node.getName().equals(finalS)).collect(Collectors.toList()); - if (nodes.isEmpty()) { - return null; - } else { - return nodes.get(0); - } - } - } - public static List getNodeTabcomplete(SteamwarUser user, String[] strings, String s) { List list = new ArrayList<>(); boolean sws = s.startsWith("/"); @@ -87,7 +48,7 @@ public class SchematicCommandUtils { } if (s.contains("/")) { String preTab = s.substring(0, s.lastIndexOf("/") + 1); - SchematicNode pa = mapNode(user, strings, preTab); + SchematicNode pa = SchematicNode.getNodeFromPath(user, preTab); if (pa == null) return Collections.emptyList(); List nodes = SchematicNode.getSchematicNodeInNode(pa); nodes.forEach(node -> list.add((sws ? "/" : "") + node.generateBreadcrumbs(user))); @@ -281,14 +242,14 @@ public class SchematicCommandUtils { rename.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " umbenennen"))); rename.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem rename " + node.generateBreadcrumbs(user) + " [Neuer Name]")); base.addExtra(rename); - - TextComponent delete = new TextComponent("[Löschen] "); - delete.setColor(ChatColor.DARK_RED); - delete.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " Löschen"))); - delete.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + node.generateBreadcrumbs(user))); - base.addExtra(delete); } + TextComponent delete = new TextComponent("[" + (node.getOwner()==user.getId()?"Löschen":"Entfernen") + "] "); + delete.setColor(ChatColor.DARK_RED); + delete.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " Löschen"))); + delete.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + node.generateBreadcrumbs(user))); + base.addExtra(delete); + if (!base.getExtra().isEmpty()) { player.spigot().sendMessage(base); }