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

Trying to fix plugins using EntityDamageEvent

Comments in 'Plugin Development' started by Jazzwhistle, Feb 19, 2016.

  1. Jazzwhistle
    Offline

    Jazzwhistle Notable Member

    Joined:
    Dec 27, 2014
    Posts:
    364
    Minecraft User:
    Awzaw
    Hi, I have a problem with both Worldprotect and PeacefulSpawn that don't seem to be able to disable pvp since the update. The code is very simple for both, and I can't see any reason why the pvp restriction feature of both these plugins won't work with PHP7 and recent API 2.0.0 builds, unless there's now some problem cancelling the EntityDamageEvent? Thanks for any help

    Code:
        public function onPvP(EntityDamageEvent $ev) {
            if ($ev->isCancelled()) return;
            if(!($ev instanceof EntityDamageByEntityEvent)) return;
            if (!(($pl = $ev->getEntity()) instanceof Player
                    && $ev->getDamager() instanceof Player)) return;
            $world = $pl->getLevel()->getName();
            if (!isset($this->wcfg[$world])) return;
            if ($this->wcfg[$world] !== false) {
                $sp = $pl->getLevel()->getSpawnLocation();
                $dist = $sp->distance($pl);
                if ($dist > $this->owner->getServer()->getSpawnRadius()) return;
            }
            $this->owner->msg($ev->getDamager(),mc::_("You are not allowed to do that here"));
            $ev->setCancelled();
        }
  2. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    Theres an issue with the client not sending the event

Share This Page

Advertisement