1.15.2 HELP cannot give item after death

Discussion in 'Spigot Plugin Development' started by MrDefault, Feb 28, 2020.

  1. Hello, I'm new for plugin development I don't know why it doesn't give an item after death

    Here my code
    Code (Java):
    public void onRespawn(PlayerRespawnEvent re) {
           
                PlayerInventory pinv = re.getPlayer().getInventory();
                ItemStack stack = new ItemStack(Material.APPLE, 1);
                pinv.addItem(stack);
            }
     
  2. Do you implement Listener? Do you register the Listener? Did you forget the EventHandler annotation?
     
    • Useful Useful x 1
  3. Other than this, I was unable to give a player when they respawned, I had to use Bukkit's getScheduler#scheduleSyncDelayedTask to delay the task by about 1 - 2.5 seconds and it worked.
     
    • Useful Useful x 1
  4. SteelPhoenix

    Moderator

    At the time the event is called, the player is not yet respawned. Try scheduling it a tick later.
     
    • Useful Useful x 1
  5. Thank you Mr.robertlit, I forgot to add Eventhandler annotation. :LOL:
     
    • Friendly Friendly x 2