Interface CommandAbstractionApi

All Known Subinterfaces:
ModdedCommandAbstractionApi
All Known Implementing Classes:
CommandAbstractionImpl

public interface CommandAbstractionApi
Provides some abstractions for dealing with commands.
Mostly for internal use for the config command.

An Object is used as the generic type for the argument builders, but the implementations (literalImpl(String) and argumentImpl(String, ArgumentType)) will create them with platform-specific command sources.
This way, the methods here can be called with a context containing with the generic Object and implementations will cast that to the platform-specific command sources for implementing the methods.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> com.mojang.brigadier.builder.RequiredArgumentBuilder<Object,T>
    argument(String name, com.mojang.brigadier.arguments.ArgumentType<T> type)
    Creates a RequiredArgumentBuilder for the current platform specific command source and provided ArgumentType.
    <T> com.mojang.brigadier.builder.RequiredArgumentBuilder<?,T>
    argumentImpl(String name, com.mojang.brigadier.arguments.ArgumentType<T> type)
     
    static boolean
    Checks whether the provided command source is executed by a player.
    boolean
     
    static boolean
    isAdmin(Object source)
    Checks whether the provided command source has operator permissions or is the host of a singleplayer server.
    static boolean
    isHost(Object source)
    Checks whether the provided command source is the host of a singleplayer server.
    boolean
     
    static boolean
    isOp(Object source)
    Checks whether the provided command source has operator permissions.
    boolean
    isOpImpl(Object source)
     
    static com.mojang.brigadier.builder.LiteralArgumentBuilder<Object>
    Creates a LiteralArgumentBuilder for the current platform specific command source.
    com.mojang.brigadier.builder.LiteralArgumentBuilder<?>
     
    static void
    sendError(com.mojang.brigadier.context.CommandContext<Object> ctx, String message)
    Sends an error message to the command source.
    static void
    sendError(com.mojang.brigadier.context.CommandContext<Object> ctx, String message, Object... args)
    Sends an error message to the command source.
    void
    sendErrorImpl(com.mojang.brigadier.context.CommandContext<Object> ctx, String message)
     
    static void
    sendMessage(com.mojang.brigadier.context.CommandContext<Object> ctx, String message)
    Sends a message to the command source.
    static void
    sendMessage(com.mojang.brigadier.context.CommandContext<Object> ctx, String message, Object... args)
    Sends a message to the command source.
    void
    sendMessageImpl(com.mojang.brigadier.context.CommandContext<Object> ctx, String message)
     
    static void
    sendText(com.mojang.brigadier.context.CommandContext<Object> ctx, MonkeyLibText text)
    Sends a MonkeyLibText to the command source.
    void
    sendTextImpl(com.mojang.brigadier.context.CommandContext<Object> ctx, MonkeyLibText text)
     
  • Field Details

  • Method Details

    • literal

      static com.mojang.brigadier.builder.LiteralArgumentBuilder<Object> literal(String name)
      Creates a LiteralArgumentBuilder for the current platform specific command source.
      Parameters:
      name - the name of the LiteralArgumentBuilder
      Returns:
      a LiteralArgumentBuilder for the current platform specific command source.
    • argument

      static <T> com.mojang.brigadier.builder.RequiredArgumentBuilder<Object,T> argument(String name, com.mojang.brigadier.arguments.ArgumentType<T> type)
      Creates a RequiredArgumentBuilder for the current platform specific command source and provided ArgumentType.
      Type Parameters:
      T - the type for the ArgumentType
      Parameters:
      name - the name of the RequiredArgumentBuilder
      type - the ArgumentType to use.
      Returns:
      a RequiredArgumentBuilder for the current platform specific command source and provided ArgumentType.
    • sendMessage

      static void sendMessage(com.mojang.brigadier.context.CommandContext<Object> ctx, String message, Object... args)
      Sends a message to the command source.
      Parameters:
      ctx - the CommandContext to get the current-platform-specific command source from.
      message - the message to send, formatted using args and String.formatted(Object...)
      args - the args for formatting the message using String.formatted(Object...)
    • sendMessage

      static void sendMessage(com.mojang.brigadier.context.CommandContext<Object> ctx, String message)
      Sends a message to the command source.
      Parameters:
      ctx - the CommandContext to get the current-platform-specific command source from.
      message - the message to send
    • sendError

      static void sendError(com.mojang.brigadier.context.CommandContext<Object> ctx, String message, Object... args)
      Sends an error message to the command source.
      Parameters:
      ctx - the CommandContext to get the current-platform-specific command source from.
      message - the error message to send, formatted using String.formatted(Object...) with the provided args
      args - the args for formatting the error message using String.formatted(Object...)
    • sendError

      static void sendError(com.mojang.brigadier.context.CommandContext<Object> ctx, String message)
      Sends an error message to the command source.
      Parameters:
      ctx - the CommandContext to get the current-platform-specific command source from.
      message - the error message to send
    • sendText

      static void sendText(com.mojang.brigadier.context.CommandContext<Object> ctx, MonkeyLibText text)
      Sends a MonkeyLibText to the command source.
      Parameters:
      ctx - the CommandContext to get the current-platform-specific command source from.
      text - the MonkeyLibText to send
    • executedByPlayer

      static boolean executedByPlayer(Object source)
      Checks whether the provided command source is executed by a player.
      Parameters:
      source - the current-platform-specific command source.
      Returns:
      whether the provided command source is executed by a player.
    • isAdmin

      static boolean isAdmin(Object source)
      Checks whether the provided command source has operator permissions or is the host of a singleplayer server.
      This returns true for singleplayer hosts even when cheats are disabled.
      Parameters:
      source - the current-platform-specific command source.
      Returns:
      whether the provided command source has operator permissions or is the host of a singleplayer server
      See Also:
    • isOp

      static boolean isOp(Object source)
      Checks whether the provided command source has operator permissions.
      Parameters:
      source - the current-platform-specific command source.
      Returns:
      whether the provided command source has operator permissions
      See Also:
    • isHost

      static boolean isHost(Object source)
      Checks whether the provided command source is the host of a singleplayer server.
      Unlike isOp(Object), this method returns true even when cheats aren't enabled.
      Parameters:
      source - the current-platform-specific command source.
      Returns:
      whether the provided command source is the host of a singleplayer server
      See Also:
    • literalImpl

      @Internal com.mojang.brigadier.builder.LiteralArgumentBuilder<?> literalImpl(String name)
    • argumentImpl

      @Internal <T> com.mojang.brigadier.builder.RequiredArgumentBuilder<?,T> argumentImpl(String name, com.mojang.brigadier.arguments.ArgumentType<T> type)
    • sendMessageImpl

      @Internal void sendMessageImpl(com.mojang.brigadier.context.CommandContext<Object> ctx, String message)
    • sendErrorImpl

      @Internal void sendErrorImpl(com.mojang.brigadier.context.CommandContext<Object> ctx, String message)
    • sendTextImpl

      @Internal void sendTextImpl(com.mojang.brigadier.context.CommandContext<Object> ctx, MonkeyLibText text)
    • executedByPlayerImpl

      @Internal boolean executedByPlayerImpl(Object source)
    • isOpImpl

      @Internal boolean isOpImpl(Object source)
    • isHostImpl

      @Internal boolean isHostImpl(Object source)