Skip to content

CommandBase

Package: com.hypixel.hytale.server.core.command.system.basecommands

Synchronous command base class. Wraps execute(CommandContext) to call executeSync(CommandContext) and return null (no future). Most simple commands extend this class.

public abstract class CommandBase extends AbstractCommand
public CommandBase(@Nonnull String name, @Nonnull String description)

Standard constructor with command name and description translation key.

public CommandBase(@Nonnull String name, @Nonnull String description, boolean requiresConfirmation)

Constructor with confirmation flag — adds a --confirm flag that must be provided.

public CommandBase(@Nonnull String description)

Description-only constructor for usage variant commands.

protected abstract void executeSync(@Nonnull CommandContext var1);

Implement this to define the command’s behavior. Called synchronously on ForkJoinPool.commonPool(). Use CommandContext to access parsed arguments, the sender, and send responses.

@Nullable
@Override
protected final CompletableFuture<Void> execute(@Nonnull CommandContext context) {
this.executeSync(context);
return null;
}

The execute() method is final — it delegates to executeSync() and returns null, signaling synchronous completion to the command dispatcher.

public class KickCommand extends CommandBase {
private final RequiredArg<PlayerRef> playerArg;
public KickCommand() {
super("kick", "server.commands.kick.description");
this.playerArg = withRequiredArg("player", "server.commands.kick.player", ArgumentType.PLAYER_REF);
}
@Override
protected void executeSync(@Nonnull CommandContext context) {
PlayerRef player = context.get(playerArg);
player.disconnect(Message.raw("Kicked by " + context.sender().getDisplayName()));
}
}