Command not doing anything?

Discussion in 'Plugin Development' started by frogman6102, Apr 21, 2014.

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

    frogman6102

    Code:
    main: com.gmail.frogman6102.Frogasaur
    name: Frogasaurs
    author: frogman6102
    version: 0.1
    commands:
      frog:
        description: Open frogasaurs menu!
        permission: frogasaurs.frog
        permission-message: You can't open the Frogasaur menu!
    Code:java
    1. ackage com.gmail.frogman6102;
    2. [B]My plugin.yml is up there.[/B]
    3. [B]My code is down here.[/B]
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Effect;
    8. import org.bukkit.Location;
    9. import org.bukkit.Material;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandExecutor;
    12. import org.bukkit.command.CommandSender;
    13. import org.bukkit.entity.EntityType;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.entity.Snowball;
    16. import org.bukkit.event.EventHandler;
    17. import org.bukkit.event.Listener;
    18. import org.bukkit.event.block.Action;
    19. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    20. import org.bukkit.event.inventory.InventoryClickEvent;
    21. import org.bukkit.event.player.PlayerInteractEvent;
    22. import org.bukkit.inventory.Inventory;
    23. import org.bukkit.inventory.InventoryHolder;
    24. import org.bukkit.inventory.ItemStack;
    25. import org.bukkit.inventory.ShapelessRecipe;
    26. import org.bukkit.inventory.meta.ItemMeta;
    27. import org.bukkit.plugin.java.JavaPlugin;
    28.  
    29. public class Frogasaur extends JavaPlugin implements Listener, InventoryHolder, CommandExecutor {
    30.  
    31.  
    32.  
    33. @Override
    34. public void onEnable() {
    35.  
    36. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    37.  
    38. ItemStack gun = new ItemStack(Material.FEATHER);
    39. ItemMeta g = gun.getItemMeta();
    40. g.setDisplayName(ChatColor.AQUA + "Frogasaur Rifle");
    41. gun.setItemMeta(g);
    42.  
    43.  
    44. ShapelessRecipe p = new ShapelessRecipe(gun);
    45. p.addIngredient(Material.DIAMOND);
    46. p.addIngredient(Material.ARROW);
    47. p.addIngredient(Material.STICK);
    48. Bukkit.getServer().addRecipe(p);
    49.  
    50. getCommand("frog").setExecutor(this);
    51.  
    52.  
    53. }
    54. @Override
    55. public void onDisable() {
    56. System.out.println("Frogasaurs has been disabled!");
    57. }
    58. public boolean onCommand(CommandSender sender, Command command, String label[], String args[]) {
    59. if(command.getName().equalsIgnoreCase("frog")) {
    60. if(sender instanceof Player) {
    61. if(sender.hasPermission("frogasaurs.frog")) {
    62. Player p = (Player) sender;
    63.  
    64. Inventory inv = Bukkit.getServer().createInventory(this, 9, ChatColor.AQUA + "Frogasaurs");
    65. ItemStack em = new ItemStack(Material.EMERALD_BLOCK);
    66. ItemMeta me = em.getItemMeta();
    67. me.setDisplayName(ChatColor.AQUA + "Spawn a Pigosaur!");
    68. em.setItemMeta(me);
    69.  
    70. ItemStack close = new ItemStack(Material.EMERALD_ORE);
    71. ItemMeta closeMeta = close.getItemMeta();
    72. closeMeta.setDisplayName(ChatColor.AQUA + "Disable the Frogasaurs plugin.");
    73. close.setItemMeta(closeMeta);
    74.  
    75. inv.addItem(em);
    76. inv.addItem(close);
    77.  
    78.  
    79. p.openInventory(inv);
    80.  
    81.  
    82. return true;
    83. }else{
    84.  
    85. sender.sendMessage(ChatColor.RED + "You can't open the frogasaur menu through the console, you must be in-game!");
    86. return false;
    87. }
    88. }else{
    89. return false;
    90. }
    91. }else{
    92. return false;
    93. }
    94.  
    95. }
    96.  
    97. @Override
    98. public Inventory getInventory() {
    99.  
    100. return null;
    101. }
    102. @EventHandler
    103. public void InvClick(InventoryClickEvent event) {
    104. if(event.getInventory().getName().equalsIgnoreCase(ChatColor.AQUA + "Frogasaurs")) {
    105. if(event.getInventory().getHolder().equals(EntityType.PLAYER)) {
    106.  
    107. Player Hold = (Player) event;
    108. if(Hold.getItemOnCursor().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.AQUA + "Spawn a Frogasaur!")) {
    109. Location HoldLocation = Hold.getLocation();
    110.  
    111. HoldLocation.getWorld().spawnEntity(HoldLocation, EntityType.PIG_ZOMBIE);
    112.  
    113. }else{
    114. return;
    115. }
    116. if(Hold.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.AQUA + "Disable the frogasurs plugin.")) {
    117.  
    118.  
    119. Bukkit.getServer().getPluginManager().disablePlugin(this);
    120. }else{
    121. return;
    122. }
    123.  
    124.  
    125. }else{
    126. return;
    127. }
    128. }else{
    129. return;
    130. }
    131.  
    132.  
    133. return;
    134. }
    135.  
    136.  
    137.  
    138. @EventHandler
    139. public void gunShoot(PlayerInteractEvent event) {
    140. if(event.getAction() == Action.RIGHT_CLICK_AIR) {
    141. if(event.getPlayer().getItemInHand().equals(Material.FEATHER)) {
    142. Player pShooter = event.getPlayer();
    143.  
    144.  
    145. pShooter.launchProjectile(Snowball.class);
    146.  
    147. pShooter.launchProjectile(Snowball.class);
    148.  
    149.  
    150. }else{
    151. return;
    152. }
    153. }else{
    154. return;
    155. }
    156. }
    157. @EventHandler
    158. public void onDamage(EntityDamageByEntityEvent event) {
    159. if(event.getDamager() instanceof Player) {
    160. Player pShot = (Player) event.getDamager();
    161.  
    162. if(pShot.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.AQUA + "Frogasaur Rifle")) {
    163. if(event.getEntity().equals(EntityType.PIG_ZOMBIE)){
    164. Location pShotLocation = pShot.getLocation();
    165. event.setDamage(5);
    166. pShot.getWorld().playEffect(pShotLocation, Effect.ENDER_SIGNAL, 1);
    167. }else{
    168. return;
    169. }
    170.  
    171.  
    172. }else{
    173. return;
    174. }
    175.  
    176. }else{
    177. return;
    178. }
    179. }
    180. }
    181.  

    I type /frog in my Minecraft game and nothing happens?

    I also get no errors on startup or when I type the command?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    will181

    One thing, the p is missing in "package" on the first line. Not sure if that was just you not copying it though.

    If you do /pl or /? is the plugin listed?
     
  3. Offline

    beeselmane

    Are you sure you have the permission? :p
     
  4. Offline

    Wizehh

    frogman6102
    Code:java
    1. public boolean onCommand(CommandSender sender, Command command, String label[], String args[]) {

    Should be:
    PHP:
    public boolean onCommand(CommandSender senderCommand commandString labelString args[]) {
    (The alias is not a String[])
     
  5. Offline

    frogman6102

    OMG thank you!!!! Wizehh

    The plugin shows up and the problem was fixed, beeselmane will181

    Although, since you guys are online, can you help me with another problem and explain what to do and why?
    The problem is that I want to check if the player has clicked on a item called "Spawn a frogasaur!" then it will spawn a Zombie Pig where his or her location is at, same for the "Disable the frogasaurs plugin.". I understand checking for the name although I don't know how to check if a item within that inventory is clicked? I know how to check if that inventory is opened.
    Thanks,
    frogman6102

    Wizehh beeselmane

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  6. Offline

    Nateb1121

  7. Offline

    frogman6102

  8. Offline

    Nateb1121

    frogman6102
    We all have brain farts every now and then ;) No worries.
     
  9. Offline

    frogman6102

    Nateb1121
    Code:java
    1. @EventHandler
    2. public void InvClick(InventoryClickEvent event) {
    3. if(event.getInventory().getName().equalsIgnoreCase(ChatColor.AQUA + "Frogasaurs")) {
    4. if(event.getInventory().getHolder().equals(EntityType.PLAYER)) {
    5.  
    6. Player Hold = (Player) event;
    7. if(Hold.getItemOnCursor().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.AQUA + "Spawn a Frogasaur!")) {
    8. Location HoldLocation = Hold.getLocation();
    9.  
    10. HoldLocation.getWorld().spawnEntity(HoldLocation, EntityType.PIG_ZOMBIE);
    11.  
    12. }else{
    13. return;
    14. }
    15. if(Hold.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.AQUA + "Disable the frogasurs plugin.")) {
    16.  
    17.  
    18. Bukkit.getServer().getPluginManager().disablePlugin(this);
    19. }else{
    20. return;
    21. }
    22.  
    23.  
    24. }else{
    25. return;
    26. }
    27.  
    28.  
    29.  
    30. }else{
    31. return;
    32. }
    33.  
    34.  
    35. return;
    36. }
    37.  

    Here's my code:



    It doesn't spawn a Zombie Pig. I am also wondering how to make it so that when I click in that inventory I take something it wait's a second then puts it back in there? If you could help me that would be great.

    Nvm, I fixed the part of where I check what was clicked. But I still don't know the other parts.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  10. Offline

    Nateb1121

    I don't know if you're meaning to do this but
    Code:java
    1. event.getInventory().getName().equalsIgnoreCase(ChatColor.AQUA + "Frogasaurs")

    gets the name of the inventory, not the item... though that could be intentional.

    Another thing
    Code:java
    1. event.getInventory().getHolder().equals(EntityType.PLAYER)

    compares the objects, not the classes you'll want to do something like
    Code:java
    1. event.getInventory().getHolder() instaceof Player


    Something that never hurts is to add debugging code so you know where exactly it's breaking. So you might want to add print outs something like "I got past the forgasarus name check thing" that way you know which line is breaking.
     
  11. Offline

    frogman6102

Thread Status:
Not open for further replies.

Share This Page