[SOLVED] How to prevent player invulnerability after join?

Discussion in 'Plugin Development' started by fromgate, Feb 14, 2012.

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

    fromgate

    When player joining on server he gain 3-5 second invulnerability. It allows player to cheat in PVP, and prevent damage when falling.

    Is it possible to prevent on join invulnerability?
     
  2. Offline

    thehutch

    This is built into minecraft so players don't get killed whilst joining instantly if players are quiting just to get this invunerability then maybe you should add some sort of penalty for leaving the server whilst in combat? maybe clear inventory or you actually die
     
  3. Offline

    mushroomhostage

    When a player joins, the server does setNoDamageTicks(60).

    Listen for the player join event in your plugin, then call player.setNoDamageTicks(0)
     
    fromgate likes this.
  4. Offline

    fromgate

    Thank you!!!
     
  5. Offline

    fromgate

    player.setNoDamageTicks(0) did not works.

    I've tested, and when I call player.getNoDamageTicks() in onJoin event, method returns 0. But player is still invulnerable abot 3-5 seconds after joining...
     
  6. worldguard also have an feacture what does this, you tried running whitout plugins?
     
  7. If it is actually noDamageTicks which is set, then it probably happens after a PlayerJoinEvent is launched. Try delaying the call to setNoDamageTicks by 1 tick, like that:
    Code:
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(yourPluginInstance, yourRunnable);
    Note that by omitting the 3rd (delay) parameter, the task is scheduled for the very next tick.
    I've no clue if that has the intended effect, but it could ;)
     
  8. Offline

    Galaran

    I guess noDamageTicks is for delay between taking damage, e.g. in lava
    Invulnerability after join is due to invulnerableTicks in the EntityPlayer behind API (or already not?)
    Something like this:

    Code:
        @EventHandler(priority = EventPriority.MONITOR)
        private void onPlayerJoin(PlayerJoinEvent event) {
            try {
                Field underlyingEntityField = CraftEntity.class.getDeclaredField("entity");
                underlyingEntityField.setAccessible(true);
                Object underlyingPlayerObj = underlyingEntityField.get(event.getPlayer());
                if (underlyingPlayerObj instanceof EntityPlayer) {
                    EntityPlayer underlyingPlayer = (EntityPlayer) underlyingPlayerObj;
                    underlyingPlayer.invulnerableTicks = 1;
                }
            } catch (Exception e) {
                log.info("LoginInvulnerabilityFix exception: " + e.getMessage());
                e.printStackTrace();
            }
        }
     
  9. Offline

    fromgate

    Thank you it works fine :)
     
Thread Status:
Not open for further replies.

Share This Page