SteamWar/BungeeCore
Archiviert
13
2

Update TpCommand

Dieser Commit ist enthalten in:
yoyosource 2023-01-21 16:49:39 +01:00
Ursprung 24456458de
Commit 9f9d082042

Datei anzeigen

@ -22,6 +22,8 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.sql.*; import de.steamwar.bungeecore.sql.*;
import de.steamwar.bungeecore.util.Chat19; import de.steamwar.bungeecore.util.Chat19;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.messages.ChatSender; import de.steamwar.messages.ChatSender;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.CommandSender; 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 net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class TpCommand extends BasicCommand { public class TpCommand extends SWCommand {
public TpCommand(){ public TpCommand(){
super("join", null, "tp", "teleport"); super("join", null, "tp", "teleport");
} }
@Override @Register
public void execute(CommandSender s, String[] args) { public void genericCommand(ProxiedPlayer p) {
if(!(s instanceof ProxiedPlayer)) ChatSender.of(p).system(Event.get() == null ? "TP_USAGE" : "TP_USAGE_EVENT");
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]); @Register
boolean onTeamServer = Storage.teamServers.containsValue(player.getServer().getInfo()); public void teleportCommand(ProxiedPlayer p, @Mapper("to") String to, String... rest) {
ServerInfo server = getTarget(to);
//Give control of teleport command to server //Give control of teleport command to server
if (server == player.getServer().getInfo() || onTeamServer || server == null) { if (server == p.getServer().getInfo() || server == null) {
Chat19.chat(player, "/tp " + String.join(" ", args)); if (rest.length == 0) {
Chat19.chat(p, "/tp " + to);
} else {
Chat19.chat(p, "/tp " + to + " " + String.join(" ", rest));
}
return; return;
} }
teleport(player, server); teleport(p, server);
}
@Mapper("to")
@Cached(cacheDuration = 10, global = true)
public TypeMapper<String> tabCompleter() {
return new TypeMapper<String>() {
@Override
public String map(CommandSender commandSender, String[] previousArguments, String s) {
return s;
} }
@Override @Override
public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) { public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
if(args.length > 0) List<String> list = new ArrayList<>();
return allPlayers(args[args.length - 1]); for (ProxiedPlayer player : BungeeCord.getInstance().getPlayers()) {
return new ArrayList<>(); 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){ public static void teleport(ProxiedPlayer player, ServerInfo server){