23
23
//
24
24
package org .incendo .cloud .help ;
25
25
26
+ import io .leangen .geantyref .GenericTypeReflector ;
26
27
import java .util .Collections ;
27
28
import java .util .HashSet ;
28
29
import java .util .LinkedList ;
@@ -122,8 +123,7 @@ public StandardHelpHandler(
122
123
.map (command -> CommandEntry .of (command , this .commandManager .commandSyntaxFormatter ()
123
124
.apply (query .sender (), command .components (), null )))
124
125
.sorted ()
125
- .filter (entry -> this .commandManager .testPermission (query .sender (),
126
- entry .command ().commandPermission ()).allowed ())
126
+ .filter (entry -> this .isAllowed (query .sender (), entry .command ()))
127
127
.collect (Collectors .toList ())
128
128
);
129
129
}
@@ -143,7 +143,7 @@ public StandardHelpHandler(
143
143
144
144
if (head .component () != null && head .command () != null ) {
145
145
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 ())) {
147
147
return VerboseCommandResult .of (
148
148
query ,
149
149
CommandEntry .of (
@@ -193,8 +193,7 @@ public StandardHelpHandler(
193
193
194
194
final List <CommandComponent <C >> traversedNodesSub = new LinkedList <>(traversedNodes );
195
195
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 ())
198
197
) {
199
198
traversedNodesSub .add (child .component ());
200
199
childSuggestions .add (this .commandManager .commandSyntaxFormatter ()
@@ -221,7 +220,7 @@ public StandardHelpHandler(
221
220
return this .commandManager .commands ()
222
221
.stream ()
223
222
.filter (this .commandFilter )
224
- .filter (command -> this .commandManager . testPermission (sender , command . commandPermission ()). allowed ( ))
223
+ .filter (command -> this .isAllowed (sender , command ))
225
224
.map (command -> CommandEntry .of (
226
225
command ,
227
226
this .commandManager .commandSyntaxFormatter ()
@@ -230,6 +229,15 @@ public StandardHelpHandler(
230
229
.collect (Collectors .toList ());
231
230
}
232
231
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
+
233
241
/**
234
242
* Checks using the predicate whether a command node or one of its children is visible
235
243
*
0 commit comments