Could not pass event PlayerInteractEvent

Discussion in 'Plugin Development' started by DevMax_Plg, Jul 6, 2019.

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

    DevMax_Plg

    Hey guys,

    I have a little problem.
    Whenever I try to click on a block or in the air I get an error every time

    here is the full error:
    Code:text
    1. [10:53:24 ERROR]: Could not pass event PlayerInteractEvent to LobbySystem v1.0 Beta
    2. org.bukkit.event.EventException
    3. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-7d15d07-c194444]
    4. at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-7d15d07-c194444]
    5. at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-7d15d07-c194444]
    6. at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-7d15d07-c194444]
    7. at org.bukkit.craftbukkit.v1_9_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:212) [spigot.jar:git-Spigot-7d15d07-c194444]
    8. at org.bukkit.craftbukkit.v1_9_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:179) [spigot.jar:git-Spigot-7d15d07-c194444]
    9. at org.bukkit.craftbukkit.v1_9_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:175) [spigot.jar:git-Spigot-7d15d07-c194444]
    10. at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1340) [spigot.jar:git-Spigot-7d15d07-c194444]
    11. at net.minecraft.server.v1_9_R1.PacketPlayInArmAnimation.a(SourceFile:32) [spigot.jar:git-Spigot-7d15d07-c194444]
    12. at net.minecraft.server.v1_9_R1.PacketPlayInArmAnimation.a(SourceFile:9) [spigot.jar:git-Spigot-7d15d07-c194444]
    13. at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-7d15d07-c194444]
    14. at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
    15. at java.base/java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
    16. at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45) [spigot.jar:git-Spigot-7d15d07-c194444]
    17. at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:716) [spigot.jar:git-Spigot-7d15d07-c194444]
    18. at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot.jar:git-Spigot-7d15d07-c194444]
    19. at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:655) [spigot.jar:git-Spigot-7d15d07-c194444]
    20. at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:554) [spigot.jar:git-Spigot-7d15d07-c194444]
    21. at java.base/java.lang.Thread.run(Unknown Source) [?:?]
    22. Caused by: java.lang.NullPointerException
    23. at de.max.lobby.listeners.OnInteract.onInteract(OnInteract.java:23) ~[?:?]
    24. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
    25. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
    26. at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
    27. at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
    28. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-7d15d07-c194444]
    29. ... 18 more


    It says that something in my OnInteract Listener equals null but i dont find the problem
    here is my OnInteract class:

    Code:Java
    1. package de.max.lobby.listeners;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.inventory.Inventory;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14.  
    15.  
    16.  
    17. public class OnInteract implements Listener{
    18.  
    19. private final String GUI_NAME = "§6§lServer-Menü";
    20.  
    21. @EventHandler(priority = EventPriority.HIGHEST)
    22. public void onInteract (PlayerInteractEvent event) {
    23. if (event.getItem().getType() == Material.NETHER_STAR) {
    24. if(event.getItem().getItemMeta().getDisplayName() == "§6Server Menü") {
    25. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    26. Player player = event.getPlayer();
    27. Inventory inventory = Bukkit.createInventory(null, 9*6, GUI_NAME);
    28. for (int i = 0; i < 54; i++) {
    29. inventory.setItem(i, new ItemStack(Material.STAINED_GLASS_PANE));
    30. }
    31. ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
    32. ItemMeta itemMeta = item.getItemMeta();
    33. itemMeta.setDisplayName("PVP");
    34. item.setItemMeta(itemMeta);
    35. inventory.setItem(28, new ItemStack(Material.GOLDEN_APPLE));
    36. inventory.setItem(34, new ItemStack(Material.GOLDEN_APPLE));
    37. inventory.setItem(13, item);
    38. player.openInventory(inventory);
    39. }
    40. }
    41. }
    42. }
    43. }


    I hope anyone can help me

    Kind regards

    Max
     
  2. Offline

    timtower Moderator Moderator

    @DevMax_Plg event.getItem()
    Check if it is null first.
    Check if there is a displayname.
     
  3. Offline

    DevMax_Plg

    My code looks now like this:

    Code:Java
    1. package de.max.lobby.listeners;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.inventory.Inventory;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14.  
    15.  
    16.  
    17. public class OnInteract implements Listener{
    18.  
    19. private final String GUI_NAME = "§6§lServer-Menü";
    20.  
    21. @EventHandler(priority = EventPriority.HIGHEST)
    22. public void onInteract (PlayerInteractEvent event) {
    23. if (event.getItem() == null) {
    24. return;
    25. } else if (event.getItem().getType() == Material.NETHER_STAR) {
    26. if (event.getItem().getItemMeta().getDisplayName() == null) {
    27. return;
    28. } else if(event.getItem().getItemMeta().getDisplayName() == GUI_NAME) {
    29. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    30. Player player = event.getPlayer();
    31. Inventory inventory = Bukkit.createInventory(null, 9*6, GUI_NAME);
    32. for (int i = 0; i < 54; i++) {
    33. inventory.setItem(i, new ItemStack(Material.STAINED_GLASS_PANE));
    34. }
    35. ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
    36. ItemMeta itemMeta = item.getItemMeta();
    37. itemMeta.setDisplayName("PVP");
    38. item.setItemMeta(itemMeta);
    39. inventory.setItem(28, new ItemStack(Material.GOLDEN_APPLE));
    40. inventory.setItem(34, new ItemStack(Material.GOLDEN_APPLE));
    41. inventory.setItem(13, item);
    42. player.openInventory(inventory);
    43. }
    44. }
    45. }
    46. }
    47. }


    No errors so far
    But now it doesnt recognise when i click the item
     
    Last edited by a moderator: Jul 6, 2019
  4. Offline

    timtower Moderator Moderator

    @DevMax_Plg String compares are done with .equals and .equalsIgnoreCase, not with ==
     
  5. Offline

    DevMax_Plg

    My code now looks like this:
    Code:Java
    1. package de.max.lobby.listeners;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.inventory.Inventory;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14.  
    15.  
    16.  
    17. public class OnInteract implements Listener{
    18.  
    19. private final String GUI_NAME = "§6§lServer-Menü";
    20.  
    21. @EventHandler(priority = EventPriority.HIGHEST)
    22. public void onInteract (PlayerInteractEvent event) {
    23. if (event.getItem().equals(null)) {
    24. return;
    25. } else if (event.getItem().getType().equals(Material.NETHER_STAR)) {
    26. if (event.getItem().getItemMeta().getDisplayName().equals(null)) {
    27. return;
    28. } else if(event.getItem().getItemMeta().getDisplayName().equals(GUI_NAME)) {
    29. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    30. Player player = event.getPlayer();
    31. Inventory inventory = Bukkit.createInventory(null, 9*6, GUI_NAME);
    32. for (int i = 0; i < 54; i++) {
    33. inventory.setItem(i, new ItemStack(Material.STAINED_GLASS_PANE));
    34. }
    35. ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
    36. ItemMeta itemMeta = item.getItemMeta();
    37. itemMeta.setDisplayName("PVP");
    38. item.setItemMeta(itemMeta);
    39. inventory.setItem(28, new ItemStack(Material.GOLDEN_APPLE));
    40. inventory.setItem(34, new ItemStack(Material.GOLDEN_APPLE));
    41. inventory.setItem(13, item);
    42. player.openInventory(inventory);
    43. }
    44. }
    45. }
    46. }
    47. }


    Now i get the same error as at the beginning
     
  6. Offline

    timtower Moderator Moderator

  7. Offline

    DevMax_Plg

    Code:Java
    1. package de.max.lobby.listeners;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.inventory.Inventory;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14.  
    15.  
    16.  
    17. public class OnInteract implements Listener{
    18.  
    19. private final String GUI_NAME = "§6§lServer-Menü";
    20.  
    21. @EventHandler(priority = EventPriority.HIGHEST)
    22. public void onInteract (PlayerInteractEvent event) {
    23. if (event.getItem().equals(null)) {
    24. return;
    25. } else if (event.getItem().getType().equals(Material.NETHER_STAR)) {
    26. if (event.getItem().getItemMeta().hasDisplayName() == false) {
    27. return;
    28. } else if(event.getItem().getItemMeta().getDisplayName().equals(GUI_NAME)) {
    29. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    30. Player player = event.getPlayer();
    31. Inventory inventory = Bukkit.createInventory(null, 9*6, GUI_NAME);
    32. for (int i = 0; i < 54; i++) {
    33. inventory.setItem(i, new ItemStack(Material.STAINED_GLASS_PANE));
    34. }
    35. ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
    36. ItemMeta itemMeta = item.getItemMeta();
    37. itemMeta.setDisplayName("PVP");
    38. item.setItemMeta(itemMeta);
    39. inventory.setItem(28, new ItemStack(Material.GOLDEN_APPLE));
    40. inventory.setItem(34, new ItemStack(Material.GOLDEN_APPLE));
    41. inventory.setItem(13, item);
    42. player.openInventory(inventory);
    43. }
    44. }
    45. }
    46. }
    47. }


    still get the same error
     
  8. Offline

    timtower Moderator Moderator

    @DevMax_Plg Null checks are done with ==
    Why did you change everything when I said that it was with string compares?
     
  9. Offline

    DevMax_Plg

    Sorry i am from germany i don't understand english well
    again here is my code:
    Code:Java
    1. package de.max.lobby.listeners;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.inventory.Inventory;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14.  
    15.  
    16.  
    17. public class OnInteract implements Listener{
    18.  
    19. private final String GUI_NAME = "§6§lServer-Menü";
    20.  
    21. @EventHandler(priority = EventPriority.HIGHEST)
    22. public void onInteract (PlayerInteractEvent event) {
    23. if (event.getItem() == null) {
    24. return;
    25. } else if (event.getItem().getType().equals(Material.NETHER_STAR)) {
    26. if (event.getItem().getItemMeta().hasDisplayName() == false) {
    27. return;
    28. } else if(event.getItem().getItemMeta().getDisplayName().equals(GUI_NAME)) {
    29. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    30. Player player = event.getPlayer();
    31. Inventory inventory = Bukkit.createInventory(null, 9*6, GUI_NAME);
    32. for (int i = 0; i < 54; i++) {
    33. inventory.setItem(i, new ItemStack(Material.STAINED_GLASS_PANE));
    34. }
    35. ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
    36. ItemMeta itemMeta = item.getItemMeta();
    37. itemMeta.setDisplayName("PVP");
    38. item.setItemMeta(itemMeta);
    39. inventory.setItem(28, new ItemStack(Material.GOLDEN_APPLE));
    40. inventory.setItem(34, new ItemStack(Material.GOLDEN_APPLE));
    41. inventory.setItem(13, item);
    42. player.openInventory(inventory);
    43. }
    44. }
    45. }
    46. }
    47. }


    again no errors but it dont recognize when i click the netherstar
     
  10. Offline

    timtower Moderator Moderator

  11. Offline

    DevMax_Plg

    Code:Java
    1. package de.max.lobby.listeners;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.inventory.Inventory;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14.  
    15.  
    16.  
    17. public class OnInteract implements Listener{
    18.  
    19. private final String GUI_NAME = "§6§lServer-Menü";
    20.  
    21. @EventHandler(priority = EventPriority.HIGHEST)
    22. public void onInteract (PlayerInteractEvent event) {
    23. if (event.getItem() == null) {
    24. return;
    25. } else if (event.getItem().getType().equals(Material.NETHER_STAR)) {
    26. if (event.getItem().getItemMeta().hasDisplayName() == false) {
    27. return;
    28. } else if(event.getItem().getItemMeta().getDisplayName() == GUI_NAME) {
    29. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    30. Player player = event.getPlayer();
    31. Inventory inventory = Bukkit.createInventory(null, 9*6, GUI_NAME);
    32. for (int i = 0; i < 54; i++) {
    33. inventory.setItem(i, new ItemStack(Material.STAINED_GLASS_PANE));
    34. }
    35. ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
    36. ItemMeta itemMeta = item.getItemMeta();
    37. itemMeta.setDisplayName("PVP");
    38. item.setItemMeta(itemMeta);
    39. inventory.setItem(28, new ItemStack(Material.GOLDEN_APPLE));
    40. inventory.setItem(34, new ItemStack(Material.GOLDEN_APPLE));
    41. inventory.setItem(13, item);
    42. player.openInventory(inventory);
    43. }
    44. }
    45. }
    46. }
    47. }


    still doesnt recognize
     
  12. Offline

    timtower Moderator Moderator

    @DevMax_Plg Why is the displayname check using == again?
     
  13. Offline

    DevMax_Plg

    still doesnt work
    Code:Java
    1. package de.max.lobby.listeners;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.inventory.Inventory;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14.  
    15.  
    16.  
    17. public class OnInteract implements Listener{
    18.  
    19. private final String GUI_NAME = "§6§lServer-Menü";
    20.  
    21. @EventHandler(priority = EventPriority.HIGHEST)
    22. public void onInteract (PlayerInteractEvent event) {
    23. if (event.getItem() == null) {
    24. return;
    25. } else if (event.getItem().getType().equals(Material.NETHER_STAR)) {
    26. if (event.getItem().getItemMeta().hasDisplayName() == false) {
    27. return;
    28. } else if(event.getItem().getItemMeta().getDisplayName().equals(GUI_NAME)) {
    29. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    30. Player player = event.getPlayer();
    31. Inventory inventory = Bukkit.createInventory(null, 9*6, GUI_NAME);
    32. for (int i = 0; i < 54; i++) {
    33. inventory.setItem(i, new ItemStack(Material.STAINED_GLASS_PANE));
    34. }
    35. ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
    36. ItemMeta itemMeta = item.getItemMeta();
    37. itemMeta.setDisplayName("PVP");
    38. item.setItemMeta(itemMeta);
    39. inventory.setItem(28, new ItemStack(Material.GOLDEN_APPLE));
    40. inventory.setItem(34, new ItemStack(Material.GOLDEN_APPLE));
    41. inventory.setItem(13, item);
    42. player.openInventory(inventory);
    43. }
    44. }
    45. }
    46. }
    47. }
     
  14. Offline

    timtower Moderator Moderator

    @DevMax_Plg Then add debug lines.
    Printlines to see which statement is failing.
     
  15. Offline

    DevMax_Plg

    it looks like the problem is in this line:

    Code:Java
    1. if(event.getItem().getItemMeta().getDisplayName() == "§6§lServer-Menü")
     
  16. Offline

    timtower Moderator Moderator

  17. Offline

    DevMax_Plg

    when i use equals it also doesnt work
     
  18. Offline

    timtower Moderator Moderator

    Then print both values and see what is different.
     
Thread Status:
Not open for further replies.

Share This Page