Solved Remove @Override annotation?

Discussion in 'Plugin Development' started by iAmGuus, May 17, 2014.

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

    iAmGuus

    Hey Guys,
    If i want to do a onCommand method, i cant.
    I thought we need to set the @Override annotation on top of the method?
    So i did it, and the hole public boolean onCommand became red?
    If you want my code, ask it.
    Anyways, Thanks for your help.
    iAmGuus
     
  2. Offline

    DxDy

    That's exactly the purpose of the @Override. It only will make your method produce an error if you've not overriden anything ;) So be happy that the compiler protected you :p

    Possible reasons: Your Plugin-Class needs to extend JavaPlugin. The method signature of your onCommand needs to match the one defined in the Plugin-Interface.
     
  3. Offline

    Azubuso

    iAmGuus What's the error your IDE is telling you if you hover over your onCommand method?

    Another thing, that @Override annotation isn't anything you have to have in order for it work, all @Override does is tell the compiler to actually check you're properly overriding the method from the implemented interface, in this case CommandExecutor. In that case it'll show errors if your method is, as an example, misspelled. It also just makes it easier for other developers to read your code and see what's being overwritten. (Hope I explained that well ;))
     
  4. Offline

    iAmGuus

    Azubuso It says : "The method onCommand(Command, CommandSender, String, String[]) of type Main must override a superclass method"

    and by the way, here is my code:
    Code:java
    1. package com.cookiedeveloped.main;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.Arrays;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.enchantments.Enchantment;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.inventory.Inventory;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. public class Main extends JavaPlugin implements Listener{
    19.  
    20. @Override
    21. public void onEnable() {
    22. getLogger().info("xKits has been enabled!");
    23. getCommand("pvp").setExecutor(this);
    24. getCommand("archer").setExecutor(this);
    25. }
    26.  
    27. @Override
    28. public void onDisable() {
    29. getLogger().info("xKits has been disabled!");
    30. }
    31. ArrayList<String> pvp = new ArrayList<String>();
    32. ArrayList<String> archer = new ArrayList<String>();
    33.  
    34.  
    35.  
    36. @Override
    37. public boolean onCommand(Command cmd, CommandSender sender, String label, String[] args) {
    38. //PVP KIT
    39. if(cmd.getName().equalsIgnoreCase("pvp")) {
    40. if(sender instanceof Player) {
    41. Player p = (Player) sender;
    42. if(!pvp.contains(p.getName())) {
    43. pvp.add(p.getName());
    44. } else {
    45. p.sendMessage("" + ChatColor.GRAY + ChatColor.BOLD + "eXperiencePvP>" + ChatColor.GREEN + ChatColor.BOLD + "You already have this kit!");
    46. }
    47. ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP);
    48.  
    49. Inventory inv = p.getInventory();
    50. inv.addItem(new ItemStack(Material.STONE_SWORD));
    51. inv.addItem(soup);
    52. inv.addItem(soup);
    53. inv.addItem(soup);
    54. inv.addItem(soup);
    55. inv.addItem(soup);
    56. inv.addItem(soup);
    57. inv.addItem(soup);
    58. inv.addItem(soup);
    59.  
    60. inv.addItem(soup);
    61. inv.addItem(soup);
    62. inv.addItem(soup);
    63. inv.addItem(soup);
    64. inv.addItem(soup);
    65. inv.addItem(soup);
    66. inv.addItem(soup);
    67. inv.addItem(soup);
    68. inv.addItem(soup);
    69.  
    70. inv.addItem(soup);
    71. inv.addItem(soup);
    72. inv.addItem(soup);
    73. inv.addItem(soup);
    74. inv.addItem(soup);
    75. inv.addItem(soup);
    76. inv.addItem(soup);
    77. inv.addItem(soup);
    78. inv.addItem(soup);
    79.  
    80. inv.addItem(soup);
    81. inv.addItem(soup);
    82. inv.addItem(soup);
    83. inv.addItem(soup);
    84. inv.addItem(soup);
    85. inv.addItem(soup);
    86. inv.addItem(soup);
    87. inv.addItem(soup);
    88. inv.addItem(soup);
    89.  
    90. p.sendMessage("" + ChatColor.GRAY + ChatColor.BOLD + "eXperiencePvP>" + ChatColor.GREEN + ChatColor.BOLD + "You have recieved the PvP kit!");
    91.  
    92. }
    93. }
    94. //END PVP KIT
    95.  
    96. //ARCHER KIT
    97. if(cmd.getName().equalsIgnoreCase("archer")) {
    98. if(sender instanceof Player) {
    99. Player p = (Player) sender;
    100. if(!archer.contains(p.getName())) {
    101. archer.add(p.getName());
    102. } else {
    103. p.sendMessage("" + ChatColor.GRAY + ChatColor.BOLD + "eXperiencePvP>" + ChatColor.GREEN + ChatColor.BOLD + "You already have this kit!");
    104. }
    105. ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP);
    106. ItemStack bow = new ItemStack(Material.BOW);
    107. ItemMeta bowmeta = bow.getItemMeta();
    108. bowmeta.setDisplayName("" + ChatColor.BOLD + ChatColor.DARK_BLUE + "Archer Bow!");
    109. bowmeta.setLore(Arrays.asList("" + ChatColor.BOLD + ChatColor.DARK_BLUE + "This is the archer bow!"));
    110. bow.setItemMeta(bowmeta);
    111. bow.addEnchantment(Enchantment.ARROW_INFINITE, 1);
    112. bow.addEnchantment(Enchantment.ARROW_KNOCKBACK, 1);
    113.  
    114. Inventory inv = p.getInventory();
    115. inv.addItem(new ItemStack(Material.STONE_SWORD));
    116. inv.addItem(soup);
    117. inv.addItem(soup);
    118. inv.addItem(soup);
    119. inv.addItem(soup);
    120. inv.addItem(soup);
    121. inv.addItem(soup);
    122. inv.addItem(soup);
    123. inv.addItem(bow);
    124.  
    125. inv.addItem(soup);
    126. inv.addItem(soup);
    127. inv.addItem(soup);
    128. inv.addItem(soup);
    129. inv.addItem(soup);
    130. inv.addItem(soup);
    131. inv.addItem(soup);
    132. inv.addItem(soup);
    133. inv.addItem(new ItemStack(Material.ARROW));
    134.  
    135. inv.addItem(soup);
    136. inv.addItem(soup);
    137. inv.addItem(soup);
    138. inv.addItem(soup);
    139. inv.addItem(soup);
    140. inv.addItem(soup);
    141. inv.addItem(soup);
    142. inv.addItem(soup);
    143. inv.addItem(soup);
    144.  
    145. inv.addItem(soup);
    146. inv.addItem(soup);
    147. inv.addItem(soup);
    148. inv.addItem(soup);
    149. inv.addItem(soup);
    150. inv.addItem(soup);
    151. inv.addItem(soup);
    152. inv.addItem(soup);
    153. inv.addItem(soup);
    154.  
    155. p.sendMessage("" + ChatColor.GRAY + ChatColor.BOLD + "eXperiencePvP>" + ChatColor.GREEN + ChatColor.BOLD + "You have recieved the Archer! kit!");
    156. }
    157. }
    158. //END ARCHER
    159.  
    160. return false;
    161. }
    162.  
    163. }
    164.  

    And DxDy, its in my main class which already extends JavaPlugin :)
     
  5. Offline

    DxDy

    iAmGuus
    It's onCommand(CommandSender, Command, ...) not onCommand(Command, CommandSender, ...) ;)

    A little sidenote: Lines 51-88 can be written in 2 lines using a loop ;)
     
  6. Offline

    Azubuso

    iAmGuus Ah I see, that's becuase your onCommand method is "Command cmd, CommandSender sender, String label, String[] args) ..." instead of "CommandSender sender, Command cmd, String label, String[] args) ..." Change that and you should be good to go. :)

    Also, you might wanna do something about the way you're giving that "soup" itemstack...why aren't you using a loop?

    EDIT: God dangit ninjad
     
  7. You can use a loop, although I believe loops require calling player.updateInventory() too.
     
  8. Offline

    AoH_Ruthless

    iAmGuus
    You can shorten the "inv.addItem(soup) * 5000000" by making a for loop, and looping however many times you want to add the soup. This makes 40+ lines into about 5 at most.

    Edit: Ninja'd by KingFaris11 :( Just realized that DxDy said that a while ago

    It's also strange your are getting that error.. what version of Bukkit are you building against?
    Azubuso found your error, never mind.
     
  9. Offline

    iAmGuus

    DxDy & Azubuso Thanks guys, Could someone make an example like KingFaris10 said.
     
  10. Offline

    Azubuso

    iAmGuus
    Basic for loop:
    Code:java
    1. for (int i = 1; int <= 50; i++) {
    2. inv.addItem(soup);
    3. // p.updateInventory();?
    4. }
     
  11. Offline

    iAmGuus

    Azubuso Thanks, i got it. I was trying to make my own KitPvP plugin for my server, so if i need anymore help. I'll come back here.
    Thanks for all your support!
    iAmGuus
     
Thread Status:
Not open for further replies.

Share This Page