Permission and config improvements, fixes #66

Merged
NorbiPeti merged 13 commits from dev into master 2019-06-06 18:39:52 +00:00
3 changed files with 13 additions and 1 deletions
Showing only changes of commit 4132a33037 - Show all commits

View file

@ -54,7 +54,7 @@ public abstract class Command2<TC extends ICommand2, TP extends Command2Sender>
/**
* The main permission which allows using this command (individual access can be still granted with "thorpe.command.X").
* Used to be "tbmc.admin"
* Used to be "tbmc.admin". The {@link #MOD_GROUP} is provided to use with this.
*/
String permGroup() default ""; //TODO
}

View file

@ -2,6 +2,9 @@ package buttondevteam.lib.chat;
import buttondevteam.core.MainPlugin;
import lombok.val;
import org.bukkit.Bukkit;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import java.util.function.Function;
@ -9,12 +12,15 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> {
@Override
public void registerCommand(ICommand2MC command) {
super.registerCommand(command, '/');
Bukkit.getPluginManager().addPermission(new Permission("thorpe.command." + command.getCommandPath().replace(' ', '.'),
modOnly(command) ? PermissionDefault.OP : PermissionDefault.TRUE)); //Allow commands by default, unless it's mod only - TODO: Test
}
@Override
public boolean hasPermission(Command2MCSender sender, ICommand2MC command) {
return modOnly(command)
? MainPlugin.permission.has(sender.getSender(), "tbmc.admin") //TODO: Change when groups are implemented
//: MainPlugin.permission.has(sender.getSender(), permGroup()) - TODO: Check for subcommands (permGroup)
: MainPlugin.permission.has(sender.getSender(), "thorpe.command." + command.getCommandPath().replace(' ', '.'));
}

View file

@ -44,4 +44,10 @@ public @interface CommandClass {
* @return The help text
*/
String[] helpText() default {};
/**
* The main permission which allows using this command (individual access can be still granted with "thorpe.command.X").
* Used to be "tbmc.admin"
*/
String permGroup() default ""; //TODO: A single annotation instead of these two
}