Skip to content

Commit

Permalink
Fixed Creative issues :D (also Spectator ones :P)
Browse files Browse the repository at this point in the history
  • Loading branch information
iksaku committed Jul 29, 2014
1 parent bc3ece6 commit da32e5b
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/HealthBar/EventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\Player;
use pocketmine\Server;

class EventHandler implements Listener{
/** @var \HealthBar\Loader */
Expand All @@ -26,8 +27,6 @@ public function onRegainHealth(EntityRegainHealthEvent $event){
$health = $entity->getHealth() + $event->getAmount();
if($health > $entity->getMaxHealth()){
$health = $entity->getMaxHealth();
}elseif($health <= 0){
$health = 0;
}
$this->plugin->updateHealthBar($entity, $health);
}
Expand All @@ -39,8 +38,12 @@ public function onRegainHealth(EntityRegainHealthEvent $event){
public function onHealthLose(EntityDamageEvent $event){
$entity = $event->getEntity();
if($entity instanceof Player && !$event->isCancelled()){
$health = $entity->getHealth() - $event->getFinalDamage();
$this->plugin->updateHealthBar($entity, $health);
if(Server::getGamemodeString($entity->getGamemode()) === "SPECTATOR" || Server::getGamemodeString($entity->getGamemode()) === "CREATIVE"){
$event->setCancelled(true);
}else{
$health = $entity->getHealth() - $event->getFinalDamage();
$this->plugin->updateHealthBar($entity, $health);
}
}
}

Expand All @@ -50,8 +53,12 @@ public function onHealthLose(EntityDamageEvent $event){
public function onAttack(EntityDamageByEntityEvent $event){
$entity = $event->getEntity();
if($entity instanceof Player && !$event->isCancelled()){
$health = $entity->getHealth() - $event->getFinalDamage();
$this->plugin->updateHealthBar($entity, $health);
if(Server::getGamemodeString($entity->getGamemode()) === "SPECTATOR" || Server::getGamemodeString($entity->getGamemode()) === "CREATIVE"){
$event->setCancelled(true);
}else{
$health = $entity->getHealth() - $event->getFinalDamage();
$this->plugin->updateHealthBar($entity, $health);
}
}
}

Expand Down

0 comments on commit da32e5b

Please sign in to comment.