SteamWar/SpigotCore
Archiviert
13
0

Add Command Mapper and some more Functions
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Chaoscaot 2021-11-30 18:09:20 +01:00
Ursprung 4d40d1aa46
Commit 646d9f7dab
2 geänderte Dateien mit 32 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.command; package de.steamwar.command;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -72,6 +73,17 @@ public class SWCommandUtils {
return null; return null;
}, s -> Arrays.asList("s", "survival", "0", "c", "creative", "1", "sp", "spectator", "3", "a", "adventure", "2"))); }, 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(SteamwarUser.class.getTypeName(), createMapper(SteamwarUser::get, s -> Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList())));
MAPPER_FUNCTIONS.put(SchematicNode.class.getTypeName(), new TypeMapper<SchematicNode>() {
@Override
public List<String> 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) { private static void addMapper(Class<?> clazz, Class<?> alternativeClazz, TypeMapper<?> mapper) {

Datei anzeigen

@ -582,4 +582,24 @@ public class SchematicNode {
SchematicNode node = (SchematicNode) obj; SchematicNode node = (SchematicNode) obj;
return node.getId() == id; return node.getId() == id;
} }
public static List<String> getNodeTabcomplete(SteamwarUser user, String s) {
List<String> 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<SchematicNode> nodes = SchematicNode.getSchematicNodeInNode(pa);
nodes.forEach(node -> list.add((sws ? "/" : "") + node.generateBreadcrumbs(user)));
} else {
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0);
nodes.forEach(node -> list.add((sws ? "/" : "") + node.getName() + (node.isDir() ? "/" : "")));
}
list.remove("//copy");
return list;
}
} }