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