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

What's wrong?

Comments in 'Plugin Development' started by BlackJIeBPlayer, Jun 4, 2015.

  1. BlackJIeBPlayer
    Offline

    BlackJIeBPlayer New Member

    Joined:
    May 19, 2015
    Posts:
    18
    Minecraft User:
    BlackJIeB
    PHP:
    function OffPvP(EntityDamageEvent $e)
    {
                  if(
    $this->isGameOn == 1){
             if (
    $e instanceof EntityDamageByEntityEvent and $e->getDamager() instanceof Player and $e->getEntity() instanceof Player) {
                 
    $e->setCancelled();
              }
              }
              if(
    $this->isGameOn == 0){
                   
    $killer $e->getDamager()->getEntity()->getPlayer();
                   if (
    $e instanceof EntityDamageByEntityEvent and $e->getDamager() instanceof Player and $e->getEntity() instanceof Player) {
                        if(
    $this->whoIs[$e->getEntity()->getPlayer()->getName()] == 1){
                             
    $e->setCancelled();
                             
    e->getDamager()->sendMessage('ok');
                        }
                   }
                   if(
    $this->whoIs[$e->getEntity()->getPlayer()->getName()] == 2){
                             if(
    $this->whoIs[$killer->getName()] == 2){
                             
    $e->setCancelled();
                        }
                   }
                   if(
    $this->whoIs[$e->getEntity()->getPlayer()->getName()] == 3){
                             if(
    $this->whoIs[$killer->getName()] == 3){
                             
    $e->setCancelled();
                        }
                   }
                   if(
    $this->whoIs[$e->getEntity()->getPlayer()->getName()] == 4){
                             if(
    $this->whoIs[$killer->getName()] == 4){
                             
    $e->setCancelled();
                        }
                   }
                   }
                }
              }
    What could be wrong?
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    What's the Error?
    BlackJIeBPlayer likes this.
  3. BlackJIeBPlayer
    Offline

    BlackJIeBPlayer New Member

    Joined:
    May 19, 2015
    Posts:
    18
    Minecraft User:
    BlackJIeB
    Error: Call to undefined method pocketmine\event\entity\EntityDamageEvent::getDamager()
  4. BlackJIeBPlayer
    Offline

    BlackJIeBPlayer New Member

    Joined:
    May 19, 2015
    Posts:
    18
    Minecraft User:
    BlackJIeB
    I did not quite understand what you mean. You can be more precise ?
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Please search the Forum before creating the Thread. The Cause has to be instanceof EntityDamageByEntityEvent, not the Event. You can get the Damager out of the cause:
    PHP:
    $cause $event->getEntity()->getLastDamageCause();
            if(
    $cause instanceof EntityDamageByEntityEvent){
                
    $killer $cause->getDamager();
            }
    Also:
    PHP:
    function OffPvP(EntityDamageEvent $e)
    {
                  if(
    $this->isGameOn == 1){
             if (
    $e instanceof EntityDamageByEntityEvent and $e->getDamager() instanceof Player and $e->getEntity() instanceof Player) {
                 
    $e->setCancelled();
              }
              }
              if(
    $this->isGameOn == 0){
                   
    $killer $e->getDamager()->getEntity()->getPlayer();
                   if (
    $e instanceof EntityDamageByEntityEvent and $e->getDamager() instanceof Player and $e->getEntity() instanceof Player) {
                        if(
    $this->whoIs[$e->getEntity()->getPlayer()->getName()] == 1){
                             
    $e->setCancelled();
                             
    e->getDamager()->sendMessage('ok'); // You forgot a $ here
                        
    }
                   }
                   if(
    $this->whoIs[$e->getEntity()->getPlayer()->getName()] == 2){
                             if(
    $this->whoIs[$killer->getName()] == 2){
                             
    $e->setCancelled();
                        }
                   }
                   if(
    $this->whoIs[$e->getEntity()->getPlayer()->getName()] == 3){
                             if(
    $this->whoIs[$killer->getName()] == 3){
                             
    $e->setCancelled();
                        }
                   }
                   if(
    $this->whoIs[$e->getEntity()->getPlayer()->getName()] == 4){
                             if(
    $this->whoIs[$killer->getName()] == 4){
                             
    $e->setCancelled();
                        }
                   }
                   }
                }
              }
    BlackJIeBPlayer likes this.
  6. BlackJIeBPlayer
    Offline

    BlackJIeBPlayer New Member

    Joined:
    May 19, 2015
    Posts:
    18
    Minecraft User:
    BlackJIeB
    thank you
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Mind using a switch instead of a series of if-blocks.

Share This Page

Advertisement