package stream.flarebot.flarebot.commands.general;

import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.entities.Guild;
import stream.flarebot.flarebot.FlareBot;
import stream.flarebot.flarebot.commands.Command;
import stream.flarebot.flarebot.commands.CommandType;
import stream.flarebot.flarebot.objects.GuildWrapper;
import stream.flarebot.flarebot.permissions.PerGuildPermissions;
import stream.flarebot.flarebot.util.MessageUtils;

public class CommandUsageCommand implements Command {

    @Override
    public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
        if (args.length == 0) {
            MessageUtils.sendUsage(this, channel, sender, args);
        } else {
            Command c = FlareBot.getInstance().getCommand(args[0], sender);
            if (!canRunCommand(c, sender))
                MessageUtils.sendErrorMessage("That is not a command!", channel);
            else
                MessageUtils.sendUsage(c, channel, sender, new String[]{});
        }
    }
    
    private boolean canRunCommand(Command command, User user) {
        if (command == null) return false;
        
        if (command.getType().isInternal()) {
            Guild g = FlareBot.getInstance().getOfficialGuild();
            
            if (g.getMember(user) != null)
                return g.getMember(user).getRoles().contains(g.getRoleById(command.getType().getRoleId()));
            else
                return false;
        } else
            return true;
    }

    @Override
    public String getCommand() {
        return "usage";
    }

    @Override
    public String getDescription() {
        return "Allows you to view usages for other commands";
    }

    @Override
    public String getUsage() {
        return "`{%}usage <command_name>` - Displays the usage for another command.";
    }

    @Override
    public CommandType getType() {
        return CommandType.GENERAL;
    }
}

@@ -588,16 +588,67 @@
 geUtils;
+%0Aimport stream.flarebot.flarebot.util.GeneralUtils;
 %0A%0Apublic
@@ -1046,16 +1046,29 @@
    if (!
+GeneralUtils.
 canRunCo
@@ -1260,16 +1260,16 @@
 g%5B%5D%7B%7D);%0A
+
         
@@ -1279,497 +1279,8 @@
    %7D
-%0A    %0A    private boolean canRunCommand(Command command, User user) %7B%0A        if (command == null) return false;%0A        %0A        if (command.getType().isInternal()) %7B%0A            Guild g = FlareBot.getInstance().getOfficialGuild();%0A            %0A            if (g.getMember(user) != null)%0A                return g.getMember(user).getRoles().contains(g.getRoleById(command.getType().getRoleId()));%0A            else%0A                return false;%0A        %7D else%0A            return true;%0A    %7D
 %0A%0A  

Replace check with GeneralUtils one