整理代码
This commit is contained in:
parent
f36607df8d
commit
1a3c8872d1
5 changed files with 26 additions and 32 deletions
|
@ -54,7 +54,7 @@ public class CommandGlobalChat implements SimpleCommand {
|
|||
|
||||
@Override
|
||||
public List<String> suggest(Invocation invocation) {
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package de.strifel.VTools.commands;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
@ -19,7 +18,6 @@ public class CommandRestart implements SimpleCommand {
|
|||
|
||||
@Override
|
||||
public void execute(SimpleCommand.Invocation invocation) {
|
||||
CommandSource commandSource = invocation.source();
|
||||
String[] strings = invocation.arguments();
|
||||
|
||||
if (strings.length > 0) {
|
||||
|
@ -33,7 +31,7 @@ public class CommandRestart implements SimpleCommand {
|
|||
|
||||
@Override
|
||||
public List<String> suggest(SimpleCommand.Invocation invocation) {
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,10 +9,7 @@ import com.velocitypowered.api.proxy.ServerConnection;
|
|||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -39,23 +36,20 @@ public class CommandSend implements SimpleCommand {
|
|||
for (Player player : server.getAllPlayers()) {
|
||||
oPlayer.add(player);
|
||||
}
|
||||
}
|
||||
else if (strings[0].equals("current")) {
|
||||
} else if (strings[0].equals("current")) {
|
||||
if (commandSource instanceof Player) {
|
||||
Player playerSource = (Player)commandSource;
|
||||
Player playerSource = (Player) commandSource;
|
||||
Optional<ServerConnection> conn = playerSource.getCurrentServer();
|
||||
if (conn.isPresent()) {
|
||||
for (Player player : conn.get().getServer().getPlayersConnected()) {
|
||||
oPlayer.add(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
commandSource.sendMessage(Component.text("Command is only for players.").color(COLOR_RED));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Optional<Player> p = server.getPlayer(strings[0]);
|
||||
if (p.isPresent()) {
|
||||
oPlayer.add(p.get());
|
||||
|
@ -96,7 +90,7 @@ public class CommandSend implements SimpleCommand {
|
|||
String sendResults = results.isEmpty() ? "nothing" : results.entrySet().stream().map(
|
||||
entry -> String.format("%s : %d", entry.getKey(), entry.getValue())
|
||||
).collect(Collectors.joining("\n"));
|
||||
commandSource.sendMessage(Component.text(String.format("Send Results:\n%s", sendResults)).color(COLOR_YELLOW));
|
||||
commandSource.sendMessage(Component.text("Send Results:%n%s".formatted(sendResults)).color(COLOR_YELLOW));
|
||||
}).start();
|
||||
} else {
|
||||
commandSource.sendMessage(Component.text("The server or user does not exist!").color(COLOR_RED));
|
||||
|
@ -108,21 +102,23 @@ public class CommandSend implements SimpleCommand {
|
|||
|
||||
public List<String> suggest(SimpleCommand.Invocation invocation) {
|
||||
String[] currentArgs = invocation.arguments();
|
||||
|
||||
List<String> arg = new ArrayList<String>();
|
||||
if (currentArgs.length <= 1) {
|
||||
switch (currentArgs.length) {
|
||||
case 0, 1 -> {
|
||||
List<String> arg = new ArrayList<>(server.getPlayerCount() + 2);
|
||||
arg.add("all");
|
||||
arg.add("current");
|
||||
for (Player player : server.getAllPlayers()) {
|
||||
arg.add(player.getUsername());
|
||||
}
|
||||
return arg;
|
||||
} else if (currentArgs.length == 2) {
|
||||
for (RegisteredServer server : server.getAllServers()) {
|
||||
arg.add(server.getServerInfo().getName());
|
||||
}
|
||||
case 2 -> {
|
||||
return server.getAllServers().stream().map(s -> s.getServerInfo().getName()).toList();
|
||||
}
|
||||
default -> {
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
public boolean hasPermission(SimpleCommand.Invocation invocation) {
|
||||
|
|
|
@ -34,7 +34,7 @@ public class CommandServers implements SimpleCommand {
|
|||
|
||||
@Override
|
||||
public List<String> suggest(SimpleCommand.Invocation invocation) {
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,11 +26,11 @@ public class CommandTp implements SimpleCommand {
|
|||
CommandSource commandSource = commandInvocation.source();
|
||||
String[] strings = commandInvocation.arguments();
|
||||
|
||||
if (commandSource instanceof Player) {
|
||||
if (commandSource instanceof Player playerCommandSource) {
|
||||
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());
|
||||
player.get().getCurrentServer().ifPresent(serverConnection -> playerCommandSource.createConnectionRequest(serverConnection.getServer()).fireAndForget());
|
||||
commandSource.sendMessage(Component.text("Connecting to the server of " + strings[0]).color(COLOR_YELLOW));
|
||||
} else {
|
||||
commandSource.sendMessage(Component.text("Player does not exists.").color(COLOR_RED));
|
||||
|
|
Loading…
Reference in a new issue