Check subcommand perms, show help text on wrong sender type

#89
This commit is contained in:
Norbi Peti 2020-02-16 18:21:10 +01:00
parent c947c887a1
commit dd1f42d420
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 5 additions and 1 deletions

View file

@ -186,6 +186,7 @@ public abstract class Command2<TC extends ICommand2, TP extends Command2Sender>
params.add(cg);
else {
sender.sendMessage("§cYou need to be a " + sendertype.getSimpleName() + " to use this command.");
sender.sendMessage(sd.helpText); //Send what the command is about, could be useful for commands like /member where some subcommands aren't player-only
return;
}
val paramArr = sd.method.getParameters();

View file

@ -63,8 +63,11 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
if (command == null) return true; //Allow viewing the command - it doesn't do anything anyway
String pg;
boolean p = true;
var cmdperm = "chroma.command." + command.getCommandPath().replace(' ', '.');
var path = getCommandPath(method.getName(), '.');
String[] perms = {
"chroma.command." + command.getCommandPath().replace(' ', '.'),
path.length() > 0 ? cmdperm + path : null,
cmdperm,
(pg = permGroup(command, method)).length() > 0 ? "chroma." + pg : null
};
for (String perm : perms) {