Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Cancel player death and set health

Comments in 'Plugin Development' started by thebigsmileXD, Sep 20, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Any hacks to cancel PlayerDeathEvent?
  2. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Right, but NoVoid checks if the player is on a specific y-position and then teleports it
    (and yes, off toppic: almost done. Multiple spawns work, players get their stuff and you can kill+win and leave; also if you die too often you get a message that you've died too often and then you are in spectator mode. I changed swords back from onehitkill to standard, because in the original pc OITC its also that swords take several hits. (i'll cut some videos of a pc-oitc gameplay today and upload them tomorrow on my youtube channel))
    so can i check if the damage is too high?
  3. pomee4
    Offline

    pomee4 Active Member

    Joined:
    Jul 8, 2015
    Posts:
    106
    Minecraft User:
    pomee4
    Maybe you can cancel the demage if its more then the players health(i dont know the how-to, its just an idea)
    thebigsmileXD likes this.
  4. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    If($event->getDamage() >= $player->getHealth()) {
      
    $event->setCancelled(true);
    }
    Last edited: Sep 21, 2015
    thebigsmileXD and CrazedMiner like this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You can cancel EntityDamageEvent...
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PlayerDeathEvent extends EntityDamageEvent. If EntityDamageEvent is cancellable, PlayerDeathEvent must be cancellable as its parent class implements Cancellable.

    The problem is, Neither PlayerDeathEvent nor EntityDeathEvent is cancellable, but EntityDamageEvent is cancellable.
    Hotshot_9930 likes this.
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Even on PC, I believe you can not cancel PlayerDeathEvent.
  8. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    what about to fill health when only been reached to 1 half-heart or more?
  9. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    this should "cancel" death:
    PHP:
    public function onDamage(EntityDamageByEntityEvent $event) {
      
    $entity $event->getEntity();
      
    $cause $entity->getLastDamageCause();
      
    $attacker $cause->getDamager();

      if(
    $entity instanceof Player && $attacker instanceof Player) {
        If(
    $event->getDamage() >= $entity->getHealth()) {
          
    $event->setCancelled(true);
           
    // $entity->setHealth(10); Maybe?
          
    }
        }
      }
      
    // Or
      
    public function onDamage(EntityDamageEvent $event) {
        
    $entity $event->getEntity();
        
         if(
    $event->getDamage() >= $entity->getHealth()) {
             
    $event->setCancelled(true);
             
    // $entity->setHealth(10); Maybe?
      
    }
    }
    I have not tested this
    Last edited: Sep 22, 2015
  10. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Use
    PHP:
    public function onDamage(EntityDamageEvent $event) {
    if(
    $event instanceof EntityDamageByEntityEvent){
    // the rest of your code here
    Legoboy0215 and Hotshot_9930 like this.
  11. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    This actually did it :)
    I added setHealth(20) and getInventory->clearAll, teleport the Player to spawn.. Done!
    Legoboy0215 and Hotshot_9930 like this.
  12. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Does anyone know how i can see if the player is hit by an arrow? And then output the attackers name?
    PHP:
    if($attacker instanceof Arrow){
    $this->getLogger()->info("arrow");
    $attacker=$attacker->shootingEntity;}
    $this->getLogger()->info($attacker->getName);
    I had this, didn't work
  13. pomee4
    Offline

    pomee4 Active Member

    Joined:
    Jul 8, 2015
    Posts:
    106
    Minecraft User:
    pomee4
    Check CombatLogger 's source ;)
    thebigsmileXD likes this.
  14. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Okay, i will!
    By the way, i'll create an instantrespawn plugin and upload it.
  15. pomee4
    Offline

    pomee4 Active Member

    Joined:
    Jul 8, 2015
    Posts:
    106
    Minecraft User:
    pomee4
    Cool :) don't forget to make the "dead" players inventory drop (can be swtchable in a cfg file[it would be cool])
    thebigsmileXD likes this.
  16. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Well.. No nice results:
    PHP:
        public function EntityDamageEvent(EntityDamageEvent $event){
            if(
    $event instanceof EntityDamageByEntityEvent){
                if(
    $event->getDamager() instanceof Player and $event->getEntity() instanceof Player){
                    foreach(array(
    $event->getDamager(),$event->getEntity()) as $players){
                        
    $this->setTime($players);
                    }
                }
            }
        }
  17. pomee4
    Offline

    pomee4 Active Member

    Joined:
    Jul 8, 2015
    Posts:
    106
    Minecraft User:
    pomee4
    Sorry the code is in @EvolSoft 's Custom Alert plugin (i don't know wich line is the right one,but must be somewhere here :) ) :
    PHP:
     if($cause instanceof EntityDamageEvent){
                if(
    $cause->getCause() == EntityDamageEvent::CAUSE_CONTACT){
                    
    $message $cfg["Death"]["death-contact-message"]["message"];
                    if(
    $cause instanceof EntityDamageByBlockEvent){
                        
    $message str_replace("{BLOCK}"$cause->getDamager()->getName(), $message);
                    }else{
                        
    $message str_replace("{BLOCK}""Unknown"$message);
                    }
                }elseif(
    $cause->getCause() == EntityDamageEvent::CAUSE_ENTITY_ATTACK){
                    
    $message $cfg["Death"]["kill-message"]["message"];
                    
    $killer $cause->getDamager();
                    if(
    $killer instanceof Living){
                        
    $message str_replace("{KILLER}"$killer->getName(), $message);
                    }else{
                        
    $message str_replace("{KILLER}""Unknown"$message);
                    }
                }elseif(
    $cause->getCause() == EntityDamageEvent::CAUSE_PROJECTILE){
                    
    $message $cfg["Death"]["death-projectile-message"]["message"];
                    
    $killer $cause->getDamager();
                    if(
    $killer instanceof Living){
                        
    $message str_replace("{KILLER}"$killer->getName(), $message);
                    }else{
                        
    $message str_replace("{KILLER}""Unknown"$message);
                    }
                }elseif(
    $cause->getCause() == EntityDamageEvent::CAUSE_SUFFOCATION){
                    
    $message $cfg["Death"]["death-suffocation-message"]["message"];
                }elseif(
    $cause->getCause() == EntityDamageEvent::CAUSE_FALL){
                    
    $message $cfg["Death"]["death-fall-message"]["message"];
                }elseif(
    $cause->getCause() == EntityDamageEvent::CAUSE_FIRE){
                    
    $message $cfg["Death"]["death-fire-message"]["message"];
                }elseif(
    $cause->getCause() == EntityDamageEvent::CAUSE_FIRE_TICK){
                    
    $message $cfg["Death"]["death-on-fire-message"]["message"];
                }elseif(
    $cause->getCause() == EntityDamageEvent::CAUSE_LAVA){
                    
    $message $cfg["Death"]["death-lava-message"]["message"];
                }elseif(
    $cause->getCause() == EntityDamageEvent::CAUSE_DROWNING){
                    
    $message $cfg["Death"]["death-drowning-message"]["message"];
                }elseif(
    $cause->getCause() == EntityDamageEvent::CAUSE_ENTITY_EXPLOSION || $cause->getCause() == EntityDamageEvent::CAUSE_BLOCK_EXPLOSION){
                    
    $message $cfg["Death"]["death-explosion-message"]["message"];
                }elseif(
    $cause->getCause() == EntityDamageEvent::CAUSE_VOID){
                    
    $message $cfg["Death"]["death-void-message"]["message"];
                }elseif(
    $cause->getCause() == EntityDamageEvent::CAUSE_SUICIDE){
                    
    $message $cfg["Death"]["death-suicide-message"]["message"];
                }elseif(
    $cause->getCause() == EntityDamageEvent::CAUSE_MAGIC){
                    
    $message $cfg["Death"]["death-magic-message"]["message"];
                }else{
    thebigsmileXD likes this.
  18. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Thats so nice that you've researched! You saved me so much time! Thanks alot!
    By the way, the lines are
    PHP:
    elseif($cause->getCause() == EntityDamageEvent::CAUSE_PROJECTILE){
                    
    $message $cfg["Death"]["death-projectile-message"]["message"];
                    
    $killer $cause->getDamager();
                    if(
    $killer instanceof Living){
                        
    $message str_replace("{KILLER}"$killer->getName(), $message);
                    }else{
                        
    $message str_replace("{KILLER}""Unknown"$message);
                    }
    pomee4 likes this.
  19. pomee4
    Offline

    pomee4 Active Member

    Joined:
    Jul 8, 2015
    Posts:
    106
    Minecraft User:
    pomee4
    I like to be apart of developeing :) mostly plugins i use/i will use :)
    And I knew, i saw somewhere the usage of these lines.I just tought CombatLogger or KillRate use it, but i remembered it was Custom Alerts :)
    I help with pleasure :D
    If you need anything, JUST DO IT ( :'D ) thats why this thread category was created!
    thebigsmileXD likes this.
  20. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    :D i love your motivation!

    If anyone needs the code:
    PHP:
      public function damageHandler(EntityDamageEvent $event){
            
    $entity $event->getEntity();
            
    $cause $event->getCause();
            if(
    $entity instanceof Player && $this->isPlaying($entity)){
                if(
    $cause == EntityDamageEvent::CAUSE_ENTITY_ATTACK){
                    
    $this->getServer()->broadcastMessage($entity->getName() . " was hit by someone");
                }
                elseif(
    $cause == EntityDamageEvent::CAUSE_PROJECTILE){
                    
    $this->getServer()->broadcastMessage($entity->getName() . " was hit by arrow");
                }
            }
        }
        

Share This Page

Advertisement