Solved 2nd arguments and weird error

Discussion in 'Plugin Development' started by WHQ, Oct 18, 2015.

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

    WHQ

    Hey guys!

    I am making a plugin (it's based on league of legends as you might notice)
    I have the following questions about it:

    - i get this error on the 1st line: Syntax error, insert "}" to complete ClassBody, but it wont go away after trying to put more "}" at the end.

    - How do i add second arguments? like for example /lom championselect <arg2>.

    My code
    Code:
    public class LOM_Commands extends JavaPlugin {
      
        public List<String> champions = this.getConfig().getStringList("champions");
      
        public boolean onCommand(CommandSender sender, Command cmd, String label, String [] args){
            Player p = (Player) sender;
          
            if(cmd.getName().equalsIgnoreCase("lom") || cmd.getName().equalsIgnoreCase("leagueofminecraft")){
                p.sendMessage(ChatColor.DARK_BLUE + "<[" + ChatColor.GOLD + "League of Minecraft" + ChatColor.DARK_BLUE + "]>");
                p.sendMessage("version: 0.2 (beta)");
                p.sendMessage("made by WHQ");
            }
    
                else if(args.length == 1){
                    if(args[0].equalsIgnoreCase("championlist") ||args[0].equalsIgnoreCase("champlist")){
                        p.sendMessage(ChatColor.DARK_BLUE + "<[" + ChatColor.GOLD + "Available Champions" + ChatColor.DARK_BLUE + "]>");
                      
                        for (String champs : champions)
                            p.sendMessage(champs);
                }
              
                    if(args[0].equalsIgnoreCase("championselect") || args[0].equalsIgnoreCase("champselect")){
                        p.sendMessage(ChatColor.DARK_RED + "Wrong usage! try: /lom championselect <champion>");
                    }
                }
            return true;
        }
    }
    
     
  2. Offline

    mcdorli

    If you use eclipse, it can stuck, and disolay an error, wheb there aren't any. Just save the file, it can go away sometimes.
     
    WHQ likes this.
  3. Offline

    SuperSniper

    @WHQ Which line is giving you the error?

    Also, there's a couple of things in your code that could be fixed to make it "better" I guess you could say.

    1. Don't check for 2 commands at once if it's just the same command just different way of typing it, add aliases inside of the plugin.yml
    Code:
    commands:
      leagueofminecraft:
        usage: /<command>
        aliases: [lom]
    
    2. Check if the sender is instanceof Player before casting.
    Code:
    if(sender instanceof Player) {
    Player player = (Player)sender;
    
     
  4. Offline

    WHQ

    @SuperSniper

    Ah okay, thanks for those improvements :)
    the first line:
    Code:
    publicclass LOM_Commands extends JavaPlugin
    Gives me an error that i should add a "}"
     
  5. Offline

    SuperSniper

    @WHQ It works perfectly for me when I did it inside my IDE, I think what happened is what @mcdorli said above. Try exporting it and it should go away.
     
    WHQ likes this.
  6. Offline

    WHQ

    @SuperSniper
    Yeah, you guys are probably right about the "}" thanks

    I had a second question about how to add second args like for example: /lom championselect <arg2>.
    How would i do this, it shouldnt be too hard i guess, but i couldnt find it after searching the forums and google
     
  7. Offline

    mcdorli

    Plugin developement tutorial on the bukkit wiki? You know, the thing that you should check out first. So, the args array contains the arguments.

    /lom args[0] args[1] ...
     
    WHQ likes this.
  8. Offline

    WHQ

    @mcdorli
    yeah, i kinda feel like an idiot now,
    thanks for your and @SuperSniper 's help, you guys are the best!

    Cheers,
     
Thread Status:
Not open for further replies.

Share This Page