Plugin returning command usage message?

Discussion in 'Plugin Development' started by iMurder, Jan 7, 2014.

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

    iMurder

    So, my plugin is returning the command usage message from the plugin.yml, and I cannot figure out why..
    Suggestions?


    Code:java
    1. package tk.murdercraftmc.tk.MCHub;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.Material;
    9. import org.bukkit.Sound;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.inventory.InventoryClickEvent;
    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 {
    19. public void onEnable() {
    20. getLogger().info("onEnable has been invoked!");
    21. super.onEnable();
    22. getConfig().options().copyDefaults(true);
    23. saveConfig();
    24. }
    25. public void onDisable()
    26. {
    27. getLogger().info("MurderCraftHub");
    28. super.onDisable();
    29. }
    30.  
    31. public String prefixhats = "§4[§cHats§4] §a";
    32.  
    33. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    34. if ((cmd.getName().equalsIgnoreCase("mchats")) || (cmd.getName().equalsIgnoreCase("hats"))) {
    35. if (args.length == 0) {
    36. Player p = (Player)sender;
    37. Location loc = p.getLocation();
    38. sender.sendMessage(this.prefixhats + ChatColor.GREEN + "Please use the hat menu, and not commands to manage your hat.");
    39. p.playSound(loc, Sound.CREEPER_HISS, 1, 10);
    40. } else {
    41. Player p = (Player)sender;
    42. if (args[0].equalsIgnoreCase("remove")) {
    43. p.getEquipment().setHelmet(new ItemStack(Material.AIR));
    44. p.sendMessage(this.prefixhats + ChatColor.GREEN + "Hat removed.");
    45. } else {
    46. try {
    47. try {
    48. ItemStack hatItem = new ItemStack(Material.getMaterial(Integer.parseInt(args[0])));
    49. ItemMeta meta = hatItem.getItemMeta();
    50. meta.setDisplayName(ChatColor.LIGHT_PURPLE + "[Hat] " + ChatColor.GREEN + hatItem.getType().name());
    51. List lore = new ArrayList();
    52. lore.add("This is a nice fancy hat, right!?!");
    53. meta.setLore(lore);
    54. hatItem.setItemMeta(meta);
    55. if ((p.hasPermission("murdercraft.hat." + hatItem.getTypeId())) || (p.hasPermission("murdercraft.hat.all"))) {
    56. p.getEquipment().setHelmet(hatItem);
    57. p.sendMessage(this.prefixhats + ChatColor.GREEN + "Enjoy your new hat!");
    58. Location loc = p.getLocation();
    59. p.playSound(loc, Sound.SUCCESSFUL_HIT, 1, 10);
    60. p.playSound(loc, Sound.ARROW_HIT, 1, 5);
    61. } else {
    62. p.sendMessage(this.prefixhats + ChatColor.GREEN + "You have not unlocked this hat.");
    63. Location loc = p.getLocation();
    64. p.playSound(loc, Sound.CREEPER_HISS, 1, 10);
    65. }
    66. } catch (NullPointerException e) {
    67. Location loc = p.getLocation();
    68. p.sendMessage(this.prefixhats + ChatColor.GREEN + "Please use the hat menu, and not commands to manage your hat.");
    69. p.playSound(loc, Sound.CREEPER_HISS, 1, 10);
    70. }
    71. } catch (NumberFormatException e) {
    72. Location loc = p.getLocation();
    73. p.sendMessage(this.prefixhats + ChatColor.GREEN + "Please use the hat menu, and not commands to manage your hat.");
    74. p.playSound(loc, Sound.CREEPER_HISS, 1, 10);
    75. }
    76. }
    77. }
    78. }
    79. return true;
    80. }
    81. public void onClick(InventoryClickEvent ev) {
    82. if ((ev.getRawSlot() == 5) &&
    83. (ev.getCurrentItem().hasItemMeta()) &&
    84. (ev.getCurrentItem().getItemMeta().hasLore()) &&
    85. (((String)ev.getCurrentItem().getItemMeta().getLore().get(0)).equals("This is a nice fancy hat, right!?!"))) {
    86. Player p = (Player)ev.getWhoClicked();
    87. ev.setCancelled(true);
    88. p.sendMessage(this.prefixhats + ChatColor.GREEN + "Please use hat menu to remove your hat.");
    89. ev.getView().close();
    90. }
    91. }
    92. }
    93.  


    Code:
    name: MCHats
    main: tk.murdercraftmc.tk.MCHub.Main
    version: 1.0
     
    commands:
      hats:
        aliases: [mchats, hat]
        description: Command that puts the item on your head.
        usage: /<command> - puts item on head
    Thanks :D
     
  2. Offline

    felixfritz

    Does the command even work? Because your command-method is called "onCommandHats". Shouldn't it be "onCommand"?
     
  3. Offline

    iMurder

    I feel extremely stupid for not realising that >_<
    Thanks.
     
Thread Status:
Not open for further replies.

Share This Page