Could not pass event InventoryClickEvent to ServerSelector v1.0

Discussion in 'Spigot Plugin Development' started by HarutCraft, May 21, 2015.

  1. Help me !
    in my console i am getting :

    Could not pass event InventoryClickEvent to ServerSelector v1.0


    at$1.execute( ~[spigot.jar:git-Spigot-870264a-0a645a2]

    at org.bukkit.plugin.RegisteredListener.callEvent( ~[spigot.jar:git-Spigot-870264a-0a645a2]

    at org.bukkit.plugin.SimplePluginManager.fireEvent( [spigot.jar:git-Spigot-870264a-0a645a2]

    at org.bukkit.plugin.SimplePluginManager.callEvent( [spigot.jar:git-Spigot-870264a-0a645a2]

    at net.minecraft.server.v1_8_R2.PlayerConnection.a( [spigot.jar:git-Spigot-870264a-0a645a2]

    at net.minecraft.server.v1_8_R2.PacketPlayInWindowClick.a(SourceFile:31) [spigot.jar:git-Spigot-870264a-0a645a2]

    at net.minecraft.server.v1_8_R2.PacketPlayInWindowClick.a(SourceFile:9) [spigot.jar:git-Spigot-870264a-0a645a2]

    at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$ [spigot.jar:git-Spigot-870264a-0a645a2]

    at java.util.concurrent.Executors$ [?:1.8.0_45]

    at [?:1.8.0_45]

    at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot.jar:git-Spigot-870264a-0a645a2]

    at net.minecraft.server.v1_8_R2.MinecraftServer.A( [spigot.jar:git-Spigot-870264a-0a645a2]

    at net.minecraft.server.v1_8_R2.DedicatedServer.A( [spigot.jar:git-Spigot-870264a-0a645a2]

    at net.minecraft.server.v1_8_R2.MinecraftServer.z( [spigot.jar:git-Spigot-870264a-0a645a2]

    at [spigot.jar:git-Spigot-870264a-0a645a2]

    at [?:1.8.0_45]

    Caused by: java.lang.NullPointerException

    at me.TheRealHarut.ServerSelector.Main.onClick( ~[?:?]

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]

    at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:1.8.0_45]

    at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:1.8.0_45]

    at java.lang.reflect.Method.invoke( ~[?:1.8.0_45]

    at$1.execute( ~[spigot.jar:git-Spigot-870264a-0a645a2]

    ... 15 more

    my inventory click event code :


    public void onClick(InventoryClickEvent e){

    if (e.getInventory().getName().equals(inv.getName())) {

    if (e.getCurrentItem() != null) {


    if (e.getCurrentItem().getType().equals(Material.GOLDEN_APPLE)) {


    p.performCommand("server opfactions");
  2. Check line 46 of Whatever is on that line is null.
    Also, please use spoilers and code tags.
  3. im trying to make the item in the inventory execute a command here is my code what could i have to add to make it execute a command?
  4. Under your InventoryClickEvent listener, make sure to check if the inventory is not null. For instance, if when a player clicks outside of the inventory window, the event is still called, but the inventory will be null.
  5. can i have a example of this?
  6. It would look something along the lines of the following:
    Code (Java):
    public void onInventoryClicked(InventoryClickEvent event) {
         Inventory inventory = event.getInventory();
         if(inventory != null) {
              // We clicked in a valid inventory!
         } else {
              // We clicked outside of the inventory window!
  7. how could i execute a command if they click a item
  8. @HarutCraft in general why even use a command from a GUI?
    A command just preforms an action so why not just call the method that contains the action you want to preform

    A quick example. lets say you wanted to start a countdown, then you could call the countdown method with the inventoryClickEvent if all your conditions are fulfilled

    Code (Text):

    String itemName = e.getCurrentItem().getItemMeta().getDisplayName();
    if (itemName.equals(ChatColor.YELLOW.toString() + ChatColor.BOLD + "Game Start")){

          Player player = (Player)e.getWhoClicked();
    //i get the player that clicked

           if (e.getWhoClicked() instanceof Player){
    //checks if the clicker was a Player
    //Im calling the method here which allows my game to start its countdown
    //then i close the inventory
  9. You don't need to check if it was a player.
    Just use this:
    Code (Text):
    Inventory inventory = e.getInventory();
    if (inventory != null){
        if (e.getCurrentItem().equals(itemstack){
        perform a command what u want.
    You need to make a ItemStack for your equals(). And if you want 'your' inventory just replace e.getInventory() to inv (your var).
    • Like Like x 1
  10. Can you implement this in my code ? Please if you can it would be helpful
  11. Although I can't speak for @Svenna, this forum is for plugin development. If you want to make plugins, please search around on Google for well-known problems, as well as searching Oracle's (and I believe Google's) Java tutorials. It will help you a million times more to learn and implement it yourself than to have someone else do it for you.

    @CBPlugins, what is funny about this post?
    #11 NinjaWaffles, May 22, 2015
    Last edited: May 23, 2015
    • Agree Agree x 1
    • Funny Funny x 1
  12. Just use

    Code (Text):
    if(e.getSlot() == -1){
    If a slot isn't clicked it will return -1 and in your case, throw an error.