From f054c00147ffe19dba2177d177e23cfcc6a04f13 Mon Sep 17 00:00:00 2001 From: Felix Date: Sat, 9 Nov 2019 19:38:30 +0100 Subject: [PATCH] Add tps command --- src/main/java/de/strifel/VTools/VTools.java | 3 +- .../de/strifel/VTools/commands/CommandTp.java | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/strifel/VTools/commands/CommandTp.java diff --git a/src/main/java/de/strifel/VTools/VTools.java b/src/main/java/de/strifel/VTools/VTools.java index 4947742..9b42755 100644 --- a/src/main/java/de/strifel/VTools/VTools.java +++ b/src/main/java/de/strifel/VTools/VTools.java @@ -21,12 +21,13 @@ public class VTools { @Subscribe public void onProxyInitialization(ProxyInitializeEvent event) { - server.getCommandManager().register(new CommandSend(server), "send", "tps"); + server.getCommandManager().register(new CommandSend(server), "send"); server.getCommandManager().register(new CommandSendall(server), "sendall"); server.getCommandManager().register(new CommandBroadcast(server), "broadcast", "bc", "alert"); server.getCommandManager().register(new CommandFind(server), "find", "search"); server.getCommandManager().register(new CommandStaffChat(server), "staffchat", "sc"); server.getCommandManager().register(new CommandRestart(server), "restart"); + server.getCommandManager().register(new CommandTp(server), "tps", "jump"); } } diff --git a/src/main/java/de/strifel/VTools/commands/CommandTp.java b/src/main/java/de/strifel/VTools/commands/CommandTp.java new file mode 100644 index 0000000..7429cd1 --- /dev/null +++ b/src/main/java/de/strifel/VTools/commands/CommandTp.java @@ -0,0 +1,57 @@ +package de.strifel.VTools.commands; + +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ProxyServer; +import net.kyori.text.TextComponent; +import net.kyori.text.format.TextColor; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class CommandTp implements Command { + + private final ProxyServer server; + + public CommandTp(ProxyServer server) { + this.server = server; + } + + @Override + public void execute(CommandSource commandSource, @NonNull String[] strings) { + if (commandSource instanceof Player) { + if (strings.length == 1) { + Optional player = server.getPlayer(strings[0]); + if (player.isPresent()) { + player.get().getCurrentServer().ifPresent(serverConnection -> ((Player) commandSource).createConnectionRequest(serverConnection.getServer()).fireAndForget()); + commandSource.sendMessage(TextComponent.of("Connecting to the server of " + strings[0]).color(TextColor.YELLOW)); + } else { + commandSource.sendMessage(TextComponent.of("Player does not exists.").color(TextColor.RED)); + } + } else { + commandSource.sendMessage(TextComponent.of("Usage: /tps ").color(TextColor.RED)); + } + } else { + commandSource.sendMessage(TextComponent.of("Command is only for players.").color(TextColor.RED)); + } + } + + @Override + public List suggest(CommandSource source, @NonNull String[] currentArgs) { + List arg = new ArrayList<>(); + if (currentArgs.length == 1) { + for (Player player : server.getAllPlayers()) { + arg.add(player.getUsername()); + } + } + return arg; + } + + @Override + public boolean hasPermission(CommandSource source, @NonNull String[] args) { + return source.hasPermission("VTools.tps"); + } +}