Solved Force Respawn

Discussion in 'Plugin Development' started by caderape, May 12, 2015.

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


    Hello, i'm develloping a MiniGame plugin. But i have a problem.
    I would like to find a way to force the respawn of a player.

    When a player die in the game, and when it causes the end of the game, the plugin teleport the players in the lobby then delete the world created for the game.

    But it doesnt teleport dead people. So when the player respawn, it causes a worldconflictexception.

    I tried different way to wait the respawn for delete the world, but it doent work. getWorld().getPlayers() don't contains dead players cuz it returns 0 when i try..
  2. Offline


    Maybe you could add the players to an ArrayList or HashMap and teleport the players in the list to lobby
  3. Offline


    I tried that.

    Iterator<UUID> it = this.players.iterator();
            while(it.hasNext()) {
                Player p = Bukkit.getPlayer(;
                if (p != null && !p.isDead()) {
                } else {
    But the broadbast 'dead' does not perform. It's like p.isdead() is not recognize. I tried to schedul it 2 second later, but it still do not know if the player is dead or no
  4. Offline


    @caderape Death events aren't cancellable, but you can listen to the damage event and figure out if the hit will kill them. At that point if you use lives, subtract a life, set their health to full, cancel the event and if they're out then move them to the lobby.

    As for worlds, you can turn off autosaving so that anything the players do to the world isn't saved and then when everyone's out, you can just unload the world and everything should revert back
  5. @Abs0rbed They are cancellable, but it loops and glitchs

    @caderape onPlayerDamage, check if the damage is greater than the player's hp. If it's, cancel the event, heal the player and do death stuff.
  6. Offline


    @Juancomaster1998 Pretty sure you can't cancel them, at least not from what I've seen from the Javadocs, just went and double checked.
    As for the playerdamage, that was pretty much what I was thinking he should do
  7. @Abs0rbed
    Well, I remember cancelling it once just to see what happens (or restoring the player's hp, I don't remember which)
  8. Offline


        public void onPlayerDeath(final PlayerDeathEvent e)
            new BukkitRunnable()
                public void run()
                        Object nmsPlayer = e.getEntity().getClass().getMethod("getHandle").invoke(e.getEntity());
                        Object con = nmsPlayer.getClass().getDeclaredField("playerConnection").get(nmsPlayer);
                        Class< ? > EntityPlayer = Class.forName(nmsPlayer.getClass().getPackage().getName() + ".EntityPlayer");
                        Field minecraftServer = con.getClass().getDeclaredField("minecraftServer");
                        Object mcserver = minecraftServer.get(con);
                        Object playerlist = mcserver.getClass().getDeclaredMethod("getPlayerList").invoke(mcserver);
                        Method moveToWorld = playerlist.getClass().getMethod("moveToWorld" , EntityPlayer , int.class , boolean.class);
                        moveToWorld.invoke(playerlist , nmsPlayer , 0 , false);
                    catch (Exception ex)
            }.runTaskLater(plugin , 2);
  9. Offline


    Okay guys thx. I will try to do something with this.
Thread Status:
Not open for further replies.

Share This Page