From 043911dc991d4d282a23e5c88ec24800d4b375a7 Mon Sep 17 00:00:00 2001 From: Felix Date: Thu, 17 Oct 2019 14:33:04 +0200 Subject: [PATCH] Add restart command: This needs your server to automatically restart on close --- src/main/java/de/strifel/VTools/VTools.java | 1 + .../VTools/commands/CommandRestart.java | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/java/de/strifel/VTools/commands/CommandRestart.java diff --git a/src/main/java/de/strifel/VTools/VTools.java b/src/main/java/de/strifel/VTools/VTools.java index 31f07ff..4947742 100644 --- a/src/main/java/de/strifel/VTools/VTools.java +++ b/src/main/java/de/strifel/VTools/VTools.java @@ -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"); } } diff --git a/src/main/java/de/strifel/VTools/commands/CommandRestart.java b/src/main/java/de/strifel/VTools/commands/CommandRestart.java new file mode 100644 index 0000000..e19cce5 --- /dev/null +++ b/src/main/java/de/strifel/VTools/commands/CommandRestart.java @@ -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 suggest(CommandSource source, @NonNull String[] currentArgs) { + return new ArrayList(); + } + + @Override + public boolean hasPermission(CommandSource source, @NonNull String[] args) { + return source.hasPermission("vtools.shutdown"); + } +}