Hey Guys..Here i have a code:: so after a player join he should gets every few seconds his coins and levels...But If you can see in the code the server will send all coins and levels of the joined players to all Players who are online! But How to send the Player datas only to the right player? Main: PHP: public function onJoin(PlayerJoinEvent $event) { $player = $event->getPlayer();$this->player = new Config($this->getDataFolder() . "PlayersInfo/" . strtolower($player->getName()) . ".yml" , Config::YAML, array()); $level = $this->player->get("Level"); $coins = $this->player->get("coins"); $playerworld = $player->getLevel()->getName(); $this->config = new config($this->getDataFolder() . "config.yml", Config::YAML, array()); $time1 = intval($this->config->get("time")) * 2; $this->getServer()->getScheduler()->scheduleRepeatingTask(new SendInfoCoinsLevelTask($this, $player, $coins, $level, $playerworld), $time1); } SendInfoCoinsLevelTask: PHP: <?phpnamespace 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 $plugin, Player $player, $coins, $level){ $this->plugin = $plugin; $this->player = $player; $this->coins = $coins; $this->level = $level; parent::__construct($plugin, $player, $coins, $level); } public function getPlugin(){ return $this->plugin; } public function onRun($currentTick){ foreach($this->getPlugin()->getServer()->getOnlinePlayers() as $player){ $this->player = new Config($this->getPlugin()->getDataFolder() . "PlayersInfo/" . strtolower($player->getName()) . ".yml" , Config::YAML); $this->config = new config($this->getPlugin()->getDataFolder() . "config.yml", Config::YAML, array()); $language = $this->player->get("Language"); $vip = $this->player->get("V.I.P."); $limitedviptime = $this->player->get("limited_V.I.P._time"); $playerworld = $player->getLevel()->getName(); $servertime = $this->config->get("servertime"); 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->coins.MT::GOLD." Dein Level: ".MT::GRAY.$this->level,MT::BOLD.MT::AQUA."[V.I.P.]"); } if($language == "EN") { $player->sendPopup(MT::BOLD.MT::GOLD."Your Coins: ".MT::GRAY.$this->coins.MT::GOLD." Your Level: ".MT::GRAY.$this->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->coins.MT::GOLD." Dein Level: ".MT::GRAY.$this->level); } if($language == "EN") { $player->sendPopup(MT::BOLD.MT::GOLD."Your Coins: ".MT::GRAY.$this->coins.MT::GOLD." Your Level: ".MT::GRAY.$this->level); } $this->player->set("V.I.P.", "false"); $this->player->set("limited_V.I.P.", "false"); } } }} Thanks Marcelo234
why using global variables (ex. $this->player when not needed? why creating different schedulers for each player ? why passing $player $coins and $level to the PluginTask construct ? why using $this->getPlugin() instead of using $this->getOwner() ? do you know $playerworld is not used (in Main) ? why looping into online players if you need to send the popup only to 1 player? to get only one player you can do: PHP: Server->getPlayer('playerName');//or if you want to get the player by the exact name:Server->getPlayerExact('playerName'); //if i remember correctly btw , very bad coded plugin seems like you just wrote random things copying other plugins and without understanding nothing
1. Create the config in onJoin() because at onRun() it will be made every second 2. Why == "true" its called true without "" 3. The problem why everyone gets the stats of the same player: PHP: if($vip == "false"){ if($language == "DE") {$player->sendPopup(MT::BOLD.MT::GOLD."Deine Coins: ".MT::GRAY.$this->coins.MT::GOLD." Dein Level: ".MT::GRAY.$this->level); } if($language == "EN") {$player->sendPopup(MT::BOLD.MT::GOLD."Your Coins: ".MT::GRAY.$this->coins.MT::GOLD." Your Level: ".MT::GRAY.$this->level); }$this->player->set("V.I.P.", "false");$this->player->set("limited_V.I.P.", "false"); } Why do you use a public variable? Just do $playerconfig->get("coins"); Btw I recommend you to decompile your code a bit
You don't need to call parent constructor with so many parameters. PluginTask::__construct() only requires one parameter.
Ok thanks .... I created the Global variable...And I changed the code...But there is an error. Main: PHP: class Main extends PluginBase implements Listener { public $playerconfig; public function onJoin(PlayerJoinEvent $event) {$player = $event->getPlayer(); $this->playerconfig = new Config($this->getDataFolder() . "PlayersInfo/" . strtolower($player->getName()) . ".yml" , Config::YAML); $this->config = new config($this->getDataFolder() . "config.yml", Config::YAML, array()); $time1 = intval($this->config->get("time")) * 2; $this->getServer()->getScheduler()->scheduleRepeatingTask(new SendInfoCoinsLevelTask($this, $player), $time1);}} SendInfoCoinsLevelTask: PHP: <?phpnamespace 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 $plugin, Player $player){ $this->plugin = $plugin; $this->player = $player; parent::__construct($plugin, $player); } public function getPlugin(){ return $this->plugin; } public function onRun($currentTick){ $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($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"); } }} Thanks Marcelo234
No, the problem is that you create everytime onRun gets triggered a new config for each player will be created
*Undefined property SendInfoCoinsTask::$playerconfig* you defined the property for the Main class, you did not define it for the SendInfoCoins class. so you would have to passing the Main::$playerconfig to the SendInfoCoinsTask and adding an argument for it and setting SendInfoCoinsTask::$playerconfig to that given argument.