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

How to get the walking position on PlayerMoveEvent

Comments in 'Plugin Development' started by Taha_The_Hacker, Oct 17, 2015.

  1. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Hey,

    I want to get the position of the player when walking on PlayerMoveEvent, i tried this :
    PHP:
    public function spleefItems(PlayerMoveEvent $event){
      
    $player $event->getPlayer();
        foreach(
    $this->items["Items"] as $i){
          for(
    $x $this->yml["spleef-Min-floor-X"]; $x <= $this->yml["spleef-Max-floor-X"]; $x++){
          for(
    $y $this->yml["spleef-Min-floor-Y"]; $y <= $this->yml["spleef-Max-floor-Y"]; $y++){
          for(
    $z $this->yml["spleef-Min-floor-Z"]; $z <= $this->yml["spleef-Max-floor-X"]; $z++){
       if(
    $player->getX() == $x && $player->getY()-== $y && $player->getZ() == $z){
        
    $player->getInventory()->addItem(Item::get($i["id"], $i["damage"]));
        } elseif(
    $player->getX() == $x && $player->getY()-== $y && $player->getZ() == $z){ $player->getInventory()->addItem(Item::get($i["id"], $i["damage"])); } else { $player->getInventory()->removeItem(Item::get($i["id"], $i["damage"])); }//if
      
    }//3
      
    }//2
      
    }//1
      
    }//foreach
    }//spleefItems
    But doesn't work
    did i do something wrong, or i am Completely wrong?
    Thanks for your reply :)
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    BTW: $this->items is defined as
    PHP:
          $items = new Config($this->getDataFolder() . "Items.yml"Config::YAML);
          
    $this->items $items->getAll();
  3. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    You should look at $event->getTo() and $event->getFrom(). Also be aware that getX(), getY() and getZ() return floats (with decimal), so you will want to implement round() or truncate them in some way. If you don't, it is very unlikely that the player will end up at that exact position.
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    So.. I've used
    PHP:
    public function spleefItems(PlayerMoveEvent $event){
      
    $player $event->getPlayer();
        foreach(
    $this->items["Items"] as $i){
          for(
    $x $this->yml["spleef-Min-floor-X"]; $x <= $this->yml["spleef-Max-floor-X"]; $x++){
          for(
    $y $this->yml["spleef-Min-floor-Y"]; $y <= $this->yml["spleef-Max-floor-Y"]; $y++){
          for(
    $z $this->yml["spleef-Min-floor-Z"]; $z <= $this->yml["spleef-Max-floor-X"]; $z++){
       if(
    round($event->getFrom()->getX()) == round($x) && round($event->getFrom()->getY())-== round($y) && round($event->getFrom()->getZ()) == round($z)){
        
    $player->getInventory()->addItem(Item::get($i["id"], $i["damage"]));
        } elseif(
    round($event->getFrom()->getX()) == $x && round($event->getFrom()->getY())-== $y && round($event->getFrom()->getZ()) == $z){ $player->getInventory()->addItem(Item::get($i["id"], $i["damage"])); } else { $player->getInventory()->removeItem(Item::get($i["id"], $i["damage"])); }//if
      
    }//3
      
    }//2
      
    }//1
      
    }//foreach
     
    }//spleefItems
    and my config
    Code:
    spleef-world: "lobby"
    
    spleef-Min-floor-X: 121.5927
    spleef-Min-floor-Y: 65
    spleef-Min-floor-Z: 121.6457
    
    #Max position for the spleef floor to reset (to)
    spleef-Max-floor-X: 135.4442
    spleef-Max-floor-Y: 65
    spleef-Max-floor-Z: 135.531
    
    i did round($x) because in the config it has decimels, but when i step on one of those blocks Nothing happens.
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    getFloorX();
    getFloorY();
    getFloorZ();
    zombie_Power likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Floor != Round
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Floor returns integer so i preffer Floor.
  8. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    well.. what can i do to make it work? o_O
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But they are different. floor(3.9) returns 3.0 and round(3.9) returns 4.0

Share This Page

Advertisement