Advertisement
Guest User

getPlayerInfo()

a guest
Aug 22nd, 2011
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  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) {
  18.    
  19.     // Make the function output to $playerInfo
  20.     global $playerInfo;
  21.    
  22.     // Make it more user friendly
  23.     $file = $worldLocation . $player . ".dat";
  24.    
  25.     // Use the NBT Parser to load the .dat file
  26.     $nbt = new nbt();
  27.     $nbt->loadFile($file);
  28.    
  29.     // Get position sub-array
  30.     $pos = $nbt->root[0]['value'][11]['value']['value'];
  31.    
  32.     // Get health sub-array
  33.     $health = $nbt->root[0]['value'][8]['value'];
  34.    
  35.     // Get item sub-array ?
  36.     $items = $nbt->root[0]['value'][10]['value']['value'];
  37.    
  38.     // Merge
  39.     $playerInfo[$player] = array (
  40.                         'position' => array (
  41.                                         'x' => $pos[0],
  42.                                         'y' => $pos[1],
  43.                                         'z' => $pos[2]
  44.                                     ),
  45.                         'health' => $health,
  46.                         'inventory' => $items
  47.     );
  48. }
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement