Skip to content

Commit

Permalink
feat: add /setmaxplayers command
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Oct 16, 2024
1 parent 9722498 commit 3bb2428
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.allaymc.server.command.defaults;

import org.allaymc.api.command.SimpleCommand;
import org.allaymc.api.command.tree.CommandTree;
import org.allaymc.api.i18n.TrKeys;
import org.allaymc.api.server.Server;

/**
* @author daoge_cmd
*/
public class SetMaxPlayersCommand extends SimpleCommand {

public SetMaxPlayersCommand() {
super("setmaxplayers", TrKeys.M_COMMANDS_SETMAXPLAYERS_DESCRIPTION);
}

@Override
public void prepareCommandTree(CommandTree tree) {
tree.getRoot()
.intNum("maxPlayers")
.exec(context -> {
int maxPlayers = context.getResult(0);
maxPlayers = Math.max(Server.getInstance().getOnlinePlayerCount(), maxPlayers);

Server.SETTINGS.genericSettings().maxClientCount(maxPlayers);
Server.getInstance().getNetworkServer().setMaxPlayerCount(maxPlayers);
context.addOutput(TrKeys.M_COMMANDS_SETMAXPLAYERS_SUCCESS, maxPlayers);

return context.success();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private void registerDefaultCommands() {
register(new ClearCommand());
register(new KillCommand());
register(new SummonCommand());
register(new SetMaxPlayersCommand());
}

@Override
Expand Down

0 comments on commit 3bb2428

Please sign in to comment.