diff --git a/pom.xml b/pom.xml index 8db809e..9bc3ff1 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ com.velocitypowered velocity-api - 1.0.0-SNAPSHOT + 3.1.0-SNAPSHOT provided diff --git a/src/main/java/de/strifel/VTools/VTools.java b/src/main/java/de/strifel/VTools/VTools.java index b1f65f0..4e62a1e 100644 --- a/src/main/java/de/strifel/VTools/VTools.java +++ b/src/main/java/de/strifel/VTools/VTools.java @@ -5,6 +5,7 @@ import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.proxy.ProxyServer; import de.strifel.VTools.commands.*; +import net.kyori.adventure.text.format.TextColor; import org.slf4j.Logger; import javax.inject.Inject; @@ -13,6 +14,9 @@ import javax.inject.Inject; 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"); + @Inject public VTools(ProxyServer server, Logger logger) { this.server = server; @@ -21,14 +25,14 @@ public class VTools { @Subscribe public void onProxyInitialization(ProxyInitializeEvent event) { - server.getCommandManager().register(new CommandSend(server), "send"); - server.getCommandManager().register(new CommandSendall(server), "sendall"); - server.getCommandManager().register(new CommandBroadcast(server), "broadcast", "bc", "alert"); - server.getCommandManager().register(new CommandFind(server), "find", "search"); - server.getCommandManager().register(new CommandStaffChat(server), "staffchat", "sc"); - server.getCommandManager().register(new CommandRestart(server), "restart"); - server.getCommandManager().register(new CommandTp(server), "tps", "jump"); - server.getCommandManager().register(new CommandServers(server), "servers", "allservers"); + 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("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"); } } diff --git a/src/main/java/de/strifel/VTools/commands/CommandBroadcast.java b/src/main/java/de/strifel/VTools/commands/CommandBroadcast.java index e2b431f..8945c81 100644 --- a/src/main/java/de/strifel/VTools/commands/CommandBroadcast.java +++ b/src/main/java/de/strifel/VTools/commands/CommandBroadcast.java @@ -1,17 +1,17 @@ package de.strifel.VTools.commands; -import com.velocitypowered.api.command.Command; 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 net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; -import org.checkerframework.checker.nullness.qual.NonNull; +import net.kyori.adventure.text.Component; import java.util.ArrayList; import java.util.List; -public class CommandBroadcast implements Command { +import static de.strifel.VTools.VTools.COLOR_RED; + +public class CommandBroadcast implements SimpleCommand { private final ProxyServer server; public CommandBroadcast(ProxyServer server) { @@ -19,24 +19,27 @@ public class CommandBroadcast implements Command { } @Override - public void execute(CommandSource commandSource, @NonNull String[] strings) { + public void execute(SimpleCommand.Invocation invocation) { + CommandSource commandSource = invocation.source(); + String[] strings = invocation.arguments(); + if (strings.length > 0) { String message = String.join(" ", strings).replace("&", "§"); for (Player player : server.getAllPlayers()) { - player.sendMessage(TextComponent.of(message)); + player.sendMessage(Component.text(message)); } } else { - commandSource.sendMessage(TextComponent.of("Usage: /broadcast ").color(TextColor.RED)); + commandSource.sendMessage(Component.text("Usage: /broadcast ").color(COLOR_RED)); } } @Override - public List suggest(CommandSource source, @NonNull String[] currentArgs) { + public List suggest(SimpleCommand.Invocation invocation) { return new ArrayList(); } @Override - public boolean hasPermission(CommandSource source, @NonNull String[] args) { - return source.hasPermission("vtools.broadcast"); + public boolean hasPermission(SimpleCommand.Invocation invocation) { + return invocation.source().hasPermission("vtools.broadcast"); } } diff --git a/src/main/java/de/strifel/VTools/commands/CommandFind.java b/src/main/java/de/strifel/VTools/commands/CommandFind.java index 8e5ad31..5b47769 100644 --- a/src/main/java/de/strifel/VTools/commands/CommandFind.java +++ b/src/main/java/de/strifel/VTools/commands/CommandFind.java @@ -1,18 +1,19 @@ package de.strifel.VTools.commands; -import com.velocitypowered.api.command.Command; 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 net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; -import org.checkerframework.checker.nullness.qual.NonNull; +import net.kyori.adventure.text.Component; import java.util.ArrayList; import java.util.List; import java.util.Optional; -public class CommandFind implements Command { +import static de.strifel.VTools.VTools.COLOR_RED; +import static de.strifel.VTools.VTools.COLOR_YELLOW; + +public class CommandFind implements SimpleCommand { private final ProxyServer server; public CommandFind(ProxyServer server) { @@ -21,23 +22,28 @@ public class CommandFind implements Command { @Override - public void execute(CommandSource commandSource, @NonNull String[] strings) { + public void execute(SimpleCommand.Invocation invocation) { + CommandSource commandSource = invocation.source(); + String[] strings = invocation.arguments(); + if (strings.length == 1) { Optional player = server.getPlayer(strings[0]); if (player.isPresent() && player.get().getCurrentServer().isPresent()) { - commandSource.sendMessage(TextComponent.of("Player " + strings[0] + " is on " + player.get().getCurrentServer().get().getServerInfo().getName() + "!").color(TextColor.YELLOW)); + commandSource.sendMessage(Component.text("Player " + strings[0] + " is on " + player.get().getCurrentServer().get().getServerInfo().getName() + "!").color(COLOR_YELLOW)); } else { - commandSource.sendMessage(TextComponent.of("The player is not online!").color(TextColor.YELLOW)); + commandSource.sendMessage(Component.text("The player is not online!").color(COLOR_YELLOW)); } } else { - commandSource.sendMessage(TextComponent.of("Usage: /find ").color(TextColor.RED)); + commandSource.sendMessage(Component.text("Usage: /find ").color(COLOR_RED)); } } @Override - public List suggest(CommandSource source, @NonNull String[] currentArgs) { + public List suggest(SimpleCommand.Invocation invocation) { + String[] currentArgs = invocation.arguments(); + List arg = new ArrayList<>(); - if (currentArgs.length == 1 && source.hasPermission("vtools.find.autocomplete")) { + if (currentArgs.length == 1 && invocation.source().hasPermission("vtools.find.autocomplete")) { for (Player player : server.getAllPlayers()) { arg.add(player.getUsername()); } @@ -46,7 +52,7 @@ public class CommandFind implements Command { } @Override - public boolean hasPermission(CommandSource source, @NonNull String[] args) { - return source.hasPermission("vtools.find"); + public boolean hasPermission(SimpleCommand.Invocation invocation) { + return invocation.source().hasPermission("vtools.find"); } } diff --git a/src/main/java/de/strifel/VTools/commands/CommandRestart.java b/src/main/java/de/strifel/VTools/commands/CommandRestart.java index e19cce5..a5f85c2 100644 --- a/src/main/java/de/strifel/VTools/commands/CommandRestart.java +++ b/src/main/java/de/strifel/VTools/commands/CommandRestart.java @@ -1,16 +1,15 @@ package de.strifel.VTools.commands; -import com.velocitypowered.api.command.Command; 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 net.kyori.text.TextComponent; -import org.checkerframework.checker.nullness.qual.NonNull; +import net.kyori.adventure.text.Component; import java.util.ArrayList; import java.util.List; -public class CommandRestart implements Command { +public class CommandRestart implements SimpleCommand { private final ProxyServer server; public CommandRestart(ProxyServer server) { @@ -19,23 +18,26 @@ public class CommandRestart implements Command { @Override - public void execute(CommandSource commandSource, @NonNull String[] strings) { + public void execute(SimpleCommand.Invocation invocation) { + CommandSource commandSource = invocation.source(); + String[] strings = invocation.arguments(); + if (strings.length > 0) { String message = String.join(" ", strings).replace("&", "§"); for (Player player : server.getAllPlayers()) { - player.disconnect(TextComponent.of(message)); + player.disconnect(Component.text(message)); } } - server.getCommandManager().execute(server.getConsoleCommandSource(), "shutdown"); + server.getCommandManager().executeAsync(server.getConsoleCommandSource(), "shutdown"); } @Override - public List suggest(CommandSource source, @NonNull String[] currentArgs) { + public List suggest(SimpleCommand.Invocation invocation) { return new ArrayList(); } @Override - public boolean hasPermission(CommandSource source, @NonNull String[] args) { - return source.hasPermission("vtools.shutdown"); + public boolean hasPermission(SimpleCommand.Invocation invocation) { + return invocation.source().hasPermission("vtools.shutdown"); } } diff --git a/src/main/java/de/strifel/VTools/commands/CommandSend.java b/src/main/java/de/strifel/VTools/commands/CommandSend.java index 7f78e5b..772cbbf 100644 --- a/src/main/java/de/strifel/VTools/commands/CommandSend.java +++ b/src/main/java/de/strifel/VTools/commands/CommandSend.java @@ -1,26 +1,30 @@ package de.strifel.VTools.commands; -import com.velocitypowered.api.command.Command; 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.text.TextComponent; -import net.kyori.text.format.TextColor; -import org.checkerframework.checker.nullness.qual.NonNull; +import net.kyori.adventure.text.Component; import java.util.ArrayList; import java.util.List; import java.util.Optional; -public class CommandSend implements Command { +import static de.strifel.VTools.VTools.COLOR_RED; +import static de.strifel.VTools.VTools.COLOR_YELLOW; + +public class CommandSend implements SimpleCommand { private final ProxyServer server; public CommandSend(ProxyServer server) { this.server = server; } - public void execute(CommandSource commandSource, @NonNull String[] strings) { + public void execute(SimpleCommand.Invocation invocation) { + CommandSource commandSource = invocation.source(); + String[] strings = invocation.arguments(); + if (strings.length == 2) { Optional oPlayer = server.getPlayer(strings[0]); Optional oServer = server.getServer(strings[1]); @@ -28,17 +32,19 @@ public class CommandSend implements Command { Player player = oPlayer.get(); RegisteredServer server = oServer.get(); player.createConnectionRequest(server).connect(); - commandSource.sendMessage(TextComponent.of("You send " + player.getUsername() + " to " + server.getServerInfo().getName()).color(TextColor.YELLOW)); - commandSource.sendMessage(TextComponent.of("You got send to " + server.getServerInfo().getName()).color(TextColor.YELLOW)); + 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)); } else { - commandSource.sendMessage(TextComponent.of("The server or user does not exists!").color(TextColor.RED)); + commandSource.sendMessage(Component.text("The server or user does not exists!").color(COLOR_RED)); } } else { - commandSource.sendMessage(TextComponent.of("Usage: /send ").color(TextColor.RED)); + commandSource.sendMessage(Component.text("Usage: /send ").color(COLOR_RED)); } } - public List suggest(CommandSource source, @NonNull String[] currentArgs) { + public List suggest(SimpleCommand.Invocation invocation) { + String[] currentArgs = invocation.arguments(); + List arg = new ArrayList(); if (currentArgs.length == 1) { for (Player player : server.getAllPlayers()) { @@ -53,7 +59,7 @@ public class CommandSend implements Command { return arg; } - public boolean hasPermission(CommandSource source, @NonNull String[] args) { - return source.hasPermission("vtools.send"); + public boolean hasPermission(SimpleCommand.Invocation invocation) { + return invocation.source().hasPermission("vtools.send"); } } diff --git a/src/main/java/de/strifel/VTools/commands/CommandSendall.java b/src/main/java/de/strifel/VTools/commands/CommandSendall.java index 3c40810..b260daa 100644 --- a/src/main/java/de/strifel/VTools/commands/CommandSendall.java +++ b/src/main/java/de/strifel/VTools/commands/CommandSendall.java @@ -1,19 +1,20 @@ package de.strifel.VTools.commands; -import com.velocitypowered.api.command.Command; 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.text.TextComponent; -import net.kyori.text.format.TextColor; -import org.checkerframework.checker.nullness.qual.NonNull; +import net.kyori.adventure.text.Component; import java.util.ArrayList; import java.util.List; import java.util.Optional; -public class CommandSendall implements Command { +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) { @@ -21,24 +22,29 @@ public class CommandSendall implements Command { } @Override - public void execute(CommandSource commandSource, @NonNull String[] strings) { + public void execute(SimpleCommand.Invocation invocation) { + CommandSource commandSource = invocation.source(); + String[] strings = invocation.arguments(); + if (strings.length == 1) { Optional oServer = server.getServer(strings[0]); if (oServer.isPresent()) { for (Player player : server.getAllPlayers()) { player.createConnectionRequest(oServer.get()).connect(); - player.sendMessage(TextComponent.of("You are being sent to " + strings[0]).color(TextColor.YELLOW)); + player.sendMessage(Component.text("You are being sent to " + strings[0]).color(COLOR_YELLOW)); } } else { - commandSource.sendMessage(TextComponent.of("The server does not exists!").color(TextColor.RED)); + commandSource.sendMessage(Component.text("The server does not exists!").color(COLOR_RED)); } } else { - commandSource.sendMessage(TextComponent.of("Usage: /sendall ").color(TextColor.RED)); + commandSource.sendMessage(Component.text("Usage: /sendall ").color(COLOR_RED)); } } @Override - public List suggest(CommandSource source, @NonNull String[] currentArgs) { + public List suggest(SimpleCommand.Invocation invocation) { + String[] currentArgs = invocation.arguments(); + List arg = new ArrayList(); if (currentArgs.length == 1) { for (RegisteredServer server : server.getAllServers()) { @@ -49,7 +55,7 @@ public class CommandSendall implements Command { } @Override - public boolean hasPermission(CommandSource source, @NonNull String[] args) { - return source.hasPermission("vtools.sendall"); + public boolean hasPermission(SimpleCommand.Invocation invocation) { + return invocation.source().hasPermission("vtools.sendall"); } } diff --git a/src/main/java/de/strifel/VTools/commands/CommandServers.java b/src/main/java/de/strifel/VTools/commands/CommandServers.java index dea2f66..060ebfa 100644 --- a/src/main/java/de/strifel/VTools/commands/CommandServers.java +++ b/src/main/java/de/strifel/VTools/commands/CommandServers.java @@ -1,17 +1,17 @@ package de.strifel.VTools.commands; -import com.velocitypowered.api.command.Command; import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.server.RegisteredServer; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; -import org.checkerframework.checker.nullness.qual.NonNull; +import net.kyori.adventure.text.Component; import java.util.ArrayList; import java.util.List; -public class CommandServers implements Command { +import static de.strifel.VTools.VTools.COLOR_YELLOW; + +public class CommandServers implements SimpleCommand { private final ProxyServer server; public CommandServers(ProxyServer server) { @@ -20,22 +20,25 @@ public class CommandServers implements Command { @Override - public void execute(CommandSource commandSource, @NonNull String[] strings) { + public void execute(SimpleCommand.Invocation invocation) { + CommandSource commandSource = invocation.source(); + String[] strings = invocation.arguments(); + StringBuilder servers = new StringBuilder(); for (RegisteredServer server : server.getAllServers()) { servers.append(server.getServerInfo().getName()); servers.append(" "); } - commandSource.sendMessage(TextComponent.of(servers.toString()).color(TextColor.YELLOW)); + commandSource.sendMessage(Component.text(servers.toString()).color(COLOR_YELLOW)); } @Override - public List suggest(CommandSource source, @NonNull String[] currentArgs) { + public List suggest(SimpleCommand.Invocation invocation) { return new ArrayList(); } @Override - public boolean hasPermission(CommandSource source, @NonNull String[] args) { - return source.hasPermission("vtools.find"); + public boolean hasPermission(SimpleCommand.Invocation invocation) { + return invocation.source().hasPermission("vtools.find"); } } diff --git a/src/main/java/de/strifel/VTools/commands/CommandStaffChat.java b/src/main/java/de/strifel/VTools/commands/CommandStaffChat.java index e45292f..afc9f5f 100644 --- a/src/main/java/de/strifel/VTools/commands/CommandStaffChat.java +++ b/src/main/java/de/strifel/VTools/commands/CommandStaffChat.java @@ -1,18 +1,18 @@ package de.strifel.VTools.commands; -import com.velocitypowered.api.command.Command; 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 net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; -import org.checkerframework.checker.nullness.qual.NonNull; +import net.kyori.adventure.text.Component; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class CommandStaffChat implements Command { +import static de.strifel.VTools.VTools.COLOR_RED; + +public class CommandStaffChat implements SimpleCommand { private final ProxyServer server; public CommandStaffChat(ProxyServer server) { @@ -21,27 +21,30 @@ public class CommandStaffChat implements Command { @Override - public void execute(CommandSource commandSource, @NonNull String[] strings) { + public void execute(SimpleCommand.Invocation invocation) { + CommandSource commandSource = invocation.source(); + String[] strings = invocation.arguments(); + 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()) { if (player.hasPermission("vtools.staffchat" + (channel != null ? "." + channel : ""))) { - player.sendMessage(TextComponent.of(message)); + player.sendMessage(Component.text(message)); } } } else { - commandSource.sendMessage(TextComponent.of("Usage: /broadcast ").color(TextColor.RED)); + commandSource.sendMessage(Component.text("Usage: /broadcast ").color(COLOR_RED)); } } @Override - public List suggest(CommandSource source, @NonNull String[] currentArgs) { + public List suggest(SimpleCommand.Invocation invocation) { return new ArrayList(); } @Override - public boolean hasPermission(CommandSource source, @NonNull String[] args) { - return source.hasPermission("vtools.staffchat"); + public boolean hasPermission(SimpleCommand.Invocation invocation) { + return invocation.source().hasPermission("vtools.staffchat"); } } diff --git a/src/main/java/de/strifel/VTools/commands/CommandTp.java b/src/main/java/de/strifel/VTools/commands/CommandTp.java index 7429cd1..41ddd88 100644 --- a/src/main/java/de/strifel/VTools/commands/CommandTp.java +++ b/src/main/java/de/strifel/VTools/commands/CommandTp.java @@ -1,18 +1,19 @@ package de.strifel.VTools.commands; -import com.velocitypowered.api.command.Command; 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 net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; -import org.checkerframework.checker.nullness.qual.NonNull; +import net.kyori.adventure.text.Component; import java.util.ArrayList; import java.util.List; import java.util.Optional; -public class CommandTp implements Command { +import static de.strifel.VTools.VTools.COLOR_RED; +import static de.strifel.VTools.VTools.COLOR_YELLOW; + +public class CommandTp implements SimpleCommand { private final ProxyServer server; @@ -21,28 +22,31 @@ public class CommandTp implements Command { } @Override - public void execute(CommandSource commandSource, @NonNull String[] strings) { + public void execute(Invocation commandInvocation) { + CommandSource commandSource = commandInvocation.source(); + String[] strings = commandInvocation.arguments(); + if (commandSource instanceof Player) { if (strings.length == 1) { Optional player = server.getPlayer(strings[0]); if (player.isPresent()) { player.get().getCurrentServer().ifPresent(serverConnection -> ((Player) commandSource).createConnectionRequest(serverConnection.getServer()).fireAndForget()); - commandSource.sendMessage(TextComponent.of("Connecting to the server of " + strings[0]).color(TextColor.YELLOW)); + commandSource.sendMessage(Component.text("Connecting to the server of " + strings[0]).color(COLOR_YELLOW)); } else { - commandSource.sendMessage(TextComponent.of("Player does not exists.").color(TextColor.RED)); + commandSource.sendMessage(Component.text("Player does not exists.").color(COLOR_RED)); } } else { - commandSource.sendMessage(TextComponent.of("Usage: /tps ").color(TextColor.RED)); + commandSource.sendMessage(Component.text("Usage: /tps ").color(COLOR_RED)); } } else { - commandSource.sendMessage(TextComponent.of("Command is only for players.").color(TextColor.RED)); + commandSource.sendMessage(Component.text("Command is only for players.").color(COLOR_RED)); } } @Override - public List suggest(CommandSource source, @NonNull String[] currentArgs) { + public List suggest(Invocation commandInvocation) { List arg = new ArrayList<>(); - if (currentArgs.length == 1) { + if (commandInvocation.arguments().length == 1) { for (Player player : server.getAllPlayers()) { arg.add(player.getUsername()); } @@ -51,7 +55,7 @@ public class CommandTp implements Command { } @Override - public boolean hasPermission(CommandSource source, @NonNull String[] args) { - return source.hasPermission("VTools.tps"); + public boolean hasPermission(Invocation commandInvocation) { + return commandInvocation.source().hasPermission("VTools.tps"); } }