Could not pass InventoryCreativeEvent

Discussion in 'Plugin Development' started by PikaThieme, Jan 15, 2017.

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

    PikaThieme

    So I was making a dutch police plugin where anyone with a specific permission could right-click on people and then they'll get the inventory. Everything works fine but I still get the same error sometimes.

    Code:
    Code:java
    1. package main.pikathieme.eeneentwee.events;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.GameMode;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.inventory.InventoryClickEvent;
    9. import org.bukkit.event.inventory.InventoryType;
    10. import org.bukkit.event.player.PlayerInteractAtEntityEvent;
    11. import org.bukkit.event.inventory.*;
    12.  
    13. public class openinv implements Listener {
    14. @EventHandler
    15. public void PopoInvTake(PlayerInteractAtEntityEvent e) {
    16. if (e.getRightClicked() instanceof Player) {
    17.  
    18. Player p = e.getPlayer();
    19.  
    20. if (p.hasPermission("minetopia.invsee")) {
    21. Player R = (Player)e.getRightClicked();
    22. if (!R.hasPermission("minetopia.invdeny") || R.getGameMode() != GameMode.CREATIVE) {
    23. p.openInventory(R.getInventory());
    24. R.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "[" + ChatColor.WHITE + "" + ChatColor.BOLD + "112" + ChatColor.BLUE + "" + org.bukkit.ChatColor.BOLD + "] " + ChatColor.RED + p.getName() + ChatColor.WHITE + " kijkt in je inventory!");
    25. p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "[" + ChatColor.WHITE + "" + ChatColor.BOLD + "112" + ChatColor.BLUE + "" + ChatColor.BOLD + "] " + ChatColor.WHITE + "Je kijkt nu in de inventory van " + ChatColor.RED + R.getName() + ChatColor.WHITE + "!");
    26. }
    27. else{
    28. p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "[" + ChatColor.WHITE + "" + ChatColor.BOLD + "112" + ChatColor.BLUE + "" + org.bukkit.ChatColor.BOLD + "] " + ChatColor.RED + "Je hebt geen permissie om in de inventory van " + ChatColor.WHITE + R.getName() + ChatColor.RED + " te kijken!");
    29. }
    30. }
    31.  
    32. }
    33. }
    34. @EventHandler
    35. public void ClickEvent(InventoryClickEvent e) {
    36. if (e.getClickedInventory().getType().equals(InventoryType.PLAYER) && !e.getClickedInventory().equals(e.getWhoClicked().getInventory())) {
    37. if (!e.getWhoClicked().hasPermission("minetopia.invtake")) {
    38. e.setCancelled(true);
    39. }
    40. }
    41. }
    42.  
    43. }


    Error:
    Code:
    [Server thread/ERROR]: Could not pass event InventoryCreativeEvent to CuzaCraftPika v0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1950) [spigot.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.PacketPlayInSetCreativeSlot.a(SourceFile:23) [spigot.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.PacketPlayInSetCreativeSlot.a(SourceFile:9) [spigot.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-7d15d07-c194444]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
        at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45) [spigot.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:716) [spigot.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:655) [spigot.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:554) [spigot.jar:git-Spigot-7d15d07-c194444]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.NullPointerException
        at main.pikathieme.eeneentwee.events.openinv.ClickEvent(openinv.java:35) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_111]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-7d15d07-c194444]
        ... 15 more
    
    I hope you guys can help :)
     
    Last edited by a moderator: Jan 15, 2017
  2. Offline

    Zombie_Striker

    Follow java naming conventionS: Class names should start with an uppercase letter.

    Follow Java naming conventions: variable names should start with lowercase letters.

    Use == when comparing enums.

    Something is null on line 35. Please post only line 35.
     
  3. Offline

    Ilomiswir

    @Zombie_Striker
    this is line 35
    public void ClickEvent(InventoryClickEvent e) {
     
  4. Online

    timtower Administrator Administrator Moderator

    Moved to plugin development.
    @Zombie_Striker Added syntax and code blocks for you ;)
     
  5. Offline

    JanTuck

    I can only think of if the player clicks outside of the inventory the

    InventoryClickEvent#getClickedInventory()

    Will return null and you can't get the type of the inventory.

    But i dont know why it says that exact line is null.
     
  6. Online

    timtower Administrator Administrator Moderator

    Not sure, I work with commands for the most part.
     
  7. Offline

    JanTuck

    I looked it up and it returns null for sure.
     
  8. Offline

    PikaThieme

    Okay, so far I editted the plugin, I don't get the error anymore. But I only have 1 problem left. Everytime I click on a player, the message displays twice. I think it's a 1.9 bug because first I made it 1.8 and then everything worked fine.
    Hope you guys can help me again :)
     
  9. Offline

    Zombie_Striker

    @PikaThieme
    Yeah, PlayerInteractEvent is triggered for both hands as of 1.9 Do counteract this, only check if the player clicked with the right hand.
     
Thread Status:
Not open for further replies.

Share This Page