Could not pass event PlayerInteractEvent

Discussion in 'Plugin Development' started by drafix, Jul 4, 2019.

  1. Offline

    drafix

    Hi, someone will help? The console pops up such errors (plugin work well)

    "[20:08:05] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to plugin1 v1.0.0"

    Code:
    Code:
    @EventHandler
      public void onInteract(PlayerInteractEvent e) {
       Action a = e.getAction();
        Player p = e.getPlayer();
        Block clicked = e.getClickedBlock();
    
        if(clicked.getType() == Material.CHEST)
        {
      
        Chest chest = (Chest)clicked.getState();
        Inventory inv = ((HumanEntity) chest).getInventory();
        if (clicked != null && a != Action.PHYSICAL && clicked.getType() == Material.CHEST && inv.getTitle().equalsIgnoreCase(ChatColor.AQUA + "chest")) {
          if (this.canOpen.get(p) == Boolean.TRUE) {
          
            if (hasItem(p.getInventory(), p))
            {
              this.canOpen.put(p, Boolean.valueOf(false));
              p.sendMessage(ChatColor.AQUA + "opening");
              openWinCase(p);
              int x = clicked.getX();
              int y = clicked.getY();
              int z = clicked.getZ();
              String cmd = "setblock " + x + " " + y + " " + z + " minecraft:air";
    
              Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
            
              Firework f = (Firework)e.getPlayer().getWorld().spawn(e.getPlayer().getLocation(), Firework.class);
            
              FireworkMeta fm = f.getFireworkMeta();
              fm.addEffect(FireworkEffect.builder()
                  .flicker(false)
                  .trail(true)
                  .with(FireworkEffect.Type.BALL)
                  .withColor(Color.GREEN)
                  .withFade(Color.BLUE)
                  .build());
              fm.setPower(0);
              f.setFireworkMeta(fm);
            }
            else
            {
              p.sendMessage("§4you dont have key");
            }
        
          } else {
          
            p.sendMessage("§4you cant open chest now");
          }
        }
        }
      }
    
    
    
    
    
      public boolean hasItem(Inventory inv, Player player) {
        ItemStack weapon = new ItemStack(Material.TRIPWIRE_HOOK);
        ItemMeta im = weapon.getItemMeta();
        im.setDisplayName(ChatColor.AQUA + "Key");
        im.setLore(Arrays.asList(new String[] { ChatColor.GREEN + "key to open chest" }));
        weapon.setItemMeta(im);
    
      
        for (int i = 0; i < inv.getSize(); i++) {
        
          if (inv.getItem(i) != null)
          {
            if (inv.getItem(i).getItemMeta().hasDisplayName())
            {
              if (inv.getItem(i).getItemMeta().getDisplayName().equals(ChatColor.AQUA + "Key") && inv.getItem(i).getType().equals(Material.TRIPWIRE_HOOK)) {
              
                int amount = inv.getItem(i).getAmount();
              
                if (amount > 1) {
                
                  inv.getItem(i).setAmount(amount - 1);
                }
                else if (amount == 1) {
                
                  inv.setItem(i, null);
                }
              
                return true;
              }
            }
          }
        }
        return false;
      }
     
  2. Offline

    KarimAKL

    @drafix There's more of the error, post that.
     
  3. Offline

    drafix

    @KarimAKL
    Code:
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:228) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:195) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:191) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1200) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInArmAnimation.a(PacketPlayInArmAnimation.java:18) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInArmAnimation.a(PacketPlayInArmAnimation.java:1) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_211]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_211]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
    Caused by: java.lang.NullPointerException
        at me.KimPix.KCase.Main.onInteract(Main.java:116) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_211]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[silnik.jar:git-Spigot-db6de12-18fbb24]
        ... 18 more
    [19:55:53] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to KCase v1.0.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:228) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:195) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:191) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1200) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInArmAnimation.a(PacketPlayInArmAnimation.java:18) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInArmAnimation.a(PacketPlayInArmAnimation.java:1) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_211]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_211]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
    Caused by: java.lang.NullPointerException
        at me.KimPix.KCase.Main.onInteract(Main.java:116) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_211]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[silnik.jar:git-Spigot-db6de12-18fbb24]
        ... 18 more
    [19:55:54] [Server thread/INFO]: KimPix issued server command: /drop
    [19:58:59] [Server thread/INFO]: KimPix issued server command: /win add chest 1
    [19:59:01] [Server thread/INFO]: KimPix issued server command: /win add key 1
    [19:59:05] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to KCase v1.0.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:228) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerInteractManager.interact(PlayerInteractManager.java:463) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:759) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_211]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_211]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R3.block.CraftBlockState cannot be cast to org.bukkit.block.Chest
        at me.KimPix.KCase.Main.onInteract(Main.java:116) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_211]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[silnik.jar:git-Spigot-db6de12-18fbb24]
        ... 17 more
    [19:59:06] [Server thread/INFO]: The block couldn't be placed
    [19:59:07] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to KCase v1.0.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:228) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:195) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:191) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1200) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInArmAnimation.a(PacketPlayInArmAnimation.java:18) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInArmAnimation.a(PacketPlayInArmAnimation.java:1) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_211]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_211]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [silnik.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
    Caused by: java.lang.NullPointerException
        at me.KimPix.KCase.Main.onInteract(Main.java:116) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_211]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[silnik.jar:git-Spigot-db6de12-18fbb24]
        ... 18 more
    [20:01:33] [Server thread/INFO]: CONSOLE: [0;31;1mPlease note that this command is not supported and may cause issues when using some plugins.[m
    [20:01:33] [Server thread/INFO]: CONSOLE: [0;31;1mIf you encounter any issues please use the /stop command to restart your server.[m
     
  4. Offline

    KarimAKL

    What is line 116 of your 'Main' class?
     
  5. Offline

    drafix

    @KarimAKL

    if(clicked.getType() == Material.CHEST)
     
  6. Offline

    KarimAKL

    @drafix 'clicked' is null, check if 'e.getAction()' is 'Action.RIGHT_CLICK_BLOCK' or 'Action.LEFT_CLICK_BLOCK' before doing anything with 'e.getClickedBlock()'
     
  7. Offline

    drafix

    Thanks!!!
     

Share This Page