1
0
Fork 0
forked from mc/VTools
This commit is contained in:
JerryXiao 2023-03-20 21:31:47 +08:00
parent b51a964033
commit d0ecef7b37
Signed by untrusted user: Jerry
GPG key ID: 22618F758B5BE2E5
10 changed files with 62 additions and 67 deletions

12
pom.xml
View file

@ -18,16 +18,6 @@
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>.</directory>
<includes>
<include>velocity-plugin.json</include>
</includes>
</resource>
</resources>
</build>
<repositories>
@ -41,7 +31,7 @@
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

View file

@ -1,7 +1,7 @@
package de.strifel.VTools;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.lifecycle.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.proxy.ProxyServer;
import de.strifel.VTools.commands.*;
@ -16,6 +16,7 @@ public class VTools {
public static final TextColor COLOR_RED = TextColor.fromCSSHexString("#FF5555");
public static final TextColor COLOR_YELLOW = TextColor.fromCSSHexString("#FFFF55");
public static final TextColor COLOR_ORANGE = TextColor.fromCSSHexString("#FFA500");
@Inject
public VTools(ProxyServer server, Logger logger) {
@ -25,13 +26,13 @@ public class VTools {
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
server.commandManager().register("send", new CommandSend(server));
server.commandManager().register("broadcast", new CommandBroadcast(server), "bc", "alert");
server.commandManager().register("find", new CommandFind(server), "search");
server.commandManager().register("staffchat", new CommandStaffChat(server), "sc");
server.commandManager().register("restart", new CommandRestart(server));
server.commandManager().register("tps", new CommandTp(server), "jump");
server.commandManager().register("servers", new CommandServers(server), "allservers");
server.getCommandManager().register("send", new CommandSend(server));
server.getCommandManager().register("broadcast", new CommandBroadcast(server), "bc", "alert");
server.getCommandManager().register("find", new CommandFind(server), "search");
server.getCommandManager().register("staffchat", new CommandStaffChat(server), "sc");
server.getCommandManager().register("restart", new CommandRestart(server));
server.getCommandManager().register("tps", new CommandTp(server), "jump");
server.getCommandManager().register("servers", new CommandServers(server), "allservers");
}
}

View file

@ -2,7 +2,7 @@ package de.strifel.VTools.commands;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.Component;
@ -25,7 +25,7 @@ public class CommandBroadcast implements SimpleCommand {
if (strings.length > 0) {
String message = String.join(" ", strings).replace("&", "§");
for (Player player : server.connectedPlayers()) {
for (Player player : server.getAllPlayers()) {
player.sendMessage(Component.text(message));
}
} else {

View file

@ -2,12 +2,13 @@ package de.strifel.VTools.commands;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static de.strifel.VTools.VTools.COLOR_RED;
import static de.strifel.VTools.VTools.COLOR_YELLOW;
@ -26,9 +27,9 @@ public class CommandFind implements SimpleCommand {
String[] strings = invocation.arguments();
if (strings.length == 1) {
Player player = server.player(strings[0]);
if (player != null && player.connectedServer() != null) {
commandSource.sendMessage(Component.text("Player " + strings[0] + " is on " + player.connectedServer().serverInfo().name() + "!").color(COLOR_YELLOW));
Optional<Player> player = server.getPlayer(strings[0]);
if (player.isPresent() && player.get().getCurrentServer().isPresent()) {
commandSource.sendMessage(Component.text("Player " + strings[0] + " is on " + player.get().getCurrentServer().get().getServerInfo().getName() + "!").color(COLOR_YELLOW));
} else {
commandSource.sendMessage(Component.text("The player is not online!").color(COLOR_YELLOW));
}
@ -43,8 +44,8 @@ public class CommandFind implements SimpleCommand {
List<String> arg = new ArrayList<>();
if (currentArgs.length <= 1 && invocation.source().hasPermission("vtools.find.autocomplete")) {
for (Player player : server.connectedPlayers()) {
arg.add(player.username());
for (Player player : server.getAllPlayers()) {
arg.add(player.getUsername());
}
}
return arg;

View file

@ -2,7 +2,7 @@ package de.strifel.VTools.commands;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.Component;
@ -24,11 +24,11 @@ public class CommandRestart implements SimpleCommand {
if (strings.length > 0) {
String message = String.join(" ", strings).replace("&", "§");
for (Player player : server.connectedPlayers()) {
for (Player player : server.getAllPlayers()) {
player.disconnect(Component.text(message));
}
}
server.commandManager().execute(server.consoleCommandSource(), "shutdown");
server.getCommandManager().executeAsync(server.getConsoleCommandSource(), "shutdown");
}
@Override

View file

@ -2,21 +2,24 @@ package de.strifel.VTools.commands;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
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.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import static de.strifel.VTools.VTools.COLOR_RED;
import static de.strifel.VTools.VTools.COLOR_YELLOW;
import static de.strifel.VTools.VTools.COLOR_ORANGE;
public class CommandSend implements SimpleCommand {
private final ProxyServer server;
@ -33,12 +36,19 @@ public class CommandSend implements SimpleCommand {
if (strings.length == 2) {
List<Player> oPlayer = new ArrayList<>();
if (strings[0].equals("all")) {
oPlayer.addAll(server.connectedPlayers());
for (Player player : server.getAllPlayers()) {
oPlayer.add(player);
}
}
else if (strings[0].equals("current")) {
if (commandSource instanceof Player) {
Player playerSource = (Player)commandSource;
oPlayer.addAll(playerSource.connectedServer().target().connectedPlayers());
Optional<ServerConnection> conn = playerSource.getCurrentServer();
if (conn.isPresent()) {
for (Player player : conn.get().getServer().getPlayersConnected()) {
oPlayer.add(player);
}
}
}
else {
commandSource.sendMessage(Component.text("Command is only for players.").color(COLOR_RED));
@ -46,36 +56,37 @@ public class CommandSend implements SimpleCommand {
}
}
else {
Player p = server.player(strings[0]);
if (p != null) {
oPlayer.add(p);
Optional<Player> p = server.getPlayer(strings[0]);
if (p.isPresent()) {
oPlayer.add(p.get());
}
}
HashMap<Player, CompletableFuture<ConnectionRequestBuilder.Result>> futures = new HashMap<>();
RegisteredServer server = this.server.server(strings[1]);
if (!oPlayer.isEmpty() && server != null) {
Optional<RegisteredServer> oServer = server.getServer(strings[1]);
if (!oPlayer.isEmpty() && oServer.isPresent()) {
RegisteredServer server = oServer.get();
for (Player player : oPlayer) {
CompletableFuture<ConnectionRequestBuilder.Result> future = player.createConnectionRequest(server).connect();
futures.put(player, future);
if (oPlayer.size() == 1) {
commandSource.sendMessage(Component.text("Sending " + player.username() + " to " + server.serverInfo().name()).color(COLOR_YELLOW));
if (oPlayer.size() <= 1) {
commandSource.sendMessage(Component.text("Sending " + player.getUsername() + " to " + server.getServerInfo().getName()).color(COLOR_ORANGE));
}
}
if (oPlayer.size() > 1) {
commandSource.sendMessage(Component.text(String.format("Sending %d players to %s", oPlayer.size(), server.serverInfo().name())).color(COLOR_YELLOW));
commandSource.sendMessage(Component.text(String.format("Sending %d players to %s", oPlayer.size(), server.getServerInfo().getName())).color(COLOR_ORANGE));
}
new Thread(() -> {
futures.forEach(((player, future) -> {
future.whenComplete(((result, throwable) -> {
if (result.isSuccessful() && player.hasPermission("vtools.send.recvmsg")) {
player.sendMessage(Component.text("You got sent to " + server.serverInfo().name()).color(COLOR_YELLOW));
player.sendMessage(Component.text("You got sent to " + server.getServerInfo().getName()).color(COLOR_ORANGE));
}
}));
}));
final HashMap<String, Integer> results = new HashMap<>();
futures.forEach(((player, future) -> {
try {
String status = future.get().status().name();
String status = future.get().getStatus().name();
results.put(status, results.getOrDefault(status, 0) + 1);
} catch (InterruptedException | ExecutionException e) {
String status = e.getCause().getClass().getSimpleName();
@ -102,13 +113,13 @@ public class CommandSend implements SimpleCommand {
if (currentArgs.length <= 1) {
arg.add("all");
arg.add("current");
for (Player player : server.connectedPlayers()) {
arg.add(player.username());
for (Player player : server.getAllPlayers()) {
arg.add(player.getUsername());
}
return arg;
} else if (currentArgs.length == 2) {
for (RegisteredServer server : server.registeredServers()) {
arg.add(server.serverInfo().name());
for (RegisteredServer server : server.getAllServers()) {
arg.add(server.getServerInfo().getName());
}
}
return arg;

View file

@ -25,8 +25,8 @@ public class CommandServers implements SimpleCommand {
String[] strings = invocation.arguments();
StringBuilder servers = new StringBuilder();
for (RegisteredServer server : server.registeredServers()) {
servers.append(server.serverInfo().name());
for (RegisteredServer server : server.getAllServers()) {
servers.append(server.getServerInfo().getName());
servers.append(" ");
}
commandSource.sendMessage(Component.text(servers.toString()).color(COLOR_YELLOW));

View file

@ -2,7 +2,7 @@ package de.strifel.VTools.commands;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.Component;
@ -27,8 +27,8 @@ public class CommandStaffChat implements SimpleCommand {
if (strings.length > 0) {
String channel = strings[0].startsWith("c:") && !strings[0].equals("c:") ? strings[0].split(":")[1] : null;
String message = "§4[Staff]§r " + (commandSource instanceof Player ? ((Player) commandSource).username() : "Console") + (channel != null ? " (" + channel + ")" : "")+ " > " + String.join(" ", Arrays.copyOfRange(strings, channel == null ? 0 : 1, strings.length)).replace("&", "§");
for (Player player : server.connectedPlayers()) {
String message = "§4[Staff]§r " + (commandSource instanceof Player ? ((Player) commandSource).getUsername() : "Console") + (channel != null ? " (" + channel + ")" : "")+ " > " + String.join(" ", Arrays.copyOfRange(strings, channel == null ? 0 : 1, strings.length)).replace("&", "§");
for (Player player : server.getAllPlayers()) {
if (player.hasPermission("vtools.staffchat" + (channel != null ? "." + channel : ""))) {
player.sendMessage(Component.text(message));
}

View file

@ -2,7 +2,7 @@ package de.strifel.VTools.commands;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.Component;
@ -28,9 +28,9 @@ public class CommandTp implements SimpleCommand {
if (commandSource instanceof Player) {
if (strings.length == 1) {
Player player = server.player(strings[0]);
if (player != null) {
Optional.ofNullable(player.connectedServer()).ifPresent(serverConnection -> ((Player) commandSource).createConnectionRequest(serverConnection.target()).fireAndForget());
Optional<Player> player = server.getPlayer(strings[0]);
if (player.isPresent()) {
player.get().getCurrentServer().ifPresent(serverConnection -> ((Player) commandSource).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));
@ -47,8 +47,8 @@ public class CommandTp implements SimpleCommand {
public List<String> suggest(Invocation commandInvocation) {
List<String> arg = new ArrayList<>();
if (commandInvocation.arguments().length <= 1) {
for (Player player : server.connectedPlayers()) {
arg.add(player.username());
for (Player player : server.getAllPlayers()) {
arg.add(player.getUsername());
}
}
return arg;

View file

@ -1,8 +0,0 @@
{
"id": "vtools",
"name": "VTools",
"version": "1.0-SNAPSHOT",
"authors": [ "unnamed" ],
"dependencies": [],
"main": "de.strifel.VTools.VTools"
}