Add restart command: This needs your server to automatically restart on close
This commit is contained in:
parent
94efd2e228
commit
043911dc99
2 changed files with 42 additions and 0 deletions
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
41
src/main/java/de/strifel/VTools/commands/CommandRestart.java
Normal file
41
src/main/java/de/strifel/VTools/commands/CommandRestart.java
Normal 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");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue