Tell me what i am doing wrong

Discussion in 'Plugin Development' started by Danielh90, Aug 18, 2014.

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

    Danielh90

    So i what a command when i do /duty it gives me and then if i do /duty again it removes item from the plugin tell me what i am dong wrong here is the code
    I am just pasteing the command not the public boolean onCommand stuff

    Code:java
    1. } else if (cmd.getName().equalsIgnoreCase("duty")) {
    2.  
    3. //message
    4. Bukkit.broadcastMessage(prefix + ChatColor.RED + sender.getName() + " Now on Duty");
    5. //ItemStack
    6. ItemStack iron_sword = new ItemStack(Material.IRON_SWORD, 1);
    7. ItemStack chain_helmet = new ItemStack(Material.CHAINMAIL_HELMET, 1);
    8. ItemStack chain_chestplate = new ItemStack(Material.CHAINMAIL_CHESTPLATE, 1);
    9. ItemStack chain_legs = new ItemStack(Material.CHAINMAIL_LEGGINGS, 1);
    10. ItemStack chain_boots = new ItemStack(Material.CHAINMAIL_BOOTS, 1);
    11. ItemStack steak = new ItemStack(Material.COOKED_BEEF, 64);
    12. ItemStack golden_apple = new ItemStack(Material.GOLDEN_APPLE, 5);
    13. //Enchantment
    14. iron_sword.addEnchantment(Enchantment.DAMAGE_ALL, 4);
    15. iron_sword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
    16. //chain_helmet
    17. chain_helmet.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 3);
    18. //chain_chestplate
    19. chain_chestplate.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 3);
    20. //chain_legs
    21. chain_legs.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 3);
    22. //chain_boots
    23. chain_boots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 3);
    24. //ItemeMeta
    25. ItemMeta iron_sowrdmeta = iron_sword.getItemMeta();
    26. ItemMeta chain_helmetmeta = chain_chestplate.getItemMeta();
    27. ItemMeta chain_chestplatemeta = chain_chestplate.getItemMeta();
    28. ItemMeta chain_legsmeta = chain_legs.getItemMeta();
    29. ItemMeta chain_bootsmeta = chain_boots.getItemMeta();
    30. //display
    31. iron_sowrdmeta.setDisplayName(ChatColor.GOLD + "Guard Sword");
    32. chain_helmetmeta.setDisplayName(ChatColor.GOLD + "Guard Helmet");
    33. chain_chestplatemeta.setDisplayName(ChatColor.GOLD + "Guard Chestplate");
    34. chain_legsmeta.setDisplayName(ChatColor.GOLD + "Guard Legs");
    35. chain_bootsmeta.setDisplayName(ChatColor.GOLD + "Guard Boots");
    36. //ArrayList
    37. ArrayList<String> iron_sword1 = new ArrayList<String>();
    38. ArrayList<String> chain_helmet1 = new ArrayList<String>();
    39. ArrayList<String> chain_chestplate1 = new ArrayList<String>();
    40. ArrayList<String> chain_legs1 = new ArrayList<String>();
    41. ArrayList<String> chain_boots1 = new ArrayList<String>();
    42. //Lore Message
    43. iron_sword1.add(ChatColor.GOLD + "Guard Sword");
    44. chain_helmet1.add(ChatColor.GOLD + "Guard Helmet");
    45. chain_chestplate1.add(ChatColor.GOLD + "Guard Chestplate");
    46. chain_legs1.add(ChatColor.GOLD + "Guard Legs");
    47. chain_boots1.add(ChatColor.GOLD + "Guard Boots");
    48. //SetLore
    49. iron_sowrdmeta.setLore(iron_sword1);
    50. chain_helmetmeta.setLore(chain_helmet1);
    51. chain_chestplatemeta.setLore(chain_chestplate1);
    52. chain_legsmeta.setLore(chain_legs1);
    53. chain_bootsmeta.setLore(chain_boots1);
    54. //set Itememta
    55. iron_sword.setItemMeta(iron_sowrdmeta);
    56. chain_helmet.setItemMeta(chain_helmetmeta);
    57. chain_legs.setItemMeta(chain_legsmeta);
    58. chain_boots.setItemMeta(chain_bootsmeta);
    59. //pi
    60. pi.addItem(iron_sword);
    61. pi.addItem(chain_helmet);
    62. pi.addItem(chain_chestplate);
    63. pi.addItem(chain_legs);
    64. pi.addItem(chain_boots);
    65. pi.addItem(steak);
    66. pi.addItem(golden_apple);
    67. }
    68. else
    69. {
    70. player.getInventory().clear();
    71. sender.getServer().broadcastMessage(this.prefix + getName() + " now off duty.");
    72. player.getInventory().setHelmet(null);
    73. player.getInventory().setChestplate(null);
    74. player.getInventory().setLeggings(null);
    75. player.getInventory().setBoots(null);
    76. return true;
     
  2. Offline

    _Filip

    Learn how to use if statements.
     
  3. Offline

    Danielh90

    Anyone else ?
     
  4. Offline

    Lactem

    I'll give you the logic and you give me the code. When someone types /duty, check if they already have the stuff. If they do, take it away. If they don't (else), give it to them.
     
  5. Offline

    stormneo7

    Really, learn how to use your else statements correctly.
    Since you didn't put your full class, I can only infer that
    Code:java
    1. } else if (cmd.getName().equalsIgnoreCase("duty")) {

    was an else if from a cmd.getName().
    But do you notice what you've put under it?
    Without your code, this is what I see.
    Code:
    } else if (cmd.getName().equalsIgnoreCase("duty")) {
    // Code
    }else{
    return true;
    So if the command doesn't equal duty, they're off duty? What?... That's a lot of commands... Don't think that what you wanted to do.
     
Thread Status:
Not open for further replies.

Share This Page