1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

get player country

Discussion in 'Development' started by Pqoster, Aug 5, 2020.

  1. Pqoster

    Pqoster Spider Jockey

    Messages:
    25
    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
     
  2. newcoolboys

    newcoolboys Spider

    Messages:
    12
    GitHub:
    Newcoolboys
    Pqoster likes this.
  3. newcoolboys

    newcoolboys Spider

    Messages:
    12
    GitHub:
    Newcoolboys
    Here is a bit of code to help :)
     
    Pqoster likes this.
  4. newcoolboys

    newcoolboys Spider

    Messages:
    12
    GitHub:
    Newcoolboys
    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");
    
            }
        }
    }
     
    Diduhless and Pqoster like this.
  5. newcoolboys

    newcoolboys Spider

    Messages:
    12
    GitHub:
    Newcoolboys
    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
     
    Pqoster likes this.
  6. Pqoster

    Pqoster Spider Jockey

    Messages:
    25
    thx bro
     
  7. Pqoster

    Pqoster Spider Jockey

    Messages:
    25
    erro :/ http://imgur.com/a/CDKh9AO
     
  8. newcoolboys

    newcoolboys Spider

    Messages:
    12
    GitHub:
    Newcoolboys
    did you change anything in the code?
     
    Pqoster likes this.
  9. newcoolboys

    newcoolboys Spider

    Messages:
    12
    GitHub:
    Newcoolboys
    on The Main file at 24 what does it say?
     
  10. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    bad coding, why are you using dispatch cmd?
     
  11. Pqoster

    Pqoster Spider Jockey

    Messages:
    25
    yes, I changed the commands
     
  12. newcoolboys

    newcoolboys Spider

    Messages:
    12
    GitHub:
    Newcoolboys
    to set the players rank
     
  13. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    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. ;)
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.