u
This commit is contained in:
parent
ee63121964
commit
b51a964033
10 changed files with 100 additions and 66 deletions
16
pom.xml
16
pom.xml
|
@ -13,11 +13,21 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>.</directory>
|
||||
<includes>
|
||||
<include>velocity-plugin.json</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
|
@ -31,7 +41,7 @@
|
|||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package de.strifel.VTools;
|
||||
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.lifecycle.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import de.strifel.VTools.commands.*;
|
||||
|
@ -10,12 +10,12 @@ import org.slf4j.Logger;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@Plugin(id = "vtools", name="VTools", version="1.0-SNAPSHOT", description="Some commands!")
|
||||
@Plugin(id = "vtools", name="VTools", version="1.0-SNAPSHOT", description="Some commands!", authors="unnamed")
|
||||
public class VTools {
|
||||
private final ProxyServer server;
|
||||
|
||||
public static final TextColor COLOR_RED = TextColor.fromCSSHexString("FF5555");
|
||||
public static final TextColor COLOR_YELLOW = TextColor.fromCSSHexString("FFFF55");
|
||||
public static final TextColor COLOR_RED = TextColor.fromCSSHexString("#FF5555");
|
||||
public static final TextColor COLOR_YELLOW = TextColor.fromCSSHexString("#FFFF55");
|
||||
|
||||
@Inject
|
||||
public VTools(ProxyServer server, Logger logger) {
|
||||
|
@ -25,13 +25,13 @@ public class VTools {
|
|||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
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");
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.Player;
|
||||
import com.velocitypowered.api.proxy.connection.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.getAllPlayers()) {
|
||||
for (Player player : server.connectedPlayers()) {
|
||||
player.sendMessage(Component.text(message));
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -2,13 +2,12 @@ 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.connection.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;
|
||||
|
@ -27,9 +26,9 @@ public class CommandFind implements SimpleCommand {
|
|||
String[] strings = invocation.arguments();
|
||||
|
||||
if (strings.length == 1) {
|
||||
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));
|
||||
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));
|
||||
} else {
|
||||
commandSource.sendMessage(Component.text("The player is not online!").color(COLOR_YELLOW));
|
||||
}
|
||||
|
@ -44,8 +43,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.getAllPlayers()) {
|
||||
arg.add(player.getUsername());
|
||||
for (Player player : server.connectedPlayers()) {
|
||||
arg.add(player.username());
|
||||
}
|
||||
}
|
||||
return arg;
|
||||
|
|
|
@ -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.Player;
|
||||
import com.velocitypowered.api.proxy.connection.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.getAllPlayers()) {
|
||||
for (Player player : server.connectedPlayers()) {
|
||||
player.disconnect(Component.text(message));
|
||||
}
|
||||
}
|
||||
server.getCommandManager().executeAsync(server.getConsoleCommandSource(), "shutdown");
|
||||
server.commandManager().execute(server.consoleCommandSource(), "shutdown");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,15 +2,18 @@ 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.player.ConnectionRequestBuilder;
|
||||
import com.velocitypowered.api.proxy.connection.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;
|
||||
|
@ -30,19 +33,12 @@ public class CommandSend implements SimpleCommand {
|
|||
if (strings.length == 2) {
|
||||
List<Player> oPlayer = new ArrayList<>();
|
||||
if (strings[0].equals("all")) {
|
||||
for (Player player : server.getAllPlayers()) {
|
||||
oPlayer.add(player);
|
||||
}
|
||||
oPlayer.addAll(server.connectedPlayers());
|
||||
}
|
||||
else if (strings[0].equals("current")) {
|
||||
if (commandSource instanceof Player) {
|
||||
Player playerSource = (Player)commandSource;
|
||||
Optional<ServerConnection> conn = playerSource.getCurrentServer();
|
||||
if (conn.isPresent()) {
|
||||
for (Player player : conn.get().getServer().getPlayersConnected()) {
|
||||
oPlayer.add(player);
|
||||
}
|
||||
}
|
||||
oPlayer.addAll(playerSource.connectedServer().target().connectedPlayers());
|
||||
}
|
||||
else {
|
||||
commandSource.sendMessage(Component.text("Command is only for players.").color(COLOR_RED));
|
||||
|
@ -50,26 +46,47 @@ public class CommandSend implements SimpleCommand {
|
|||
}
|
||||
}
|
||||
else {
|
||||
Optional<Player> p = server.getPlayer(strings[0]);
|
||||
if (p.isPresent()) {
|
||||
oPlayer.add(p.get());
|
||||
Player p = server.player(strings[0]);
|
||||
if (p != null) {
|
||||
oPlayer.add(p);
|
||||
}
|
||||
}
|
||||
Optional<RegisteredServer> oServer = server.getServer(strings[1]);
|
||||
if (!oPlayer.isEmpty() && oServer.isPresent()) {
|
||||
RegisteredServer server = oServer.get();
|
||||
HashMap<Player, CompletableFuture<ConnectionRequestBuilder.Result>> futures = new HashMap<>();
|
||||
RegisteredServer server = this.server.server(strings[1]);
|
||||
if (!oPlayer.isEmpty() && server != null) {
|
||||
for (Player player : oPlayer) {
|
||||
player.createConnectionRequest(server).connect();
|
||||
if (oPlayer.size() <= 1) {
|
||||
commandSource.sendMessage(Component.text("You send " + player.getUsername() + " to " + server.getServerInfo().getName()).color(COLOR_YELLOW));
|
||||
}
|
||||
if (player.hasPermission("vtools.send.recvmsg")) {
|
||||
commandSource.sendMessage(Component.text("You got send to " + server.getServerInfo().getName()).color(COLOR_YELLOW));
|
||||
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(String.format("You send %d players to %s", oPlayer.size(), server.getServerInfo().getName())).color(COLOR_YELLOW));
|
||||
commandSource.sendMessage(Component.text(String.format("Sending %d players to %s", oPlayer.size(), server.serverInfo().name())).color(COLOR_YELLOW));
|
||||
}
|
||||
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));
|
||||
}
|
||||
}));
|
||||
}));
|
||||
final HashMap<String, Integer> results = new HashMap<>();
|
||||
futures.forEach(((player, future) -> {
|
||||
try {
|
||||
String status = future.get().status().name();
|
||||
results.put(status, results.getOrDefault(status, 0) + 1);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
String status = e.getCause().getClass().getSimpleName();
|
||||
results.put(status, results.getOrDefault(status, 0) + 1);
|
||||
}
|
||||
}));
|
||||
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));
|
||||
}).start();
|
||||
} else {
|
||||
commandSource.sendMessage(Component.text("The server or user does not exist!").color(COLOR_RED));
|
||||
}
|
||||
|
@ -85,13 +102,13 @@ public class CommandSend implements SimpleCommand {
|
|||
if (currentArgs.length <= 1) {
|
||||
arg.add("all");
|
||||
arg.add("current");
|
||||
for (Player player : server.getAllPlayers()) {
|
||||
arg.add(player.getUsername());
|
||||
for (Player player : server.connectedPlayers()) {
|
||||
arg.add(player.username());
|
||||
}
|
||||
return arg;
|
||||
} else if (currentArgs.length == 2) {
|
||||
for (RegisteredServer server : server.getAllServers()) {
|
||||
arg.add(server.getServerInfo().getName());
|
||||
for (RegisteredServer server : server.registeredServers()) {
|
||||
arg.add(server.serverInfo().name());
|
||||
}
|
||||
}
|
||||
return arg;
|
||||
|
|
|
@ -25,8 +25,8 @@ public class CommandServers implements SimpleCommand {
|
|||
String[] strings = invocation.arguments();
|
||||
|
||||
StringBuilder servers = new StringBuilder();
|
||||
for (RegisteredServer server : server.getAllServers()) {
|
||||
servers.append(server.getServerInfo().getName());
|
||||
for (RegisteredServer server : server.registeredServers()) {
|
||||
servers.append(server.serverInfo().name());
|
||||
servers.append(" ");
|
||||
}
|
||||
commandSource.sendMessage(Component.text(servers.toString()).color(COLOR_YELLOW));
|
||||
|
|
|
@ -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.Player;
|
||||
import com.velocitypowered.api.proxy.connection.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).getUsername() : "Console") + (channel != null ? " (" + channel + ")" : "")+ " > " + String.join(" ", Arrays.copyOfRange(strings, channel == null ? 0 : 1, strings.length)).replace("&", "§");
|
||||
for (Player player : server.getAllPlayers()) {
|
||||
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()) {
|
||||
if (player.hasPermission("vtools.staffchat" + (channel != null ? "." + channel : ""))) {
|
||||
player.sendMessage(Component.text(message));
|
||||
}
|
||||
|
|
|
@ -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.Player;
|
||||
import com.velocitypowered.api.proxy.connection.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) {
|
||||
Optional<Player> player = server.getPlayer(strings[0]);
|
||||
if (player.isPresent()) {
|
||||
player.get().getCurrentServer().ifPresent(serverConnection -> ((Player) commandSource).createConnectionRequest(serverConnection.getServer()).fireAndForget());
|
||||
Player player = server.player(strings[0]);
|
||||
if (player != null) {
|
||||
Optional.ofNullable(player.connectedServer()).ifPresent(serverConnection -> ((Player) commandSource).createConnectionRequest(serverConnection.target()).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.getAllPlayers()) {
|
||||
arg.add(player.getUsername());
|
||||
for (Player player : server.connectedPlayers()) {
|
||||
arg.add(player.username());
|
||||
}
|
||||
}
|
||||
return arg;
|
||||
|
|
8
velocity-plugin.json
Normal file
8
velocity-plugin.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"id": "vtools",
|
||||
"name": "VTools",
|
||||
"version": "1.0-SNAPSHOT",
|
||||
"authors": [ "unnamed" ],
|
||||
"dependencies": [],
|
||||
"main": "de.strifel.VTools.VTools"
|
||||
}
|
Loading…
Reference in a new issue