1
0
Fork 0
forked from mc/VTools

Initial commit

This commit is contained in:
Felix 2019-10-17 11:08:30 +02:00
commit 94efd2e228
No known key found for this signature in database
GPG key ID: 52065E788E443D9B
9 changed files with 338 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
.idea/
out/
target/
*.iml

11
README.md Normal file
View file

@ -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|

39
pom.xml Normal file
View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.strifel.VTools</groupId>
<artifactId>VTools</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>velocity</id>
<url>https://repo.velocitypowered.com/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

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

View file

@ -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 <message>").color(TextColor.RED));
}
}
@Override
public List<String> suggest(CommandSource source, @NonNull String[] currentArgs) {
return new ArrayList<String>();
}
@Override
public boolean hasPermission(CommandSource source, @NonNull String[] args) {
return source.hasPermission("vtools.broadcast");
}
}

View file

@ -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> 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 <username>").color(TextColor.RED));
}
}
@Override
public List<String> suggest(CommandSource source, @NonNull String[] currentArgs) {
List<String> 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");
}
}

View file

@ -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<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));
} else {
commandSource.sendMessage(TextComponent.of("The server or user does not exists!").color(TextColor.RED));
}
} else {
commandSource.sendMessage(TextComponent.of("Usage: /send <username> <server>").color(TextColor.RED));
}
}
public List<String> suggest(CommandSource source, @NonNull String[] currentArgs) {
List<String> arg = new ArrayList<String>();
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");
}
}

View file

@ -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<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));
}
} else {
commandSource.sendMessage(TextComponent.of("The server does not exists!").color(TextColor.RED));
}
} else {
commandSource.sendMessage(TextComponent.of("Usage: /sendall <server>").color(TextColor.RED));
}
}
@Override
public List<String> suggest(CommandSource source, @NonNull String[] currentArgs) {
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(CommandSource source, @NonNull String[] args) {
return source.hasPermission("vtools.sendall");
}
}

View file

@ -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 <message>").color(TextColor.RED));
}
}
@Override
public List<String> suggest(CommandSource source, @NonNull String[] currentArgs) {
return new ArrayList<String>();
}
@Override
public boolean hasPermission(CommandSource source, @NonNull String[] args) {
return source.hasPermission("vtools.staffchat");
}
}