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

World Player limit

Comments in 'Plugin Development' started by LCraftPE, Aug 16, 2015.

  1. LCraftPE
    Offline

    LCraftPE New Member

    Joined:
    Nov 16, 2014
    Posts:
    30
    Minecraft User:
    LCraftPE
    <?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?
  2. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    please use PHPtags -3-
    PHP:
    PEMapModder likes this.
  3. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    please use code function
    PHP:
    <?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() > /* 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');
    }
    Last edited: Aug 16, 2015
  4. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  5. LCraftPE
    Offline

    LCraftPE New Member

    Joined:
    Nov 16, 2014
    Posts:
    30
    Minecraft User:
    LCraftPE
    I add this but it always doesn't work
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Register Listener
  7. LCraftPE
    Offline

    LCraftPE New Member

    Joined:
    Nov 16, 2014
    Posts:
    30
    Minecraft User:
    LCraftPE
    $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); ?
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
  9. LCraftPE
    Offline

    LCraftPE New Member

    Joined:
    Nov 16, 2014
    Posts:
    30
    Minecraft User:
    LCraftPE
    I add this but it always doesn't work :(
  10. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    forgott

    use pocketmine *blabla* /Level;

    but u use it here if($world instanceof Level)
  11. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Any erros or what?
  12. LCraftPE
    Offline

    LCraftPE New Member

    Joined:
    Nov 16, 2014
    Posts:
    30
    Minecraft User:
    LCraftPE
    No just the limit doesn't work ! :s
  13. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    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.
    CrazedMiner likes this.
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, assuming you have an EventListener class.

Share This Page

Advertisement