Package studio.mevera.imperat
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:
-
CommandSourcePrintStream
-
Field Summary
Fields inherited from interface studio.mevera.imperat.context.CommandSource
CONSOLE_UUID -
Constructor Summary
ConstructorsConstructorDescriptionConsoleCommandSource(ConsoleLogger consoleLogger) Creates a new ConsoleCommandSource that outputs to the specified PrintStream. -
Method Summary
Modifier and TypeMethodDescriptionvoidSends an error message to the console logger.booleanChecks if this command source is the console.name()Gets the name of this command source.origin()Gets the original ConsoleLogger that this ConsoleCommandSource wraps.voidSends a message to the console output stream.voidSends a warning message to the console logger.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface studio.mevera.imperat.context.CommandSource
as, uuid
-
Constructor Details
-
ConsoleCommandSource
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
Gets the name of this command source. For console sources, this is always "CONSOLE".- Specified by:
namein interfacestudio.mevera.imperat.context.CommandSource- Returns:
- "CONSOLE"
-
origin
Gets the original ConsoleLogger that this ConsoleCommandSource wraps.- Specified by:
originin interfacestudio.mevera.imperat.context.CommandSource- Returns:
- the underlying ConsoleLogger
-
reply
Sends a message to the console output stream.- Specified by:
replyin interfacestudio.mevera.imperat.context.CommandSource- Parameters:
message- the message to send
-
warn
Sends a warning message to the console logger. Warning messages are prefixed with "[WARN]".- Specified by:
warnin interfacestudio.mevera.imperat.context.CommandSource- Parameters:
message- the warning message to send
-
error
Sends an error message to the console logger. Error messages are prefixed with "[ERROR]".- Specified by:
errorin interfacestudio.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:
isConsolein interfacestudio.mevera.imperat.context.CommandSource- Returns:
- true (always, since this is a console source)
-