Answers for "no invulnerability on join plugin"

0

no invulnerability on join plugin

@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();
        }
    }
Posted by: Guest on February-06-2021

Browse Popular Code Answers by Language