I want to make all players invencible in a map. I don't know why my code isn't working. Can anyone tell me how?
here's what you might need Spoiler Code: public function onPvP(EntityDamageEvent $eventPvP){ if($eventPvP instanceof EntityDamageByEntityEvent){ if($eventPvP->getEntity() instanceof Player && $eventPvP->getDamager() instanceof Player){ $map = $eventPvP->getEntity()->getLevel()->getFolderName(); if(in_array($map, $this->worlds)){ $player = $eventPvP->getDamager(); if($this->error == ""){ if($this->oppvp == "true" && !$player->isOP() || $this->oppvp != "true"){ $eventPvP->setCancelled();
if you want DisablePVP ? PHP: public function onDamage(EntityDamageEvent $los){if($los instanceof EntityDamageByEntityEvent) {$player = $los->getEntity();$damger = $los->getDamager();if($damger instanceof Player) {if($this->getServer()->getLevelByName("FLAT")){$los->setCancelled();$damager->sendMessage("Disable PVP IN The World");}}}}
getLevelByName() returns a level, so it wouldn't work by itself, you gotta make it equal to something. PHP: public function onDamage(EntityDamageEvent $ede){$target = $ede->getEntity();$damager = $ede->getDamager();if($damager instanceof Player && $target instanceof Player){if($damager->getLevel()->getName()==="levelname"){$e->setCancelled();}}}
Actually if($this->getServer()->getLevelByName("FLAT")) will work, its because the level object returned will be treated as true, if the returned is null then it will be treated as false. Your code is comparing a level object with a string, which won't work at all and you have a typo at $damage instanceof Player
Oh yeah, sirry, I get confused with the api sometimes. But that will just check if the level exists and not if the damager is in that world.