InventoryClickEvent

Discussion in 'Plugin Development' started by pvtr_, Jan 1, 2020.

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

    pvtr_

    hi I have a problem with the code that generates the error and I can't handle it myself ... Please help :(
    Code:
    [19:11:07 ERROR]: Could not pass event InventoryClickEvent to aCORE v1.2-SNAPSHOT
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1630) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:31) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:9) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_231]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_231]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_231]
    Caused by: java.lang.NullPointerException
            at com.gmail.pvtr.listeners.inventory.InventoryClickerListener.onInteract(InventoryClickerListener.java:55) ~[?:?]
            at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source) ~[?:?]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_231]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            ... 15 more
    My code:
    Code:
          @EventHandler
          public void onInteract(final InventoryClickEvent e) {
              final Player p = (Player)e.getWhoClicked();
              if (e.getInventory().getName().equalsIgnoreCase(ChatUtil.fixColors("&8(&fDiscoZbroja&8)&7 - Menu"))) {
                  e.setCancelled(true);
              }
                  if (e.getClickedInventory().getName() == null) {
                      return;
                  }
                  if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatUtil.fixColors("&8&lDISCO-ZBROJA"))) {
                      if (!DataManager.getDisco().containsKey(p.getName())) {
                          DataManager.getDisco().put(p.getName(), ArmorType.RANDOM);
                          ChatUtil.sendMessage((CommandSender)p, "&8>> &7Tryb disco zbroji zostal ustawiony na &2RANDOM");
                          DiscoMenu.inv(p);
                          return;
                      }
                      if (DataManager.getDisco().get(p.getName()).equals(ArmorType.RANDOM)) {
                          DataManager.getDisco().put(p.getName(), ArmorType.SMOOTH);
                          DataManager.getLastColor().put(p.getName(), Color.fromRGB(255, 0, 0));
                          ChatUtil.sendMessage((CommandSender)p, "&8>> &7Tryb disco zbroji zostal ustawiony na &2SMOOTH");
                          DiscoMenu.inv(p);
                          return;
                      }
                      if (DataManager.getDisco().get(p.getName()).equals(ArmorType.SMOOTH)) {
                          DataManager.getDisco().put(p.getName(), ArmorType.GRAY);
                          DataManager.getLastColor().put(p.getName(), Color.fromRGB(255, 0, 0));
                          ChatUtil.sendMessage((CommandSender)p, "&8>> &7Tryb disco zbroji zostal ustawiony na &2GRAY");
                          DiscoMenu.inv(p);
                          return;
                      }
                      if (DataManager.getDisco().get(p.getName()).equals(ArmorType.GRAY)) {
                          for (int i = 0; i < 4; ++i) {
                              for (final Player online : Bukkit.getOnlinePlayers()) {
                                  if (!online.getName().equals(p.getName())) {
                                      PacketEquipment.sendEquipment(online, p.getEntityId(), 1 + i, p.getInventory().getArmorContents()[i]);
                                  }
                              }
                          }
                          DataManager.getDisco().remove(p.getName());
                          DataManager.getLastColor().remove(p.getName());
                          DataManager.getShiftArmor().remove(p.getName());
                          ChatUtil.sendMessage((CommandSender)p, "&8>> &7Tryb disco zbroji zostal ustawiony na &2OFF");
                          DiscoMenu.inv(p);
    
    this is a 55 line

    Code:
    if (e.getClickedInventory().getName() == null) {
     
  2. Online

    timtower Administrator Moderator

    @pvtr_ Do a nullcheck on e.getClickedInventory
     
  3. Offline

    pvtr_

    Thank you very much! it works!
     
Thread Status:
Not open for further replies.

Share This Page