From 9f9d0820420eb8b3f92b0b857ea2772a2b78e56b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 21 Jan 2023 16:49:39 +0100 Subject: [PATCH] Update TpCommand --- .../bungeecore/commands/TpCommand.java | 81 ++++++++++++------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index de61885..d9dd23d 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -22,6 +22,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.*; import de.steamwar.bungeecore.util.Chat19; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; import de.steamwar.messages.ChatSender; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.CommandSender; @@ -30,45 +32,62 @@ import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; +import java.util.Collection; +import java.util.List; -public class TpCommand extends BasicCommand { +public class TpCommand extends SWCommand { public TpCommand(){ super("join", null, "tp", "teleport"); } - @Override - public void execute(CommandSender s, String[] args) { - if(!(s instanceof ProxiedPlayer)) - return; - ProxiedPlayer player = (ProxiedPlayer) s; - - ChatSender sender = ChatSender.of(player); - if(args.length == 0){ - if(Event.get() == null) - sender.system("TP_USAGE"); - else - sender.system("TP_USAGE_EVENT"); - return; - } - - ServerInfo server = getTarget(args[0]); - boolean onTeamServer = Storage.teamServers.containsValue(player.getServer().getInfo()); - - //Give control of teleport command to server - if (server == player.getServer().getInfo() || onTeamServer || server == null) { - Chat19.chat(player, "/tp " + String.join(" ", args)); - return; - } - - teleport(player, server); + @Register + public void genericCommand(ProxiedPlayer p) { + ChatSender.of(p).system(Event.get() == null ? "TP_USAGE" : "TP_USAGE_EVENT"); } - @Override - public Iterable onTabComplete(CommandSender commandSender, String[] args) { - if(args.length > 0) - return allPlayers(args[args.length - 1]); - return new ArrayList<>(); + @Register + public void teleportCommand(ProxiedPlayer p, @Mapper("to") String to, String... rest) { + ServerInfo server = getTarget(to); + + //Give control of teleport command to server + if (server == p.getServer().getInfo() || server == null) { + if (rest.length == 0) { + Chat19.chat(p, "/tp " + to); + } else { + Chat19.chat(p, "/tp " + to + " " + String.join(" ", rest)); + } + return; + } + + teleport(p, server); + } + + @Mapper("to") + @Cached(cacheDuration = 10, global = true) + public TypeMapper tabCompleter() { + return new TypeMapper() { + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + return s; + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + List list = new ArrayList<>(); + for (ProxiedPlayer player : BungeeCord.getInstance().getPlayers()) { + list.add(player.getName()); + } + if (Event.get() != null) { + EventStarter.getEventServer().keySet().forEach(teamId -> { + Team team = Team.get(teamId); + list.add(team.getTeamName()); + list.add(team.getTeamKuerzel()); + }); + } + return list; + } + }; } public static void teleport(ProxiedPlayer player, ServerInfo server){