Pr4w

getPlayerInfo()

Aug 22nd, 2011
139
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3.  @Filename : getPlayerInfo.php
  4.  @Description : Parses all the useful information from player.dat
  5.  to a user-friendly array
  6.  @Written by Pr4w for Bukkit.org
  7.  @Usage :  getPlayerInfo('Pr4w', '/opt/minecraft/World1/');
  8.  This outputs a $playerInfo['Pr4w'] variable that you can mess with
  9.  Outputs : Position, Health, Inventory
  10.  
  11.  Have fun :)
  12. */
  13.  
  14. // This requires an NBT Parser
  15. require('nbt.class.php');
  16.  
  17. function getPlayerInfo($player, $worldLocation = NULL) {
  18.    
  19.     // Make it more user friendly
  20.     $file = $worldLocation . $player . ".dat";
  21.    
  22.     // Use the NBT Parser to load the .dat file
  23.     $nbt = new nbt();
  24.     $nbt->loadFile($file);
  25.    
  26.     // Get position sub-array
  27.     $pos = $nbt->root[0]['value'][11]['value']['value'];
  28.    
  29.     // Get health sub-array
  30.     $health = $nbt->root[0]['value'][8]['value'];
  31.    
  32.     // Get item sub-array ?
  33.     $items = $nbt->root[0]['value'][10]['value']['value'];
  34.    
  35.     // Merge
  36.     $playerInfo = array (
  37.                         'position' => array (
  38.                                         'x' => $pos[0],
  39.                                         'y' => $pos[1],
  40.                                         'z' => $pos[2]
  41.                                     ),
  42.                         'health' => $health,
  43.                         'inventory' => $items
  44.     );
  45.     return $playerInfo;
  46.    
  47. }
  48. ?>
RAW Paste Data