@@ -93,49 +93,63 @@ def _get_client_callback(self):
9393
9494
9595class FeatureCommand (BaseFeatureCommand ):
96- def _get_public_chat_callback (self ):
97- def public_chat_callback (command_info ):
98- client = clients [command_info .index ]
96+ def _execute (self , command_info ):
97+ client = clients [command_info .index ]
9998
100- # Sync execution to avoid issuer replacement if the feature itself
101- # is going to execute any commands
102- client .sync_execution (self .feature .execute , (client , ))
99+ # Sync execution to avoid issuer replacement if the feature itself
100+ # is going to execute any commands
101+ client .sync_execution (self .feature .execute , (client ,))
103102
103+ def _get_public_chat_callback (self ):
104+ def public_chat_callback (command_info ):
105+ self ._execute (command_info )
104106 return CommandReturn .CONTINUE
105107
106108 return public_chat_callback
107109
108110 def _get_private_chat_callback (self ):
109111 def private_chat_callback (command_info ):
110- client = clients [command_info .index ]
111- client .sync_execution (self .feature .execute , (client ,))
112+ self ._execute (command_info )
112113 return CommandReturn .BLOCK
113114
114115 return private_chat_callback
115116
116117 def _get_client_callback (self ):
117118 def client_callback (command_info ):
118- client = clients [command_info .index ]
119- client .sync_execution (self .feature .execute , (client ,))
119+ self ._execute (command_info )
120120
121121 return client_callback
122122
123123
124124class PlayerBasedFeatureCommand (BaseFeatureCommand ):
125- def _get_public_chat_callback (self ):
126- def public_chat_callback (
127- command_info , filter_str :str , filter_args :str = "" ):
125+ def __init__ (self , commands , feature , deny_mass_execution = False ):
126+ super ().__init__ (commands , feature )
127+
128+ self ._deny_mass_execution = deny_mass_execution
129+
130+ def _execute (self , command_info , filter_str , filter_args ):
131+ client = clients [command_info .index ]
128132
129- client = clients [command_info .index ]
133+ players = []
134+ for player in iter_filter_targets (
135+ filter_str , filter_args , client .player ):
130136
131- for player in iter_filter_targets (
132- filter_str , filter_args , client . player ):
137+ if not self . feature . filter ( client , player ):
138+ continue
133139
134- if not self .feature .filter (client , player ):
135- continue
140+ players .append (player )
136141
137- client .sync_execution (self .feature .execute , (client , player ))
142+ if self ._deny_mass_execution and len (players ) > 1 :
143+ return
138144
145+ for player in players :
146+ client .sync_execution (self .feature .execute , (client , player ))
147+
148+ def _get_public_chat_callback (self ):
149+ def public_chat_callback (
150+ command_info , filter_str :str , filter_args :str = "" ):
151+
152+ self ._execute (command_info , filter_str , filter_args )
139153 return CommandReturn .CONTINUE
140154
141155 return public_chat_callback
@@ -144,30 +158,13 @@ def _get_private_chat_callback(self):
144158 def private_chat_callback (
145159 command_info , filter_str :str , filter_args :str = "" ):
146160
147- client = clients [command_info .index ]
148-
149- for player in iter_filter_targets (
150- filter_str , filter_args , client .player ):
151-
152- if not self .feature .filter (client , player ):
153- continue
154-
155- client .sync_execution (self .feature .execute , (client , player ))
156-
161+ self ._execute (command_info , filter_str , filter_args )
157162 return CommandReturn .BLOCK
158163
159164 return private_chat_callback
160165
161166 def _get_client_callback (self ):
162167 def client_callback (command_info , filter_str :str , filter_args :str = "" ):
163- client = clients [command_info .index ]
164-
165- for player in iter_filter_targets (
166- filter_str , filter_args , client .player ):
167-
168- if not self .feature .filter (client , player ):
169- continue
170-
171- client .sync_execution (self .feature .execute , (client , player ))
168+ self ._execute (command_info , filter_str , filter_args )
172169
173170 return client_callback
0 commit comments