Add effect with attack to player

Discussion in 'Plugin Help' started by kristian, Mar 9, 2019.

  1. kristian

    kristian Creeper

    Messages:
    1
    <?php

    namespace Stick;

    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;
    use pocketmine\entity\Effect;
    use pocketmine\event\entity\EntityDamageByEntityEvent;
    use pocketmine\event\entity\EntityDamageEvent;
    use pocketmine\event\Listener;
    use pocketmine\item\Armor;
    use pocketmine\item\Axe;
    use pocketmine\item\Item;
    use pocketmine\item\Pickaxe;
    use pocketmine\item\Shovel;
    use pocketmine\item\Sword;
    use pocketmine\math\Vector3;
    use pocketmine\Player;
    use pocketmine\plugin\PluginBase;
    use pocketmine\utils\Config;
    use pocketmine\utils\TextFormat as TF;

    class Stick extends PluginBase implements Listener
    {
    private $config;

    public function onEnable()
    {
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    public function onEntityDamage(EntityDamageEvent $event)
    {

    if ($event instanceof EntityDamageByEntityEvent) {

    $player = $event->getEntity();
    $effect = $event->getEffect();

    if($effect instanceof Player){

    $item = $effect->getInventory()->getItemInHand();

    if($item->getId(376)){
    $player->addEffect(Effect::getEffect(Effect::pOISON));

    }
    }
    }
    }
    }
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin Noobiest member in the PMMP Team

    Messages:
    1,796
    GitHub:
    sof3
    Tip: you no longer need to check $event instanceof EntityDamageByEntityEvent. You could directly put EntityDamageByEntityEvent in the parameter type.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.