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

2 Questions..

Comments in 'Plugin Development' started by mamayadesu, Apr 9, 2015.

  1. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu
    1. How get chunk on which you stand?
    2. How to realize: Player came to spawn territory (or other chunk) and he get message: "Welcome to spawn"?
  2. Blubbll
    Offline

    Blubbll Active Member

    Joined:
    Oct 3, 2013
    Posts:
    325
    Minecraft User:
    Blubbll
    idk how to, but i know it's possible.

    for the second thing: eg look at factionspro, it has areas & notifications on enter
  3. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    1.
    PHP:
    /**@var Player $player*/
    $player->getLevel()->getChunk($player->getFloorX() >> 4$player->getFloorZ() >> 4); #thanks PEMapModder
    //returns the player chuck object
    2. I don't know if this works or if there is a better way to do this
    PHP:
    private $inSpawn = array();
    public function 
    onMove(PlayerMoveEvent $event){
      
    $p $event->getPlayer();
      
    $s $p->getLevel()->getSpawnLocation();
      
    $pos = new Vector3($p->getX(), $p->getY(), $p->getZ());
      
    $spawn = new Vector3($s->getX(), $s->getY(), $s->getZ();
      if(
    $pos->distance($spawn)) <= $this->getServer()->getSpawnRadius()){
        if(!
    in_array($p->getName(), $this->inSpawn)){
          
    $p->sendMessage("Welcome to spawn");
          
    $this->inSpawn[] = $p->getName();
        }
      }else{
        if((
    $k array_search($p->getName(), $this->inSpawn)) !== false){
          unset(
    $this->inSpawn[$k]);
        }
      }
    }
    edit: compressed version of #2
    PHP:
    private $inSpawn = [];
    public function 
    onMove(PlayerMoveEvent $event){
      
    $s $event->getPlayer()->getLevel()->getSpawnLocation();
      if((new 
    Vector3($event->getPlayer()->getX(), $event->getPlayer()->getY(), $event->getPlayer()->getZ()))->distance(new Vector3($s->getX(), $s->getY(), $s->getZ())) <= $this->getServer()->getSpawnRadius()){
        if(!
    in_array($event->getPlayer()->getName(), $this->inSpawn)){
          
    $event->getPlayer()->sendMessage("Welcome to spawn");
          
    $this->inSpawn[] = $event->getPlayer()->getName();
        }
      }else{
        if((
    $k array_search($event->getPlayer()->getName(), $this->inSpawn)) !== false){
          unset(
    $this->inSpawn[$k]);
        }
      }
    }
    Last edited: Apr 11, 2015
    EvolSoft, DA_Swagnemite and LDX like this.
  4. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu
    Thank you!
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No. It is $player->getLevel()->getChunk($player->getFloorX() >> 4, $player->getFloorZ() >> 4)
    luca28pet likes this.
  6. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu
    Thank you. And how I can get chunk id? Example: 89,25
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Isn't that the chunk ID?
  8. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu
    Sorry. I didn't know one thing. I looked at the WorldEdit (CraftBukkit) code - I learned as they get that "ID" of chunks.
    PHP:
    $x 500// Player's X position
    $z = -120// Player's Z position
    $chunk_x = (int) round($x 16);
    $chunk_z = (int) round($z 16);
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That's wrong. You should use >> 4 not / 16, because bit shifting is much faster than division. Also, it should be floor not round. And what do you think happens if the $x and/or $z is/are -1? If you use bit shifting, you need to neither call functions (thus prevent some overhead that is fixed in PHP 5.7), nor to do rounding and division. I am not sure if it works well for extreme coordinates like those in the farlands, though.
  10. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    -1 >> 4 is still -1 which is what you want. If you want to reduce stuff you can skip the round or floor. $x >> 4 is an int operation only so an int stays an int (no need to floor or cast to (int).
    PEMapModder likes this.

Share This Page

Advertisement