Skip to content

Commit

Permalink
⬆️ Upgrade to Velocity 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
strifel committed Feb 27, 2022
1 parent 151f95d commit 9eab9b0
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 103 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/de/strifel/VTools/VTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand All @@ -13,6 +14,9 @@
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;
Expand All @@ -21,14 +25,14 @@ public VTools(ProxyServer server, Logger logger) {

@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");
}

}
25 changes: 14 additions & 11 deletions src/main/java/de/strifel/VTools/commands/CommandBroadcast.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
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) {
this.server = server;
}

@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 <message>").color(TextColor.RED));
commandSource.sendMessage(Component.text("Usage: /broadcast <message>").color(COLOR_RED));
}
}

@Override
public List<String> suggest(CommandSource source, @NonNull String[] currentArgs) {
public List<String> suggest(SimpleCommand.Invocation invocation) {
return new ArrayList<String>();
}

@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");
}
}
32 changes: 19 additions & 13 deletions src/main/java/de/strifel/VTools/commands/CommandFind.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -21,23 +22,28 @@ public CommandFind(ProxyServer server) {


@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> 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 <username>").color(TextColor.RED));
commandSource.sendMessage(Component.text("Usage: /find <username>").color(COLOR_RED));
}
}

@Override
public List<String> suggest(CommandSource source, @NonNull String[] currentArgs) {
public List<String> suggest(SimpleCommand.Invocation invocation) {
String[] currentArgs = invocation.arguments();

List<String> 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());
}
Expand All @@ -46,7 +52,7 @@ public List<String> suggest(CommandSource source, @NonNull String[] currentArgs)
}

@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");
}
}
22 changes: 12 additions & 10 deletions src/main/java/de/strifel/VTools/commands/CommandRestart.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -19,23 +18,26 @@ public CommandRestart(ProxyServer server) {


@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<String> suggest(CommandSource source, @NonNull String[] currentArgs) {
public List<String> suggest(SimpleCommand.Invocation invocation) {
return new ArrayList<String>();
}

@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");
}
}
32 changes: 19 additions & 13 deletions src/main/java/de/strifel/VTools/commands/CommandSend.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
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<Player> oPlayer = server.getPlayer(strings[0]);
Optional<RegisteredServer> oServer = server.getServer(strings[1]);
if (oPlayer.isPresent() && oServer.isPresent()) {
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 <username> <server>").color(TextColor.RED));
commandSource.sendMessage(Component.text("Usage: /send <username> <server>").color(COLOR_RED));
}
}

public List<String> suggest(CommandSource source, @NonNull String[] currentArgs) {
public List<String> suggest(SimpleCommand.Invocation invocation) {
String[] currentArgs = invocation.arguments();

List<String> arg = new ArrayList<String>();
if (currentArgs.length == 1) {
for (Player player : server.getAllPlayers()) {
Expand All @@ -53,7 +59,7 @@ public List<String> suggest(CommandSource source, @NonNull String[] currentArgs)
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");
}
}
30 changes: 18 additions & 12 deletions src/main/java/de/strifel/VTools/commands/CommandSendall.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
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) {
this.server = server;
}

@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<RegisteredServer> 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 <server>").color(TextColor.RED));
commandSource.sendMessage(Component.text("Usage: /sendall <server>").color(COLOR_RED));
}
}

@Override
public List<String> suggest(CommandSource source, @NonNull String[] currentArgs) {
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()) {
Expand All @@ -49,7 +55,7 @@ public List<String> suggest(CommandSource source, @NonNull String[] currentArgs)
}

@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");
}
}
Loading

0 comments on commit 9eab9b0

Please sign in to comment.