3737# =============================================================================
3838# >> ALL DECLARATION
3939# =============================================================================
40- __all__ = ('SUPPORTED_KINDS' ,
40+ __all__ = ('PRIVATE_COMMAND_PREFIX' ,
41+ 'SUPPORTED_KINDS' ,
4142 'ArgumentError' ,
4243 'ArgumentNumberMismatch' ,
4344 'CommandInfo' ,
6970 Parameter .VAR_POSITIONAL ,
7071)
7172
73+ PRIVATE_COMMAND_PREFIX = '/'
74+
7275
7376# =============================================================================
7477# >> GLOBAL VARIABLES
@@ -493,6 +496,28 @@ def reply(self, msg):
493496 """
494497 self .typed_command_cls .send_message (self , msg )
495498
499+ def is_private_command (self ):
500+ """Return ``True`` if it's a private command.
501+
502+ :rtype: bool
503+ """
504+ return self .command [0 ].startswith (PRIVATE_COMMAND_PREFIX )
505+
506+ @property
507+ def auto_command_return (self ):
508+ """Determine the probably most desired ``CommandReturn`` value.
509+
510+ For server commands it will always return ``CommandReturn.CONTINUE``.
511+ Client commands will always use ``CommandReturn.BLOCK``. For say
512+ commands it's determined by checking the prefix. If the command starts
513+ with a slash (``/``) it's handled as a private command. Thus,
514+ ``CommandReturn.BLOCK`` is returned. Otherwise
515+ ``CommandReturn.CONTINUE`` is used.
516+
517+ :rtype: CommandReturn
518+ """
519+ return self .typed_command_cls .get_auto_command_return (self )
520+
496521
497522# We can't integrate this into SayCommand, ServerCommand and ClientCommand,
498523# because multiple callbacks are not supported by this system (because of the
@@ -558,14 +583,16 @@ def on_command(cls, command, *args):
558583 Parse the command, clean its arguments and execute the callback.
559584 """
560585 # TODO: Translations!
561- command_info = CommandInfo (command , cls , * args )
586+ info = CommandInfo (command , cls , * args )
562587 try :
563- command_node , args = cls .parser .parse_command (
564- command_info .command )
565- result = cls .on_clean_command (command_info , command_node , args )
588+ command_node , args = cls .parser .parse_command (info .command )
589+ result = cls .on_clean_command (info , command_node , args )
566590 except ValidationError as e :
567- command_info .reply (e .message )
591+ info .reply (e .message )
568592 else :
593+ if result is None :
594+ return info .auto_command_return
595+
569596 return result
570597
571598 return CommandReturn .CONTINUE
@@ -600,6 +627,14 @@ def send_message(command_info, message):
600627 """Send a message."""
601628 raise NotImplementedError ('Needs to be implemented by a sub class.' )
602629
630+ @classmethod
631+ def get_auto_command_return (cls , info ):
632+ """Return the most desired ``CommandReturn`` value.
633+
634+ :rtype: CommandReturn
635+ """
636+ raise NotImplementedError ('Needs to be implemented by a sub class.' )
637+
603638
604639class TypedServerCommand (_TypedCommand ):
605640 """Decorator class to create typed server commands."""
@@ -611,6 +646,10 @@ class TypedServerCommand(_TypedCommand):
611646 def send_message (command_info , message ):
612647 logger .log_message (message )
613648
649+ @classmethod
650+ def get_auto_command_return (cls , info ):
651+ return CommandReturn .CONTINUE
652+
614653
615654class _TypedPlayerCommand (_TypedCommand ):
616655 """Decorator class to create typed player based commands."""
@@ -648,6 +687,10 @@ class TypedClientCommand(_TypedPlayerCommand):
648687 def send_message (command_info , message ):
649688 TextMsg (message , HudDestination .CONSOLE ).send (command_info .index )
650689
690+ @classmethod
691+ def get_auto_command_return (cls , info ):
692+ return CommandReturn .BLOCK
693+
651694
652695class TypedSayCommand (_TypedPlayerCommand ):
653696 """Decorator class to create typed say commands."""
@@ -659,6 +702,13 @@ class TypedSayCommand(_TypedPlayerCommand):
659702 def send_message (command_info , message ):
660703 SayText2 (message ).send (command_info .index )
661704
705+ @classmethod
706+ def get_auto_command_return (cls , info ):
707+ if info .is_private_command ():
708+ return CommandReturn .BLOCK
709+
710+ return CommandReturn .CONTINUE
711+
662712
663713# =============================================================================
664714# >> COMMAND ANNOTATIONS
0 commit comments