Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Get the nearest player on the spawn

Comments in 'Plugin Development' started by cake23, Mar 27, 2016.

  1. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Hey! I wanna make the following plugin:
    The nearest player, they are in the near of the spawn, get a message like "You are in the near of the spawn!".
    Does anyone know how can I make this plugin? Thanks! :D
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    $distance PHP_INT_MAX;
    $player null;
    $lvl $this->getServer()->getLevelByName("world");
    foreach(
    $lvl->getPlayers() as $pl){
      if(
    $pl->distanceSquared($lvl->getSafeSpawn()) < $distance){
        
    $distance $pl->distanceSquared($lvl->getSafeSpawn());
        
    $player $pl;
      }
    }

    if(
    $player != null){
      
    $player->sendMessage("Hi");
    }
    applqpak and cake23 like this.
  3. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Thank you!! I will try it out! :3
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    How much difference is this from a direct plugin request :/
    ImagicalGamer and applqpak like this.

Share This Page

Advertisement