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

    org.bukkit.event.EventException

    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-870264a-0a645a2]

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

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

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

    at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:1620) [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$1.run(SourceFile:13) [spigot.jar:git-Spigot-870264a-0a645a2]

    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_45]

    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?: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(MinecraftServer.java:712) [spigot.jar:git-Spigot-870264a-0a645a2]

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

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

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

    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]

    Caused by: java.lang.NullPointerException

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

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

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

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

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

    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-870264a-0a645a2]

    ... 15 more















    my inventory click event code :

















    @EventHandler

    public void onClick(InventoryClickEvent e){

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

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

    e.setCancelled(true);

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

    e.getWhoClicked();

    p.performCommand("server opfactions");
     
  2. Check line 46 of Main.java. 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?
    http://pastebin.com/4Ce39DPN
     
  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
                  PayloadStarter.starter(player);
    //Im calling the method here which allows my game to start its countdown
                   player.closeInventory();
    //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 ? http://pastebin.com/4Ce39DPN 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){
    e.setCancelled(true);
    }
    If a slot isn't clicked it will return -1 and in your case, throw an error.