Command still works but chat says internal error

Discussion in 'Plugin Development' started by mcaustin1, Apr 12, 2014.

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

    mcaustin1

    The command still works but the chat says there an internal error.

    Error: http://pastebin.com/hcFXepDw

    Area of code that is causing the problem:
    Code:java
    1. public HashMap<Player, ItemStack[]> invsave = new HashMap<Player, ItemStack[]>();
    2.  
    3. public HashMap<Player, ItemStack[]> armorsave = new HashMap<Player, ItemStack[]>();
    4.  
    5. @SuppressWarnings("deprecation")
    6. public boolean onCommand(CommandSender sender, Command cmd,
    7. String commandLabel, String[] args) {
    8.  
    9. Player player = (Player) sender;
    10.  
    11. if (commandLabel.equalsIgnoreCase("duty")) {
    12. if (args.length == 0) {
    13.  
    14. if (player.hasPermission("duty.enable")) {
    15. Player p = (Player) sender;
    16.  
    17. invsave.put(p, p.getInventory().getContents());
    18. armorsave.put(p, p.getInventory().getArmorContents());
    19.  
    20. Inventory pinv = (Inventory) player.getInventory();
    21. Bukkit.broadcastMessage(((Player) sender).getDisplayName()
    22. + ChatColor.GOLD + " is now on duty!!");
    23. pinv.clear();
    24. player.sendMessage(ChatColor.AQUA
    25. + "Your inventory has been cleared");
    26. // All int's for enchantment and item id's
    27. int fire = 20;
    28. int firelevel = 2;
    29. int sword = 276;
    30. int boots = 305;
    31. int helmet = 302;
    32. int chest = 303;
    33. int legs = 304;
    34. int effect = 0;
    35. int effect1 = 34;
    36. int effect2 = 16;
    37. int level2 = 5;
    38. int level = 4;
    39. int level1 = 3;
    40.  
    41. ItemStack sword1 = new ItemStack(sword);
    42. ItemStack boots1 = new ItemStack(boots);
    43. ItemStack chest1 = new ItemStack(chest);
    44. ItemStack helmet1 = new ItemStack(helmet);
    45. ItemStack legs1 = new ItemStack(legs);
    46. Enchantment myEnchantment = new EnchantmentWrapper(effect);
    47. Enchantment myEnchantment1 = new EnchantmentWrapper(effect1);
    48. Enchantment myEnchantment2 = new EnchantmentWrapper(effect2);
    49. Enchantment myEnchantment3 = new EnchantmentWrapper(fire);
    50. boots1.addEnchantment(myEnchantment, level);
    51. chest1.addEnchantment(myEnchantment, level);
    52. helmet1.addEnchantment(myEnchantment, level);
    53. legs1.addEnchantment(myEnchantment, level);
    54. boots1.addEnchantment(myEnchantment1, level1);
    55. chest1.addEnchantment(myEnchantment1, level1);
    56. helmet1.addEnchantment(myEnchantment1, level1);
    57. legs1.addEnchantment(myEnchantment1, level1);
    58. sword1.addEnchantment(myEnchantment2, level2);
    59. sword1.addEnchantment(myEnchantment1, level1);
    60. sword1.addEnchantment(myEnchantment3, firelevel);
    61. player.getInventory().setChestplate(chest1);
    62. player.getInventory().setHelmet(helmet1);
    63. player.getInventory().setBoots(boots1);
    64. player.getInventory().setLeggings(legs1);
    65. player.getInventory().addItem(sword1);
    66. player.sendMessage(ChatColor.GRAY
    67. + "Armor and Items have be given to you.");
    68. } else {
    69. sender.sendMessage(ChatColor.DARK_RED
    70. + "YOU DO NOT HAVE PREMISSION TO DO THIS COMMAND!!");
    71. }
    72. }



    Sorry for so much code. Apparently the error is with the hasmaps but it still works so, I dont know what the problem is.
     
  2. Offline

    Wizehh

    PHP:
    Caused byjava.lang.ArrayIndexOutOfBoundsException0
            at me
    .Austin.Duty.Duty.onCommand(Duty.java:121) ~[?:?]
    Also, don't explicitly cast Player to CommandSender unless you've used an instanceof check.
     
  3. Offline

    mcaustin1

    So how would I do that
    Wizehh
     
  4. Offline

    Wizehh

    Well, first show us line 121; or, to be safe, just post the entire class (imports and all).
    And to check the sender you'd do something like this:
    PHP:
    //(assuming your CommandSender paramater is named 'sender')
     
    if (!(sender instanceof Player)) {
        
    //the sender is not a player
    } else {
        
    //the sender is a player
    }
     
  5. Offline

    mcaustin1

    Thank you problem solved.
     
Thread Status:
Not open for further replies.

Share This Page