<?php namespace WorldPlayerLimit; use pocketmine\command\CommandExecutor; use pocketmine\command\CommandSender; use pocketmine\plugin\PluginBase; use pocketmine\Server; use pocketmine\Player; class Main extends PluginBase{ public $worlds; public function onLevelChange(EntityLevelChangeEvent $event){ $entity = ($event->getEntity() instanceof Player ? $event->getEntity() : null); if($entity === null) return; $targetLevel = $event->getTarget(); // if you have more then one world it will be better to put in array foreach($this->worlds as $world){ if($world instanceof Level){ if($targetLevel->getPlayers() > 2 /* PLAYER LIMIT */ || $world->getName() === $targetLevel->getName()){ $event->setCancelled(true); // Will it cancel level change properly? if($entity->getLevel() == $event->getOrigin() || $event->isCancelled()){ $entity->sendMessage('[?] Le monde est complet.'); } } } } } public function onEnable(){ $this->worlds[] = $this->getServer()->getLevelByName('Mine'); $this->worlds[] = $this->getServer()->getLevelByName('Bonbon'); $this->worlds[] = $this->getServer()->getLevelByName('Arene'); $this->worlds[] = $this->getServer()->getLevelByName('Dome'); } } This code does not work, could you help me?
please use code function PHP: <?phpnamespace WorldPlayerLimit;use pocketmine\command\CommandExecutor;use pocketmine\command\CommandSender;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\Player;class Main extends PluginBase{public $worlds;public function onLevelChange(EntityLevelChangeEvent $event){ $entity = ($event->getEntity() instanceof Player ? $event->getEntity() : null); if($entity === null) return; $targetLevel = $event->getTarget();// if you have more then one world it will be better to put in array foreach($this->worlds as $world) { if($world instanceof Level) { if($targetLevel->getPlayers() > 2 /* PLAYER LIMIT */ || $world->getName() === $targetLevel->getName()) { $event->setCancelled(true); // Will it cancel level change properly? if($entity->getLevel() == $event->getOrigin() || $event->isCancelled()) { $entity->sendMessage('[?] Le monde est complet.'); } } } }}public function onEnable(){ $this->worlds[] = $this->getServer()->getLevelByName('Mine'); $this->worlds[] = $this->getServer()->getLevelByName('Bonbon'); $this->worlds[] = $this->getServer()->getLevelByName('Arene'); $this->worlds[] = $this->getServer()->getLevelByName('Dome');}}
Learn PHP. And then the PocketMine API. And how many times do we have to tell you: use a code block! And I don't know how many threads you have created regarding your "plugin", but stop, it's annoying.