Resource Skip respawn screen but keep the death animation

Discussion in 'Spigot Plugin Development' started by QAQT0T, Jan 24, 2020.

Thread Status:
Not open for further replies.
  1. Code like this:
    Code (Text):
        @EventHandler
        public void DeathEvent(PlayerDeathEvent event) {
            respawnPlayer(event.getEntity());
        }
     
        private void respawnPlayer(Player player) {
            player.setHealth(20.0);
            player.setFoodLevel(20);
            player.setSaturation(20.0F);
            player.setVelocity(player.getVelocity().clone());
            player.setWalkSpeed(0.0F);
            player.setFlySpeed(0.0F);
            player.setSprinting(false);
            player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 200));
    // Cancel move or there'll be a 'walking dead'
            new BukkitRunnable() {
                @Override
                public void run() {
                    PacketPlayOutEntityStatus entityStatus = new PacketPlayOutEntityStatus(((CraftPlayer)player).getHandle(), (byte)3);
                    Bukkit.getOnlinePlayers().forEach(Other -> {
                        if (Other != player) {
                            ((CraftPlayer)Other).getHandle().playerConnection.sendPacket(entityStatus);
                        }
                    });
                }
            }.runTaskLater(Main.getInstance(), 2L);
            new BukkitRunnable() {
                @Override
                public void run() {
                    Bukkit.getOnlinePlayers().forEach(others -> {
                        others.hidePlayer(player); #Hide,or player will disappear forever.
                    });
                    player.setWalkSpeed(0.2F);
                    player.setFlySpeed(0.0001F);
                    player.removePotionEffect(PotionEffectType.JUMP);  // Allow move
                }
            }.runTaskLater(Main.getInstance(), 40L);
            new BukkitRunnable() {
                @Override
                public void run() {
                    Bukkit.getOnlinePlayers().forEach(others -> {
                        others.showPlayer(player);  // Show when you need.
                    });
                }
            }.runTaskLater(Main.getInstance(), 40L);
        }
    It can smoothly skip the respawn screen and play the death animation.
     
    #1 QAQT0T, Jan 24, 2020
    Last edited: Aug 20, 2020
    • Funny Funny x 3
Thread Status:
Not open for further replies.