Hey, Can anyone tell me the public function: How to deactivate PvP in specified Worlds (more than two)? Sorry for my bad English Thanks!
PHP: public function onDamage(EntityDamageEvent $event) { $player = $event->getEntity(); $cause = $player->getLastDamageCause(); if($cause instanceof EntityDamageByEntityEvent) { if($level->getName() == "YourWorldName") { $event->setCancelled(); } }}
But I don't know how to define it. Is that PHP: $player->getLevelByName("blablabla"); or PHP: $this->getServer()-getLevelByName("blablabla"); ?
Well, that isn't exactly the wrong way to do it. PHP: $level = $this->getServer()->getLevelByName($player->getLevel()->getName());if($level->getName() == "Blah") {} and: PHP: $level = $player->getLevel();if($level->getName() == "Blah") {} Both return a Level object, so they will work the same. The second way is much faster though.