-
Notifications
You must be signed in to change notification settings - Fork 10
command handler
mtanksl edited this page Dec 21, 2024
·
5 revisions
Commands
can be intercepted and changed as they pass through Pipeline
of Command Handlers
before executing.
Let's intercept the PlayerSayCommand
, which occurs when any player says anything on the default chat window. If the message starts with /me
, a magic effect command is dispatched.
public class DisplayMagicEffectHandler : CommandHandler<PlayerSayCommand>
{
public override Promise Handle(Func<Promise> next, PlayerSayCommand command)
{
if (command.Message.StartsWith("/me ") && int.TryParse(command.Message.Substring(4), out int id) && id >= 1 && id <= 70)
{
return Context.AddCommand(new ShowMagicEffectCommand(command.Player, (MagicEffectType)id) );
}
return next();
}
}