Solved getting the player

Discussion in 'Plugin Development' started by xelatercero, Jan 6, 2020.

  1. Offline

    xelatercero

    So i jave this method where i open my custom inventory , before that i set an item and initialize the "Player sender" variable , but when i want tocheck for the name its just null. I get a NullPointerException and if i check if its null , it returns nothing (Sorry for my english)

    Code:java
    1. private Player sender;
    2.  
    3. public void openInventory(Player p) {
    4. inv.setItem(0, Items.sendButton());
    5. this.sender = p;
    6. p.openInventory(inv);
    7.  
    8. }
    9.  
    10. @EventHandler
    11. public void onClickSendButton(InventoryClickEvent e) {
    12.  
    13. if(!(e.getInventory().getHolder() instanceof SendMailInventory)) {System.out.println("ITS NOT"); return;}
    14. if(sender!=null) {System.out.println(sender.getName());}
    15.  
    16. }
    17.  
    18. //Edit:Obv like this i get the name right but i dont get when i check for the global variable
    19. //its null . When the clickEvent happens i check if its my custom inventory and by that moment
    20. //the "sender" variable its already initialized
    21.  
    22.  
    23. public void openInventory(Player p) {
    24. inv.setItem(0, Items.sendButton());
    25. sender = p;
    26. System.out.println(sender.getName());
    27. p.openInventory(inv);
    28.  
    29. }
    30.  
    31.  
    32.  
    33.  
    34.  
     
    Last edited: Jan 6, 2020

Share This Page