commit 94efd2e228a3660add3310f4ec9e8e7939ce2989 Author: Felix Date: Thu Oct 17 11:08:30 2019 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42a697f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/ +out/ +target/ +*.iml \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..94886ae --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# VTools +Tools for Velocity proxy server. + +## Commands +|Command|What is does?|Permission| +|-------|-------------|----------| +|/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 a user to a different server|vtools.send| +|/sendall|Send all users to a specific server|vtools.sendall| +|/staffchat|Chat over multiple servers in a staff only chat|vtools.staffchat| \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8db809e --- /dev/null +++ b/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + + de.strifel.VTools + VTools + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + + + + velocity + https://repo.velocitypowered.com/snapshots/ + + + + + + com.velocitypowered + velocity-api + 1.0.0-SNAPSHOT + provided + + + + \ No newline at end of file diff --git a/src/main/java/de/strifel/VTools/VTools.java b/src/main/java/de/strifel/VTools/VTools.java new file mode 100644 index 0000000..31f07ff --- /dev/null +++ b/src/main/java/de/strifel/VTools/VTools.java @@ -0,0 +1,31 @@ +package de.strifel.VTools; + +import com.velocitypowered.api.event.Subscribe; +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 org.slf4j.Logger; + +import javax.inject.Inject; + +@Plugin(id = "vtools", name="VTools", version="1.0-SNAPSHOT", description="Some commands!") +public class VTools { + private final ProxyServer server; + + @Inject + public VTools(ProxyServer server, Logger logger) { + this.server = server; + } + + + @Subscribe + public void onProxyInitialization(ProxyInitializeEvent event) { + server.getCommandManager().register(new CommandSend(server), "send", "tps"); + 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"); + } + +} diff --git a/src/main/java/de/strifel/VTools/commands/CommandBroadcast.java b/src/main/java/de/strifel/VTools/commands/CommandBroadcast.java new file mode 100644 index 0000000..e2b431f --- /dev/null +++ b/src/main/java/de/strifel/VTools/commands/CommandBroadcast.java @@ -0,0 +1,42 @@ +package de.strifel.VTools.commands; + +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +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 java.util.ArrayList; +import java.util.List; + +public class CommandBroadcast implements Command { + private final ProxyServer server; + + public CommandBroadcast(ProxyServer server) { + this.server = server; + } + + @Override + public void execute(CommandSource commandSource, @NonNull String[] strings) { + if (strings.length > 0) { + String message = String.join(" ", strings).replace("&", "§"); + for (Player player : server.getAllPlayers()) { + player.sendMessage(TextComponent.of(message)); + } + } else { + commandSource.sendMessage(TextComponent.of("Usage: /broadcast ").color(TextColor.RED)); + } + } + + @Override + public List suggest(CommandSource source, @NonNull String[] currentArgs) { + return new ArrayList(); + } + + @Override + public boolean hasPermission(CommandSource source, @NonNull String[] args) { + return 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 new file mode 100644 index 0000000..8e5ad31 --- /dev/null +++ b/src/main/java/de/strifel/VTools/commands/CommandFind.java @@ -0,0 +1,52 @@ +package de.strifel.VTools.commands; + +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +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 java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class CommandFind implements Command { + private final ProxyServer server; + + public CommandFind(ProxyServer server) { + this.server = server; + } + + + @Override + public void execute(CommandSource commandSource, @NonNull String[] strings) { + 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)); + } else { + commandSource.sendMessage(TextComponent.of("The player is not online!").color(TextColor.YELLOW)); + } + } else { + commandSource.sendMessage(TextComponent.of("Usage: /find ").color(TextColor.RED)); + } + } + + @Override + public List suggest(CommandSource source, @NonNull String[] currentArgs) { + List arg = new ArrayList<>(); + if (currentArgs.length == 1 && source.hasPermission("vtools.find.autocomplete")) { + for (Player player : server.getAllPlayers()) { + arg.add(player.getUsername()); + } + } + return arg; + } + + @Override + public boolean hasPermission(CommandSource source, @NonNull String[] args) { + return source.hasPermission("vtools.find"); + } +} diff --git a/src/main/java/de/strifel/VTools/commands/CommandSend.java b/src/main/java/de/strifel/VTools/commands/CommandSend.java new file mode 100644 index 0000000..7f78e5b --- /dev/null +++ b/src/main/java/de/strifel/VTools/commands/CommandSend.java @@ -0,0 +1,59 @@ +package de.strifel.VTools.commands; + +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +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 java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class CommandSend implements Command { + private final ProxyServer server; + + public CommandSend(ProxyServer server) { + this.server = server; + } + + public void execute(CommandSource commandSource, @NonNull String[] strings) { + if (strings.length == 2) { + Optional oPlayer = server.getPlayer(strings[0]); + Optional 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)); + } else { + commandSource.sendMessage(TextComponent.of("The server or user does not exists!").color(TextColor.RED)); + } + } else { + commandSource.sendMessage(TextComponent.of("Usage: /send ").color(TextColor.RED)); + } + } + + public List suggest(CommandSource source, @NonNull String[] currentArgs) { + List arg = new ArrayList(); + if (currentArgs.length == 1) { + for (Player player : server.getAllPlayers()) { + arg.add(player.getUsername()); + } + return arg; + } else if (currentArgs.length == 2) { + for (RegisteredServer server : server.getAllServers()) { + arg.add(server.getServerInfo().getName()); + } + } + return arg; + } + + public boolean hasPermission(CommandSource source, @NonNull String[] args) { + return 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 new file mode 100644 index 0000000..3c40810 --- /dev/null +++ b/src/main/java/de/strifel/VTools/commands/CommandSendall.java @@ -0,0 +1,55 @@ +package de.strifel.VTools.commands; + +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +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 java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class CommandSendall implements Command { + private final ProxyServer server; + + public CommandSendall(ProxyServer server) { + this.server = server; + } + + @Override + public void execute(CommandSource commandSource, @NonNull String[] strings) { + 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)); + } + } else { + commandSource.sendMessage(TextComponent.of("The server does not exists!").color(TextColor.RED)); + } + } else { + commandSource.sendMessage(TextComponent.of("Usage: /sendall ").color(TextColor.RED)); + } + } + + @Override + public List suggest(CommandSource source, @NonNull String[] currentArgs) { + List arg = new ArrayList(); + if (currentArgs.length == 1) { + for (RegisteredServer server : server.getAllServers()) { + arg.add(server.getServerInfo().getName()); + } + } + return arg; + } + + @Override + public boolean hasPermission(CommandSource source, @NonNull String[] args) { + return source.hasPermission("vtools.sendall"); + } +} diff --git a/src/main/java/de/strifel/VTools/commands/CommandStaffChat.java b/src/main/java/de/strifel/VTools/commands/CommandStaffChat.java new file mode 100644 index 0000000..9888d08 --- /dev/null +++ b/src/main/java/de/strifel/VTools/commands/CommandStaffChat.java @@ -0,0 +1,45 @@ +package de.strifel.VTools.commands; + +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +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 java.util.ArrayList; +import java.util.List; + +public class CommandStaffChat implements Command { + private final ProxyServer server; + + public CommandStaffChat(ProxyServer server) { + this.server = server; + } + + + @Override + public void execute(CommandSource commandSource, @NonNull String[] strings) { + if (strings.length > 0) { + String message = "§4[Staff]§r " + (commandSource instanceof Player ? ((Player) commandSource).getUsername() : "Console") + " > " + String.join(" ", strings).replace("&", "§"); + for (Player player : server.getAllPlayers()) { + if (player.hasPermission("vtools.staffchat")) { + player.sendMessage(TextComponent.of(message)); + } + } + } else { + commandSource.sendMessage(TextComponent.of("Usage: /broadcast ").color(TextColor.RED)); + } + } + + @Override + public List suggest(CommandSource source, @NonNull String[] currentArgs) { + return new ArrayList(); + } + + @Override + public boolean hasPermission(CommandSource source, @NonNull String[] args) { + return source.hasPermission("vtools.staffchat"); + } +}