Two errors in my plugin...

Discussion in 'Plugin Development' started by TheMcScavenger, May 8, 2013.

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

    TheMcScavenger

    Yes, I know this is a bit early (just a little bit though :p).

    Anyway, I have two bugs in my plugin, and would like some help fixing them:
    - When spawning a horse (cow atm.), I receive the "Too many arguments! Use: /spawnhorse" error.
    - When trying to craft (e.g. saddle), it doesn't work. It just doesn't show the output of the crafting table.

    Codes:
    Main .java:
    Code:
    package com.McScavenger.HorsePlus;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class HorsePlus extends JavaPlugin{
       
        public void onEnable(){
            Server server = this.getServer();
           
            ShapedRecipe IronHorseArmour = new ShapedRecipe(new ItemStack(417,1));
            IronHorseArmour.shape("  I", "IWI", "III");
            IronHorseArmour.setIngredient('I', Material.IRON_INGOT);
            IronHorseArmour.setIngredient('W', Material.WOOL);
            server.addRecipe(IronHorseArmour);
           
            ShapedRecipe GoldHorseArmour = new ShapedRecipe(new ItemStack(418,1));
            GoldHorseArmour.shape("  G", "GWG", "GGG");
            GoldHorseArmour.setIngredient('G', Material.GOLD_INGOT);
            GoldHorseArmour.setIngredient('W', Material.WOOL);
            server.addRecipe(GoldHorseArmour);
           
            ShapedRecipe DiamondHorseArmour = new ShapedRecipe(new ItemStack(419,1));
            DiamondHorseArmour.shape("  D", "DWD", "DDD");
            DiamondHorseArmour.setIngredient('D', Material.DIAMOND);
            DiamondHorseArmour.setIngredient('W', Material.WOOL);
            server.addRecipe(DiamondHorseArmour);
           
            ShapedRecipe Saddle = new ShapedRecipe(new ItemStack(Material.SADDLE));
            Saddle.shape("LLL", "LIL", "I I");
            Saddle.setIngredient('L', Material.LEATHER);
            Saddle.setIngredient('I', Material.IRON_INGOT);
            server.addRecipe(Saddle);
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            Player player = (Player) sender;
            Location location = player.getLocation();
           
            if(cmd.getName().equalsIgnoreCase("spawnhorse")){
                if(player.hasPermission("horseplus.spawnhorse")){
                    if(args.length == 0){
                        player.getWorld().spawnEntity(location, EntityType.COW);
                    }if(args.length == 1){
                        player.sendMessage(ChatColor.DARK_RED + "Too many arguments! Use: /spawnhorse");
                    }if(args.length >= 1){
                        player.sendMessage(ChatColor.DARK_RED + "Too many arguments! Use: /spawnhorse");
                    }else
                    player.sendMessage(ChatColor.DARK_RED + "You have insufficient permissions.");
                }
            }return false;
        }
    }
    
    Plugin.yml:
    Code:
    name: HorsePlus
    main: com.McScavenger.HorsePlus.HorsePlus
    version: 1.0
    description: >
                A simple lightweight plugin to get saddles, horses, and horse armour.
    commands:
      spawnhorse:
        description: Spawn a horse.
        default: op
     
    permissions:
      horseplus.spawnhorse:
        description: Gives access to the /spawnhorse command.
    Thanks in advance!

    Also note that I do not get any errors in eclipse, nor when I export the plugin. Also no errors are shown in my server console when loading the plugin, nor when trying to craft or /spawnhorse.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. Offline

    TheMcScavenger

  3. Offline

    kamakarzy

    TheMcScavenger this worked for me also the crafting recipe worked too

    [​IMG]

    Code:java
    1. package com.McScavenger.HorsePlus;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Location;
    5. import org.bukkit.Material;
    6. import org.bukkit.Server;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.EntityType;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.inventory.ItemStack;
    12. import org.bukkit.inventory.ShapedRecipe;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class HorsePlus extends JavaPlugin {
    16.  
    17. public void onEnable() {
    18. Server server = this.getServer();
    19.  
    20. // ShapedRecipe IronHorseArmour = new ShapedRecipe(new
    21. // ItemStack(417,1));
    22. // IronHorseArmour.shape(" I", "IWI", "III");
    23. // IronHorseArmour.setIngredient('I', Material.IRON_INGOT);
    24. // IronHorseArmour.setIngredient('W', Material.WOOL);
    25. // server.addRecipe(IronHorseArmour);
    26.  
    27. // ShapedRecipe GoldHorseArmour = new ShapedRecipe(new
    28. // ItemStack(418,1));
    29. // GoldHorseArmour.shape(" G", "GWG", "GGG");
    30. // GoldHorseArmour.setIngredient('G', Material.GOLD_INGOT);
    31. // GoldHorseArmour.setIngredient('W', Material.WOOL);
    32. // server.addRecipe(GoldHorseArmour);
    33.  
    34. // ShapedRecipe DiamondHorseArmour = new ShapedRecipe(new
    35. // ItemStack(419,1));
    36. // DiamondHorseArmour.shape(" D", "DWD", "DDD");
    37. // DiamondHorseArmour.setIngredient('D', Material.DIAMOND);
    38. // DiamondHorseArmour.setIngredient('W', Material.WOOL);
    39. // server.addRecipe(DiamondHorseArmour);
    40.  
    41. ShapedRecipe Saddle = new ShapedRecipe(new ItemStack(Material.SADDLE));
    42. Saddle.shape("LLL", "LIL", "I I");
    43. Saddle.setIngredient('L', Material.LEATHER);
    44. Saddle.setIngredient('I', Material.IRON_INGOT);
    45. server.addRecipe(Saddle);
    46. }
    47.  
    48. public boolean onCommand(CommandSender sender, Command cmd, String label,
    49. String[] args) {
    50. Player player = (Player) sender;
    51. Location location = player.getLocation();
    52.  
    53. if (cmd.getName().equalsIgnoreCase("spawnhorse")) {
    54. if (player.hasPermission("horseplus.spawnhorse")) {
    55. if (args.length == 0) {
    56. player.getWorld().spawnEntity(location, EntityType.COW);
    57. } else if (args.length >= 1) {
    58. player.sendMessage(ChatColor.DARK_RED
    59. + "Too many arguments! Use: /spawnhorse");
    60. }
    61.  
    62. } else
    63. player.sendMessage(ChatColor.DARK_RED
    64. + "You have insufficient permissions.");
    65.  
    66. }
    67. return true;
    68. }
    69. }
    70.  
     
  4. Offline

    ZeusAllMighty11

    If args length is 1, it is also greater than or equal to one.

    So to fix it, remove the >= check
     
  5. Offline

    TheMcScavenger

    Okay, first of all, thank you for your reply's. Basically, from what I understand, since the ID isn't in yet, it can't create any of the recipes. So commenting them out, will stop it from breaking the rest of the crafting recipes.

    Also, I did the >= instead of > because of Visual Basic 2008 (in which >= means greater than). Thanks for that! Now one last problem, using the following code, I now get the "Insufficient permissions" error I put in there, when using /spawnhorse (I am op & have given myself the permissions).

    Code:
    package com.McScavenger.HorsePlus;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class HorsePlus extends JavaPlugin{
     
    public void onEnable(){
    Server server = this.getServer();
     
    //ShapedRecipe IronHorseArmour = new ShapedRecipe(new ItemStack(417,1));
    //IronHorseArmour.shape(" I", "IWI", "III");
    //IronHorseArmour.setIngredient('I', Material.IRON_INGOT);
    //IronHorseArmour.setIngredient('W', Material.WOOL);
    //server.addRecipe(IronHorseArmour);
     
    //ShapedRecipe GoldHorseArmour = new ShapedRecipe(new ItemStack(418,1));
    //GoldHorseArmour.shape(" G", "GWG", "GGG");
    //GoldHorseArmour.setIngredient('G', Material.GOLD_INGOT);
    //GoldHorseArmour.setIngredient('W', Material.WOOL);
    //server.addRecipe(GoldHorseArmour);
     
    //ShapedRecipe DiamondHorseArmour = new ShapedRecipe(new ItemStack(419,1));
    //DiamondHorseArmour.shape(" D", "DWD", "DDD");
    //DiamondHorseArmour.setIngredient('D', Material.DIAMOND);
    //DiamondHorseArmour.setIngredient('W', Material.WOOL);
    //server.addRecipe(DiamondHorseArmour);
     
    ShapedRecipe Saddle = new ShapedRecipe(new ItemStack(Material.SADDLE));
    Saddle.shape("LLL", "LIL", "I I");
    Saddle.setIngredient('L', Material.LEATHER);
    Saddle.setIngredient('I', Material.IRON_INGOT);
    server.addRecipe(Saddle);
    }
     
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    Player player = (Player) sender;
    Location location = player.getLocation();
     
    if(cmd.getName().equalsIgnoreCase("spawnhorse")){
    if(player.hasPermission("horseplus.spawnhorse")){
    if(args.length == 0){
    player.getWorld().spawnEntity(location, EntityType.COW);
    }if(args.length == 1){
    player.sendMessage(ChatColor.DARK_RED + "Too many arguments! Use: /spawnhorse");
    }if(args.length > 1){
    player.sendMessage(ChatColor.DARK_RED + "Too many arguments! Use: /spawnhorse");
    }else
    player.sendMessage(ChatColor.DARK_RED + "You have insufficient permissions.");
    }
    }return false;
    }
    }
    
    Never mind, managed to fix it by adding another if;

    Code:
    package com.McScavenger.HorsePlus;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class HorsePlus extends JavaPlugin{
     
    public void onEnable(){
    Server server = this.getServer();
     
    //ShapedRecipe IronHorseArmour = new ShapedRecipe(new ItemStack(417,1));
    //IronHorseArmour.shape("  I", "IWI", "III");
    //IronHorseArmour.setIngredient('I', Material.IRON_INGOT);
    //IronHorseArmour.setIngredient('W', Material.WOOL);
    //server.addRecipe(IronHorseArmour);
     
    //ShapedRecipe GoldHorseArmour = new ShapedRecipe(new ItemStack(418,1));
    //GoldHorseArmour.shape("  G", "GWG", "GGG");
    //GoldHorseArmour.setIngredient('G', Material.GOLD_INGOT);
    //GoldHorseArmour.setIngredient('W', Material.WOOL);
    //server.addRecipe(GoldHorseArmour);
     
    //ShapedRecipe DiamondHorseArmour = new ShapedRecipe(new ItemStack(419,1));
    //DiamondHorseArmour.shape("  D", "DWD", "DDD");
    //DiamondHorseArmour.setIngredient('D', Material.DIAMOND);
    //DiamondHorseArmour.setIngredient('W', Material.WOOL);
    //server.addRecipe(DiamondHorseArmour);
     
    ShapedRecipe Saddle = new ShapedRecipe(new ItemStack(Material.SADDLE));
    Saddle.shape("LLL", "LIL", "I I");
    Saddle.setIngredient('L', Material.LEATHER);
    Saddle.setIngredient('I', Material.IRON_INGOT);
    server.addRecipe(Saddle);
    }
     
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    Player player = (Player) sender;
    Location location = player.getLocation();
     
    if(cmd.getName().equalsIgnoreCase("spawnhorse")){
    if(player.hasPermission("horseplus.spawnhorse")){
    if(args.length == 0){
    player.getWorld().spawnEntity(location, EntityType.COW);
    }if(args.length == 1){
    player.sendMessage(ChatColor.DARK_RED + "Too many arguments! Use: /spawnhorse");
    }if(args.length > 1){
    player.sendMessage(ChatColor.DARK_RED + "Too many arguments! Use: /spawnhorse");
    }else
    if(player.hasPermission("horseplus.spawnhorse")){
     
    }else{
    player.sendMessage(ChatColor.DARK_RED + "You have insufficient permissions.");
    }
    }
    }return false;
    }
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page