Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
Implement protection
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAz928 authored Oct 22, 2017
1 parent f5648fa commit 2971f65
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src/VanillaEnchantments/handlers/Protection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
namespace VanillaEnchantments\handlers;

use pocketmine\Player;

use pocketmine\item\enchantment\Enchantment;

use pocketmine\event\Listener;
use pocketmine\event\entity\EntityDamageEvent;

use VanillaEnchantments\Core;

class Protection extends VanillaEnchant implements Listener{

public function __construct(Core $core){
$core->getServer()->getPluginManager()->registerEvents($this, $core);
}

public function onDamage(EntityDamageEvent $event): void{
$player = $event->getEntity();
$cause = $event->getCause();
if($event->isCancelled() or $cause == $event::CAUSE_STARVATION or $cause == $event::CAUSE_MAGIC){
return;
}
if($player instanceof Player){
$level = $this->getEnchantmentLevelOfArmors($player, Enchantment::PROTECTION);
$base = $event->getDamage();
$reduce = $this->getReducedDamage(Enchantment::PROTECTION, $base, $level);
if($reduce > 0){
$event->setDamage($base - $reduce);
}
}
}
}
5 changes: 3 additions & 2 deletions src/VanillaEnchantments/handlers/VanillaEnchant.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ protected function getReducedDamage(Int $id, Int $base, Int $level): float{
$factor *= $level;
$reduce = $base * $factor;
break;
case Enchantment::PROJECTILE_PROTECTION:
$factor = (4 / 100);
case Enchantment::PROTECTION:
$factor = (2.5 / 100);
$factor *= $level;
$reduce = $base * $factor;
break;
case Enchantment::PROJECTILE_PROTECTION:
case Enchantment::BLAST_PROTECTION:
$factor = (4 / 100);
$factor *= $level;
Expand Down

0 comments on commit 2971f65

Please sign in to comment.