Need help with plugin [NEW BUG]

Discussion in 'Plugin Development' started by lubbs31, Jul 19, 2015.

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

    lubbs31

    Alright all, I came across a new bug. I remade the plugin, under the name ServerKits (/skit). I have two commands (/skit star, /skit admin). Now, anytime I use ANY of these commands, it shows up as...

    "/skit"

    Here is my main
    Code:
    package com.lubbs.ServerKits;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
      
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.BLUE + "Console cannot use this command..");
                return true;
            }
            Player p = (Player) sender;
                  
            if (cmd.getName().equalsIgnoreCase("skit star")) {
                ItemStack star = new ItemStack (Material.NETHER_STAR, 1);
                        p.getInventory().addItem(star);
            if (cmd.getName().equalsIgnoreCase("skit admin")) {
                if (sender.hasPermission("skit.admin")) {
                p.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_RED + "ServerKits" + ChatColor.BLACK + "]" + ChatColor.GOLD + " You must be lucky to be an admin!");
                    p.getInventory().setHelmet(new ItemStack(Material.DIAMOND_HELMET));
                    p.getInventory().addItem(new ItemStack(Material.DIAMOND));
                    p.updateInventory();
                } else {
                    p.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_RED + "ServerKits" + ChatColor.BLACK + "]" + ChatColor.GRAY + ChatColor.ITALIC + " You do not have permission to do this!");
                    return true;
                }
                return false;
            }
                        }
            }
            return false;
            }
              
        }
    
    My yml
    Code:
    name: ServerKits
    version: 0.1
    author: Six5_DedRetard
    main: com.lubbs.ServerKits.Main
    commands:
      skit start:
        description: Get the kit “start”!
        usage: /skit start
      skit admin:
        description: A kit for only admins!
        usage: /skit admin
        permission: skit.admin
    [/spoiler]
     
    Last edited: Jul 19, 2015
  2. Offline

    SuperSniper

    name: Kit
    version: 0.1
    main: com.lubbs.McKits
    commands:
    mckit start:
    description: Gives you items
    usage: /mckit test

    You need to put your main class inside of your main

    com.lubbs.McKits.Main
     
  3. Offline

    Zombie_Striker

    I don't see a class called McKits, so I think you forgot to put the classs name afterwards

    [edit] NINJA'D
     
  4. Offline

    SuperSniper

    His package is com.lobbs.McKits

    he forgot to put the .Main
     
  5. Offline

    Zombie_Striker

    @SuperSniper
    Yeah, that remark cost me from being first. I was just pointing out what the path means.
     
  6. Offline

    lubbs31

    Thank you all!

    but now when I do /mckits start, it says "unkown command, type /help"
     
  7. @lubbs31 That's not how you do arguments in a command. You check the command then check the argument length and finally what that argument is.
     
    Shortninja66 likes this.
  8. Offline

    Zombie_Striker

    @lubbs31
    Did you register your command in the plugin.yml
     
  9. Offline

    lubbs31

    Alright all, I came across a new bug. I remade the plugin, under the name ServerKits (/skit). I have three commands (/skit, /skit star, /skit admin). Now, anytime I use ANY of these commands, it shows up as...
    "[ServerKits]This plugin gives us kits!
    /skit"
    main class (open)

    Code:
    package com.lubbs.ServerKits;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
      
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.BLUE + "Console cannot use this command..");
                return true;
            }
            Player p = (Player) sender;
                  
            if (cmd.getName().equalsIgnoreCase("skit")) {
                p.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_RED + "ServerKits" + ChatColor.BLACK + "]" + ChatColor.GOLD + " This plugins gives us kits!");
            if (cmd.getName().equalsIgnoreCase("skit star")) {
                ItemStack star = new ItemStack (Material.NETHER_STAR, 1);
                        p.getInventory().addItem(star);
            if (cmd.getName().equalsIgnoreCase("skit admin")) {
                if (sender.hasPermission("skit.admin")) {
                p.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_RED + "ServerKits" + ChatColor.BLACK + "]" + ChatColor.GOLD + " You must be lucky to be an admin!");
                    p.getInventory().setHelmet(new ItemStack(Material.DIAMOND_HELMET));
                    p.getInventory().addItem(new ItemStack(Material.DIAMOND));
                    p.updateInventory();
                } else {
                    p.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_RED + "ServerKits" + ChatColor.BLACK + "]" + ChatColor.GRAY + ChatColor.ITALIC + " You do not have permission to do this!");
                    return true;
                }
                return false;
            }
                        }
            }
            return false;
            }
              
        }
    

    plugin.yml (open)

    Code:
    name: ServerKits
    version: 0.1
    author: Six5_DedRetard
    main: com.lubbs.ServerKits.Main
    commands:
      skit:
        description: The basic command to ServerKits!
        usage: /skit
      skit start:
        description: Get the kit “start”!
        usage: /skit start
      skit admin:
        description: A kit for only admins!
        usage: /skit admin
        permission: skit.admin
     
    Last edited: Jul 19, 2015
  10. Offline

    Evaluations

    A command can't have spaces. That's what arguments are for.
     
    Shortninja66 likes this.
  11. @lubbs31
    You only test the name of the command, "skit". Each message can have arguments, thats where the args parameter is for. Also, when you make an onCommand return false, it will send you the command usage.
     
  12. Offline

    rbrick

    Commands cannot have spaces in them...instead of trying to register them with spaces, you should test for the arguments of the command.
    Code:
    if (args.length > 0) {
       String subCommand = args[0]; // the first argument
       
         if (subCommand.equalsIgnoreCase("SOMETHING"))                  {
               // do stuff     
       } else if (subCommand.equalsIgnoreCase("SOMETHING ELSE")) {
       // do some other stuff
    } else {
       // idk. 
    }
     
    Shortninja66 likes this.
  13. Offline

    WPM

    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player p = (Player) sender;
            //If the player types /skit, it will do this vvv
            if(cmd.getName().equalsIgnoreCase("skit")){
                if(args.length == 0){
                p.sendMessage(ChatColor.RED + "Usage: /skit <kit name>");
                return true;
                }
            }
            //This is if the player does /skit star.
            if(args[0].equalsIgnoreCase("star")){
                p.sendMessage("test");
                //Do stuff
            }
            return false;
        }
    }
    
    Or here is another way to do it that I guess is more common.
     
  14. Offline

    QRS%

    Skit means poop / crap in Swedish, hehehehe :3
     
  15. Offline

    RoflFrankoc

    you needa put
    Code:
    return true;
    
    at the end of your command
    for example
    Code:
    if (cmd.getName().equalsIgnoreCase("cmd"){
    p.sendMessage("hello");
    return true;
    }
    
    and also for using spaces in a command i`d use this
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    Player p = (Player) sender;
    if (cmd.getName().equalsIgnoreCase("cmd"){
    if (args.length == 0){
    p.sendMessage("usage: /cmd welcome");
    return true;
    }
    if (args.length == 1){
    p.sendMessage("You have used the command /cmd welcome!");
    return true;
    }
    return true;
    }
    }
    
    them you`d only need to register 1 command in the config and thats the cmd so it should look like this
    Code:
    name: arguments
    main: asd.asdasd
    version: 1.0
    commands:
      cmd:
        description: the arguments
        usage: /<command>
    
     
  16. Offline

    lubbs31

    Alright. It works great... except everytime I use a command with an arg, it says right below it "/skit"

    Code:
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
            Player p = (Player) sender;
                   
            if(cmd.getName().equalsIgnoreCase("skit")) {
                if(args.length == 0) {
                    p.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_RED + "ServerKits" + ChatColor.BLACK + "]" + ChatColor.RED + " Type /skit <kitname> to get the kit!");
                    return true;
                }
            }
                if(args[0].equalsIgnoreCase("star")) {
                    p.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_RED + "ServerKits" + ChatColor.BLACK + "]" + ChatColor.RED + " You have recieved kit" + ChatColor.GOLD + " star!");
                    p.getInventory().addItem(new ItemStack (Material.NETHER_STAR, 1));
                }
                return false;
            }
    }
    Plugin.yml
    Code:
    name: ServerKits
    version: 0.2
    author: Six5_DedRetard
    main: com.lubbs.ServerKits.Main
    commands:
      skit:
        description: The basic & help command to ServerKits!
        usage: /skit
     
  17. Try doing this for you plugin.yml:
    Show Spoiler

    Code:
    name: ServerKits
    version: 0.1
    author: Six5_DedRetard
    main: com.lubbs.ServerKits.Main
    commands:
      skit:
        description: Get the kit!
        usage: /skit [start/admin]
    [/spoiler]
     
  18. Offline

    RoflFrankoc

    @lubbs31 i didnt mean it like that like this it should work
    Code:
    @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
            Player p = (Player) sender;
                
            if(cmd.getName().equalsIgnoreCase("skit")) {
                if(args.length == 0) {
                     p.sendMessage("not enough arguments");
                     return true;
                }
                if (args.length == 1){
              
                    if(args[0].equalsIgnoreCase("star")) {
                    p.sendMessage(ChatColor.BLACK + "[" + ChatColor.DARK_RED + "ServerKits" + ChatColor.BLACK + "]" + ChatColor.RED + " You have recieved kit" + ChatColor.GOLD + " star!");
                    p.getInventory().addItem(new ItemStack (Material.NETHER_STAR, 1));
                }
                }
                return true;
            }
              
                return false;
            }
    
     
  19. Offline

    lubbs31

    I will try that when I get home... for a temp fix I removed the "usage:".
     
  20. Offline

    DoggyCode™

    That is the worst thing I've ever seen... and instead of manually writing the prefix everytime.. just make it a String.

    String prefix = ChatColor.GOLD+"[hey]" + ChatColor.RESET + " ";

    sender.sendMessage(prefix + "message");
     
  21. Offline

    sam_0208

    Return onCommand true at the end and return is false when args are equal to zero so it prints out the usage when someone does /skit
     
Thread Status:
Not open for further replies.

Share This Page