Solved /help enum help!

Discussion in 'Plugin Development' started by LuckehPickle, Jan 2, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    LuckehPickle

    I have recently been developing a plugin which is going to replace the vanilla /help command with my own. I have come up with an idea: iterating over an enum with all the commands, checking if the player has the permission, and then showing them that command.

    However my experience with enum's is minimal, and after looking at this I have managed to create what I thought was a correct enum. here it is:
    Code:
    public enum commands{
            help ("All", "?", "/help", "Lists all available commands.", ""), 
            ping ("All", "", "/ping", "Tells you how much delay there is between you and the server.", ""), 
            reloadcfg ("All", "", "/reloadcfg", "Reloads the AtomicHive Config file.", "atomichive.reloadcfg"),
            reloadconfig ("Prison", "", "/reloadconfig", "Reloads the Prison Config file.", "atomichive.prison.reloadconfig"),
            killmob ("All", "", "/killmob", "Gives a death stick, which can be used to remove entity's", "atomichive.killmobs"),
            killmobs ("All", "", "/killmobs <radius>", "Kills all mobs withhin a defined radius", "atomichive.killmobs"),
            kill ("All", "", "/kill <player>", "Kills a target player", "atomichive.kill"),
            summon ("All", "", "</summon <entity> [amount]", "Spanws the desired Entity (Broken)", "atomichive.summon"), //TODO Feex
            suicide ("All", "", "/suicide", "Sepaku", "atomichive.suicide"),
            fly ("All", "", "/fly <player>", "Enables flight for the designated player.", "atomichive.fly"),
            gamemode ("All", "gm", "/gamemode <mode> <player>", "Sets the Gamemode of the designated player.", "atomichive.gamemode"),
            kick ("All", "", "/kick <player> [reason]", "Removes the designated player from the server.", "atomichive.kick"),
            vote ("All", "", "/vote", "Shows a voting link.", ""),
            donate ("All", "", "/donate", "Shows a donation link.", ""),
            slap ("All", "", "/slap", "Slaps nearby players away from you.", "atomichive.slap"),
            message ("All", "msg", "/message <player> <message>", "Sends a private message to the desired player.", "atomichive.message"),
            tp ("All", "", "/tp <player>", "Teleports you to a designated player.", "atomichive.tp"),
            tpa ("All", "", "/tpa <player>", "Sends a teleport request to the designated player.", "atomichive.tpa"),
            tphere ("All", "", "/tphere <player>", "Teleports the designated player to you.", "atomichive.tpothers"),
            tpahere ("All", "", "/tpahere <player>", "Sends a teleport request to the designated player.", "atomichive.tpothers"),
            tpall ("All", "", "/tpall", "Teleports all players to you.", "atomichive.tpall"),
            tpyes ("All", "tpaccept", "/tpyes", "Accepts the most recent teleport request.", "atomichive.tpa"),
            heal ("All", "", "/heal <player>", "Heals the target player", "atomichive.heal"),
            setspawn ("Prison", "", "/setspawn", "Sets the prison spawn point.", "atomichive.prison.setspawn"),
            spawn ("Prison", "", "/spawn", "Teleports you to the Prison spawn.", "atomichive.prison.spawn"),
            pet ("All", "", "/pet", "Opens the pet menu.", "atomichive.pets"); //TODO Create Pets Permission
             
            private final String Server;
            private final String Alias;
            private final String Syntax;
            private final String Description;
            private final String Permission;
             
            commands(String Server, String Alias, String Description, String Permission, String Syntax) {
                   this.Server = Server;
                   this.Alias = Alias;
                   this.Syntax = Syntax;
                   this.Description = Description;
                   this.Permission = Permission;
            }
             
        }
    
    However in practice, I get errors that say java.lang.ArrayIndexOutOfBoundsException: 0
    Normally I would assume this means that I have referenced part of an Array that is null, however there are no Array's involved, and because I'm such a noob with enums I have no idea what to do about it. Help?
     
  2. Offline

    Skionz

    @LuckehPickle Mind showing what your actually doing when /help is called?
     
    teej107 likes this.
  3. Offline

    LuckehPickle

    @Skionz Sure. When the command is called I run this:

    Code:
    public void showHelp(Player player, int page){
             for(commands cmd :  commands.values()){
                 if(cmd == null){
                     return;
                 }
               
                 if(cmd.Permission == "" || player.hasPermission(cmd.Permission)){
                     player.sendMessage(ChatColor.WHITE + cmd.Syntax + ChatColor.GOLD + " - " + ChatColor.GRAY + cmd.Description);
                 }
             }
           
         }
    Once I have this error free, the plan is to loop through the commands, and add any that they have permission to to an Array. Then print only five of the commands at a time by looping through the array at specific points. If that makes sense...

    Edit: And include any Alias's as well.
     
  4. Offline

    nverdier

    @LuckehPickle Well you didn't post your on command, but I'm assuming that you didn't use any arguments when using the command in game, and when you call the method showHelp you pass args[0] to it! which throws the exception.
     
    LuckehPickle likes this.
  5. Offline

    LuckehPickle

    @nverdier Yes that seems to have fixed it! Thanks!
     
    nverdier likes this.
  6. Offline

    Freack100

    @LuckehPickle
    Umm, there is another problem. In your Enum you define Permission as private final, and you try to access this private variable outside of the enum, which is not possible.
     
Thread Status:
Not open for further replies.

Share This Page