improve send command
add vtools.send.recvmsg permission
This commit is contained in:
parent
bad2c2d0c1
commit
4939482e38
4 changed files with 42 additions and 14 deletions
|
@ -6,7 +6,7 @@ Tools for Velocity proxy server.
|
|||
|-------|-------------|----------|
|
||||
|/broadcast|Broadcast a message to all servers|vtools.broadcast|
|
||||
|/find|See on which server a user is|vtools.find and vtools.find.autocomplete|
|
||||
|/send|Send user or users to a different server|vtools.send|
|
||||
|/send|Send user or users to a different server|vtools.send and vtools.send.recvmsg|
|
||||
|/staffchat|Chat over multiple servers in a staff only chat|vtools.staffchat|
|
||||
|/staffchat c:channelname|Chat over multiple servers in a staff only chat in a specific extra permissions channel|vtools.staffchat.channelname|
|
||||
|/servers|List all servers|vtools.servers|
|
||||
|
|
6
pom.xml
6
pom.xml
|
@ -13,8 +13,8 @@
|
|||
<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>
|
||||
|
@ -31,7 +31,7 @@
|
|||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -10,12 +10,13 @@ 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");
|
||||
public static final TextColor COLOR_ORANGE = TextColor.fromCSSHexString("#FFA500");
|
||||
|
||||
@Inject
|
||||
public VTools(ProxyServer server, Logger logger) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.strifel.VTools.commands;
|
|||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
|
@ -9,11 +10,16 @@ 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;
|
||||
|
@ -48,9 +54,6 @@ public class CommandSend implements SimpleCommand {
|
|||
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]);
|
||||
|
@ -58,19 +61,43 @@ public class CommandSend implements SimpleCommand {
|
|||
oPlayer.add(p.get());
|
||||
}
|
||||
}
|
||||
HashMap<Player, CompletableFuture<ConnectionRequestBuilder.Result>> futures = new HashMap<>();
|
||||
Optional<RegisteredServer> oServer = server.getServer(strings[1]);
|
||||
if (!oPlayer.isEmpty() && oServer.isPresent()) {
|
||||
RegisteredServer server = oServer.get();
|
||||
for (Player player : oPlayer) {
|
||||
player.createConnectionRequest(server).connect();
|
||||
CompletableFuture<ConnectionRequestBuilder.Result> future = player.createConnectionRequest(server).connect();
|
||||
futures.put(player, future);
|
||||
if (oPlayer.size() <= 1) {
|
||||
commandSource.sendMessage(Component.text("You send " + player.getUsername() + " to " + server.getServerInfo().getName()).color(COLOR_YELLOW));
|
||||
commandSource.sendMessage(Component.text("Sending " + player.getUsername() + " to " + server.getServerInfo().getName()).color(COLOR_ORANGE));
|
||||
}
|
||||
//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));
|
||||
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.getServerInfo().getName()).color(COLOR_ORANGE));
|
||||
}
|
||||
}));
|
||||
}));
|
||||
final HashMap<String, Integer> results = new HashMap<>();
|
||||
futures.forEach(((player, future) -> {
|
||||
try {
|
||||
String status = future.get().getStatus().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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue