Clear drops with auto respawn

Discussion in 'Plugin Development' started by IceBeast, Apr 10, 2014.

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

    IceBeast

    Hi guys. I tried to force the auto respawn with nms, but unfortunately when I try to clear player's drop the inventory gets bugged (after 1st respawn players gets no items added with addItem, after 2nd he gets all of them but after click his inventory gets cleared).

    Here is my code:
    Code:
        @EventHandler(priority = EventPriority.NORMAL)
        public void onPlayerDeath(PlayerDeathEvent e) {
              e.getDrops().clear();
                PacketPlayInClientCommand in = new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN);
                EntityPlayer cPlayer = ((CraftPlayer)p).getHandle();
                cPlayer.playerConnection.a(in);
    }
    How can I make it work?
     
  2. Why are you explicitly setting the priority to normal?

    I'd delay that respawn a bit and, if it still doesn't work, try using p.updateInventory() at some point.
     
  3. Offline

    IceBeast

    How can I properly thread-safe delay it in an event? I tried to do just:
    Code:
                plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
    
                    @Override
                    public void run() {
                        PacketPlayInClientCommand in = new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN); // Gets the packet class
                        EntityPlayer cPlayer = ((CraftPlayer)cp).getHandle();
                        cPlayer.playerConnection.a(in); 
                    }
                    
                }, 20L);
    And actually it works, but randomly throws "Exception in server tick loop".
     
  4. Offline

    Zethariel

    In an async task schedule a sync event, it will run on the next tick
     
  5. Offline

    IceBeast

    Zethariel
    What did you mean? Should I schedule PlayerDeathEvent in an async task?
     
  6. Offline

    Zethariel

    If you want something to happen asynchronously but require it to use Bukkit sutff later (send message, do something to player, whatever) you have to run a synchronous task in the asynchronous task.
     
Thread Status:
Not open for further replies.

Share This Page