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

Send different Popups when player join

Comments in 'Plugin Development' started by Marcelo234, Mar 22, 2016.

  1. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey Guys...So I want to send a few players this Popup am the others the other popup:
    Main:
    PHP:
    public function onJoin(PlayerJoinEvent $event) {
    $player $event->getPlayer();
    $time intval($this->config->get("time")) * 2;
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new SendInfoCoinsLevelTask($this$player), $time);
    }
    And now the SendInfoCoinsLevelTask:
    PHP:
    <?php

    namespace McKaff_Settings;

    use 
    pocketmine\Player;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    McKaff_Settings\Main;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\utils\TextFormat as MT;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\event\Listener;

    class 
    SendInfoCoinsLevelTask extends PluginTask{
       
         public function 
    __construct(Main $pluginPlayer $player){
            
    $this->plugin $plugin;
            
    $this->player $player;
            
    parent::__construct($plugin$player);
        }
        public function 
    getPlugin(){  
            return 
    $this->plugin;
        }

        public function 
    onRun($currentTick){
           foreach(
    $this->getPlugin()->getServer()->getPlayer() as $player){
                
    $this->config = new config($this->getPlugin()->getDataFolder() . "config.yml"Config::YAML, array());
                
    $language $this->playerconfig->get("Language");
                
    $vip =  $this->playerconfig->get("V.I.P.");
                
    $limitedviptime $this->playerconfig->get("limited_V.I.P._time");
                
    $playerworld $player->getLevel()->getName();
                
    $servertime $this->config->get("servertime");
         if(
    $this->player instanceof Player && $this->getOwner()->getServer()->getPlayer($this->player->getName()) !== null){
         
    $player $this->getOwner()->getServer()->getPlayer($this->player->getName());

          if(
    $playerworld == $this->config->get("lobby_spawn_world")){
            if(
    $vip == "true"){
                if(
    $language == "DE") {
                    
    $player->sendPopup(MT::BOLD.MT::GOLD."Deine Coins: ".MT::GRAY.$this->playerconfig->get("coins").MT::GOLD." Dein Level: ".MT::GRAY.$this->playerconfig->get("Level"),MT::BOLD.MT::AQUA."[V.I.P.]");
                }
                if(
    $language == "EN") {
                    
    $player->sendPopup(MT::BOLD.MT::GOLD."Your Coins: ".MT::GRAY.$this->playerconfig->get("coins").MT::GOLD." Your Level: ".MT::GRAY.$this->playerconfig->get("Level"),MT::BOLD.MT::AQUA."[V.I.P.]");
                }
            }
            }
            if(
    $vip == "false"){
                if(
    $language == "DE") {
                    
    $player->sendPopup(MT::BOLD.MT::GOLD."Deine Coins: ".MT::GRAY.$this->playerconfig->get("coins").MT::GOLD." Dein Level: ".MT::GRAY.$this->playerconfig->get("Level"));
                }
                if(
    $language == "EN") {
                    
    $player->sendPopup(MT::BOLD.MT::GOLD."Your Coins: ".MT::GRAY.$this->playerconfig->get("coins").MT::GOLD." Your Level: ".MT::GRAY.$this->playerconfig->get("Level"));
                }
            
    $this->player->set("V.I.P.""false");
            
    $this->player->set("limited_V.I.P.""false");
            }
         }
           }
        }
    }
    So here you see...
    The "playerconfig" is right..Nothing wrong there..
    So if I would start the Server now many People would get all the Messages! Everyone should get her messagen own Messages with her right coins! But every Player get the coins of the others displayed!
    So maybe anywhat with this?:
    PHP:
    $this->player[1] = $p->getName();
    Thanks for help Marcelo234
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    What are you doing?
    PHP:
    foreach($this->getPlugin()->getServer()->getPlayer() as $player){
    Why are you creating a PluginTask for each player, and even more you are trying to loop each player on server? And if so, just get player popup and language on __construct method instead of doing it on each loop/run. Use more switch().

    No offence but your code is dumb.
    Last edited: Mar 22, 2016
    ImagicalGamer likes this.
  3. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Think about your code, a task for each player is not good, just saying
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Jeesus. Just create a task for example HUD, schedule it when plugin enables and then loop through Server::getOnlinePlayers()
  5. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    That would be a good idea...but I want only send the popup to the Players who are in the Lobby..is there an solution?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use Level::getPlayers() on the lobby level.
  7. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Sorry.. How to use? $this->$server->$GetPlugin()->$grtServer()->GetLevel("Yo")->GetPlayers();
    Like that??
    And.....
    If I do that Every player get the Coins of the other players who are in this level too...How i can fix this?
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    By logically thinking.
  9. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    You can fix it with foreach()

    Foreach executes for every element in the array a function, here a little demonstration:

    PHP:
    $players $this->plugin->getServer()->getDefaultLevel()->getPlayers();  // default level is the lobby

    foreach($players as $player){
    $player->sendTip($player->getName());
    }

    I personally recommend executing at onRun a function like $this->plugin->Second(); and then put everything you want to execute in a public function Second(){} in your main file, because there you mustnt do $this->plugin and have all imported classes instead the constructed ones
  10. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    So than every player will get their own coins? Cool...I will Test it morning...

Share This Page

Advertisement