Help With Custom Inventory Menu and Events

Discussion in 'Plugin Help/Development/Requests' started by snamakool123, Jun 3, 2015.

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

    snamakool123

    Hello, so I am making a plugin with a custom inventory menu, I want to check which item in the menu has beem clicked. This is the error I get, how do I fix the error or can I achieve the same result in a different way.

    Code:
    [20:35:05 ERROR]: Could not pass event InventoryClickEvent to Commands v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:305) ~[spigot-1.8.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[spigot-1.8.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:502) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:487) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :1588) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.PacketPlayInWindowClick.a(SourceFile:31)
    [spigot-1.8.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.PacketPlayInWindowClick.a(SourceFile:9)
    [spigot-1.8.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spi
    got-1.8.jar:git-Spigot-550ebac-7019900]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_31]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_31]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    96) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    16) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    34) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :537) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Caused by: java.lang.NullPointerException
            at me.snamakool123.Commands.onInventoryClickEvent(Commands.java:115) ~[?
    :?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
    _31]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
    _31]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .8.0_31]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:301) ~[spigot-1.8.jar:git-Spigot-550ebac-7019900]
            ... 14 more
    And this is my source code
    Code:
    public class Commands extends JavaPlugin implements Listener{
       
        public Permission setSpawn = new Permission("setSpawn.allowed");
       
        @Override
        public void onEnable() {
            getLogger().info("Commands plugin has been enabled!");
            getServer().getPluginManager().registerEvents(this, this);
           
            this.getConfig().addDefault("spawn.x", 0);
            this.getConfig().addDefault("spawn.y", 0);
            this.getConfig().addDefault("spawn.z", 0);
            this.getConfig().addDefault("spawn.world", 0);
            this.getConfig().addDefault("spawn.Yaw", 0);
            this.getConfig().addDefault("spawn.Pitch", 0);
           
            this.getConfig().options().copyDefaults(true);
            saveConfig();
           
        }
       
        @Override
        public void onDisable() {
           
            saveConfig();
        }
       
        //Commands GUI
        public ItemStack home;
        public ItemStack spawn;
        public static void openGUI(Player player){
            Inventory commandsInv = Bukkit.createInventory(null, 9, ChatColor.BLUE + "Commands");
           
            ItemStack home = new ItemStack(Material.WOOL,3,(short)3);
            ItemMeta homeMeta = home.getItemMeta();
           
            ItemStack spawn = new ItemStack(Material.WOOL,2,(short)2);
            ItemMeta spawnMeta = home.getItemMeta();
           
            homeMeta.setDisplayName(ChatColor.RED + "/home");
            home.setItemMeta(homeMeta);
           
            spawnMeta.setDisplayName(ChatColor.RED + "/spawn");
            spawn.setItemMeta(spawnMeta);
           
            commandsInv.setItem(5, home);
            commandsInv.setItem(3, spawn);
           
            player.openInventory(commandsInv);
        }
       
        //PlayerListerners
        //Which Item Clicked on Commands Shop
        @EventHandler
        public void onInventoryClickEvent(InventoryClickEvent event) {
            if (!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Commands")) {
                return;
            }
    
            Player player = (Player) event.getWhoClicked();
            event.setCancelled(true);
    
            if (event.getCurrentItem().getType() == Material.AIR || !event.getCurrentItem().hasItemMeta()) {
                player.closeInventory();
                return;
            }
           
            ItemStack clicked = event.getCurrentItem();
           
            if(clicked.getItemMeta().equals(home.getItemMeta())){           
                World w = Bukkit.getServer().getWorld(getConfig().getString("spawn.world"));
                player.teleport(new Location(w,100, 50, 100));
                event.setCancelled(true);
                player.closeInventory();
                player.sendMessage(ChatColor.BLUE + "You have been teleported somewhere!");
            }
        }
     
  2. Moved to Bukkit Alternates.
     
Thread Status:
Not open for further replies.

Share This Page