Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void handleCommand() {
- boolean channelCorrect;
- boolean permsCorrect;
- Method[] methods = this.getClass().getMethods();
- for (Method m : methods) {
- if (m.isAnnotationPresent(CommandAnnotation.class)) {
- CommandAnnotation commandAnno = m.getAnnotation(CommandAnnotation.class);
- List<String> aliases = new ArrayList<>();
- if (m.isAnnotationPresent(AliasAnnotation.class)) {
- AliasAnnotation aliasAnno = m.getAnnotation(AliasAnnotation.class);
- aliases = new ArrayList<>(Arrays.asList(aliasAnno.alias()));
- }
- aliases.add(commandAnno.name());
- for (String s : aliases) {
- if ((Constants.PREFIX_COMMAND + s).equalsIgnoreCase(command)) {
- //init files
- if (commandAnno.requiresArgs() && args.equals("")) {
- Utility.sendMessage("Command is missing Arguments: \n" + Utility.getCommandInfo(commandAnno), channel);
- return;
- }
- if (commandAnno.type().equals(Constants.TYPE_SERVERS) || commandAnno.type().equals(Constants.TYPE_ADMIN)) {
- loadServers();
- }
- if (commandAnno.type().equals(Constants.TYPE_ROLE_SELECT) || commandAnno.type().equals(Constants.TYPE_ADMIN)) {
- loadCharacters();
- }
- if (commandAnno.type().equals(Constants.TYPE_CC) || commandAnno.type().equals(Constants.TYPE_ADMIN)) {
- loadCC();
- }
- //Logging Handling
- if (guildConfig.doLogging) {
- IChannel loggingChannel;
- if (commandAnno.doLogging() && guildConfig.getChannelTypeID(Constants.CHANNEL_ADMIN_LOG) != null) {
- loggingChannel = guild.getChannelByID(guildConfig.getChannelTypeID(Constants.CHANNEL_ADMIN_LOG));
- handleLogging(loggingChannel, commandAnno);
- } else if (guildConfig.getChannelTypeID(Constants.CHANNEL_SERVER_LOG) != null) {
- loggingChannel = guild.getChannelByID(guildConfig.getChannelTypeID(Constants.CHANNEL_SERVER_LOG));
- handleLogging(loggingChannel, commandAnno);
- }
- }
- //Channel Validation
- if (!commandAnno.channel().equals(Constants.CHANNEL_ANY)) {
- if (guildConfig.getChannelTypeID(commandAnno.channel()) == null || channel.getID().equals(guildConfig.getChannelTypeID(commandAnno.channel()))) {
- channelCorrect = true;
- } else channelCorrect = false;
- } else channelCorrect = true;
- if (guild.getOwner().equals(author) || author.getID().equals(Globals.creatorID)) {
- channelCorrect = true;
- }
- //Permission Validation
- if (channelCorrect) {
- if (!Arrays.equals(commandAnno.perms(), new Permissions[]{Permissions.SEND_MESSAGES})) {
- Permissions[] compiledPerms = new Permissions[commandAnno.perms().length];
- int permsIndex = 0;
- for (Permissions aP : commandAnno.perms()) {
- for (IRole r : author.getRolesForGuild(guild)) {
- for (Permissions p : r.getPermissions()) {
- if (aP.equals(p)) {
- compiledPerms[permsIndex] = p;
- }
- }
- }
- permsIndex++;
- }
- if (Arrays.equals(compiledPerms, commandAnno.perms())) {
- permsCorrect = true;
- } else permsCorrect = false;
- } else permsCorrect = true;
- //bypasses
- if (guild.getOwner().equals(author) || author.getID().equals(Globals.creatorID)) {
- permsCorrect = true;
- }
- //message sending
- if (channelCorrect && permsCorrect) {
- try {
- if (commandAnno.doResponseGeneral()) {
- channel = guild.getChannelByID(guildConfig.getChannelTypeID(Constants.CHANNEL_GENERAL));
- }
- Utility.sendMessage((String) m.invoke(this), channel);
- } catch (IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- }
- } else
- Utility.sendMessage(noAllowed, channel);
- } else {
- Utility.sendMessage("> Command must be performed in the " + guild.getChannelByID(guildConfig.getChannelTypeID(commandAnno.channel())).mention() + " channel.", channel);
- }
- flushFiles();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment