1
0
Fork 0
forked from mc/VTools

Add tps command

This commit is contained in:
Felix 2019-11-09 19:38:30 +01:00
parent 043911dc99
commit f054c00147
No known key found for this signature in database
GPG key ID: 52065E788E443D9B
2 changed files with 59 additions and 1 deletions

View file

@ -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");
}
}

View file

@ -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> 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 <username>").color(TextColor.RED));
}
} else {
commandSource.sendMessage(TextComponent.of("Command is only for players.").color(TextColor.RED));
}
}
@Override
public List<String> suggest(CommandSource source, @NonNull String[] currentArgs) {
List<String> 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");
}
}