Bypass death screen (1.6)?

Discussion in 'Plugin Development' started by Kepler_, Jul 19, 2013.

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

    Kepler_

    How can I bypass the death screen when a player dies? I found this code, but it has errors (maybe it's no longer compatible with the 1.6 api).

    http://forums.bukkit.org/threads/bypass-respawn-screen.89891/#post-1483748
    Code:
    Packet205ClientCommand packet = new Packet205ClientCommand();
    packet.a = 1;
    ((CraftPlayer) player).getHandle().playerConnection.a(packet);
    I don't fully understand how packets work either, so please explain if you can. Thanks :D
     
  2. Offline

    fanaticmw2

    Put that in PlayerDeathEvent, and to fix errors, add craftbukkit to your build path.
     
  3. Offline

    Kepler_

    That helped somewhat. What do I import to get CraftPlayer? I'm getting an error with that.
    edit:
    I found it in org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer
     
  4. Offline

    Quackster

    Eclipse has an auto-import function. I'm guessing you're using NetBeans but in Eclipse you can hover over the class and choose which class you want to import from a list.
     
  5. Offline

    Kepler_

    I am using eclipse, but the auto importer couldn't find the class for some reason, so I had to search for it manually.
     
  6. Offline

    JjPwN1

    You don't even need to use packets or any of that.

    Make a simple listen for EntityDamageByEntityEvent, check if the entity being damaged is a player, if so, then continue to check if the damage dealt subtracted by the player's current health is less than 1. If that is true, then reset the player's health, hunger, and inventory.

    Code:java
    1. @EventHandler
    2. public void hitEvent(EntityDamageByEntityEvent event){
    3. if(event.getEntity() instanceof Player){
    4. Player player = (Player) event.getEntity();
    5. if((player.getHealth() - event.getDamage()) < 1){
    6. player.setHealth(20);
    7. player.setFoodLevel(20);
    8. player.getInventory().clear();
    9. player.teleport(player.getWorld().getSpawnLocation());
    10. }
    11. }
    12. }
     
  7. Offline

    chasechocolate

    JjPwN1 I would change that to EntityDamageEvent, also, don't forget to cancel the event otherwise they may die. It may also be a good idea to call PlayerDeathEvent (Bukkit.getPluginManager().callEvent(new PlayerDeathEvent(<params>))) so plugins using it will still work.
     
  8. Offline

    sheigutn

    JjPwN1 That's not too good, because the damage you get from the event is the complete damage and armor is not calculated in it... :3
     
  9. Offline

    JjPwN1

    Create a method which returns how many hearts a piece of armor protects the player from, and add it to the if statement.
     
  10. Offline

    sheigutn

    I know^^ or you use an API
     
  11. Please don't start over that whole discussion once again.
    I've discussed in-depth in the other threads why this is a bad idea:
    http://forums.bukkit.org/threads/bypass-respawn-screen.89891/
    http://forums.bukkit.org/threads/skip-respawn-title-screen-dialog-on-death.92406/

    TL;DR: There's way more to respawning than "resetting health, hunger and inventory".
    Few are possible, but still complex to do with the Bukkit API (e.g. potion effects, death and respawn events),
    but others are less obvious and very technical (scoreboard counters, resetting AI targets of enemies attacking the dying player, properly clearing client caches, etc.).
    There is probably even more to take care of by now with the recent Minecraft updates ...
     
  12. Offline

    JjPwN1

    This isn't a bad idea at all.

    chasechocolate already stated you can fire the PlayerDeathEvent, which will clear all of those other necessary things for a complete respawn.

    It may not clear the caches or stop mobs from targeting you, but it's better than nothing.
     
  13. No it won't. All it will do is call all event handlers from listening plugins, that's it. Firing the event as well as a PlayerRespawnEvent AND handling their results properly gets you a little closer to a "real death", but it doesn't take care of everything.

    And how is an error-prone "better than nothing" solution that requires tons of complex code better than actually using the death mechanic provided by the game itself with 3 lines of code?
    All that my solution does is tell the server after the death "the client pressed respawn, do your stuff now".

    I know about the CraftBukkit dependency, but without that you won't get very far. And using Reflection it is possible to make it somewhat forward-compatible, if that's really an issue.
     
  14. Offline

    JjPwN1

    How are you sure the OP isn't requesting this help for a mini-game plugin, rather than a typical death? I use this method of respawning for a mini-game plugin I created and it works just dandy.

    If the OP needs this to control typical deaths, then sure, you're absolutely right. ;)
     
  15. Because it is stated nowhere that it is for a mini-game ;) I'm generally speaking about typical deaths, and I don't want people who might read this to use it as a general solution (my original solution is almost a year old now, and people still seem to find it ^^).

    For a mini-game respawn which your plugin takes full control over, you do however have a point. In this case it's probably even better NOT to do all the stuff that interacts with other plugins that would normally handle a regular death.
    In my plugin DeathControl, I have to hook into arena plugins specifically to cancel out arena deaths to prevent dupes. If an arena death isn't to be changed by other plugins under any circumstances, not having death and respawn events might even increase compatibility. Difficult to find the correct path, though ...
     
  16. Offline

    gomeow

    Listen to PlayerDeathEvent, set health to player.getMaxHealth()
    they won't die anymore, but they will drop items, and everything else associated to death
     
  17. Offline

    kreashenz

Thread Status:
Not open for further replies.

Share This Page