Code For Instant Respawn?

Discussion in 'Spigot Plugin Development' started by DeadlyDeath001, May 7, 2015.

Thread Status:
Not open for further replies.
  1. Trying to make a kitpvp server And I want player to auto respawn.
    Remove the Respawn screen U know what I mean. What is the code?!?!?!?!
     
  2. Post what you have tried.
     
    • Agree Agree x 2
  3. Try: player.spigot().respawn(); in playerdeathevent.
     
    • Like Like x 1
  4. To add on to @zeshan321 :
    Code (Text):
    public void onPlayerDeath(PlayerDeathEvent event){
        event.getPlayer().Spigot().respawn();
    }
    Is an example of using this.
     
    • Like Like x 1
  5. Firstly that is not a question you should ever be asking.

    Secondly as skionz has said post what you have tried. You are going to get an answer a lot quicker if you show that you put in some effort and arent just lazily asking for everything handed to you on a silver platter.

    Thirdly you could have atleast done a google search. This question has been answered soooo many times on this forum alone!
     
    • Agree Agree x 2
    • Funny Funny x 1
  6. Using Spigot 1.8.3.jar
    Error: The method getPlayer() is undefined for the type PlayerDeathEvent
    [​IMG]
     
  7. gigosaurus

    Supporter

  8. Don't Work.
    Code (Text):
    e.getEntity().spigot().respawn();
    Code (Text):
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e){
            e.getEntity().spigot().respawn();
            e.setDroppedExp(1);
            e.getDrops().clear();
            e.getDrops().add(new ItemStack(Material.GOLD_INGOT, 5));
        }
    No Errors
    public Player getEntity()
    Description copied from class: EntityEvent
    Returns the Entity involved in this event
    Overrides:
    getEntity in class EntityDeathEvent
    Returns:
    Entity who is involved in this event
     
  9. There is no .getplayer :/
     
  10. Works But How can I make this go faster Instant Respawn Not a 1 tick Load up screen. I wast Instant
    Code (Text):
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e){
            Player p = e.getEntity();
            p.spigot().respawn();
            e.setDroppedExp(1);
            e.getDrops().clear();
            e.getDrops().add(new ItemStack(Material.GOLD_INGOT, 5));
        }
     
  11. I'll just tell you the idea, and the coding will be up to you.

    PlayerDeathEvent is NOT cancellable, which means you cannot shield a player from their actual death.
    What you should do is to listen to EntityDamageEvent instead. Upon a player take lethal damage, cancel that event, simulate a death action, in your case, drop 1 exp and 5 GOLD_INGOTs. Teleport the player to the respawn point, simple.
    How do you check the damage is lethal? Take a look into the docs.
     
  12. I just posted this in a different thread
     
  13. This Will have "instant" Respawn? Without a Loading Screen?
     
  14. There will be no respawn screen
     
  15. Okay I'll Try To Code It,
     
  16. If the Player#spigot().respawn() method shows you the death screen and you're anal about seeing it for half a second, you'll have to catch the damage event when they are about to die, and call your own respawn event.
     
  17. Im not too sure if this still works but in the past I would just set the player's health back to max and teleport them to the spawn. It simulated the instant respawn. Again, i don't know if it still works but it's worth a shot because it used to work really well.
     
  18. You can cancel PlayerDeathEvent by setting player's health > 0 ... Then you can teleport the player to his spawn again, done.
     
    • Like Like x 1
  19. XD the last 5 answers are telling the exactly same thing :D
     
  20. Nogtail

    Artist

    Asking for code is generally a bad idea. Tell us what you have tried, what isn't working? This is honestly a terrible attitude to have when trying to learn something.
     
    • Agree Agree x 4
    • Like Like x 1
Thread Status:
Not open for further replies.