How can I get the object of the player, If I only have the name? Also how can I check if that player is offline/online? Thanks!
I have this bug where: $isValid = $this->getServer()->getPlayer("Steve"); var_dump("$isValid"); returns null even though Steve is online and breathing. How do u fix this? This only happens from time to time.
with or without quotes, the same thing happens. so to avoid crashes, i always do $isValid instanceof Player
of course, its pointless if not. only this: $isValid = $this->getServer()->getPlayer("Steve"); which returns null. it only happens from time to time.
Run this? PHP: var_dump( $this->getServer()->getPlayer("Steve"), $this->getServer()->getPlayerExact("Steve"), $this->getServer()->getOnlinePlayers());
Actually you can't get the object of a player if he is offline. Unless you try to get an OfflinePlayer object, whose functions are more limited than a Player object because the player is offline (and you can't do things like sendMessage())
so i loaded a new user named as JohnSmith. it didnt return null this time. it happens from time to time which sucks.
no. only $this->getServer()->getPlayer("Steve"), $this->getServer()->getPlayerExact("Steve"), which the getOnlinePlayers returned Steve and JohnSmith
Yes i know about this to avoid crashes if getPlayer returns null. Its just that it gets annoying when it returns null even though you know its not
Im having trouble debug this as it just teleports me to a random player. No matter what player I tp to. PHP: public function issueCommand($sender, $victem){ $user = new Config($this->myuser . "users/" . strtolower($sender->getName() . ".yml"), Config::YAML); $mybalance = $user->get("coins"); $name = $sender->getName(); $name = strtolower($name); $object = $this->getServer()->getPlayer($victem); if($mybalance > 49){ if($object !== null and $object->isOnline()){ $sender->sendMessage("[Teleport] Teleporting you to $victem."); $sender->sendMessage("-50 coins, teleport command cost."); $mybalance = $mybalance - 50; $user->set("coins", $mybalance); $user->save(); $x = $object->getY(); $y = $object->getX(); $z = $object->getZ(); $sender->teleport(new Vector3($x, $y, $z)); //Not teleporting to the object it randomly tps you. return true; } else{ $sender->sendMessage("[Teleport] $victem is not online."); return true; } } else{ $sender->sendMessage("[Teleport] You need at least 50 coins to teleport."); return true; } } -------------------------- command code: PHP: case "tpme": $victem = $args[0]; $this->issueCommand($sender, $victem); return true; break;