Solved Inventory menu

Discussion in 'Plugin Development' started by nelson2tm, Jun 24, 2014.

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

    nelson2tm

    Hello everyone!
    I am currently developing an plugin for my server, using effectlib.
    The problem is, that when you click the dirt in the inventory, it does not what it suposed to be. It doesn't go back in the spot, and it doesn't close the inventory. It just acts like a normal chest (1 row, what its supposed to be.).
    Here is my code:
    Code:java
    1. package me.nelson2tm.catcrafteffects;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.inventory.InventoryClickEvent;
    11. import org.bukkit.inventory.Inventory;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. import de.slikey.effectlib.EffectLib;
    16. import de.slikey.effectlib.EffectManager;
    17. import de.slikey.effectlib.effect.TextLocationEffect;
    18. import de.slikey.effectlib.effect.VortexLocationEffect;
    19. import de.slikey.effectlib.util.ParticleEffect;
    20.  
    21. public class CatCraftEffects extends JavaPlugin implements Listener {
    22. private EffectManager effectManager;
    23.  
    24. public void onEnable(){
    25. getLogger().info("Enabled!");
    26. EffectLib lib = EffectLib.instance();
    27. effectManager = new EffectManager(lib);
    28. }
    29.  
    30. public void onDisable(){
    31. getLogger().info("Disabled!");
    32. }
    33.  
    34. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    35. if(!(sender instanceof Player)){
    36. sender.sendMessage("[CatCraftEffects] You can only use this command as player!");
    37. return true;
    38. }
    39. Player player = (Player) sender;
    40. if(cmd.getName().equalsIgnoreCase("catcrafteffects")){
    41. VortexLocationEffect vortexeffect = new VortexLocationEffect (effectManager, player.getLocation());
    42. vortexeffect.iterations = 200;
    43. vortexeffect.start();
    44. player.openInventory(myInventory);
    45. } else if(cmd.getName().equalsIgnoreCase("happyname")) {
    46. TextLocationEffect texteffect = new TextLocationEffect (effectManager, player.getLocation());
    47. texteffect.text = player.getDisplayName();
    48. texteffect.particle = ParticleEffect.CLOUD;
    49. texteffect.iterations = 200;
    50. texteffect.start();
    51. }
    52. return false;
    53. }
    54. public static Inventory myInventory = Bukkit.createInventory(null, 9, "My custom Inventory!");
    55. // The first parameter, is the inventory owner. I make it null to let everyone use it.
    56. //The second parameter, is the slots in a inventory. Must be a multiple of 9. Can be up to 54.
    57. //The third parameter, is the inventory name. This will accept chat colors
    58. static {
    59. myInventory.setItem(0, new ItemStack(Material.DIRT, 1));
    60. myInventory.setItem(8, new ItemStack(Material.GOLD_BLOCK, 1));
    61. }
    62. @EventHandler
    63. public void onInventoryClick(InventoryClickEvent event) {
    64. Player player = (Player) event.getWhoClicked(); // The player that clicked the item
    65. ItemStack clicked = event.getCurrentItem(); // The item that was clicked
    66. Inventory inventory = event.getInventory(); // The inventory that was clicked in
    67. if (inventory.getName().equals(myInventory.getName())) {
    68. if (clicked.getType() == Material.DIRT) { // The item that the player clicked it (diamond)
    69. event.setCancelled(true);// Make it so the diamond is back in it's spot
    70. player.closeInventory();
    71. }
    72. }
    73. }
    74. }

    Can anyone help me with what i did wrong? The console doesn't give errors and eclipse also doesn't give errors.
    Thanks!
     
  2. Offline

    TheRage66

    Didn't register your events.
     
    nelson2tm likes this.
  3. Offline

    nelson2tm

  4. Offline

    fireblast709

  5. Offline

    Glass_Eater84

  6. Offline

    nelson2tm

Thread Status:
Not open for further replies.

Share This Page