I want to get the player's country to set a rank according to his continent Example: I am from ARG and when I enter the server for the first time I already earn the "South America" rank
Code: public function checkCountry($player) : string{ $json = json_decode(file_get_contents("http://ip-api.com/json/" . $player), true); if($json['status'] == "success"){ $country = $json['countryCode']; } return $country; } public function playerJoinEvent(PlayerJoinEvent $event) { $country = $this->checkCountry($event->getPlayer()->getAddress()); $player = $event->getPlayer(); if ($player->hasPlayedBefore() == false) { if (in_array($country, array_map('strtoupper', "United States"))){ $player = $event->getPlayer()->getName(); $this->getServer()->dispatchCommand(new ConsoleCommandSender(), "setrank {$player} USA"); } if (in_array($country, array_map('strtoupper', "Argentina"))){ $player = $event->getPlayer()->getName(); $this->getServer()->dispatchCommand(new ConsoleCommandSender(), "setrank {$player} ARG"); } } }
Keep on using if statements for all of them and change the ConsoleCommandSender to have the different ranks. You can change any commands I did and change it to your system's
so i said, its bad for coding, use PureChat - PurePerms API to set player rank, dispatch cmd is bad way but its working, its better to use ppchat api to set player rank.