From 646d9f7dab9c261cd93b6c8aff800a61072311a5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 30 Nov 2021 18:09:20 +0100 Subject: [PATCH] Add Command Mapper and some more Functions Signed-off-by: Chaoscaot --- .../de/steamwar/command/SWCommandUtils.java | 12 +++++++++++ .../src/de/steamwar/sql/SchematicNode.java | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index 52e362e..1d7110f 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -19,6 +19,7 @@ package de.steamwar.command; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -72,6 +73,17 @@ public class SWCommandUtils { return null; }, s -> Arrays.asList("s", "survival", "0", "c", "creative", "1", "sp", "spectator", "3", "a", "adventure", "2"))); MAPPER_FUNCTIONS.put(SteamwarUser.class.getTypeName(), createMapper(SteamwarUser::get, s -> Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()))); + MAPPER_FUNCTIONS.put(SchematicNode.class.getTypeName(), new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + return SchematicNode.getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), s); + } + + @Override + public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { + return SchematicNode.getNodeFromPath(SteamwarUser.get(((Player) commandSender).getUniqueId()), s); + } + }); } private static void addMapper(Class clazz, Class alternativeClazz, TypeMapper mapper) { diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 4e959a3..faea608 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -582,4 +582,24 @@ public class SchematicNode { SchematicNode node = (SchematicNode) obj; return node.getId() == id; } + + public static List getNodeTabcomplete(SteamwarUser user, String s) { + List list = new ArrayList<>(); + boolean sws = s.startsWith("/"); + if (sws) { + s = s.substring(1); + } + if (s.contains("/")) { + String preTab = s.substring(0, s.lastIndexOf("/") + 1); + 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))); + } else { + List nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0); + nodes.forEach(node -> list.add((sws ? "/" : "") + node.getName() + (node.isDir() ? "/" : ""))); + } + list.remove("//copy"); + return list; + } }