#2568: Check permissions for inject_commands

This commit is contained in:
md_5
2018-12-21 09:50:54 +11:00
parent 14fbe6178f
commit a47b803385
3 changed files with 19 additions and 7 deletions

View File

@@ -51,4 +51,15 @@ public abstract class Command
* @param args arguments used to invoke this command
*/
public abstract void execute(CommandSender sender, String[] args);
/**
* Check if this command can be executed by the given sender.
*
* @param sender the sender to check
* @return whether the sender can execute this
*/
public boolean hasPermission(CommandSender sender)
{
return permission == null || permission.isEmpty() || sender.hasPermission( permission );
}
}

View File

@@ -144,8 +144,7 @@ public class PluginManager
return false;
}
String permission = command.getPermission();
if ( permission != null && !permission.isEmpty() && !sender.hasPermission( permission ) )
if ( !command.hasPermission( sender ) )
{
if ( tabResults == null )
{
@@ -435,8 +434,8 @@ public class PluginManager
*
* @return commands
*/
public Collection<String> getCommands()
public Collection<Map.Entry<String, Command>> getCommands()
{
return Collections.unmodifiableCollection( commandMap.keySet() );
return Collections.unmodifiableCollection( commandMap.entrySet() );
}
}