1
0
Fork 0
forked from mc/VTools

Add restart command: This needs your server to automatically restart on close

This commit is contained in:
Felix 2019-10-17 14:33:04 +02:00
parent 94efd2e228
commit 043911dc99
No known key found for this signature in database
GPG key ID: 52065E788E443D9B
2 changed files with 42 additions and 0 deletions

View file

@ -26,6 +26,7 @@ public class VTools {
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");
}
}

View file

@ -0,0 +1,41 @@
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 org.checkerframework.checker.nullness.qual.NonNull;
import java.util.ArrayList;
import java.util.List;
public class CommandRestart implements Command {
private final ProxyServer server;
public CommandRestart(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.disconnect(TextComponent.of(message));
}
}
server.getCommandManager().execute(server.getConsoleCommandSource(), "shutdown");
}
@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.shutdown");
}
}