Command Problem Help

Discussion in 'Plugin Development' started by moe097, Jul 24, 2014.

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

    moe097

    I am creating a simple Kit PvP Plugin for my server but, whenever I try the command nothing happens. The plugin loads without error so I have no stacktrace. Here is the code:
    Code:java
    1. package me.moe097.MindItKitPvP;
    2.  
    3. import net.milkbowl.vault.chat.Chat;
    4. import net.milkbowl.vault.economy.Economy;
    5. import net.milkbowl.vault.permission.Permission;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.Material;
    10. import org.bukkit.World;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.enchantments.Enchantment;
    13. import org.bukkit.entity.Entity;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.entity.PlayerDeathEvent;
    18. import org.bukkit.inventory.ItemStack;
    19. import org.bukkit.inventory.meta.ItemMeta;
    20. import org.bukkit.material.Command;
    21. import org.bukkit.plugin.RegisteredServiceProvider;
    22. import org.bukkit.plugin.java.JavaPlugin;
    23.  
    24. public class MindItKitPvP extends JavaPlugin implements Listener {
    25.  
    26. public static Permission permission = null;
    27. public static Economy economy = null;
    28. public static Chat chat = null;
    29.  
    30. private boolean setupPermissions()
    31. {
    32. RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
    33. if (permissionProvider != null) {
    34. permission = permissionProvider.getProvider();
    35. }
    36. return (permission != null);
    37. }
    38.  
    39. private boolean setupChat()
    40. {
    41. RegisteredServiceProvider<Chat> chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class);
    42. if (chatProvider != null) {
    43. chat = chatProvider.getProvider();
    44. }
    45.  
    46. return (chat != null);
    47. }
    48.  
    49. private boolean setupEconomy()
    50. {
    51. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    52. if (economyProvider != null) {
    53. economy = economyProvider.getProvider();
    54. }
    55.  
    56. return (economy != null);
    57. }
    58.  
    59. @Override
    60. public void onEnable() {
    61. if(!setupEconomy()) {
    62. getLogger().severe("ERROR - COULD NOT LOAD PLUGIN - REQUIRES VAULT - MAKE SURE YOU HAVE VAULT INSTALLED!");
    63. }
    64. getLogger().info("MindItKitPvP has been enabled!");
    65. getServer().getPluginManager().registerEvents(this, this);
    66. }
    67.  
    68. @EventHandler
    69. public void onDeath(PlayerDeathEvent e) {
    70. Entity killer = e.getEntity().getKiller();
    71.  
    72. World world = Bukkit.getWorld("KitPvP");
    73.  
    74. if(killer.getWorld().equals(world)) {
    75. if ((killer instanceof Player)) {
    76. Player player = (Player)killer;
    77. economy.depositPlayer(player.getName(), 3.0D);
    78. }
    79. }
    80. }
    81.  
    82. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    83. if(sender instanceof Player) {
    84. Player player = (Player) sender;
    85. if(commandLabel.equalsIgnoreCase("KitPvP")) {
    86. player.sendMessage(ChatColor.RED + "Incorrect Ussage! Do /KitPvP <Kit> Type /KitHelp for a list of commands!");
    87. if(args[0].equalsIgnoreCase("PvP")) {
    88. String playername = player.getName();
    89.  
    90. ItemStack helm = new ItemStack(Material.GOLD_HELMET);
    91. ItemStack chest = new ItemStack(Material.CHAINMAIL_CHESTPLATE);
    92. ItemStack leg = new ItemStack(Material.GOLD_LEGGINGS);
    93. ItemStack boots = new ItemStack(Material.CHAINMAIL_BOOTS);
    94.  
    95. ItemStack sword = new ItemStack(Material.IRON_SWORD);
    96. ItemMeta meta1 = sword.getItemMeta();
    97. meta1.setDisplayName(playername + " Sword");
    98.  
    99. ItemStack bow = new ItemStack(Material.BOW);
    100. ItemMeta meta2 = bow.getItemMeta();
    101. meta2.setDisplayName(playername + " Bow");
    102.  
    103. ItemStack arrow = new ItemStack(Material.ARROW);
    104. arrow.setAmount(64);
    105.  
    106. player.getInventory().clear();
    107.  
    108. player.sendMessage(ChatColor.RED + "You have chosen the PvP Kit!");
    109.  
    110. player.setItemInHand(sword);
    111. player.getInventory().addItem(helm);
    112. player.getInventory().addItem(chest);
    113. player.getInventory().addItem(leg);
    114. player.getInventory().addItem(boots);
    115. player.getInventory().addItem(bow);
    116. player.getInventory().addItem(arrow);
    117.  
    118. return true;
    119. }
    120. if(args[0].equalsIgnoreCase("Archer")) {
    121.  
    122. String playername = player.getName();
    123.  
    124. ItemStack helm = new ItemStack(Material.LEATHER_HELMET);
    125. ItemStack chest = new ItemStack(Material.CHAINMAIL_CHESTPLATE);
    126. ItemStack leg = new ItemStack(Material.GOLD_LEGGINGS);
    127. ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
    128.  
    129. ItemStack sword = new ItemStack(Material.STONE_SWORD);
    130. ItemMeta meta1 = sword.getItemMeta();
    131. meta1.setDisplayName(playername + " Sword");
    132.  
    133. ItemStack bow = new ItemStack(Material.BOW);
    134. ItemMeta meta2 = bow.getItemMeta();
    135. meta2.setDisplayName(playername + " Bow");
    136.  
    137. bow.addEnchantment(Enchantment.ARROW_INFINITE, 1);
    138. bow.addEnchantment(Enchantment.ARROW_DAMAGE, 2);
    139.  
    140. ItemStack arrow = new ItemStack(Material.ARROW);
    141. arrow.setAmount(1);
    142.  
    143. player.getInventory().clear();
    144.  
    145. player.sendMessage(ChatColor.RED + "You have chosen the Archer Kit!");
    146.  
    147. player.setItemInHand(sword);
    148. player.getInventory().addItem(helm);
    149. player.getInventory().addItem(chest);
    150. player.getInventory().addItem(leg);
    151. player.getInventory().addItem(boots);
    152. player.getInventory().addItem(bow);
    153. player.getInventory().addItem(arrow);
    154.  
    155. return true;
    156. }
    157. if(args[0].equalsIgnoreCase("Help")) {
    158. player.sendMessage(ChatColor.GREEN + "Commands: /KitPvP <Kit> - Chooses a kit - /KitPvP Kits - Displays all kits and kits you can buy - /KitPvP Buy<Kit> - Buys the selected kit!");
    159. return true;
    160. }
    161. if(args[0].equalsIgnoreCase("Kits")) {
    162. player.sendMessage(ChatColor.GREEN + "Your Kits: PvP, Archer");
    163. return true;
    164. }
    165. }
    166. }
    167. return false;
    168. }
    169.  
    170. }


    This is the code on pastebin: http://pastebin.com/Vn2L2vDN

    Plugin.yml:
    Code:
    name: MindItKitPvP
    version: 1 
    description: Adds KitPvP to the server! 
    main: me.moe097.MindItKitPvP.MindItKitPvP
    depend: [Vault]
    commands: 
        KitPvP:
          description: BASE COMMAND
        KitPvP PvP:
          description: Gives player pvp kit!
        KitPvP Archer: 
          description: Gives the player archer kit!
        KitPvP Help:
          description: Shows kitpvp help!
        KitPvP Kits:
          description: Shows all kits!
    Plugin.yml Pastebin: http://pastebin.com/qYdFQ9Bg

    Thanks!
     
  2. Offline

    ImDeJay

    Since your using arguments as command constructers, you dont have to put those into your plugin.yml
    plugin.yml is only for the initial command, not the aruments afterwards, meaning only "KitPvP" should be in the commands portion.

    Also, its bad practice to use commandLabel for checking the command, its better to use "if(cmd.getname.equalsignorecase("kitpvp")"
    Reason being, if you use cmd.getname it automatically check for any aliases etc.

    so remove all constructors from your plugin.yml under commands except for "kitpvp" and change commandlabel to cmd.getname and see if that changes anything and reply back.
     
  3. Offline

    moe097

    ImDeJay
    Thanks! The commands work now.
     
Thread Status:
Not open for further replies.

Share This Page