Response handlers
This page explains how to use response handlers, which process the return values of command methods, enabling custom handling of command outputs.
Using the ResponseHandler Interface
ResponseHandler InterfaceExample: Handling Adventure's Component Type
Component TypeCustom Response Handler
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
public class ComponentResponseHandler implements ResponseHandler<BukkitCommandActor, Component> {
@Override
public void handleResponse(Component response, ExecutionContext<BukkitCommandActor> context) {
// Get the sender from the command context
var sender = context.actor().sender();
// Send the Component response to the sender
sender.sendMessage(response);
}
}import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.TextColor
class ComponentResponseHandler : ResponseHandler<CommandActor, Component> {
override fun handleResponse(response: Component?, context: ExecutionContext<CommandActor>) {
// Get the sender from the command context
val sender = context.actor().sender()
// Send the Component response to the sender
sender.sendMessage(response)
}
}Registering the Handler
Example Command Method
Dynamic Response Handlers with ResponseHandler.Factory
Interface Method
Example: Handling Optional<T>
Optional<T>Explanation
Last updated
Was this helpful?