Hi, I can't seem to get my variable to update when I call the function that updates it. MySQL runs and sends all the data, but it still won't update the variable. Code that updates the variable. PHP: public $group = ""; /** @var \mysqli */ protected $sql; public function __construct(Player $player, Core $core){ $this->sql = $core->sql; } public function sendJoinData(Player $player){ $group = "guest"; $user = $player->getName(); $prepare = $this->sql->prepare("INSERT IGNORE INTO players(username, groupUser) VALUES(?, ?)"); $prepare->bind_param("ss", $user, $group); $prepare->execute(); $prepare->close(); $this->getData($player); } public function getData(Player $player){ $result = $this->sql->query("SELECT * FROM players WHERE username='{$player->getName()}'"); $data = []; while($row = $result->fetch_assoc()){ $data = $row; } $this->group = $data["groupUser"]; } Misc: PHP: public function onLogin(PlayerLoginEvent $ev){ $player = $ev->getPlayer(); $this->getData($player, $this->sql)->sendJoinData($player); }
At a glance the first obvious error is that in onLogin the call to getData doesn't return anything - which is unexpected considering the name - let alone an object which has the method sendJoinData.
It sounds as though you need to learn some more PHP if you are going to develop a plugin - is the code yours, or are you trying to fix code written by someone else?
OK, then what this does: Code: $this->getData($player, $this->sql)->sendJoinData($player); Is look in $this (the class to which current code belongs) for the function getData(), to which it sends the arguments $player and $this->sql. Then it looks for the method (function) sendJoinData on the object returned by getData... but since you don't return anything from getData(), that function will not be found. Either you need to return $this from getData()... or simply break the line into two, one to run getData, the next to run sendJoinData(). Again, I haven't looked closely so there may well be other problems too, but this one shows that you aren't really familiar with how objects work.