2323//
2424package org .incendo .cloud .help ;
2525
26+ import io .leangen .geantyref .GenericTypeReflector ;
2627import java .util .Collections ;
2728import java .util .HashSet ;
2829import java .util .LinkedList ;
@@ -122,8 +123,7 @@ public StandardHelpHandler(
122123 .map (command -> CommandEntry .of (command , this .commandManager .commandSyntaxFormatter ()
123124 .apply (query .sender (), command .components (), null )))
124125 .sorted ()
125- .filter (entry -> this .commandManager .testPermission (query .sender (),
126- entry .command ().commandPermission ()).allowed ())
126+ .filter (entry -> this .isAllowed (query .sender (), entry .command ()))
127127 .collect (Collectors .toList ())
128128 );
129129 }
@@ -143,7 +143,7 @@ public StandardHelpHandler(
143143
144144 if (head .component () != null && head .command () != null ) {
145145 if (head .isLeaf () || index == queryFragments .size ()) {
146- if (this .commandManager . testPermission (query .sender (), head .command (). commandPermission ()). allowed ( )) {
146+ if (this .isAllowed (query .sender (), head .command ())) {
147147 return VerboseCommandResult .of (
148148 query ,
149149 CommandEntry .of (
@@ -193,8 +193,7 @@ public StandardHelpHandler(
193193
194194 final List <CommandComponent <C >> traversedNodesSub = new LinkedList <>(traversedNodes );
195195 if (child .component () == null || child .command () == null
196- || this .commandManager .testPermission (query .sender (),
197- child .command ().commandPermission ()).allowed ()
196+ || this .isAllowed (query .sender (), child .command ())
198197 ) {
199198 traversedNodesSub .add (child .component ());
200199 childSuggestions .add (this .commandManager .commandSyntaxFormatter ()
@@ -221,7 +220,7 @@ public StandardHelpHandler(
221220 return this .commandManager .commands ()
222221 .stream ()
223222 .filter (this .commandFilter )
224- .filter (command -> this .commandManager . testPermission (sender , command . commandPermission ()). allowed ( ))
223+ .filter (command -> this .isAllowed (sender , command ))
225224 .map (command -> CommandEntry .of (
226225 command ,
227226 this .commandManager .commandSyntaxFormatter ()
@@ -230,6 +229,15 @@ public StandardHelpHandler(
230229 .collect (Collectors .toList ());
231230 }
232231
232+ private boolean isAllowed (final C sender , final Command <C > command ) {
233+ if (command .senderType ().isPresent ()) {
234+ if (!GenericTypeReflector .isSuperType (command .senderType ().get ().getType (), sender .getClass ())) {
235+ return false ;
236+ }
237+ }
238+ return this .commandManager .testPermission (sender , command .commandPermission ()).allowed ();
239+ }
240+
233241 /**
234242 * Checks using the predicate whether a command node or one of its children is visible
235243 *
0 commit comments