Class ConsoleCommandSource

java.lang.Object
studio.mevera.imperat.ConsoleCommandSource
All Implemented Interfaces:
studio.mevera.imperat.context.CommandSource

public class ConsoleCommandSource extends Object implements studio.mevera.imperat.context.CommandSource
A command-line interface implementation of CommandSource that wraps a PrintStream. This class provides a bridge between command-line applications and the Imperat framework, enabling console-based command execution and output.

Features:

  • Simple text-based output to any PrintStream
  • Support for console applications and CLI tools
  • Basic message formatting with prefixes for warnings and errors
  • Always represents a console source (no player distinction)

Usage Example:


 CommandLineImperat imperat = CommandLineImperat.builder(System.in)
     .build();

 // The ConsoleCommandSource will automatically use System.out for output
 
Since:
1.0
See Also:
  • Field Summary

    Fields inherited from interface studio.mevera.imperat.context.CommandSource

    CONSOLE_UUID
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new ConsoleCommandSource that outputs to the specified PrintStream.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    error(String message)
    Sends an error message to the console logger.
    boolean
    Checks if this command source is the console.
    Gets the name of this command source.
    Gets the original ConsoleLogger that this ConsoleCommandSource wraps.
    void
    reply(String message)
    Sends a message to the console output stream.
    void
    warn(String message)
    Sends a warning message to the console logger.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface studio.mevera.imperat.context.CommandSource

    as, uuid
  • Constructor Details

    • ConsoleCommandSource

      public ConsoleCommandSource(ConsoleLogger consoleLogger)
      Creates a new ConsoleCommandSource that outputs to the specified PrintStream.
      Parameters:
      consoleLogger - the logger to write output to (e.g., ConsoleLogger.SYSTEM)
  • Method Details

    • name

      public String name()
      Gets the name of this command source. For console sources, this is always "CONSOLE".
      Specified by:
      name in interface studio.mevera.imperat.context.CommandSource
      Returns:
      "CONSOLE"
    • origin

      public ConsoleLogger origin()
      Gets the original ConsoleLogger that this ConsoleCommandSource wraps.
      Specified by:
      origin in interface studio.mevera.imperat.context.CommandSource
      Returns:
      the underlying ConsoleLogger
    • reply

      public void reply(String message)
      Sends a message to the console output stream.
      Specified by:
      reply in interface studio.mevera.imperat.context.CommandSource
      Parameters:
      message - the message to send
    • warn

      public void warn(String message)
      Sends a warning message to the console logger. Warning messages are prefixed with "[WARN]".
      Specified by:
      warn in interface studio.mevera.imperat.context.CommandSource
      Parameters:
      message - the warning message to send
    • error

      public void error(String message)
      Sends an error message to the console logger. Error messages are prefixed with "[ERROR]".
      Specified by:
      error in interface studio.mevera.imperat.context.CommandSource
      Parameters:
      message - the error message to send
    • isConsole

      public boolean isConsole()
      Checks if this command source is the console. For ConsoleCommandSource, this always returns true.
      Specified by:
      isConsole in interface studio.mevera.imperat.context.CommandSource
      Returns:
      true (always, since this is a console source)