Multiple fixes/improvements to command system

This commit is contained in:
Luck 2016-06-28 18:07:55 +01:00
parent ebbc0511bf
commit 776ec45701
12 changed files with 55 additions and 8 deletions

View File

@ -12,7 +12,7 @@ class MainCommand extends Command {
private final CommandManager manager;
public MainCommand(CommandManager manager) {
super("luckpermsbungee", "luckperms.use", "bperms", "lpb", "bpermissions", "bp", "bperm");
super("luckpermsbungee", null, "bperms", "lpb", "bpermissions", "bp", "bperm");
this.manager = manager;
}

View File

@ -68,11 +68,9 @@ public class CommandManager {
if (args.size() == 0) {
Util.sendPluginMessage(sender, "&6Running &bLuckPerms " + plugin.getVersion() + "&6.");
if (sender.hasPermission("luckperms.info")) {
for (MainCommand c : mainCommands) {
Util.sendPluginMessage(sender, "&e-> &d" + c.getUsage());
}
}
mainCommands.stream()
.filter(c -> c.canUse(sender))
.forEach(c -> Util.sendPluginMessage(sender, "&e-> &d" + c.getUsage()));
} else {
String c = args.get(0);

View File

@ -39,4 +39,13 @@ public abstract class MainCommand {
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
}
}
protected boolean canUse(Sender sender) {
for (SubCommand sc : getSubCommands()) {
if (sc.isAuthorized(sender)) {
return true;
}
}
return false;
}
}

View File

@ -24,7 +24,7 @@ public abstract class SubCommand {
}
public boolean isAuthorized(Sender sender) {
return sender.hasPermission(permission);
return sender.hasPermission(permission) || sender.hasPermission("luckperms.*");
}
public void sendUsage(Sender sender) {

View File

@ -48,4 +48,9 @@ public class CreateGroupCommand extends MainCommand {
public List<SubCommand> getSubCommands() {
return new ArrayList<>();
}
@Override
protected boolean canUse(Sender sender) {
return sender.hasPermission("luckperms.creategroup") || sender.hasPermission("luckperms.*");
}
}

View File

@ -60,4 +60,9 @@ public class DeleteGroupCommand extends MainCommand {
public List<SubCommand> getSubCommands() {
return new ArrayList<>();
}
@Override
protected boolean canUse(Sender sender) {
return sender.hasPermission("luckperms.deletegroup") || sender.hasPermission("luckperms.*");
}
}

View File

@ -15,6 +15,11 @@ public abstract class GroupSubCommand extends SubCommand {
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args);
@Override
public boolean isAuthorized(Sender sender) {
return sender.hasPermission(getPermission()) || sender.hasPermission("luckperms.group.*") || sender.hasPermission("luckperms.*");
}
protected void saveGroup(Group group, Sender sender, LuckPermsPlugin plugin) {
plugin.getDatastore().saveGroup(group, success -> {
if (success) {

View File

@ -32,6 +32,11 @@ public class ListGroupsCommand extends MainCommand {
@Override
public List<SubCommand> getSubCommands() {
return null;
return new ArrayList<>();
}
@Override
protected boolean canUse(Sender sender) {
return sender.hasPermission("luckperms.listgroups") || sender.hasPermission("luckperms.*");
}
}

View File

@ -31,4 +31,9 @@ public class DebugCommand extends MainCommand {
public List<? extends SubCommand> getSubCommands() {
return new ArrayList<>();
}
@Override
protected boolean canUse(Sender sender) {
return sender.hasPermission("luckperms.debug") || sender.hasPermission("luckperms.*");
}
}

View File

@ -30,4 +30,9 @@ public class InfoCommand extends MainCommand {
public List<? extends SubCommand> getSubCommands() {
return new ArrayList<>();
}
@Override
protected boolean canUse(Sender sender) {
return sender.hasPermission("luckperms.info") || sender.hasPermission("luckperms.*");
}
}

View File

@ -29,4 +29,9 @@ public class SyncCommand extends MainCommand {
public List<? extends SubCommand> getSubCommands() {
return new ArrayList<>();
}
@Override
protected boolean canUse(Sender sender) {
return sender.hasPermission("luckperms.sync") || sender.hasPermission("luckperms.*");
}
}

View File

@ -15,6 +15,11 @@ public abstract class UserSubCommand extends SubCommand {
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args);
@Override
public boolean isAuthorized(Sender sender) {
return sender.hasPermission(getPermission()) || sender.hasPermission("luckperms.user.*") || sender.hasPermission("luckperms.*");
}
protected void saveUser(User user, Sender sender, LuckPermsPlugin plugin) {
user.refreshPermissions();