Hide player on dead

Discussion in 'Plugin Development' started by Zenok, Jan 3, 2014.

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

    Zenok

    Hello, I am trying to that when the player dies is a to a spectator mode, so the unseen to all players of the game. The problem is, that even hiding the zombies continue attack, also I have tried to do so invisible, but does not work.

    Code:java
    1. public void onPlayerDeath(PlayerDeathEvent event) {
    2. Player player = event.getEntity().getPlayer();
    3.  
    4. if(event.getEntity().getPlayer().isDead()) {
    5. player.setAllowFlight(true);
    6. player.setHealth(20);
    7.  
    8. for(Player players : Bukkit.getOnlinePlayers()) {
    9. if(GamePlayers[game].contains(players.getName())) {
    10. players.hidePlayer(player);
    11. players.sendMessage("[V] The player " + player.getName()+ " has died");
    12. }
    13.  
    14. }
    15.  
    16. }
    17. }


    I also tried that if the player is in the array, it can not be attacked, but the zombies followed even when invisible

    Code:java
    1. public void onEntityDamage(EntityDamageEvent event) {
    2. if(event.getEntity() instanceof Player) {
    3. Player player = (Player)event.getEntity();
    4.  
    5. if(Spectators.contains(player.getName())) {
    6. event.setCancelled(true);
    7. }
    8. }
    9. }
     
  2. Offline

    xize

    you can use EntityTargetLivingEntityEvent and EntityTargetEvent and cancel it:)
     
  3. Offline

    Zenok


    But the entity has already selected target and they go to attack
     
  4. Offline

    Desle


    Code:java
    1. public void onEntityTargetLivingEntity(EntityTargetLivingEntityEvent e) {
    2. //if target == spectator {
    3. e.setCancelled(true);
    4. }
    5. }
     
  5. Offline

    Zenok


    Yes, already have this:

    Code:java
    1. @EventHandler
    2. public void onEntityTarget(EntityTargetLivingEntityEvent event) {
    3. Player player = (Player) event.getTarget();
    4. player.sendMessage("TEST");
    5. if(Spectators.contains(player.getName())) {
    6. event.setCancelled(true);
    7. }
    8. }


    But continue attacking
    PD: I got an error: Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R1.entity.CraftVillager cannot be cast to org.bukkit.entity.Player
     
  6. Offline

    Desle


    Try move the message "TEST" below the if(Spectators.contains(blabalabla..
     
  7. Offline

    Zenok

    Error solved, but they continue attacking :S. I think, this is caused because entities have already selected target
     
  8. Offline

    Desle


    Probably because they respawn close to the mobs..
    So if they spawn far away, and teleport back to the mobs it won't do that.
     
  9. Offline

    Zenok

    And there is another solution?
     
  10. Offline

    Desle

    Tp the player far away for a split second when they respawn.
     
Thread Status:
Not open for further replies.

Share This Page