Introducing the Permission System
This commit is contained in:
parent
deb59caad2
commit
dde3848d37
4 changed files with 69 additions and 17 deletions
|
|
@ -4,20 +4,64 @@
|
|||
|
||||
package com.bbn.hadder.commands;
|
||||
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
|
||||
public enum Perm {
|
||||
|
||||
BOT_OWNER() {
|
||||
public boolean check() {
|
||||
return true;
|
||||
@Override
|
||||
public boolean check(CommandEvent commandEvent) {
|
||||
return commandEvent.getConfig().getOwners().contains(commandEvent.getAuthor().getId());
|
||||
}
|
||||
},
|
||||
MANAGE_MESSAGES,
|
||||
EMBED_MESSAGES,
|
||||
BAN_MEMBERS,
|
||||
KICK_MEMBERS,
|
||||
MANAGE_SERVER,
|
||||
MANAGE_ROLES,
|
||||
CHANGE_NICKNAME,
|
||||
ADMIN_PERMISSIONS
|
||||
MANAGE_MESSAGES {
|
||||
@Override
|
||||
public boolean check(CommandEvent commandEvent) {
|
||||
return commandEvent.getMember().hasPermission(Permission.MESSAGE_MANAGE);
|
||||
}
|
||||
},
|
||||
EMBED_MESSAGES {
|
||||
@Override
|
||||
public boolean check(CommandEvent commandEvent) {
|
||||
return commandEvent.getMember().hasPermission(Permission.MESSAGE_EMBED_LINKS);
|
||||
}
|
||||
},
|
||||
BAN_MEMBERS {
|
||||
@Override
|
||||
public boolean check(CommandEvent commandEvent) {
|
||||
return commandEvent.getMember().hasPermission(Permission.BAN_MEMBERS);
|
||||
}
|
||||
},
|
||||
KICK_MEMBERS {
|
||||
@Override
|
||||
public boolean check(CommandEvent commandEvent) {
|
||||
return commandEvent.getMember().hasPermission(Permission.KICK_MEMBERS);
|
||||
}
|
||||
},
|
||||
MANAGE_SERVER {
|
||||
@Override
|
||||
public boolean check(CommandEvent commandEvent) {
|
||||
return commandEvent.getMember().hasPermission(Permission.MANAGE_SERVER);
|
||||
}
|
||||
},
|
||||
MANAGE_ROLES {
|
||||
@Override
|
||||
public boolean check(CommandEvent commandEvent) {
|
||||
return commandEvent.getMember().hasPermission(Permission.MANAGE_ROLES);
|
||||
}
|
||||
},
|
||||
CHANGE_NICKNAME {
|
||||
@Override
|
||||
public boolean check(CommandEvent commandEvent) {
|
||||
return commandEvent.getMember().hasPermission(Permission.NICKNAME_CHANGE);
|
||||
}
|
||||
},
|
||||
ADMIN_PERMISSIONS {
|
||||
@Override
|
||||
public boolean check(CommandEvent commandEvent) {
|
||||
return commandEvent.getMember().hasPermission(Permission.ADMINISTRATOR);
|
||||
}
|
||||
};
|
||||
|
||||
public abstract boolean check(CommandEvent commandEvent);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@
|
|||
package com.bbn.hadder.commands;
|
||||
|
||||
public @interface Perms {
|
||||
Perm[] perms() default {};
|
||||
Perm[] value() default {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.bbn.hadder.commands.owner;
|
|||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.commands.Perm;
|
||||
import com.bbn.hadder.commands.Perms;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import com.bbn.hadder.utils.MessageEditor.MessageType;
|
||||
|
|
@ -12,7 +13,7 @@ import static com.bbn.hadder.commands.Perm.BOT_OWNER;
|
|||
* @author Skidder / GregTCLTK
|
||||
*/
|
||||
|
||||
@Perms(perms = BOT_OWNER)
|
||||
@Perms(Perm.BOT_OWNER)
|
||||
public class TestCommand implements Command {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.bbn.hadder.core;
|
|||
import com.bbn.hadder.Rethink;
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.commands.Perm;
|
||||
import com.bbn.hadder.commands.Perms;
|
||||
import com.bbn.hadder.commands.general.HelpCommand;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
|
@ -30,11 +32,16 @@ public class CommandHandler {
|
|||
.replaceFirst(prefix, "").replaceFirst(invoke, "");
|
||||
if (argString.startsWith(" ")) argString = argString.replaceFirst(" ", "");
|
||||
String[] args = argString.split(" ");
|
||||
if (args.length>0&&args[0].equals("")) args = new String[0];
|
||||
cmd.executed(args,
|
||||
new CommandEvent(event.getJDA(), event.getResponseNumber(), event.getMessage(), rethink,
|
||||
config, this, helpCommand, new MessageEditor(rethink, event.getAuthor()))
|
||||
);
|
||||
if (args.length > 0 && args[0].equals("")) args = new String[0];
|
||||
|
||||
CommandEvent commandEvent = new CommandEvent(event.getJDA(), event.getResponseNumber(), event.getMessage(), rethink,
|
||||
config, this, helpCommand, new MessageEditor(rethink, event.getAuthor()));
|
||||
|
||||
for (Perm perm : ((Perms) cmd).value()) {
|
||||
if (!perm.check(commandEvent)) return;
|
||||
}
|
||||
|
||||
cmd.executed(args, commandEvent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue