Solved spigot().respawn(); Problem: Not dropping items

Discussion in 'Spigot Plugin Development' started by SirCodalot, May 22, 2016.

Thread Status:
Not open for further replies.
  1. I want to make a better deaths plugins but I found a problem while trying to skip the death screen. I used the easiest way :
    Code (Text):
    player.spigot().respawn();
    but it has a bug with the dropping items system; sometimes it drops the items in the respawn location. Sometimes it drops the items both in the death and respawn locations and sometimes it never drops the items. Do you know how to fix this bug?

    Event Code:
    Code (Text):
        @EventHandler

        public void onPlayerDeath(PlayerDeathEvent event) {
            Player player = (Player) event.getEntity();
            if (getConfig().getString("DisableDeathScreen").equalsIgnoreCase("true")) {
                player.spigot().respawn();;
            }
        }

    Thanks.
     
    #1 SirCodalot, May 22, 2016
    Last edited: May 23, 2016
  2. I might be mistaken but I am pretty sure this works better:

    Code (Text):
    getConfig().getBoolean("DisableDeathScreen", true);
     
    for the getConfig thing you have there.
     
    • Agree Agree x 1
  3. I've never heard of the spigot respawn method, an alternative could be listening for an EntityDamageEvent, and checking if the event.getDamage() > event.getPlayer().getHealth(). If so, then the player has "died", you can cancel the event, drop the player's items, and reset them to spawn.
     
    #3 akselm, May 22, 2016
    Last edited: May 22, 2016
  4. Its a string currently :p
     
  5. Tux

    Tux

    You should delay the respawn operation by one tick.
     
    • Like Like x 1
    • Agree Agree x 1
  6. How can I do that? *feeling like a noob*
     
  7. Use a runTaskLater bukkit runnable and set the delay to 10.
     
    • Funny Funny x 1
  8. Bukkit.getScheduler.sceduleAsyncDelayedTask

    Edit: Do what @avighnash said
     
  9. 10 ticks? The delay should be 1 tick.
     
  10. 1second is 20 ticks...
     
  11. Oops lol
     
  12. Just do
    Code (Text):
    new BukkitRunnable() {

    @Override
    public void run() {

    }

    }.runTaskLater(parameters)

    P.s if this does not compile, not my fault lol, I just typed it up. I did not use Eclipse or any of that jazz.
     
  13. I solved the problem, thanks.
     
Thread Status:
Not open for further replies.