Package studio.mevera.imperat
Class BukkitCommandSource
java.lang.Object
studio.mevera.imperat.BukkitCommandSource
- All Implemented Interfaces:
studio.mevera.imperat.adventure.AdventureCommandSource,studio.mevera.imperat.context.CommandSource
public class BukkitCommandSource
extends Object
implements studio.mevera.imperat.adventure.AdventureCommandSource
A Bukkit-specific implementation of
CommandSource that wraps a Bukkit CommandSender.
This class provides a bridge between Bukkit's command system and the Imperat framework,
supporting both legacy Bukkit messaging and modern Adventure API components.
Features:
- Support for both Player and Console command sources
- Adventure API integration for rich text messaging
- Legacy color code support for backward compatibility
- Type-safe casting to Player or CommandSender
- UUID-based identification for players
Usage Example:
// In a command method
@Command("teleport")
public void teleport(BukkitCommandSource source, Player target) {
if (source.isConsole()) {
source.error("Only players can teleport!");
return;
}
Player player = source.asPlayer();
// ... teleport logic
}
- Since:
- 1.0
- See Also:
-
CommandSourceCommandSender
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final studio.mevera.imperat.adventure.AdventureProvider<org.bukkit.command.CommandSender>protected final org.bukkit.command.CommandSenderFields inherited from interface studio.mevera.imperat.context.CommandSource
CONSOLE_UUID -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBukkitCommandSource(org.bukkit.command.CommandSender sender, studio.mevera.imperat.adventure.AdventureProvider<org.bukkit.command.CommandSender> provider) Creates a new BukkitCommandSource wrapping the specified CommandSender. -
Method Summary
Modifier and TypeMethodDescription<T> TCasts the origin command sender to the specified class type.org.bukkit.entity.PlayerasPlayer()Casts this source to a Player, if possible.booleanvoidSends an error message to the command sender.studio.mevera.imperat.adventure.AdventureProvider<org.bukkit.command.CommandSender>Gets the Adventure provider used for rich text messaging.inthashCode()booleanChecks if the command source is from the console.name()Gets the name of this command source.org.bukkit.command.CommandSenderorigin()Gets the original command sender instance.voidReplies to the command sender with a string message.voidreply(net.kyori.adventure.text.ComponentLike component) Replies to the command sender with a component message.uuid()Gets the UUID of the command source.voidSends a warning message to the command sender.
-
Field Details
-
sender
protected final org.bukkit.command.CommandSender sender -
provider
protected final studio.mevera.imperat.adventure.AdventureProvider<org.bukkit.command.CommandSender> provider
-
-
Constructor Details
-
BukkitCommandSource
protected BukkitCommandSource(org.bukkit.command.CommandSender sender, studio.mevera.imperat.adventure.AdventureProvider<org.bukkit.command.CommandSender> provider) Creates a new BukkitCommandSource wrapping the specified CommandSender.- Parameters:
sender- the Bukkit CommandSender to wrap (player or console)provider- the Adventure provider for rich text support
-
-
Method Details
-
getProvider
public studio.mevera.imperat.adventure.AdventureProvider<org.bukkit.command.CommandSender> getProvider()Gets the Adventure provider used for rich text messaging.- Returns:
- the Adventure provider instance
-
name
Gets the name of this command source.- Specified by:
namein interfacestudio.mevera.imperat.context.CommandSource- Returns:
- the player name if this is a player, or "CONSOLE" if this is the console
-
origin
public org.bukkit.command.CommandSender origin()Gets the original command sender instance. This can be used to access Bukkit's API directly if needed.- Specified by:
originin interfacestudio.mevera.imperat.context.CommandSource- Returns:
- the original CommandSender instance
-
asPlayer
public org.bukkit.entity.Player asPlayer()Casts this source to a Player, if possible.- Returns:
- the Player instance, or null if this source is not a player
-
reply
Replies to the command sender with a string message. This method supports legacy color codes (&f) for backward compatibility.- Specified by:
replyin interfacestudio.mevera.imperat.context.CommandSource- Parameters:
message- the message to send
-
warn
Sends a warning message to the command sender. Warning messages are prefixed with yellow color.- Specified by:
warnin interfacestudio.mevera.imperat.context.CommandSource- Parameters:
message- the warning message
-
error
Sends an error message to the command sender. Error messages are prefixed with red color.- Specified by:
errorin interfacestudio.mevera.imperat.context.CommandSource- Parameters:
message- the error message
-
reply
public void reply(net.kyori.adventure.text.ComponentLike component) Replies to the command sender with a component message. This method should be used for sending rich text messages using the Adventure API.- Specified by:
replyin interfacestudio.mevera.imperat.adventure.AdventureCommandSource- Parameters:
component- the message component
-
isConsole
public boolean isConsole()Checks if the command source is from the console.- Specified by:
isConsolein interfacestudio.mevera.imperat.context.CommandSource- Returns:
- true if this source is from the console, false if from a player
-
uuid
Gets the UUID of the command source. For console sources, a constant UUID is returned.- Specified by:
uuidin interfacestudio.mevera.imperat.context.CommandSource- Returns:
- the UUID of the source
-
as
Casts the origin command sender to the specified class type. This method is type-safe and avoids the need for explicit casting.- Specified by:
asin interfacestudio.mevera.imperat.context.CommandSource- Type Parameters:
T- the type parameter- Parameters:
clazz- the class to cast to- Returns:
- the casted instance
-
equals
-
hashCode
public int hashCode()
-