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

Solved Sign Bug...

Comments in 'Plugin Development' started by LCraftPE, Sep 26, 2016.

  1. LCraftPE
    Offline

    LCraftPE New Member

    Joined:
    Nov 16, 2014
    Posts:
    30
    Minecraft User:
    LCraftPE
    Hello,
    I have a problem... When a player arrives at the server, the sign adds a player but when he leaves, the sign does not removed the player...

    The plugin Main:
    PHP:
    <?php

    namespace HB;

    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\entity\Entity;

    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent

    use pocketmine\scheduler\Task;
    use 
    HB\{SignTaskTaskEndTaskInvTaskPvP};

    class 
    Main extends PluginBase implements Listener{

      public 
    $status = array();

      public 
    $player = array();

      public function 
    onEnable(){
        
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        
    $this->getLogger()->info("HotBlock Enabled !");
        if(!isset(
    $this->status['HB'])){
          
    $this->status['HB'] = 0;
        }
        
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new SignTask($this), 20 3);
      }
     
      public function 
    onPlayerJoin(PlayerJoinEvent $event){
        
    $player $event->getPlayer();
        
    array_push($this->player$player->getName());
      }

      public function 
    onPlayerQuit(PlayerQuitEvent $event){ //Marche pas.
        
    $player $event->getPlayer();
        if(isset(
    $this->player[$player->getName()])){
          unset(
    $this->player[$player->getName()]);
          
    $player->sendMessage("LEFT");
        }
      }
     
      public function 
    SignTask(){
        
    $tile $this->getServer()->getLevelByName("world")->getTile(new Vector3(1336128));
        if(
    $tile instanceof Sign){
          if(
    $this->status["HB"] == 0){
            
    $tile->setText("[HotBlock]""Map : End""Players : ".count($this->player)." / 15""TEST");
          }else{
            
    $tile->setText("[HotBlock]""Map : End""Players : ".count($this->player)." / 15""In Game...");
          }
        }
      }
    }
    The plugin Task:
    PHP:
    <?php

    namespace HB;

    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\tile\Sign as SignTile;
    use 
    HB\Main;

    class 
    SignTask extends PluginTask{

      public function 
    __construct(Main $owner){
        
    parent::__construct($owner);
        
    $this->owner $owner;
      }
     
      public function 
    onRun($currentTick){
        
    $this->getOwner()->SignTask();
      }
    }
    Thanks you for your help.
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You need the key when using unset(). Use
    PHP:
    $array[array_search($name$array)];
    While $array is your array, and $name is the playername. array_search() returns the key.

    But... why don't you simply count all online players?
    Last edited: Sep 26, 2016
    TutoGamerWalid likes this.
  3. TutoGamerWalid
    Offline

    TutoGamerWalid Active Member

    Joined:
    Jun 11, 2015
    Posts:
    69
    Minecraft User:
    TutoGamerWalid
    PHP:
      $player $event->getPlayer();
      
    $name $player->getName();
      
    $p1 array_search($name,$this->players);
                   unset(
    $this->players[$p1]);
    //For unset solution..
  4. LCraftPE
    Offline

    LCraftPE New Member

    Joined:
    Nov 16, 2014
    Posts:
    30
    Minecraft User:
    LCraftPE
    Hello,
    I do not count online players because this code is not the real... (in truth, it's the players on arenas but I simplified the code).
    Thanks, I'll try !
    I'll keep you informed.
    CraftYourBukkit likes this.

Share This Page

Advertisement