1
0
Fork 0
forked from mc/VTools

bungeecord-like command send

This commit is contained in:
JerryXiao 2023-03-20 00:24:18 +08:00
parent 9eab9b0c53
commit c1ee5ad77b
Signed by untrusted user: Jerry
GPG key ID: 22618F758B5BE2E5
4 changed files with 49 additions and 72 deletions

View file

@ -23,7 +23,7 @@
<repositories> <repositories>
<repository> <repository>
<id>velocity</id> <id>velocity</id>
<url>https://repo.velocitypowered.com/snapshots/</url> <url>https://repo.papermc.io/repository/maven-public/</url>
</repository> </repository>
</repositories> </repositories>
@ -31,7 +31,7 @@
<dependency> <dependency>
<groupId>com.velocitypowered</groupId> <groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId> <artifactId>velocity-api</artifactId>
<version>3.1.0-SNAPSHOT</version> <version>3.1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -26,7 +26,6 @@ public class VTools {
@Subscribe @Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) { public void onProxyInitialization(ProxyInitializeEvent event) {
server.getCommandManager().register("send", new CommandSend(server)); server.getCommandManager().register("send", new CommandSend(server));
server.getCommandManager().register("sendall", new CommandSendall(server));
server.getCommandManager().register("broadcast", new CommandBroadcast(server), "bc", "alert"); server.getCommandManager().register("broadcast", new CommandBroadcast(server), "bc", "alert");
server.getCommandManager().register("find", new CommandFind(server), "search"); server.getCommandManager().register("find", new CommandFind(server), "search");
server.getCommandManager().register("staffchat", new CommandStaffChat(server), "sc"); server.getCommandManager().register("staffchat", new CommandStaffChat(server), "sc");

View file

@ -4,6 +4,7 @@ import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -25,17 +26,53 @@ public class CommandSend implements SimpleCommand {
CommandSource commandSource = invocation.source(); CommandSource commandSource = invocation.source();
String[] strings = invocation.arguments(); String[] strings = invocation.arguments();
if (strings.length == 2) { if (strings.length == 2) {
Optional<Player> oPlayer = server.getPlayer(strings[0]); List<Player> oPlayer = new ArrayList<>();
if (strings[0].equals("all")) {
for (Player player : server.getAllPlayers()) {
oPlayer.add(player);
}
}
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);
}
}
}
else {
commandSource.sendMessage(Component.text("Command is only for players.").color(COLOR_RED));
return;
}
for (Player player : server.getAllPlayers()) {
oPlayer.add(player);
}
}
else {
Optional<Player> p = server.getPlayer(strings[0]);
if (p.isPresent()) {
oPlayer.add(p.get());
}
}
Optional<RegisteredServer> oServer = server.getServer(strings[1]); Optional<RegisteredServer> oServer = server.getServer(strings[1]);
if (oPlayer.isPresent() && oServer.isPresent()) { if (!oPlayer.isEmpty() && oServer.isPresent()) {
Player player = oPlayer.get();
RegisteredServer server = oServer.get(); RegisteredServer server = oServer.get();
player.createConnectionRequest(server).connect(); for (Player player : oPlayer) {
commandSource.sendMessage(Component.text("You send " + player.getUsername() + " to " + server.getServerInfo().getName()).color(COLOR_YELLOW)); player.createConnectionRequest(server).connect();
commandSource.sendMessage(Component.text("You got send to " + server.getServerInfo().getName()).color(COLOR_YELLOW)); if (oPlayer.size() <= 1) {
commandSource.sendMessage(Component.text("You send " + player.getUsername() + " to " + server.getServerInfo().getName()).color(COLOR_YELLOW));
}
//commandSource.sendMessage(Component.text("You got send to " + server.getServerInfo().getName()).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));
}
} else { } else {
commandSource.sendMessage(Component.text("The server or user does not exists!").color(COLOR_RED)); commandSource.sendMessage(Component.text("The server or user does not exist!").color(COLOR_RED));
} }
} else { } else {
commandSource.sendMessage(Component.text("Usage: /send <username> <server>").color(COLOR_RED)); commandSource.sendMessage(Component.text("Usage: /send <username> <server>").color(COLOR_RED));
@ -47,6 +84,8 @@ public class CommandSend implements SimpleCommand {
List<String> arg = new ArrayList<String>(); List<String> arg = new ArrayList<String>();
if (currentArgs.length == 1) { if (currentArgs.length == 1) {
arg.add("all");
arg.add("current");
for (Player player : server.getAllPlayers()) { for (Player player : server.getAllPlayers()) {
arg.add(player.getUsername()); arg.add(player.getUsername());
} }

View file

@ -1,61 +0,0 @@
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;
import com.velocitypowered.api.proxy.server.RegisteredServer;
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;
public class CommandSendall implements SimpleCommand {
private final ProxyServer server;
public CommandSendall(ProxyServer server) {
this.server = server;
}
@Override
public void execute(SimpleCommand.Invocation invocation) {
CommandSource commandSource = invocation.source();
String[] strings = invocation.arguments();
if (strings.length == 1) {
Optional<RegisteredServer> oServer = server.getServer(strings[0]);
if (oServer.isPresent()) {
for (Player player : server.getAllPlayers()) {
player.createConnectionRequest(oServer.get()).connect();
player.sendMessage(Component.text("You are being sent to " + strings[0]).color(COLOR_YELLOW));
}
} else {
commandSource.sendMessage(Component.text("The server does not exists!").color(COLOR_RED));
}
} else {
commandSource.sendMessage(Component.text("Usage: /sendall <server>").color(COLOR_RED));
}
}
@Override
public List<String> suggest(SimpleCommand.Invocation invocation) {
String[] currentArgs = invocation.arguments();
List<String> arg = new ArrayList<String>();
if (currentArgs.length == 1) {
for (RegisteredServer server : server.getAllServers()) {
arg.add(server.getServerInfo().getName());
}
}
return arg;
}
@Override
public boolean hasPermission(SimpleCommand.Invocation invocation) {
return invocation.source().hasPermission("vtools.sendall");
}
}