1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Popup

Discussion in 'Development' started by di2134876, Mar 20, 2018.

  1. di2134876

    di2134876 Spider Jockey

    Messages:
    29
    GitHub:
    dk1234987
    Hello.
    I am using
    PHP:
    foreach($this->getServer()->getOnlinePlayers() as $players){
    }
    To display my popup which is a task, what i want is to send a different popup to a specified player.
    Is there any way of doing that?
    Thanks in advanced.
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
    <?php

    namespace yourpluginnamespace;

    use 
    pocketmine\Player;
    use 
    pocketmine\scheduler\PluginTask;

    use 
    plugin\Loader;

    class 
    Task extends PluginTask{

         private 
    $plugin$player;

         public function 
    __construct(Loader $pluginPlayer $player){
             
    $this->plugin $plugin;
             
    $this->player $player;
        }

         public function 
    onRun(int $currentTick){
            
    $this->player->sendPopup("Message");
            
    $this->plugin->getServer()->broadcastPopup("Broadcast");
         }
    }
     
  3. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    You can get the player IDs and match them with your specified player ID if I remember correctly
    However,I am wondering what do you mean by "specified"
     
  4. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    What..
     
  5. korado531m7

    korado531m7 Slime

    Messages:
    77
    GitHub:
    korado531m7
    put in the player name in array
    Code:
    $array = array(“player”,”name”,”here”);
    
    then, send each player
    Code:
    foreach($array as $player){
    $this->getServer()->getPlayer($player)->sendPopup(“message”);
    }
    
     
    OnTheVerge likes this.
  6. di2134876

    di2134876 Spider Jockey

    Messages:
    29
    GitHub:
    dk1234987
    Thank you, you are the one who understands.
    I want to assure that i put an extra param in the task to check the array right?
     
  7. korado531m7

    korado531m7 Slime

    Messages:
    77
    GitHub:
    korado531m7
    well... put in the player name who want you to send popup.
    e.g. to send 'abc', 'def', 'ghi' and 'jkl', please write like
    Code:
    $a = array('abc','def','ghi','jkl');
    
    then, send each player (before get player object)
    Code:
    foreach($a as $name){
        $this->getServer()->getPlayer($name)->sendPopup("Message Here");
    }
    
    to use task, write like
    Code:
    //defined player array in onEnable in $this->example
    //PluginTask
    
    public function __construct(Main $plugin) {
            parent::__construct($plugin);
            $this->plugin = $plugin;
    }
    
    public function onRun(int $ticks){
        foreach($this->plugin->example as $name){
            $this->getOwner()->getServer()->getPlayer($name)->sendPopup("message");
        }
    }
    
     
  8. di2134876

    di2134876 Spider Jockey

    Messages:
    29
    GitHub:
    dk1234987
    I don't think you understand, but i now know the answer due to testing
    I have an array in the main file which i can get through the task, i check if
    PHP:
    foreach($this->plugin->getServer()->getOnlinePlayers() as $players){
        
    //i check if $players is in the array of the main file
        
    if(in_array($players->getName(), $this->plugin->players)){
            
    //unique players
        
    }else{
        
    //normal players
        
    }
    }
     
  9. korado531m7

    korado531m7 Slime

    Messages:
    77
    GitHub:
    korado531m7
    PHP:
    if(in_array($this->getOwner()->getServer()->getOnlinePlayers(),$this->getOwner()->getServer()->getPlayer($this->plugin->players))){
        
    //unique players
    }else{
        
    //normal players
    }
     
  10. di2134876

    di2134876 Spider Jockey

    Messages:
    29
    GitHub:
    dk1234987
    You're searching for an array in an array that returns an object
     
  11. korado531m7

    korado531m7 Slime

    Messages:
    77
    GitHub:
    korado531m7
    sorry,
    PHP:
    foreach($this->getOwner()->getServer()->getOnlinePlayers() as $players){
        if(
    in_array($players->getName(), $this->plugin->players)){
            
    //unique players
        
    }else{
            
    //normal players
        
    }
    }
     
  12. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    For the sake of efficiency, you can have $this->plugin->players array structured like this:
    PHP:
    /** @var string[] */
    private $players = [];

    public function 
    addPlayer(Player $player) : void{
        
    $this->players[$player->getRawUniqueId()] = $player->getName();
    }
    and then broadcast the pop-up.
    PHP:
    /** @var Server $server */
    foreach($server->getOnlinePlayers() as $k => $player){
        if(isset(
    $this->players[$k])){
            
    //unique player
        
    }else{
            
    //normal player
        
    }
    }
    Or have an array of player names mapped to their pop-up
    PHP:
    $this->players["steve"] = "Enter pop-up here.";

    foreach(
    $server->getOnlinePlayers() as $player){
        if(isset(
    $this->players[$key $player->getLowerCaseName()])){
            
    $player->sendPopup($this->players[$key]);
        }else{
            
    //normal player
        
    }
    }
     
    OnTheVerge likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.