Used namespacer tool

This commit is contained in:
Shoghi Cervantes 2014-03-06 05:47:00 +01:00
parent c9c6d5a5f4
commit 42ae544d0d
132 changed files with 1171 additions and 760 deletions

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
abstract class Achievement{ abstract class Achievement{
public static $list = array( public static $list = array(

View File

@ -20,6 +20,9 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Utils\Config as Config;
use PocketMine\Player as Player;
class BanAPI{ class BanAPI{
private $server; private $server;
@ -40,10 +43,10 @@ class BanAPI{
} }
public function init(){ public function init(){
$this->whitelist = new Utils\Config(\PocketMine\DATA."white-list.txt", Utils\Config::ENUM);//Open whitelist list file $this->whitelist = new Config(\PocketMine\DATA."white-list.txt", Config::ENUM);//Open whitelist list file
$this->bannedIPs = new Utils\Config(\PocketMine\DATA."banned-ips.txt", Utils\Config::ENUM);//Open Banned IPs list file $this->bannedIPs = new Config(\PocketMine\DATA."banned-ips.txt", Config::ENUM);//Open Banned IPs list file
$this->banned = new Utils\Config(\PocketMine\DATA."banned.txt", Utils\Config::ENUM);//Open Banned Usernames list file $this->banned = new Config(\PocketMine\DATA."banned.txt", Config::ENUM);//Open Banned Usernames list file
$this->ops = new Utils\Config(\PocketMine\DATA."ops.txt", Utils\Config::ENUM);//Open list of OPs $this->ops = new Config(\PocketMine\DATA."ops.txt", Config::ENUM);//Open list of OPs
$this->server->api->console->register("banip", "<add|remove|list|reload> [IP|player]", array($this, "commandHandler")); $this->server->api->console->register("banip", "<add|remove|list|reload> [IP|player]", array($this, "commandHandler"));
$this->server->api->console->register("ban", "<add|remove|list|reload> [username]", array($this, "commandHandler")); $this->server->api->console->register("ban", "<add|remove|list|reload> [username]", array($this, "commandHandler"));
$this->server->api->console->register("kick", "<player> [reason ...]", array($this, "commandHandler")); $this->server->api->console->register("kick", "<player> [reason ...]", array($this, "commandHandler"));
@ -213,7 +216,7 @@ class BanAPI{
$output .= "Player \"$user\" added to white-list\n"; $output .= "Player \"$user\" added to white-list\n";
break; break;
case "reload": case "reload":
$this->whitelist = new Utils\Config(\PocketMine\DATA."white-list.txt", Utils\Config::ENUM); $this->whitelist = new Config(\PocketMine\DATA."white-list.txt", Config::ENUM);
break; break;
case "list": case "list":
$output .= "White-list: ".implode(", ", $this->whitelist->getAll(true))."\n"; $output .= "White-list: ".implode(", ", $this->whitelist->getAll(true))."\n";
@ -258,7 +261,7 @@ class BanAPI{
$output .= "IP \"$ip\" added to ban list\n"; $output .= "IP \"$ip\" added to ban list\n";
break; break;
case "reload": case "reload":
$this->bannedIPs = new Utils\Config(\PocketMine\DATA."banned-ips.txt", Utils\Config::ENUM); $this->bannedIPs = new Config(\PocketMine\DATA."banned-ips.txt", Config::ENUM);
break; break;
case "list": case "list":
$output .= "IP ban list: ".implode(", ", $this->bannedIPs->getAll(true))."\n"; $output .= "IP ban list: ".implode(", ", $this->bannedIPs->getAll(true))."\n";
@ -296,7 +299,7 @@ class BanAPI{
$output .= "Player \"$user\" added to ban list\n"; $output .= "Player \"$user\" added to ban list\n";
break; break;
case "reload": case "reload":
$this->banned = new Utils\Config(\PocketMine\DATA."banned.txt", Utils\Config::ENUM); $this->banned = new Config(\PocketMine\DATA."banned.txt", Config::ENUM);
break; break;
case "list": case "list":
$output .= "Ban list: ".implode(", ", $this->banned->getAll(true))."\n"; $output .= "Ban list: ".implode(", ", $this->banned->getAll(true))."\n";

View File

@ -20,6 +20,16 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\Level\Position as Position;
use PocketMine\Block\GenericBlock as GenericBlock;
use PocketMine\Item\Item as Item;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Player as Player;
use PocketMine\Block\Block as Block;
use PocketMine\Tile\Sign as Sign;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\NBT\Tag\String as String;
use PocketMine\NBT\Tag\Int as Int;
class BlockAPI{ class BlockAPI{
private $server; private $server;
@ -248,14 +258,14 @@ class BlockAPI{
} }
} }
public static function get($id, $meta = 0, Level\Position $v = null){ public static function get($id, $meta = 0, Position $v = null){
if(isset(Block::$class[$id])){ if(isset(Block::$class[$id])){
$classname = Block::$class[$id]; $classname = Block::$class[$id];
$b = new $classname($meta); $b = new $classname($meta);
}else{ }else{
$b = new Block\GenericBlock((int) $id, $meta); $b = new GenericBlock((int) $id, $meta);
} }
if($v instanceof Level\Position){ if($v instanceof Position){
$b->position($v); $b->position($v);
} }
return $b; return $b;
@ -263,11 +273,11 @@ class BlockAPI{
public static function getItem($id, $meta = 0, $count = 1){ public static function getItem($id, $meta = 0, $count = 1){
$id = (int) $id; $id = (int) $id;
if(isset(Item\Item::$class[$id])){ if(isset(Item::$class[$id])){
$classname = Item\Item::$class[$id]; $classname = Item::$class[$id];
$i = new $classname($meta, $count); $i = new $classname($meta, $count);
}else{ }else{
$i = new Item\Item($id, $meta, $count); $i = new Item($id, $meta, $count);
} }
return $i; return $i;
} }
@ -318,7 +328,7 @@ class BlockAPI{
return $output; return $output;
} }
private function cancelAction(Block\Block $block, Player $player, $send = true){ private function cancelAction(Block $block, Player $player, $send = true){
$pk = new Network\Protocol\UpdateBlockPacket; $pk = new Network\Protocol\UpdateBlockPacket;
$pk->x = $block->x; $pk->x = $block->x;
$pk->y = $block->y; $pk->y = $block->y;
@ -356,7 +366,7 @@ class BlockAPI{
return $this->cancelAction($target, $player, false); return $this->cancelAction($target, $player, false);
} }
if(($player->gamemode & 0x01) === 0 and $item->useOn($target) and $item->getMetadata() >= $item->getMaxDurability()){ if(($player->gamemode & 0x01) === 0 and $item->useOn($target) and $item->getMetadata() >= $item->getMaxDurability()){
$player->setSlot($player->slot, new Item\Item(AIR, 0, 0)); $player->setSlot($player->slot, new Item(AIR, 0, 0));
} }
}else{ }else{
return $this->cancelAction($target, $player, false); return $this->cancelAction($target, $player, false);
@ -453,16 +463,16 @@ class BlockAPI{
return $this->cancelAction($block, $player, false); return $this->cancelAction($block, $player, false);
} }
if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){ if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){
new Tile\Sign($player->level, new NBT\Tag\Compound(false, array( new Sign($player->level, new Compound(false, array(
"id" => new NBT\Tag\String("id", Tile::Sign), "id" => new String("id", Tile::Sign),
"x" => new NBT\Tag\Int("x", $block->x), "x" => new Int("x", $block->x),
"y" => new NBT\Tag\Int("y", $block->y), "y" => new Int("y", $block->y),
"z" => new NBT\Tag\Int("z", $block->z), "z" => new Int("z", $block->z),
"Text1" => new NBT\Tag\String("Text1", ""), "Text1" => new String("Text1", ""),
"Text2" => new NBT\Tag\String("Text2", ""), "Text2" => new String("Text2", ""),
"Text3" => new NBT\Tag\String("Text3", ""), "Text3" => new String("Text3", ""),
"Text4" => new NBT\Tag\String("Text4", ""), "Text4" => new String("Text4", ""),
"creator" => new NBT\Tag\String("creator", $player->getUsername()) "creator" => new String("creator", $player->getUsername())
))); )));
} }
@ -476,7 +486,7 @@ class BlockAPI{
return false; return false;
} }
public function blockUpdateAround(Level\Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){ public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){
if($delay !== false){ if($delay !== false){
$this->scheduleBlockUpdate($pos->getSide(0), $delay, $type); $this->scheduleBlockUpdate($pos->getSide(0), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(1), $delay, $type); $this->scheduleBlockUpdate($pos->getSide(1), $delay, $type);
@ -494,11 +504,11 @@ class BlockAPI{
} }
} }
public function blockUpdate(Level\Position $pos, $type = BLOCK_UPDATE_NORMAL){ public function blockUpdate(Position $pos, $type = BLOCK_UPDATE_NORMAL){
if(!($pos instanceof Block\Block)){ if(!($pos instanceof Block)){
$block = $pos->level->getBlock($pos); $block = $pos->level->getBlock($pos);
}else{ }else{
$pos = new Level\Position($pos->x, $pos->y, $pos->z, $pos->level); $pos = new Position($pos->x, $pos->y, $pos->z, $pos->level);
$block = $pos->level->getBlock($pos); $block = $pos->level->getBlock($pos);
} }
if($block === false){ if($block === false){
@ -512,7 +522,7 @@ class BlockAPI{
return $level; return $level;
} }
public function scheduleBlockUpdate(Level\Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){ public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){
$type = (int) $type; $type = (int) $type;
if($delay < 0){ if($delay < 0){
return false; return false;

View File

@ -20,6 +20,8 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Player as Player;
class ChatAPI{ class ChatAPI{
private $server; private $server;

View File

@ -20,6 +20,9 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Utils\TextFormat as TextFormat;
use PocketMine\Player as Player;
class ConsoleAPI{ class ConsoleAPI{
private $loop, $server, $event, $help, $cmds, $alias; private $loop, $server, $event, $help, $cmds, $alias;
@ -132,7 +135,7 @@ class ConsoleAPI{
$max = ceil(count($cmds) / 5); $max = ceil(count($cmds) / 5);
$page = (int) (isset($params[0]) ? min($max, max(1, intval($params[0]))):1); $page = (int) (isset($params[0]) ? min($max, max(1, intval($params[0]))):1);
$output .= Utils\TextFormat::RED."-".Utils\TextFormat::RESET." Showing help page $page of $max (/help <page>) ".Utils\TextFormat::RED."-".Utils\TextFormat::RESET."\n"; $output .= TextFormat::RED."-".TextFormat::RESET." Showing help page $page of $max (/help <page>) ".TextFormat::RED."-".TextFormat::RESET."\n";
$current = 1; $current = 1;
foreach($cmds as $c => $h){ foreach($cmds as $c => $h){
$curpage = (int) ceil($current / 5); $curpage = (int) ceil($current / 5);
@ -179,9 +182,9 @@ class ConsoleAPI{
return $this->run($this->alias[$cmd] . ($params !== "" ? " " .$params:""), $issuer, $cmd); return $this->run($this->alias[$cmd] . ($params !== "" ? " " .$params:""), $issuer, $cmd);
} }
if($issuer instanceof Player){ if($issuer instanceof Player){
console("[DEBUG] ".Utils\TextFormat::AQUA.$issuer->getUsername().Utils\TextFormat::RESET." issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2); console("[DEBUG] ".TextFormat::AQUA.$issuer->getUsername().TextFormat::RESET." issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2);
}else{ }else{
console("[DEBUG] ".Utils\TextFormat::YELLOW."*".$issuer.Utils\TextFormat::RESET." issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2); console("[DEBUG] ".TextFormat::YELLOW."*".$issuer.TextFormat::RESET." issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2);
} }
if(preg_match_all('#@([@a-z]{1,})#', $params, $matches, PREG_OFFSET_CAPTURE) > 0){ if(preg_match_all('#@([@a-z]{1,})#', $params, $matches, PREG_OFFSET_CAPTURE) > 0){

View File

@ -22,6 +22,7 @@
//TODO: REMOVE //TODO: REMOVE
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
class Deprecation{ class Deprecation{
public static $events = array( public static $events = array(

View File

@ -20,6 +20,27 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Level\Generator\Flat as Flat;
use PocketMine\Level\Generator\Normal as Normal;
use PocketMine\Level\WorldGenerator as WorldGenerator;
use PocketMine\Utils\Utils as Utils;
use PocketMine\Level\LevelImport as LevelImport;
use PocketMine\Level\Level as Level;
use PocketMine\PMF\LevelFormat as LevelFormat;
use PocketMine\Utils\Config as Config;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\NBT\Tag\Enum as Enum;
use PocketMine\NBT\Tag\Byte as Byte;
use PocketMine\NBT\Tag\Short as Short;
use PocketMine\NBT\Tag\String as String;
use PocketMine\NBT\Tag\Int as Int;
use PocketMine\Tile\Tile as Tile;
use PocketMine\Tile\Furnace as Furnace;
use PocketMine\Tile\Chest as Chest;
use PocketMine\Tile\Sign as Sign;
use PocketMine\Level\Position as Position;
class LevelAPI{ class LevelAPI{
private $server, $levels, $default; private $server, $levels, $default;
@ -94,12 +115,12 @@ class LevelAPI{
$generator = new $generator($options); $generator = new $generator($options);
}else{ }else{
if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){ if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){
$generator = new Level\Generator\Flat($options); $generator = new Flat($options);
}else{ }else{
$generator = new Level\Generator\Normal($options); $generator = new Normal($options);
} }
} }
$gen = new Level\WorldGenerator($generator, $name, $seed === false ? Utils\Utils::readInt(Utils\Utils::getRandomBytes(4, false)):(int) $seed); $gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):(int) $seed);
$gen->generate(); $gen->generate();
$gen->close(); $gen->close();
return true; return true;
@ -111,7 +132,7 @@ class LevelAPI{
} }
$path = \PocketMine\DATA."worlds/".$name."/"; $path = \PocketMine\DATA."worlds/".$name."/";
if($this->get($name) === false and !file_exists($path."level.pmf")){ if($this->get($name) === false and !file_exists($path."level.pmf")){
$level = new Level\LevelImport($path); $level = new LevelImport($path);
if($level->import() === false){ if($level->import() === false){
return false; return false;
} }
@ -119,7 +140,7 @@ class LevelAPI{
return true; return true;
} }
public function unloadLevel(Level\Level $level, $force = false){ public function unloadLevel(Level $level, $force = false){
$name = $level->getName(); $name = $level->getName();
if($name === $this->default and $force !== true){ if($name === $this->default and $force !== true){
return false; return false;
@ -144,17 +165,17 @@ class LevelAPI{
} }
$path = \PocketMine\DATA."worlds/".$name."/"; $path = \PocketMine\DATA."worlds/".$name."/";
console("[INFO] Preparing level \"".$name."\""); console("[INFO] Preparing level \"".$name."\"");
$level = new PMF\LevelFormat($path."level.pmf"); $level = new LevelFormat($path."level.pmf");
if(!$level->isLoaded){ if(!$level->isLoaded){
console("[ERROR] Could not load level \"".$name."\""); console("[ERROR] Could not load level \"".$name."\"");
return false; return false;
} }
//$entities = new Utils\Config($path."entities.yml", Utils\Config::YAML); //$entities = new Config($path."entities.yml", Config::YAML);
if(file_exists($path."tileEntities.yml")){ if(file_exists($path."tileEntities.yml")){
@rename($path."tileEntities.yml", $path."tiles.yml"); @rename($path."tileEntities.yml", $path."tiles.yml");
} }
$blockUpdates = new Utils\Config($path."bupdates.yml", Utils\Config::YAML); $blockUpdates = new Config($path."bupdates.yml", Config::YAML);
$this->levels[$name] = new Level\Level($level, $name); $this->levels[$name] = new Level($level, $name);
/*foreach($entities->getAll() as $entity){ /*foreach($entities->getAll() as $entity){
if(!isset($entity["id"])){ if(!isset($entity["id"])){
break; break;
@ -171,39 +192,39 @@ class LevelAPI{
)); ));
}elseif($entity["id"] === FALLING_SAND){ }elseif($entity["id"] === FALLING_SAND){
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_FALLING, $entity["id"], $entity); $e = $this->server->api->entity->add($this->levels[$name], ENTITY_FALLING, $entity["id"], $entity);
$e->setPosition(new Math\Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); $e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
$e->setHealth($entity["Health"]); $e->setHealth($entity["Health"]);
}elseif($entity["id"] === OBJECT_PAINTING or $entity["id"] === OBJECT_ARROW){ //Painting }elseif($entity["id"] === OBJECT_PAINTING or $entity["id"] === OBJECT_ARROW){ //Painting
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_OBJECT, $entity["id"], $entity); $e = $this->server->api->entity->add($this->levels[$name], ENTITY_OBJECT, $entity["id"], $entity);
$e->setPosition(new Math\Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); $e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
$e->setHealth(1); $e->setHealth(1);
}else{ }else{
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_MOB, $entity["id"], $entity); $e = $this->server->api->entity->add($this->levels[$name], ENTITY_MOB, $entity["id"], $entity);
$e->setPosition(new Math\Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); $e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
$e->setHealth($entity["Health"]); $e->setHealth($entity["Health"]);
} }
}*/ }*/
if(file_exists($path ."tiles.yml")){ if(file_exists($path ."tiles.yml")){
$tiles = new Utils\Config($path."tiles.yml", Utils\Config::YAML); $tiles = new Config($path."tiles.yml", Config::YAML);
foreach($tiles->getAll() as $tile){ foreach($tiles->getAll() as $tile){
if(!isset($tile["id"])){ if(!isset($tile["id"])){
continue; continue;
} }
$this->levels[$name]->loadChunk($tile["x"] >> 4, $tile["z"] >> 4); $this->levels[$name]->loadChunk($tile["x"] >> 4, $tile["z"] >> 4);
$nbt = new NBT\Tag\Compound(false, array()); $nbt = new Compound(false, array());
foreach($tile as $index => $data){ foreach($tile as $index => $data){
switch($index){ switch($index){
case "Items": case "Items":
$tag = new NBT\Tag\Enum("Items", array()); $tag = new Enum("Items", array());
$tag->setTagType(NBT\TAG_Compound); $tag->setTagType(NBT\TAG_Compound);
foreach($data as $slot => $fields){ foreach($data as $slot => $fields){
$tag[(int) $slot] = new NBT\Tag\Compound(false, array( $tag[(int) $slot] = new Compound(false, array(
"Count" => new NBT\Tag\Byte("Count", $fields["Count"]), "Count" => new Byte("Count", $fields["Count"]),
"Slot" => new NBT\Tag\Short("Slot", $fields["Slot"]), "Slot" => new Short("Slot", $fields["Slot"]),
"Damage" => new NBT\Tag\Short("Damage", $fields["Damage"]), "Damage" => new Short("Damage", $fields["Damage"]),
"id" => new NBT\Tag\String("id", $fields["id"]) "id" => new String("id", $fields["id"])
)); ));
} }
$nbt["Items"] = $tag; $nbt["Items"] = $tag;
@ -214,7 +235,7 @@ class LevelAPI{
case "Text2": case "Text2":
case "Text3": case "Text3":
case "Text4": case "Text4":
$nbt[$index] = new NBT\Tag\String($index, $data); $nbt[$index] = new String($index, $data);
break; break;
case "x": case "x":
@ -222,25 +243,25 @@ class LevelAPI{
case "z": case "z":
case "pairx": case "pairx":
case "pairz": case "pairz":
$nbt[$index] = new NBT\Tag\Int($index, $data); $nbt[$index] = new Int($index, $data);
break; break;
case "BurnTime": case "BurnTime":
case "CookTime": case "CookTime":
case "MaxTime": case "MaxTime":
$nbt[$index] = new NBT\Tag\Short($index, $data); $nbt[$index] = new Short($index, $data);
break; break;
} }
} }
switch($tile["id"]){ switch($tile["id"]){
case Tile\Tile::FURNACE: case Tile::FURNACE:
new Tile\Furnace($this->levels[$name], $nbt); new Furnace($this->levels[$name], $nbt);
break; break;
case Tile\Tile::CHEST: case Tile::CHEST:
new Tile\Chest($this->levels[$name], $nbt); new Chest($this->levels[$name], $nbt);
break; break;
case Tile\Tile::SIGN: case Tile::SIGN:
new Tile\Sign($this->levels[$name], $nbt); new Sign($this->levels[$name], $nbt);
break; break;
} }
} }
@ -249,7 +270,7 @@ class LevelAPI{
} }
foreach($blockUpdates->getAll() as $bupdate){ foreach($blockUpdates->getAll() as $bupdate){
$this->server->api->block->scheduleBlockUpdate(new Level\Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]); $this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
} }
return true; return true;
} }

View File

@ -20,8 +20,44 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\Entity\RealHuman as RealHuman;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\NBT\Tag\Enum as Enum;
use PocketMine\NBT\Tag\Double as Double;
use PocketMine\NBT\Tag\String as String;
use PocketMine\NBT\Tag\Int as Int;
use PocketMine\NBT\Tag\Byte as Byte;
use PocketMine\NBT\Tag\Float as Float;
use PocketMine\NBT\Tag\Short as Short;
use PocketMine\Utils\Config as Config;
use PocketMine\Network\Protocol\DataPacket as DataPacket;
use PocketMine\Achievement as Achievement;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Server as Server;
use PocketMine\Network\RakNet\Packet as Packet;
use PocketMine\Network\RakNet\Info as Info;
use PocketMine\Level\Position as Position;
use PocketMine\PMF\LevelFormat as LevelFormat;
use PocketMine\Tile\Spawnable as Spawnable;
use PocketMine\Utils\TextFormat as TextFormat;
use PocketMine\BlockAPI as BlockAPI;
use PocketMine\Tile\Furnace as Furnace;
use PocketMine\Item\Item as Item;
use PocketMine\Recipes\Crafting as Crafting;
use PocketMine\Network\Protocol\Info as ProtocolInfo;
use PocketMine\Event\EventHandler as EventHandler;
use PocketMine\Event\Server\DataPacketReceiveEvent as DataPacketReceiveEvent;
use PocketMine\Event\Event as Event;
use PocketMine\Utils\Utils as Utils;
use PocketMine\Entity\Entity as Entity;
use PocketMine\Tile\Chest as Chest;
use PocketMine\Tile\Sign as Sign;
use PocketMine\NBT\NBT as NBT;
use PocketMine\Tile\Tile as Tile;
use PocketMine\Event\Server\DataPacketSendEvent as DataPacketSendEvent;
class Player extends Entity\RealHuman{ class Player extends RealHuman{
public static $list = array(); public static $list = array();
private $recoveryQueue = array(); private $recoveryQueue = array();
@ -113,44 +149,44 @@ class Player extends Entity\RealHuman{
$server = ServerAPI::request(); $server = ServerAPI::request();
$iname = strtolower($name); $iname = strtolower($name);
if(!file_exists(\PocketMine\DATA."players/".$iname.".dat")){ if(!file_exists(\PocketMine\DATA."players/".$iname.".dat")){
$nbt = new NBT\Tag\Compound(false, array( $nbt = new Compound(false, array(
"Pos" => new NBT\Tag\Enum("Pos", array( "Pos" => new Enum("Pos", array(
0 => new NBT\Tag\Double(0, $server->spawn->x), 0 => new Double(0, $server->spawn->x),
1 => new NBT\Tag\Double(1, $server->spawn->y), 1 => new Double(1, $server->spawn->y),
2 => new NBT\Tag\Double(2, $server->spawn->z) 2 => new Double(2, $server->spawn->z)
)), )),
"Level" => new NBT\Tag\String("Level", $server->spawn->level->getName()), "Level" => new String("Level", $server->spawn->level->getName()),
"SpawnLevel" => new NBT\Tag\String("SpawnLevel", $server->spawn->level->getName()), "SpawnLevel" => new String("SpawnLevel", $server->spawn->level->getName()),
"SpawnX" => new NBT\Tag\Int("SpawnX", (int) $server->spawn->x), "SpawnX" => new Int("SpawnX", (int) $server->spawn->x),
"SpawnY" => new NBT\Tag\Int("SpawnY", (int) $server->spawn->y), "SpawnY" => new Int("SpawnY", (int) $server->spawn->y),
"SpawnZ" => new NBT\Tag\Int("SpawnZ", (int) $server->spawn->z), "SpawnZ" => new Int("SpawnZ", (int) $server->spawn->z),
"SpawnForced" => new NBT\Tag\Byte("SpawnForced", 1), //TODO "SpawnForced" => new Byte("SpawnForced", 1), //TODO
"Inventory" => new NBT\Tag\Enum("Inventory", array()), "Inventory" => new Enum("Inventory", array()),
"Achievements" => new NBT\Tag\Compound("Achievements", array()), "Achievements" => new Compound("Achievements", array()),
"playerGameType" => new NBT\Tag\Int("playerGameType", $server->gamemode), "playerGameType" => new Int("playerGameType", $server->gamemode),
"Motion" => new NBT\Tag\Enum("Motion", array( "Motion" => new Enum("Motion", array(
0 => new NBT\Tag\Double(0, 0.0), 0 => new Double(0, 0.0),
1 => new NBT\Tag\Double(1, 0.0), 1 => new Double(1, 0.0),
2 => new NBT\Tag\Double(2, 0.0) 2 => new Double(2, 0.0)
)), )),
"Rotation" => new NBT\Tag\Enum("Rotation", array( "Rotation" => new Enum("Rotation", array(
0 => new NBT\Tag\Float(0, 0.0), 0 => new Float(0, 0.0),
1 => new NBT\Tag\Float(1, 0.0) 1 => new Float(1, 0.0)
)), )),
"FallDistance" => new NBT\Tag\Float("FallDistance", 0.0), "FallDistance" => new Float("FallDistance", 0.0),
"Fire" => new NBT\Tag\Short("Fire", 0), "Fire" => new Short("Fire", 0),
"Air" => new NBT\Tag\Short("Air", 0), "Air" => new Short("Air", 0),
"OnGround" => new NBT\Tag\Byte("OnGround", 1), "OnGround" => new Byte("OnGround", 1),
"Invulnerable" => new NBT\Tag\Byte("Invulnerable", 0), "Invulnerable" => new Byte("Invulnerable", 0),
"NameTag" => new NBT\Tag\String("NameTag", $name), "NameTag" => new String("NameTag", $name),
)); ));
$nbt->Pos->setTagType(NBT\TAG_Double); $nbt->Pos->setTagType(NBT\TAG_Double);
$nbt->Inventory->setTagType(NBT\TAG_Compound); $nbt->Inventory->setTagType(NBT\TAG_Compound);
$nbt->Motion->setTagType(NBT\TAG_Double); $nbt->Motion->setTagType(NBT\TAG_Double);
$nbt->Rotation->setTagType(NBT\TAG_Float); $nbt->Rotation->setTagType(NBT\TAG_Float);
if(file_exists(\PocketMine\DATA."players/".$iname.".yml")){ if(file_exists(\PocketMine\DATA."players/".$iname.".yml")){
$data = new Utils\Config(\PocketMine\DATA."players/".$iname.".yml", Utils\Config::YAML, array()); $data = new Config(\PocketMine\DATA."players/".$iname.".yml", Config::YAML, array());
$nbt->playerGameType = (int) $data->get("gamemode"); $nbt->playerGameType = (int) $data->get("gamemode");
$nbt->Level = $data->get("position")["level"]; $nbt->Level = $data->get("position")["level"];
$nbt->Pos[0] = $data->get("position")["x"]; $nbt->Pos[0] = $data->get("position")["x"];
@ -163,39 +199,39 @@ class Player extends Entity\RealHuman{
console("[NOTICE] Old Player data found for \"".$iname."\", upgrading profile"); console("[NOTICE] Old Player data found for \"".$iname."\", upgrading profile");
foreach($data->get("inventory") as $slot => $item){ foreach($data->get("inventory") as $slot => $item){
if(count($item) === 3){ if(count($item) === 3){
$nbt->Inventory[$slot + 9] = new NBT\Tag\Compound(false, array( $nbt->Inventory[$slot + 9] = new Compound(false, array(
"id" => new NBT\Tag\Short("id", $item[0]), "id" => new Short("id", $item[0]),
"Damage" => new NBT\Tag\Short("Damage", $item[1]), "Damage" => new Short("Damage", $item[1]),
"Count" => new NBT\Tag\Byte("Count", $item[2]), "Count" => new Byte("Count", $item[2]),
"Slot" => new NBT\Tag\Byte("Slot", $slot + 9), "Slot" => new Byte("Slot", $slot + 9),
"TrueSlot" => new NBT\Tag\Byte("TrueSlot", $slot + 9) "TrueSlot" => new Byte("TrueSlot", $slot + 9)
)); ));
} }
} }
foreach($data->get("hotbar") as $slot => $itemSlot){ foreach($data->get("hotbar") as $slot => $itemSlot){
if(isset($nbt->Inventory[$itemSlot + 9])){ if(isset($nbt->Inventory[$itemSlot + 9])){
$item = $nbt->Inventory[$itemSlot + 9]; $item = $nbt->Inventory[$itemSlot + 9];
$nbt->Inventory[$slot] = new NBT\Tag\Compound(false, array( $nbt->Inventory[$slot] = new Compound(false, array(
"id" => new NBT\Tag\Short("id", $item->id), "id" => new Short("id", $item->id),
"Damage" => new NBT\Tag\Short("Damage", $item->Damage), "Damage" => new Short("Damage", $item->Damage),
"Count" => new NBT\Tag\Byte("Count", $item->Count), "Count" => new Byte("Count", $item->Count),
"Slot" => new NBT\Tag\Byte("Slot", $slot), "Slot" => new Byte("Slot", $slot),
"TrueSlot" => new NBT\Tag\Byte("TrueSlot", $item->TrueSlot) "TrueSlot" => new Byte("TrueSlot", $item->TrueSlot)
)); ));
} }
} }
foreach($data->get("armor") as $slot => $item){ foreach($data->get("armor") as $slot => $item){
if(count($item) === 2){ if(count($item) === 2){
$nbt->Inventory[$slot + 100] = new NBT\Tag\Compound(false, array( $nbt->Inventory[$slot + 100] = new Compound(false, array(
"id" => new NBT\Tag\Short("id", $item[0]), "id" => new Short("id", $item[0]),
"Damage" => new NBT\Tag\Short("Damage", $item[1]), "Damage" => new Short("Damage", $item[1]),
"Count" => new NBT\Tag\Byte("Count", 1), "Count" => new Byte("Count", 1),
"Slot" => new NBT\Tag\Byte("Slot", $slot + 100) "Slot" => new Byte("Slot", $slot + 100)
)); ));
} }
} }
foreach($data->get("achievements") as $achievement => $status){ foreach($data->get("achievements") as $achievement => $status){
$nbt->Achievements[$achievement] = new NBT\Tag\Byte($achievement, $status == true ? 1:0); $nbt->Achievements[$achievement] = new Byte($achievement, $status == true ? 1:0);
} }
unlink(\PocketMine\DATA."players/".$iname.".yml"); unlink(\PocketMine\DATA."players/".$iname.".yml");
}else{ }else{
@ -214,14 +250,14 @@ class Player extends Entity\RealHuman{
return $nbt; return $nbt;
} }
public static function saveOffline($name, NBT\Tag\Compound $nbtTag){ public static function saveOffline($name, Compound $nbtTag){
ServerAPI::request()->handle("player.offline.save", $nbtTag); ServerAPI::request()->handle("player.offline.save", $nbtTag);
$nbt = new NBT(NBT\BIG_ENDIAN); $nbt = new NBT(NBT\BIG_ENDIAN);
$nbt->setData($nbtTag); $nbt->setData($nbtTag);
file_put_contents(\PocketMine\DATA."players/".strtolower($name).".dat", $nbt->write()); file_put_contents(\PocketMine\DATA."players/".strtolower($name).".dat", $nbt->write());
} }
public static function broadcastPacket(array $players, Network\Protocol\DataPacket $packet){ public static function broadcastPacket(array $players, DataPacket $packet){
foreach($players as $player){ foreach($players as $player){
$player->dataPacket(clone $packet); $player->dataPacket(clone $packet);
} }
@ -280,7 +316,7 @@ class Player extends Entity\RealHuman{
} }
public function isSleeping(){ public function isSleeping(){
return $this->sleeping instanceof Math\Vector3; return $this->sleeping instanceof Vector3;
} }
public function setChunkIndex($index, $flags){ public function setChunkIndex($index, $flags){
@ -314,7 +350,7 @@ class Player extends Entity\RealHuman{
$this->slot = 0; $this->slot = 0;
$this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1); $this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1);
$this->packetStats = array(0,0); $this->packetStats = array(0,0);
$this->buffer = new Network\RakNet\Packet(Network\RakNet\Info::DATA_PACKET_0); $this->buffer = new Packet(Info::DATA_PACKET_0);
$this->buffer->data = array(); $this->buffer->data = array();
$this->server->schedule(2, array($this, "handlePacketQueues"), array(), true); $this->server->schedule(2, array($this, "handlePacketQueues"), array(), true);
$this->server->schedule(20 * 60, array($this, "clearQueue"), array(), true); $this->server->schedule(20 * 60, array($this, "clearQueue"), array(), true);
@ -327,15 +363,15 @@ class Player extends Entity\RealHuman{
} }
/** /**
* @param Math\Vector3 $pos * @param Vector3 $pos
*/ */
public function setSpawn(Math\Vector3 $pos){ public function setSpawn(Vector3 $pos){
if(!($pos instanceof Level\Position)){ if(!($pos instanceof Position)){
$level = $this->level; $level = $this->level;
}else{ }else{
$level = $pos->level; $level = $pos->level;
} }
$this->spawnPosition = new Level\Position($pos->x, $pos->y, $pos->z, $level); $this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level);
$pk = new Network\Protocol\SetSpawnPositionPacket; $pk = new Network\Protocol\SetSpawnPositionPacket;
$pk->x = (int) $this->spawnPosition->x; $pk->x = (int) $this->spawnPosition->x;
$pk->y = (int) $this->spawnPosition->y; $pk->y = (int) $this->spawnPosition->y;
@ -359,7 +395,7 @@ class Player extends Entity\RealHuman{
for($X = $startX; $X <= $finalX; ++$X){ for($X = $startX; $X <= $finalX; ++$X){
for($Z = $startZ; $Z <= $finalZ; ++$Z){ for($Z = $startZ; $Z <= $finalZ; ++$Z){
$distance = abs($X - $centerX) + abs($Z - $centerZ); $distance = abs($X - $centerX) + abs($Z - $centerZ);
$index = PMF\LevelFormat::getIndex($X, $Z); $index = LevelFormat::getIndex($X, $Z);
if(!isset($this->chunksLoaded[$index]) or $this->chunksLoaded[$index] !== 0){ if(!isset($this->chunksLoaded[$index]) or $this->chunksLoaded[$index] !== 0){
$newOrder[$index] = $distance; $newOrder[$index] = $distance;
} }
@ -370,7 +406,7 @@ class Player extends Entity\RealHuman{
$this->chunksOrder = $newOrder; $this->chunksOrder = $newOrder;
$index = key($this->chunksOrder); $index = key($this->chunksOrder);
PMF\LevelFormat::getXZ($index, $X, $Z); LevelFormat::getXZ($index, $X, $Z);
$this->level->loadChunk($X, $Z); $this->level->loadChunk($X, $Z);
if(!$this->level->isChunkPopulated($X, $Z)){ if(!$this->level->isChunkPopulated($X, $Z)){
$this->level->loadChunk($X - 1, $Z); $this->level->loadChunk($X - 1, $Z);
@ -387,7 +423,7 @@ class Player extends Entity\RealHuman{
if($Yndex !== 0xff){ if($Yndex !== 0xff){
$X = null; $X = null;
$Z = null; $Z = null;
PMF\LevelFormat::getXZ($index, $X, $Z); LevelFormat::getXZ($index, $X, $Z);
foreach($this->level->getChunkEntities($X, $Z) as $entity){ foreach($this->level->getChunkEntities($X, $Z) as $entity){
if($entity !== $this){ if($entity !== $this){
$entity->despawnFrom($this); $entity->despawnFrom($this);
@ -429,7 +465,7 @@ class Player extends Entity\RealHuman{
} }
} }
foreach($this->level->getChunkTiles($this->lastChunk[0], $this->lastChunk[1]) as $tile){ foreach($this->level->getChunkTiles($this->lastChunk[0], $this->lastChunk[1]) as $tile){
if($tile instanceof Tile\Spawnable){ if($tile instanceof Spawnable){
$tile->spawnTo($this); $tile->spawnTo($this);
} }
} }
@ -446,7 +482,7 @@ class Player extends Entity\RealHuman{
} }
$X = null; $X = null;
$Z = null; $Z = null;
PMF\LevelFormat::getXZ($index, $X, $Z); LevelFormat::getXZ($index, $X, $Z);
if(!$this->level->isChunkPopulated($X, $Z)){ if(!$this->level->isChunkPopulated($X, $Z)){
$this->orderChunks(); $this->orderChunks();
if($this->chunkScheduled === 0 or $force === true){ if($this->chunkScheduled === 0 or $force === true){
@ -493,7 +529,7 @@ class Player extends Entity\RealHuman{
$this->namedtag->SpawnZ = (int) $this->spawnPosition->z; $this->namedtag->SpawnZ = (int) $this->spawnPosition->z;
foreach($this->achievements as $achievement => $status){ foreach($this->achievements as $achievement => $status){
$this->namedtag->Achievements[$achievement] = new NBT\Tag\Byte($achievement, $status === true ? 1:0); $this->namedtag->Achievements[$achievement] = new Byte($achievement, $status === true ? 1:0);
} }
$this->namedtag->playerGameType = $this->gamemode; $this->namedtag->playerGameType = $this->gamemode;
@ -528,14 +564,14 @@ class Player extends Entity\RealHuman{
$this->receiveQueue = array(); $this->receiveQueue = array();
$this->resendQueue = array(); $this->resendQueue = array();
$this->ackQueue = array(); $this->ackQueue = array();
if($this->username != "" and ($this->namedtag instanceof NBT\Tag\Compound)){ if($this->username != "" and ($this->namedtag instanceof Compound)){
Player::saveOffline($this->username, $this->namedtag); Player::saveOffline($this->username, $this->namedtag);
} }
if($msg === true and $this->username != "" and $this->spawned !== false){ if($msg === true and $this->username != "" and $this->spawned !== false){
$this->server->api->chat->broadcast($this->username." left the game"); $this->server->api->chat->broadcast($this->username." left the game");
} }
$this->spawned = false; $this->spawned = false;
console("[INFO] ".Utils\TextFormat::AQUA.$this->username.Utils\TextFormat::RESET."[/".$this->ip.":".$this->port."] logged out due to ".$reason); console("[INFO] ".TextFormat::AQUA.$this->username.TextFormat::RESET."[/".$this->ip.":".$this->port."] logged out due to ".$reason);
$this->windows = array(); $this->windows = array();
$this->armor = array(); $this->armor = array();
$this->inventory = array(); $this->inventory = array();
@ -549,20 +585,20 @@ class Player extends Entity\RealHuman{
} }
/** /**
* @param Math\Vector3 $pos * @param Vector3 $pos
* *
* @return boolean * @return boolean
*/ */
public function sleepOn(Math\Vector3 $pos){ public function sleepOn(Vector3 $pos){
foreach($this->level->getPlayers() as $p){ foreach($this->level->getPlayers() as $p){
if($p->sleeping instanceof Math\Vector3){ if($p->sleeping instanceof Vector3){
if($pos->distance($p->sleeping) <= 0.1){ if($pos->distance($p->sleeping) <= 0.1){
return false; return false;
} }
} }
} }
$this->sleeping = $pos; $this->sleeping = $pos;
$this->teleport(new Level\Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level)); $this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level));
/*if($this->entity instanceof Entity){ /*if($this->entity instanceof Entity){
$this->updateMetadata(); $this->updateMetadata();
}*/ }*/
@ -623,7 +659,7 @@ class Player extends Entity\RealHuman{
switch($event){ switch($event){
case "tile.update": case "tile.update":
if($data->level === $this->level){ if($data->level === $this->level){
if($data instanceof Tile\Furnace){ if($data instanceof Furnace){
foreach($this->windows as $id => $w){ foreach($this->windows as $id => $w){
if($w === $data){ if($w === $data){
$pk = new Network\Protocol\ContainerSetDataPacket; $pk = new Network\Protocol\ContainerSetDataPacket;
@ -758,7 +794,7 @@ class Player extends Entity\RealHuman{
if($m !== ""){ if($m !== ""){
$pk = new Network\Protocol\MessagePacket; $pk = new Network\Protocol\MessagePacket;
$pk->source = ($author instanceof Player) ? $author->username:$author; $pk->source = ($author instanceof Player) ? $author->username:$author;
$pk->message = Utils\TextFormat::clean($m); //Colors not implemented :( $pk->message = TextFormat::clean($m); //Colors not implemented :(
$this->dataPacket($pk); $this->dataPacket($pk);
} }
} }
@ -825,7 +861,7 @@ class Player extends Entity\RealHuman{
$craftItem = array(0, true, 0); $craftItem = array(0, true, 0);
unset($craft[-1]); unset($craft[-1]);
foreach($craft as $slot => $item){ foreach($craft as $slot => $item){
if($item instanceof Item\Item){ if($item instanceof Item){
$craftItem[0] = $item->getID(); $craftItem[0] = $item->getID();
if($item->getMetadata() !== $craftItem[1] and $craftItem[1] !== true){ if($item->getMetadata() !== $craftItem[1] and $craftItem[1] !== true){
$craftItem[1] = false; $craftItem[1] = false;
@ -849,10 +885,10 @@ class Player extends Entity\RealHuman{
} }
} }
$res = Recipes\Crafting::canCraft($craftItem, $recipeItems, $type); $res = Crafting::canCraft($craftItem, $recipeItems, $type);
if(!is_array($res) and $type === 1){ if(!is_array($res) and $type === 1){
$res2 = Recipes\Crafting::canCraft($craftItem, $recipeItems, 0); $res2 = Crafting::canCraft($craftItem, $recipeItems, 0);
if(is_array($res2)){ if(is_array($res2)){
$res = $res2; $res = $res2;
} }
@ -1023,7 +1059,7 @@ class Player extends Entity\RealHuman{
$safeCount = (int) (($this->MTU - 1) / 4); $safeCount = (int) (($this->MTU - 1) / 4);
$packetCnt = (int) ($ackCnt / $safeCount + 1); $packetCnt = (int) ($ackCnt / $safeCount + 1);
for($p = 0; $p < $packetCnt; ++$p){ for($p = 0; $p < $packetCnt; ++$p){
$pk = new Network\RakNet\Packet(Network\RakNet\Info::ACK); $pk = new Packet(Info::ACK);
$pk->packets = array(); $pk->packets = array();
for($c = 0; $c < $safeCount; ++$c){ for($c = 0; $c < $safeCount; ++$c){
if(($k = array_pop($this->ackQueue)) === null){ if(($k = array_pop($this->ackQueue)) === null){
@ -1041,7 +1077,7 @@ class Player extends Entity\RealHuman{
foreach($this->receiveQueue as $count => $packets){ foreach($this->receiveQueue as $count => $packets){
unset($this->receiveQueue[$count]); unset($this->receiveQueue[$count]);
foreach($packets as $p){ foreach($packets as $p){
if($p instanceof Network\Protocol\DataPacket and $p->hasSplit === false){ if($p instanceof DataPacket and $p->hasSplit === false){
if(isset($p->messageIndex) and $p->messageIndex !== false){ if(isset($p->messageIndex) and $p->messageIndex !== false){
if($p->messageIndex > $this->receiveCount){ if($p->messageIndex > $this->receiveCount){
$this->receiveCount = $p->messageIndex; $this->receiveCount = $p->messageIndex;
@ -1051,12 +1087,12 @@ class Player extends Entity\RealHuman{
} }
switch($p->pid()){ switch($p->pid()){
case 0x01: case 0x01:
case Network\Protocol\Info::PING_PACKET: case ProtocolInfo::PING_PACKET:
case Network\Protocol\Info::PONG_PACKET: case ProtocolInfo::PONG_PACKET:
case Network\Protocol\Info::MOVE_PLAYER_PACKET: case ProtocolInfo::MOVE_PLAYER_PACKET:
case Network\Protocol\Info::REQUEST_CHUNK_PACKET: case ProtocolInfo::REQUEST_CHUNK_PACKET:
case Network\Protocol\Info::ANIMATE_PACKET: case ProtocolInfo::ANIMATE_PACKET:
case Network\Protocol\Info::SET_HEALTH_PACKET: case ProtocolInfo::SET_HEALTH_PACKET:
continue; continue;
} }
} }
@ -1097,11 +1133,11 @@ class Player extends Entity\RealHuman{
} }
} }
public function handlePacket(Network\RakNet\Packet $packet){ public function handlePacket(Packet $packet){
if($this->connected === true){ if($this->connected === true){
$this->timeout = microtime(true) + 20; $this->timeout = microtime(true) + 20;
switch($packet->pid()){ switch($packet->pid()){
case Network\RakNet\Info::NACK: case Info::NACK:
foreach($packet->packets as $count){ foreach($packet->packets as $count){
if(isset($this->recoveryQueue[$count])){ if(isset($this->recoveryQueue[$count])){
$this->resendQueue[$count] =& $this->recoveryQueue[$count]; $this->resendQueue[$count] =& $this->recoveryQueue[$count];
@ -1112,7 +1148,7 @@ class Player extends Entity\RealHuman{
} }
break; break;
case Network\RakNet\Info::ACK: case Info::ACK:
foreach($packet->packets as $count){ foreach($packet->packets as $count){
if(isset($this->recoveryQueue[$count])){ if(isset($this->recoveryQueue[$count])){
$this->lag[] = microtime(true) - $this->recoveryQueue[$count]->sendtime; $this->lag[] = microtime(true) - $this->recoveryQueue[$count]->sendtime;
@ -1123,22 +1159,22 @@ class Player extends Entity\RealHuman{
} }
break; break;
case Network\RakNet\Info::DATA_PACKET_0: case Info::DATA_PACKET_0:
case Network\RakNet\Info::DATA_PACKET_1: case Info::DATA_PACKET_1:
case Network\RakNet\Info::DATA_PACKET_2: case Info::DATA_PACKET_2:
case Network\RakNet\Info::DATA_PACKET_3: case Info::DATA_PACKET_3:
case Network\RakNet\Info::DATA_PACKET_4: case Info::DATA_PACKET_4:
case Network\RakNet\Info::DATA_PACKET_5: case Info::DATA_PACKET_5:
case Network\RakNet\Info::DATA_PACKET_6: case Info::DATA_PACKET_6:
case Network\RakNet\Info::DATA_PACKET_7: case Info::DATA_PACKET_7:
case Network\RakNet\Info::DATA_PACKET_8: case Info::DATA_PACKET_8:
case Network\RakNet\Info::DATA_PACKET_9: case Info::DATA_PACKET_9:
case Network\RakNet\Info::DATA_PACKET_A: case Info::DATA_PACKET_A:
case Network\RakNet\Info::DATA_PACKET_B: case Info::DATA_PACKET_B:
case Network\RakNet\Info::DATA_PACKET_C: case Info::DATA_PACKET_C:
case Network\RakNet\Info::DATA_PACKET_D: case Info::DATA_PACKET_D:
case Network\RakNet\Info::DATA_PACKET_E: case Info::DATA_PACKET_E:
case Network\RakNet\Info::DATA_PACKET_F: case Info::DATA_PACKET_F:
$this->ackQueue[] = $packet->seqNumber; $this->ackQueue[] = $packet->seqNumber;
$this->receiveQueue[$packet->seqNumber] = array(); $this->receiveQueue[$packet->seqNumber] = array();
foreach($packet->data as $pk){ foreach($packet->data as $pk){
@ -1149,45 +1185,45 @@ class Player extends Entity\RealHuman{
} }
} }
public function handleDataPacket(Network\Protocol\DataPacket $packet){ public function handleDataPacket(DataPacket $packet){
if($this->connected === false){ if($this->connected === false){
return; return;
} }
if(Event\EventHandler::callEvent(new Event\Server\DataPacketReceiveEvent($this, $packet)) === Event\Event::DENY){ if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === Event::DENY){
return; return;
} }
switch($packet->pid()){ switch($packet->pid()){
case 0x01: case 0x01:
break; break;
case Network\Protocol\Info::PONG_PACKET: case ProtocolInfo::PONG_PACKET:
break; break;
case Network\Protocol\Info::PING_PACKET: case ProtocolInfo::PING_PACKET:
$pk = new Network\Protocol\PongPacket; $pk = new Network\Protocol\PongPacket;
$pk->ptime = $packet->time; $pk->ptime = $packet->time;
$pk->time = abs(microtime(true) * 1000); $pk->time = abs(microtime(true) * 1000);
$this->directDataPacket($pk); $this->directDataPacket($pk);
break; break;
case Network\Protocol\Info::DISCONNECT_PACKET: case ProtocolInfo::DISCONNECT_PACKET:
$this->close("client disconnect"); $this->close("client disconnect");
break; break;
case Network\Protocol\Info::CLIENT_CONNECT_PACKET: case ProtocolInfo::CLIENT_CONNECT_PACKET:
if($this->loggedIn === true){ if($this->loggedIn === true){
break; break;
} }
$pk = new Network\Protocol\ServerHandshakePacket; $pk = new Network\Protocol\ServerHandshakePacket;
$pk->port = $this->port; $pk->port = $this->port;
$pk->session = $packet->session; $pk->session = $packet->session;
$pk->session2 = Utils\Utils::readLong("\x00\x00\x00\x00\x04\x44\x0b\xa9"); $pk->session2 = Utils::readLong("\x00\x00\x00\x00\x04\x44\x0b\xa9");
$this->dataPacket($pk); $this->dataPacket($pk);
break; break;
case Network\Protocol\Info::CLIENT_HANDSHAKE_PACKET: case ProtocolInfo::CLIENT_HANDSHAKE_PACKET:
if($this->loggedIn === true){ if($this->loggedIn === true){
break; break;
} }
break; break;
case Network\Protocol\Info::LOGIN_PACKET: case ProtocolInfo::LOGIN_PACKET:
if($this->loggedIn === true){ if($this->loggedIn === true){
break; break;
} }
@ -1198,8 +1234,8 @@ class Player extends Entity\RealHuman{
$this->close("server is full!", false); $this->close("server is full!", false);
return; return;
} }
if($packet->protocol1 !== Network\Protocol\Info::CURRENT_PROTOCOL){ if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){
if($packet->protocol1 < Network\Protocol\Info::CURRENT_PROTOCOL){ if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){
$pk = new Network\Protocol\LoginStatusPacket; $pk = new Network\Protocol\LoginStatusPacket;
$pk->status = 1; $pk->status = 1;
$this->directDataPacket($pk); $this->directDataPacket($pk);
@ -1254,7 +1290,7 @@ class Player extends Entity\RealHuman{
return; return;
} }
if(!($nbt instanceof NBT\Tag\Compound)){ if(!($nbt instanceof Compound)){
$this->close("no config created", false); $this->close("no config created", false);
return; return;
} }
@ -1292,7 +1328,7 @@ class Player extends Entity\RealHuman{
if(($level = $this->server->api->level->get($this->namedtag->SpawnLevel)) !== false){ if(($level = $this->server->api->level->get($this->namedtag->SpawnLevel)) !== false){
$this->spawnPosition = new Level\Position($this->namedtag->SpawnX, $this->namedtag->SpawnY, $this->namedtag->SpawnZ, $level); $this->spawnPosition = new Position($this->namedtag->SpawnX, $this->namedtag->SpawnY, $this->namedtag->SpawnZ, $level);
$pk = new SetSpawnPositionPacket; $pk = new SetSpawnPositionPacket;
$pk->x = (int) $this->spawnPosition->x; $pk->x = (int) $this->spawnPosition->x;
@ -1310,9 +1346,9 @@ class Player extends Entity\RealHuman{
$this->evid[] = $this->server->event("tile.update", array($this, "eventHandler")); $this->evid[] = $this->server->event("tile.update", array($this, "eventHandler"));
$this->lastMeasure = microtime(true); $this->lastMeasure = microtime(true);
$this->server->schedule(50, array($this, "measureLag"), array(), true); $this->server->schedule(50, array($this, "measureLag"), array(), true);
console("[INFO] ".Utils\TextFormat::AQUA.$this->username.Utils\TextFormat::RESET."[/".$this->ip.":".$this->port."] logged in with entity id ".$this->id." at (".$this->level->getName().", ".round($this->x, 4).", ".round($this->y, 4).", ".round($this->z, 4).")"); console("[INFO] ".TextFormat::AQUA.$this->username.TextFormat::RESET."[/".$this->ip.":".$this->port."] logged in with entity id ".$this->id." at (".$this->level->getName().", ".round($this->x, 4).", ".round($this->y, 4).", ".round($this->z, 4).")");
break; break;
case Network\Protocol\Info::READY_PACKET: case ProtocolInfo::READY_PACKET:
if($this->loggedIn === false){ if($this->loggedIn === false){
break; break;
} }
@ -1337,7 +1373,7 @@ class Player extends Entity\RealHuman{
$pk->started = $this->level->stopTime == false; $pk->started = $this->level->stopTime == false;
$this->dataPacket($pk); $this->dataPacket($pk);
$pos = new Level\Position($this->x, $this->y, $this->z, $this->level); $pos = new Position($this->x, $this->y, $this->z, $this->level);
$pos = $this->level->getSafeSpawn($pos); $pos = $this->level->getSafeSpawn($pos);
$this->teleport($pos); $this->teleport($pos);
$this->sendBuffer(); $this->sendBuffer();
@ -1347,20 +1383,20 @@ class Player extends Entity\RealHuman{
break; break;
} }
break; break;
case Network\Protocol\Info::ROTATE_HEAD_PACKET: case ProtocolInfo::ROTATE_HEAD_PACKET:
if($this->spawned === false){ if($this->spawned === false){
break; break;
} }
$this->setRotation($packet->yaw, $this->pitch); $this->setRotation($packet->yaw, $this->pitch);
break; break;
case Network\Protocol\Info::MOVE_PLAYER_PACKET: case ProtocolInfo::MOVE_PLAYER_PACKET:
if($this->spawned === false){ if($this->spawned === false){
break; break;
} }
if($packet->messageIndex > $this->lastMovement){ if($packet->messageIndex > $this->lastMovement){
$this->lastMovement = $packet->messageIndex; $this->lastMovement = $packet->messageIndex;
$newPos = new Math\Vector3($packet->x, $packet->y, $packet->z); $newPos = new Vector3($packet->x, $packet->y, $packet->z);
if($this->forceMovement instanceof Math\Vector3){ if($this->forceMovement instanceof Vector3){
if($this->forceMovement->distance($newPos) <= 0.7){ if($this->forceMovement->distance($newPos) <= 0.7){
$this->forceMovement = false; $this->forceMovement = false;
}else{ }else{
@ -1369,7 +1405,7 @@ class Player extends Entity\RealHuman{
} }
/*$speed = $this->entity->getSpeedMeasure(); /*$speed = $this->entity->getSpeedMeasure();
if($this->blocked === true or ($this->server->api->getProperty("allow-flight") !== true and (($speed > 9 and ($this->gamemode & 0x01) === 0x00) or $speed > 20 or $this->entity->distance($newPos) > 7)) or $this->server->api->handle("player.move", $this->entity) === false){ if($this->blocked === true or ($this->server->api->getProperty("allow-flight") !== true and (($speed > 9 and ($this->gamemode & 0x01) === 0x00) or $speed > 20 or $this->entity->distance($newPos) > 7)) or $this->server->api->handle("player.move", $this->entity) === false){
if($this->lastCorrect instanceof Math\Vector3){ if($this->lastCorrect instanceof Vector3){
$this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false); $this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false);
} }
if($this->blocked !== true){ if($this->blocked !== true){
@ -1380,7 +1416,7 @@ class Player extends Entity\RealHuman{
//} //}
} }
break; break;
case Network\Protocol\Info::PLAYER_EQUIPMENT_PACKET: case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:
if($this->spawned === false){ if($this->spawned === false){
break; break;
} }
@ -1421,10 +1457,10 @@ class Player extends Entity\RealHuman{
//$this->entity->updateMetadata(); //$this->entity->updateMetadata();
} }
break; break;
case Network\Protocol\Info::REQUEST_CHUNK_PACKET: case ProtocolInfo::REQUEST_CHUNK_PACKET:
break; break;
case Network\Protocol\Info::USE_ITEM_PACKET: case ProtocolInfo::USE_ITEM_PACKET:
$blockVector = new Math\Vector3($packet->x, $packet->y, $packet->z); $blockVector = new Vector3($packet->x, $packet->y, $packet->z);
if(($this->spawned === false or $this->blocked === true) and $packet->face >= 0 and $packet->face <= 5){ if(($this->spawned === false or $this->blocked === true) and $packet->face >= 0 and $packet->face <= 5){
$target = $this->level->getBlock($blockVector); $target = $this->level->getBlock($blockVector);
@ -1508,7 +1544,7 @@ class Player extends Entity\RealHuman{
//$this->updateMetadata(); //$this->updateMetadata();
} }
break; break;
/*case Network\Protocol\Info::PLAYER_ACTION_PACKET: /*case ProtocolInfo::PLAYER_ACTION_PACKET:
if($this->spawned === false or $this->blocked === true){ if($this->spawned === false or $this->blocked === true){
break; break;
} }
@ -1584,8 +1620,8 @@ class Player extends Entity\RealHuman{
$this->stopSleep(); $this->stopSleep();
} }
break;*/ break;*/
case Network\Protocol\Info::REMOVE_BLOCK_PACKET: case ProtocolInfo::REMOVE_BLOCK_PACKET:
$blockVector = new Math\Vector3($packet->x, $packet->y, $packet->z); $blockVector = new Vector3($packet->x, $packet->y, $packet->z);
if($this->spawned === false or $this->blocked === true or $this->distance($blockVector) > 8){ if($this->spawned === false or $this->blocked === true or $this->distance($blockVector) > 8){
$target = $this->level->getBlock($blockVector); $target = $this->level->getBlock($blockVector);
@ -1602,7 +1638,7 @@ class Player extends Entity\RealHuman{
$this->toCraft = array(); $this->toCraft = array();
$this->server->api->block->playerBlockBreak($this, $blockVector); $this->server->api->block->playerBlockBreak($this, $blockVector);
break; break;
case Network\Protocol\Info::PLAYER_ARMOR_EQUIPMENT_PACKET: case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET:
if($this->spawned === false or $this->blocked === true){ if($this->spawned === false or $this->blocked === true){
break; break;
} }
@ -1650,7 +1686,7 @@ class Player extends Entity\RealHuman{
//$this->entity->updateMetadata(); //$this->entity->updateMetadata();
} }
break; break;
/*case Network\Protocol\Info::INTERACT_PACKET: /*case ProtocolInfo::INTERACT_PACKET:
if($this->spawned === false){ if($this->spawned === false){
break; break;
} }
@ -1661,8 +1697,8 @@ class Player extends Entity\RealHuman{
$data["action"] = $packet->action; $data["action"] = $packet->action;
$this->craftingItems = array(); $this->craftingItems = array();
$this->toCraft = array(); $this->toCraft = array();
$target = Entity\Entity::get($packet->target); $target = Entity::get($packet->target);
if($target instanceof Entity\Entity and $this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity\Entity) and $this->entity->distance($target) <= 8){ if($target instanceof Entity and $this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity) and $this->entity->distance($target) <= 8){
$data["targetentity"] = $target; $data["targetentity"] = $target;
$data["entity"] = $this->entity; $data["entity"] = $this->entity;
if($target instanceof RealHuman and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($target->player->gamemode & 0x01) === 0x01)){ if($target instanceof RealHuman and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($target->player->gamemode & 0x01) === 0x01)){
@ -1739,14 +1775,14 @@ class Player extends Entity\RealHuman{
} }
break;*/ break;*/
/*case Network\Protocol\Info::ANIMATE_PACKET: /*case ProtocolInfo::ANIMATE_PACKET:
if($this->spawned === false){ if($this->spawned === false){
break; break;
} }
$packet->eid = $this->id; $packet->eid = $this->id;
$this->server->api->dhandle("entity.animate", array("eid" => $packet->eid, "entity" => $this->entity, "action" => $packet->action)); $this->server->api->dhandle("entity.animate", array("eid" => $packet->eid, "entity" => $this->entity, "action" => $packet->action));
break;*/ break;*/
case Network\Protocol\Info::RESPAWN_PACKET: case ProtocolInfo::RESPAWN_PACKET:
if($this->spawned === false){ if($this->spawned === false){
break; break;
} }
@ -1765,9 +1801,9 @@ class Player extends Entity\RealHuman{
$this->blocked = false; $this->blocked = false;
$this->server->handle("player.respawn", $this); $this->server->handle("player.respawn", $this);
break; break;
case Network\Protocol\Info::SET_HEALTH_PACKET: //Not used case ProtocolInfo::SET_HEALTH_PACKET: //Not used
break; break;
/*case Network\Protocol\Info::ENTITY_EVENT_PACKET: /*case ProtocolInfo::ENTITY_EVENT_PACKET:
if($this->spawned === false or $this->blocked === true){ if($this->spawned === false or $this->blocked === true){
break; break;
} }
@ -1821,7 +1857,7 @@ class Player extends Entity\RealHuman{
break; break;
} }
break;*/ break;*/
/*case Network\Protocol\Info::DROP_ITEM_PACKET: /*case ProtocolInfo::DROP_ITEM_PACKET:
if($this->spawned === false or $this->blocked === true){ if($this->spawned === false or $this->blocked === true){
break; break;
} }
@ -1843,13 +1879,13 @@ class Player extends Entity\RealHuman{
$this->entity->updateMetadata(); $this->entity->updateMetadata();
} }
break;*/ break;*/
case Network\Protocol\Info::MESSAGE_PACKET: case ProtocolInfo::MESSAGE_PACKET:
if($this->spawned === false){ if($this->spawned === false){
break; break;
} }
$this->craftingItems = array(); $this->craftingItems = array();
$this->toCraft = array(); $this->toCraft = array();
$packet->message = Utils\TextFormat::clean($packet->message); $packet->message = TextFormat::clean($packet->message);
if(trim($packet->message) != "" and strlen($packet->message) <= 255){ if(trim($packet->message) != "" and strlen($packet->message) <= 255){
$message = $packet->message; $message = $packet->message;
if($message{0} === "/"){ //Command if($message{0} === "/"){ //Command
@ -1866,7 +1902,7 @@ class Player extends Entity\RealHuman{
} }
} }
break; break;
case Network\Protocol\Info::CONTAINER_CLOSE_PACKET: case ProtocolInfo::CONTAINER_CLOSE_PACKET:
if($this->spawned === false){ if($this->spawned === false){
break; break;
} }
@ -1899,7 +1935,7 @@ class Player extends Entity\RealHuman{
$pk->windowid = $packet->windowid; $pk->windowid = $packet->windowid;
$this->dataPacket($pk); $this->dataPacket($pk);
break; break;
case Network\Protocol\Info::CONTAINER_SET_SLOT_PACKET: case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if($this->spawned === false or $this->blocked === true){ if($this->spawned === false or $this->blocked === true){
break; break;
} }
@ -1961,14 +1997,14 @@ class Player extends Entity\RealHuman{
if(is_array($this->windows[$packet->windowid])){ if(is_array($this->windows[$packet->windowid])){
$tiles = $this->windows[$packet->windowid]; $tiles = $this->windows[$packet->windowid];
if($packet->slot >= 0 and $packet->slot < Tile\Chest::SLOTS){ if($packet->slot >= 0 and $packet->slot < Chest::SLOTS){
$tile = $tiles[0]; $tile = $tiles[0];
$slotn = $packet->slot; $slotn = $packet->slot;
$offset = 0; $offset = 0;
}elseif($packet->slot >= Tile\Chest::SLOTS and $packet->slot <= (Tile\Chest::SLOTS << 1)){ }elseif($packet->slot >= Chest::SLOTS and $packet->slot <= (Chest::SLOTS << 1)){
$tile = $tiles[1]; $tile = $tiles[1];
$slotn = $packet->slot - Tile\Chest::SLOTS; $slotn = $packet->slot - Chest::SLOTS;
$offset = Tile\Chest::SLOTS; $offset = Chest::SLOTS;
}else{ }else{
break; break;
} }
@ -2015,13 +2051,13 @@ class Player extends Entity\RealHuman{
}else{ }else{
$tile = $this->windows[$packet->windowid]; $tile = $this->windows[$packet->windowid];
if( if(
!($tile instanceof Tile\Chest or $tile instanceof Tile\Furnace) !($tile instanceof Chest or $tile instanceof Furnace)
or $packet->slot < 0 or $packet->slot < 0
or ( or (
$tile instanceof Tile\Chest $tile instanceof Chest
and $packet->slot >= Tile\Chest::SLOTS and $packet->slot >= Chest::SLOTS
) or ( ) or (
$tile instanceof Tile\Furnace and $packet->slot >= Tile\Furnace::SLOTS $tile instanceof Furnace and $packet->slot >= Furnace::SLOTS
) )
){ ){
break; break;
@ -2044,7 +2080,7 @@ class Player extends Entity\RealHuman{
break; break;
} }
if($tile instanceof Tile\Furnace and $packet->slot == 2){ if($tile instanceof Furnace and $packet->slot == 2){
switch($slot->getID()){ switch($slot->getID()){
case IRON_INGOT: case IRON_INGOT:
$this->grantAchievement("acquireIron"); $this->grantAchievement("acquireIron");
@ -2075,25 +2111,25 @@ class Player extends Entity\RealHuman{
$tile->setSlot($packet->slot, $item); $tile->setSlot($packet->slot, $item);
} }
break; break;
case Network\Protocol\Info::SEND_INVENTORY_PACKET: //TODO, Mojang, enable this ´^_^` case ProtocolInfo::SEND_INVENTORY_PACKET: //TODO, Mojang, enable this ´^_^`
if($this->spawned === false){ if($this->spawned === false){
break; break;
} }
break; break;
case Network\Protocol\Info::ENTITY_DATA_PACKET: case ProtocolInfo::ENTITY_DATA_PACKET:
if($this->spawned === false or $this->blocked === true){ if($this->spawned === false or $this->blocked === true){
break; break;
} }
$this->craftingItems = array(); $this->craftingItems = array();
$this->toCraft = array(); $this->toCraft = array();
$t = $this->level->getTile(new Math\Vector3($packet->x, $packet->y, $packet->z)); $t = $this->level->getTile(new Vector3($packet->x, $packet->y, $packet->z));
if($t instanceof Tile\Sign){ if($t instanceof Sign){
if($t->namedtag->creator !== $this->username){ if($t->namedtag->creator !== $this->username){
$t->spawnTo($this); $t->spawnTo($this);
}else{ }else{
$nbt = new NBT\NBT(NBT\LITTLE_ENDIAN); $nbt = new NBT(NBT\LITTLE_ENDIAN);
$nbt->read($packet->namedtag); $nbt->read($packet->namedtag);
if($nbt->id !== Tile\Tile::SIGN){ if($nbt->id !== Tile::SIGN){
$t->spawnTo($this); $t->spawnTo($this);
}else{ }else{
$t->setText($nbt->Text1, $nbt->Text2, $nbt->Text3, $nbt->Text4); $t->setText($nbt->Text1, $nbt->Text2, $nbt->Text3, $nbt->Text4);
@ -2123,7 +2159,7 @@ class Player extends Entity\RealHuman{
$this->dataPacket($pk); $this->dataPacket($pk);
} }
public function send(Network\RakNet\Packet $packet){ public function send(Packet $packet){
if($this->connected === true){ if($this->connected === true){
$packet->ip = $this->ip; $packet->ip = $this->ip;
$packet->port = $this->port; $packet->port = $this->port;
@ -2133,12 +2169,12 @@ class Player extends Entity\RealHuman{
public function sendBuffer(){ public function sendBuffer(){
if($this->connected === true){ if($this->connected === true){
if($this->bufferLen > 0 and $this->buffer instanceof Network\RakNet\Packet){ if($this->bufferLen > 0 and $this->buffer instanceof Packet){
$this->buffer->seqNumber = $this->counter[0]++; $this->buffer->seqNumber = $this->counter[0]++;
$this->send($this->buffer); $this->send($this->buffer);
} }
$this->bufferLen = 0; $this->bufferLen = 0;
$this->buffer = new Network\RakNet\Packet(Network\RakNet\Info::DATA_PACKET_0); $this->buffer = new Packet(Info::DATA_PACKET_0);
$this->buffer->data = array(); $this->buffer->data = array();
$this->nextBuffer = microtime(true) + 0.1; $this->nextBuffer = microtime(true) + 0.1;
} }
@ -2170,7 +2206,7 @@ class Player extends Entity\RealHuman{
$pk->buffer = $buf; $pk->buffer = $buf;
$pk->messageIndex = $this->counter[3]++; $pk->messageIndex = $this->counter[3]++;
$rk = new Network\RakNet\Packet(Network\RakNet\Info::DATA_PACKET_0); $rk = new Packet(Info::DATA_PACKET_0);
$rk->data[] = $pk; $rk->data[] = $pk;
$rk->seqNumber = $count; $rk->seqNumber = $count;
$rk->sendtime = $sendtime; $rk->sendtime = $sendtime;
@ -2185,11 +2221,11 @@ class Player extends Entity\RealHuman{
return false; return false;
} }
if(Event\EventHandler::callEvent(new Event\Server\DataPacketSendEvent($this, $packet)) === Event\Event::DENY){ if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === Event::DENY){
return array(); return array();
} }
$packet->encode(); $packet->encode();
$pk = new Network\RakNet\Packet(Network\RakNet\Info::DATA_PACKET_0); $pk = new Packet(Info::DATA_PACKET_0);
$pk->data[] = $packet; $pk->data[] = $packet;
$pk->seqNumber = $this->counter[0]++; $pk->seqNumber = $this->counter[0]++;
$pk->sendtime = microtime(true); $pk->sendtime = microtime(true);
@ -2212,7 +2248,7 @@ class Player extends Entity\RealHuman{
return false; return false;
} }
if(Event\EventHandler::callEvent(new Event\Server\DataPacketSendEvent($this, $packet)) === Event\Event::DENY){ if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === Event::DENY){
return; return;
} }

View File

@ -20,6 +20,12 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Entity\Entity as Entity;
use PocketMine\Player as Player;
use PocketMine\Level\Level as Level;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Level\Position as Position;
class PlayerAPI{ class PlayerAPI{
private $server; private $server;
@ -52,7 +58,7 @@ class PlayerAPI{
$result = $this->server->preparedSQL->selectPlayersToHeal->execute(); $result = $this->server->preparedSQL->selectPlayersToHeal->execute();
if($result !== false){ if($result !== false){
while(($player = $result->fetchArray()) !== false){ while(($player = $result->fetchArray()) !== false){
if(($player = Entity\Entity::get($player["EID"])) !== false){ if(($player = Entity::get($player["EID"])) !== false){
if($player->getHealth() <= 0){ if($player->getHealth() <= 0){
continue; continue;
} }
@ -65,8 +71,8 @@ class PlayerAPI{
break; break;
case "player.death": case "player.death":
if(is_numeric($data["cause"])){ if(is_numeric($data["cause"])){
$e = Entity\Entity::get($data["cause"]); $e = Entity::get($data["cause"]);
if($e instanceof Entity\Entity){ if($e instanceof Entity){
switch($e->class){ switch($e->class){
case ENTITY_PLAYER: case ENTITY_PLAYER:
$message = " was killed by ".$e->name; $message = " was killed by ".$e->name;
@ -139,19 +145,19 @@ class PlayerAPI{
$target = $issuer; $target = $issuer;
} }
if(!($target instanceof Player) and !($target instanceof Level\Level)){ if(!($target instanceof Player) and !($target instanceof Level)){
$output .= "That player cannot be found.\n"; $output .= "That player cannot be found.\n";
break; break;
} }
if(count($params) === 3){ if(count($params) === 3){
if($target instanceof Level){ if($target instanceof Level){
$spawn = new Math\Vector3(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params))); $spawn = new Vector3(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)));
}else{ }else{
$spawn = new Level\Position(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)), $issuer->level); $spawn = new Position(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)), $issuer->level);
} }
}else{ }else{
$spawn = new Level\Position($issuer->entity->x, $issuer->entity->y, $issuer->entity->z, $issuer->entity->level); $spawn = new Position($issuer->entity->x, $issuer->entity->y, $issuer->entity->z, $issuer->entity->level);
} }
$target->setSpawn($spawn); $target->setSpawn($spawn);
@ -323,7 +329,7 @@ class PlayerAPI{
$x = $x{0} === "~" ? $player->entity->x + floatval(substr($x, 1)):floatval($x); $x = $x{0} === "~" ? $player->entity->x + floatval(substr($x, 1)):floatval($x);
$y = $y{0} === "~" ? $player->entity->y + floatval(substr($y, 1)):floatval($y); $y = $y{0} === "~" ? $player->entity->y + floatval(substr($y, 1)):floatval($y);
$z = $z{0} === "~" ? $player->entity->z + floatval(substr($z, 1)):floatval($z); $z = $z{0} === "~" ? $player->entity->z + floatval(substr($z, 1)):floatval($z);
$player->teleport(new Math\Vector3($x, $y, $z)); $player->teleport(new Vector3($x, $y, $z));
return true; return true;
} }
return false; return false;

View File

@ -20,6 +20,12 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Utils\Utils as Utils;
use PocketMine\Network\Protocol\Info as Info;
use PocketMine\PMF\Plugin as PMFPlugin;
use PocketMine\Utils\TextFormat as TextFormat;
use PocketMine\Utils\Config as Config;
class PluginAPI extends \stdClass{ class PluginAPI extends \stdClass{
private $server; private $server;
@ -27,7 +33,7 @@ class PluginAPI extends \stdClass{
private $randomNonce; private $randomNonce;
public function __construct(){ public function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->randomNonce = Utils\Utils::getRandomBytes(16, false); $this->randomNonce = Utils::getRandomBytes(16, false);
$this->server->api->console->register("plugins", "", array($this, "commandHandler")); $this->server->api->console->register("plugins", "", array($this, "commandHandler"));
$this->server->api->console->register("version", "", array($this, "commandHandler")); $this->server->api->console->register("version", "", array($this, "commandHandler"));
$this->server->api->ban->cmdWhitelist("version"); $this->server->api->ban->cmdWhitelist("version");
@ -44,7 +50,7 @@ class PluginAPI extends \stdClass{
$output = $output === "Plugins: " ? "No plugins installed.\n" : substr($output, 0, -2)."\n"; $output = $output === "Plugins: " ? "No plugins installed.\n" : substr($output, 0, -2)."\n";
break; break;
case "version": case "version":
$output = "PocketMine-MP ".VERSION."".CODENAME."」 API #".API_VERSION." for Minecraft: PE ".MINECRAFT_VERSION." protocol #".Network\Protocol\Info::CURRENT_PROTOCOL; $output = "PocketMine-MP ".VERSION."".CODENAME."」 API #".API_VERSION." for Minecraft: PE ".MINECRAFT_VERSION." protocol #".Info::CURRENT_PROTOCOL;
if(GIT_COMMIT !== str_repeat("00", 20)){ if(GIT_COMMIT !== str_repeat("00", 20)){
$output .= " (git ".GIT_COMMIT.")"; $output .= " (git ".GIT_COMMIT.")";
} }
@ -79,7 +85,7 @@ class PluginAPI extends \stdClass{
return false; return false;
} }
if(strtolower(substr($file, -3)) === "pmf"){ if(strtolower(substr($file, -3)) === "pmf"){
$pmf = new PMF\Plugin($file); $pmf = new PMFPlugin($file);
$info = $pmf->getPluginInfo(); $info = $pmf->getPluginInfo();
}else{ }else{
$content = file_get_contents($file); $content = file_get_contents($file);
@ -113,7 +119,7 @@ class PluginAPI extends \stdClass{
console("[ERROR] Failed parsing of ".basename($file)); console("[ERROR] Failed parsing of ".basename($file));
return false; return false;
} }
console("[INFO] Loading plugin \"".Utils\TextFormat::GREEN.$info["name"].Utils\TextFormat::RESET."\" ".Utils\TextFormat::AQUA.$info["version"].Utils\TextFormat::RESET." by ".Utils\TextFormat::AQUA.$info["author"].Utils\TextFormat::RESET); console("[INFO] Loading plugin \"".TextFormat::GREEN.$info["name"].TextFormat::RESET."\" ".TextFormat::AQUA.$info["version"].TextFormat::RESET." by ".TextFormat::AQUA.$info["author"].TextFormat::RESET);
if($info["class"] !== "none" and class_exists($info["class"])){ if($info["class"] !== "none" and class_exists($info["class"])){
console("[ERROR] Failed loading plugin: class already exists"); console("[ERROR] Failed loading plugin: class already exists");
return false; return false;
@ -193,7 +199,7 @@ class PluginAPI extends \stdClass{
return false; return false;
} }
$path = $this->configPath($plugin); $path = $this->configPath($plugin);
$cnf = new Utils\Config($path."config.yml", Utils\Config::YAML, $default); $cnf = new Config($path."config.yml", Config::YAML, $default);
$cnf->save(); $cnf->save();
return $path; return $path;
} }

View File

@ -20,6 +20,16 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\Utils\VersionString as VersionString;
use PocketMine\Utils\Utils as Utils;
use PocketMine\Network\Handler as Handler;
use PocketMine\Player as Player;
use PocketMine\Entity\Entity as Entity;
use PocketMine\Deprecation as Deprecation;
use PocketMine\Network\Protocol\Info as Info;
use PocketMine\Network\Packet as Packet;
use PocketMine\Network\RakNet\Info as RakNetInfo;
use PocketMine\Network\RakNet\Packet as RakNetPacket;
class Server{ class Server{
public $tCnt; public $tCnt;
@ -32,14 +42,14 @@ class Server{
public $api; public $api;
private function load(){ private function load(){
$this->version = new Utils\VersionString(); $this->version = new VersionString();
if(defined("DEBUG") and DEBUG >= 0){ if(defined("DEBUG") and DEBUG >= 0){
@cli_set_process_title("PocketMine-MP ".MAJOR_VERSION); @cli_set_process_title("PocketMine-MP ".MAJOR_VERSION);
} }
console("[INFO] Starting Minecraft PE server on ".($this->serverip === "0.0.0.0" ? "*":$this->serverip).":".$this->port); console("[INFO] Starting Minecraft PE server on ".($this->serverip === "0.0.0.0" ? "*":$this->serverip).":".$this->port);
define("BOOTUP_RANDOM", Utils\Utils::getRandomBytes(16)); define("BOOTUP_RANDOM", Utils::getRandomBytes(16));
$this->serverID = $this->serverID === false ? Utils\Utils::readLong(substr(Utils\Utils::getUniqueID(true, $this->serverip . $this->port), 8)):$this->serverID; $this->serverID = $this->serverID === false ? Utils::readLong(substr(Utils::getUniqueID(true, $this->serverip . $this->port), 8)):$this->serverID;
$this->seed = $this->seed === false ? Utils\Utils::readInt(Utils\Utils::getRandomBytes(4, false)):$this->seed; $this->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):$this->seed;
$this->startDatabase(); $this->startDatabase();
$this->api = false; $this->api = false;
$this->tCnt = 1; $this->tCnt = 1;
@ -62,7 +72,7 @@ class Server{
$this->whitelist = false; $this->whitelist = false;
$this->tickMeasure = array_fill(0, 40, 0); $this->tickMeasure = array_fill(0, 40, 0);
$this->setType("normal"); $this->setType("normal");
$this->interface = new Network\Handler("255.255.255.255", $this->port, $this->serverip); $this->interface = new Handler("255.255.255.255", $this->port, $this->serverip);
$this->stop = false; $this->stop = false;
$this->ticks = 0; $this->ticks = 0;
if(!defined("NO_THREADS")){ if(!defined("NO_THREADS")){
@ -154,7 +164,7 @@ class Server{
$info["tps"] = $this->getTPS(); $info["tps"] = $this->getTPS();
$info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2)."MB"; $info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2)."MB";
$info["memory_peak_usage"] = round((memory_get_peak_usage() / 1024) / 1024, 2)."MB"; $info["memory_peak_usage"] = round((memory_get_peak_usage() / 1024) / 1024, 2)."MB";
$info["entities"] = count(Entity\Entity::$list); $info["entities"] = count(Entity::$list);
$info["players"] = count(Player::$list); $info["players"] = count(Player::$list);
$info["events"] = count($this->eventsID); $info["events"] = count($this->eventsID);
$info["handlers"] = $this->query("SELECT count(ID) as count FROM handlers;", true); $info["handlers"] = $this->query("SELECT count(ID) as count FROM handlers;", true);
@ -213,25 +223,25 @@ class Server{
$type = (int) $type; $type = (int) $type;
switch($type){ switch($type){
case ASYNC_CURL_GET: case ASYNC_CURL_GET:
$d .= Utils\Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils\Utils::writeShort($data["timeout"]) : Utils\Utils::writeShort(10)); $d .= Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
break; break;
case ASYNC_CURL_POST: case ASYNC_CURL_POST:
$d .= Utils\Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils\Utils::writeShort($data["timeout"]) : Utils\Utils::writeShort(10)); $d .= Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
$d .= Utils\Utils::writeShort(count($data["data"])); $d .= Utils::writeShort(count($data["data"]));
foreach($data["data"] as $key => $value){ foreach($data["data"] as $key => $value){
$d .= Utils\Utils::writeShort(strlen($key)).$key . Utils\Utils::writeInt(strlen($value)).$value; $d .= Utils::writeShort(strlen($key)).$key . Utils::writeInt(strlen($value)).$value;
} }
break; break;
case ASYNC_FUNCTION: case ASYNC_FUNCTION:
$params = serialize($data["arguments"]); $params = serialize($data["arguments"]);
$d .= Utils\Utils::writeShort(strlen($data["function"])).$data["function"] . Utils\Utils::writeInt(strlen($params)) . $params; $d .= Utils::writeShort(strlen($data["function"])).$data["function"] . Utils::writeInt(strlen($params)) . $params;
break; break;
default: default:
return false; return false;
} }
$ID = $this->asyncID++; $ID = $this->asyncID++;
$this->async[$ID] = $callable; $this->async[$ID] = $callable;
$this->asyncThread->input .= Utils\Utils::writeInt($ID).Utils\Utils::writeShort($type).$d; $this->asyncThread->input .= Utils::writeInt($ID).Utils::writeShort($type).$d;
return $ID; return $ID;
} }
@ -241,21 +251,21 @@ class Server{
} }
if(isset($this->asyncThread->output{5})){ if(isset($this->asyncThread->output{5})){
$offset = 0; $offset = 0;
$ID = Utils\Utils::readInt(substr($this->asyncThread->output, $offset, 4)); $ID = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
$offset += 4; $offset += 4;
$type = Utils\Utils::readShort(substr($this->asyncThread->output, $offset, 2)); $type = Utils::readShort(substr($this->asyncThread->output, $offset, 2));
$offset += 2; $offset += 2;
$data = array(); $data = array();
switch($type){ switch($type){
case ASYNC_CURL_GET: case ASYNC_CURL_GET:
case ASYNC_CURL_POST: case ASYNC_CURL_POST:
$len = Utils\Utils::readInt(substr($this->asyncThread->output, $offset, 4)); $len = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
$offset += 4; $offset += 4;
$data["result"] = substr($this->asyncThread->output, $offset, $len); $data["result"] = substr($this->asyncThread->output, $offset, $len);
$offset += $len; $offset += $len;
break; break;
case ASYNC_FUNCTION: case ASYNC_FUNCTION:
$len = Utils\Utils::readInt(substr($this->asyncThread->output, $offset, 4)); $len = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
$offset += 4; $offset += 4;
$data["result"] = unserialize(substr($this->asyncThread->output, $offset, $len)); $data["result"] = unserialize(substr($this->asyncThread->output, $offset, $len));
$offset += $len; $offset += $len;
@ -426,13 +436,13 @@ class Server{
$dump .= "$line\r\n"; $dump .= "$line\r\n";
} }
$dump .= "\r\n\r\n"; $dump .= "\r\n\r\n";
$version = new Utils\VersionString(); $version = new VersionString();
$dump .= "PocketMine-MP version: ".$version." #".$version->getNumber()." [Protocol ".Network\Protocol\Info::CURRENT_PROTOCOL."; API ".API_VERSION."]\r\n"; $dump .= "PocketMine-MP version: ".$version." #".$version->getNumber()." [Protocol ".Info::CURRENT_PROTOCOL."; API ".API_VERSION."]\r\n";
$dump .= "Git commit: ".GIT_COMMIT."\r\n"; $dump .= "Git commit: ".GIT_COMMIT."\r\n";
$dump .= "uname -a: ".php_uname("a")."\r\n"; $dump .= "uname -a: ".php_uname("a")."\r\n";
$dump .= "PHP Version: " .phpversion()."\r\n"; $dump .= "PHP Version: " .phpversion()."\r\n";
$dump .= "Zend version: ".zend_version()."\r\n"; $dump .= "Zend version: ".zend_version()."\r\n";
$dump .= "OS : " .PHP_OS.", ".Utils\Utils::getOS()."\r\n"; $dump .= "OS : " .PHP_OS.", ".Utils::getOS()."\r\n";
$dump .= "Debug Info: ".var_export($this->debugInfo(false), true)."\r\n\r\n\r\n"; $dump .= "Debug Info: ".var_export($this->debugInfo(false), true)."\r\n\r\n\r\n";
global $arguments; global $arguments;
$dump .= "Parameters: ".var_export($arguments, true)."\r\n\r\n\r\n"; $dump .= "Parameters: ".var_export($arguments, true)."\r\n\r\n\r\n";
@ -484,17 +494,17 @@ class Server{
//return $ip . ":" . $port; //return $ip . ":" . $port;
} }
public function packetHandler(Network\Packet $packet){ public function packetHandler(Packet $packet){
$data =& $packet; $data =& $packet;
$CID = Server::clientID($packet->ip, $packet->port); $CID = Server::clientID($packet->ip, $packet->port);
if(isset(Player::$list[$CID])){ if(isset(Player::$list[$CID])){
Player::$list[$CID]->handlePacket($packet); Player::$list[$CID]->handlePacket($packet);
}else{ }else{
switch($packet->pid()){ switch($packet->pid()){
case Network\RakNet\Info::UNCONNECTED_PING: case RakNetInfo::UNCONNECTED_PING:
case Network\RakNet\Info::UNCONNECTED_PING_OPEN_CONNECTIONS: case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
if($this->invisible === true){ if($this->invisible === true){
$pk = new Network\RakNet\Packet(Network\RakNet\Info::UNCONNECTED_PONG); $pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
$pk->pingID = $packet->pingID; $pk->pingID = $packet->pingID;
$pk->serverID = $this->serverID; $pk->serverID = $this->serverID;
$pk->serverType = $this->serverType; $pk->serverType = $this->serverType;
@ -512,7 +522,7 @@ class Server{
} }
$txt = substr($this->description, $this->custom["times_".$CID], $ln); $txt = substr($this->description, $this->custom["times_".$CID], $ln);
$txt .= substr($this->description, 0, $ln - strlen($txt)); $txt .= substr($this->description, 0, $ln - strlen($txt));
$pk = new Network\RakNet\Packet(Network\RakNet\Info::UNCONNECTED_PONG); $pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
$pk->pingID = $packet->pingID; $pk->pingID = $packet->pingID;
$pk->serverID = $this->serverID; $pk->serverID = $this->serverID;
$pk->serverType = $this->serverType . $this->name . " [".count(Player::$list)."/".$this->maxClients."] ".$txt; $pk->serverType = $this->serverType . $this->name . " [".count(Player::$list)."/".$this->maxClients."] ".$txt;
@ -521,16 +531,16 @@ class Server{
$this->send($pk); $this->send($pk);
$this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description); $this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description);
break; break;
case Network\RakNet\Info::OPEN_CONNECTION_REQUEST_1: case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
if($packet->structure !== Network\RakNet\Info::STRUCTURE){ if($packet->structure !== RakNetInfo::STRUCTURE){
console("[DEBUG] Incorrect structure #".$packet->structure." from ".$packet->ip.":".$packet->port, true, true, 2); console("[DEBUG] Incorrect structure #".$packet->structure." from ".$packet->ip.":".$packet->port, true, true, 2);
$pk = new Network\RakNet\Packet(Network\RakNet\Info::INCOMPATIBLE_PROTOCOL_VERSION); $pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION);
$pk->serverID = $this->serverID; $pk->serverID = $this->serverID;
$pk->ip = $packet->ip; $pk->ip = $packet->ip;
$pk->port = $packet->port; $pk->port = $packet->port;
$this->send($pk); $this->send($pk);
}else{ }else{
$pk = new Network\RakNet\Packet(Network\RakNet\Info::OPEN_CONNECTION_REPLY_1); $pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1);
$pk->serverID = $this->serverID; $pk->serverID = $this->serverID;
$pk->mtuSize = strlen($packet->buffer); $pk->mtuSize = strlen($packet->buffer);
$pk->ip = $packet->ip; $pk->ip = $packet->ip;
@ -538,13 +548,13 @@ class Server{
$this->send($pk); $this->send($pk);
} }
break; break;
case Network\RakNet\Info::OPEN_CONNECTION_REQUEST_2: case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
if($this->invisible === true){ if($this->invisible === true){
break; break;
} }
new Player($packet->clientID, $packet->ip, $packet->port, $packet->mtuSize); //New Session! new Player($packet->clientID, $packet->ip, $packet->port, $packet->mtuSize); //New Session!
$pk = new Network\RakNet\Packet(Network\RakNet\Info::OPEN_CONNECTION_REPLY_2); $pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_2);
$pk->serverID = $this->serverID; $pk->serverID = $this->serverID;
$pk->serverPort = $this->port; $pk->serverPort = $this->port;
$pk->mtuSize = $packet->mtuSize; $pk->mtuSize = $packet->mtuSize;
@ -556,7 +566,7 @@ class Server{
} }
} }
public function send(Network\Packet $packet){ public function send(Packet $packet){
return $this->interface->writePacket($packet); return $this->interface->writePacket($packet);
} }
@ -564,7 +574,7 @@ class Server{
$lastLoop = 0; $lastLoop = 0;
while($this->stop === false){ while($this->stop === false){
$packet = $this->interface->readPacket(); $packet = $this->interface->readPacket();
if($packet instanceof Network\Packet){ if($packet instanceof Packet){
$this->packetHandler($packet); $this->packetHandler($packet);
$lastLoop = 0; $lastLoop = 0;
} }

View File

@ -20,6 +20,19 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\Utils\VersionString as VersionString;
use PocketMine\Utils\TextFormat as TextFormat;
use PocketMine\Utils\Config as Config;
use PocketMine\Utils\Utils as Utils;
use PocketMine\Network\UPnP\PortForward as PortForward;
use PocketMine\Entity\Entity as Entity;
use PocketMine\Tile\Tile as Tile;
use PocketMine\Network\Protocol\Info as Info;
use PocketMine\Player as Player;
use PocketMine\Network\RCON\RCON as RCON;
use PocketMine\Network\Query\QueryHandler as QueryHandler;
use PocketMine\Recipes\Crafting as Crafting;
use PocketMine\Network\UPnP\RemovePortForward as RemovePortForward;
class ServerAPI{ class ServerAPI{
public $restart = false; public $restart = false;
@ -103,11 +116,11 @@ class ServerAPI{
} }
} }
$version = new Utils\VersionString(); $version = new VersionString();
console("[INFO] Starting Minecraft PE server version ".Utils\TextFormat::AQUA.MINECRAFT_VERSION); console("[INFO] Starting Minecraft PE server version ".TextFormat::AQUA.MINECRAFT_VERSION);
console("[INFO] Loading properties..."); console("[INFO] Loading properties...");
$this->config = new Utils\Config(\PocketMine\DATA . "server.properties", Utils\Config::PROPERTIES, array( $this->config = new Config(\PocketMine\DATA . "server.properties", Config::PROPERTIES, array(
"server-name" => "Minecraft: PE Server", "server-name" => "Minecraft: PE Server",
"description" => "Server made using PocketMine-MP", "description" => "Server made using PocketMine-MP",
"motd" => "Welcome @player to this server!", "motd" => "Welcome @player to this server!",
@ -134,7 +147,7 @@ class ServerAPI{
"level-type" => "DEFAULT", "level-type" => "DEFAULT",
"enable-query" => true, "enable-query" => true,
"enable-rcon" => false, "enable-rcon" => false,
"rcon.password" => substr(base64_encode(Utils\Utils::getRandomBytes(20, false)), 3, 10), "rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10),
"auto-save" => true, "auto-save" => true,
)); ));
@ -149,52 +162,52 @@ class ServerAPI{
} }
if($this->getProperty("upnp-forwarding") == true){ if($this->getProperty("upnp-forwarding") == true){
console("[INFO] [UPnP] Trying to port forward..."); console("[INFO] [UPnP] Trying to port forward...");
Network\UPnP\PortForward($this->getProperty("server-port")); PortForward($this->getProperty("server-port"));
} }
$this->server = new Server($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed:false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0"); $this->server = new Server($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed:false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0");
$this->server->api = $this; $this->server->api = $this;
self::$serverRequest = $this->server; self::$serverRequest = $this->server;
console("[INFO] This server is running PocketMine-MP version ".($version->isDev() ? Utils\TextFormat::YELLOW:"").VERSION.Utils\TextFormat::RESET." \"".CODENAME."\" (MCPE: ".MINECRAFT_VERSION.") (API ".API_VERSION.")", true, true, 0); console("[INFO] This server is running PocketMine-MP version ".($version->isDev() ? TextFormat::YELLOW:"").VERSION.TextFormat::RESET." \"".CODENAME."\" (MCPE: ".MINECRAFT_VERSION.") (API ".API_VERSION.")", true, true, 0);
console("[INFO] PocketMine-MP is distributed under the LGPL License", true, true, 0); console("[INFO] PocketMine-MP is distributed under the LGPL License", true, true, 0);
if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){ if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){
console("[INFO] Checking for new server version"); console("[INFO] Checking for new server version");
console("[INFO] Last check: ".Utils\TextFormat::AQUA.date("Y-m-d H:i:s", $this->getProperty("last-update"))."\x1b[0m"); console("[INFO] Last check: ".TextFormat::AQUA.date("Y-m-d H:i:s", $this->getProperty("last-update"))."\x1b[0m");
if($this->server->version->isDev()){ if($this->server->version->isDev()){
$info = json_decode(Utils\Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/commits"), true); $info = json_decode(Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/commits"), true);
if($info === false or !isset($info[0])){ if($info === false or !isset($info[0])){
console("[ERROR] Github API error"); console("[ERROR] Github API error");
}else{ }else{
$last = new \DateTime($info[0]["commit"]["committer"]["date"]); $last = new \DateTime($info[0]["commit"]["committer"]["date"]);
$last = $last->getTimestamp(); $last = $last->getTimestamp();
if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false and GIT_COMMIT != $info[0]["sha"]){ if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false and GIT_COMMIT != $info[0]["sha"]){
console("[NOTICE] ".Utils\TextFormat::YELLOW."A new DEVELOPMENT version of PocketMine-MP has been released!"); console("[NOTICE] ".TextFormat::YELLOW."A new DEVELOPMENT version of PocketMine-MP has been released!");
console("[NOTICE] ".Utils\TextFormat::YELLOW."Commit \"".$info[0]["commit"]["message"]."\" [".substr($info[0]["sha"], 0, 10)."] by ".$info[0]["commit"]["committer"]["name"]); console("[NOTICE] ".TextFormat::YELLOW."Commit \"".$info[0]["commit"]["message"]."\" [".substr($info[0]["sha"], 0, 10)."] by ".$info[0]["commit"]["committer"]["name"]);
console("[NOTICE] ".Utils\TextFormat::YELLOW."Get it at PocketMine.net or at https://github.com/PocketMine/PocketMine-MP/archive/".$info[0]["sha"].".zip"); console("[NOTICE] ".TextFormat::YELLOW."Get it at PocketMine.net or at https://github.com/PocketMine/PocketMine-MP/archive/".$info[0]["sha"].".zip");
console("[NOTICE] This message will dissapear after issuing the command \"/update-done\""); console("[NOTICE] This message will dissapear after issuing the command \"/update-done\"");
}else{ }else{
$this->setProperty("last-update", time()); $this->setProperty("last-update", time());
console("[INFO] ".Utils\TextFormat::AQUA."This is the latest DEVELOPMENT version"); console("[INFO] ".TextFormat::AQUA."This is the latest DEVELOPMENT version");
} }
} }
}else{ }else{
$info = json_decode(Utils\Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/tags"), true); $info = json_decode(Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/tags"), true);
if($info === false or !isset($info[0])){ if($info === false or !isset($info[0])){
console("[ERROR] Github API error"); console("[ERROR] Github API error");
}else{ }else{
$newest = new Utils\VersionString(VERSION); $newest = new VersionString(VERSION);
$newestN = $newest->getNumber(); $newestN = $newest->getNumber();
$update = new Utils\VersionString($info[0]["name"]); $update = new VersionString($info[0]["name"]);
$updateN = $update->getNumber(); $updateN = $update->getNumber();
if($updateN > $newestN){ if($updateN > $newestN){
console("[NOTICE] ".Utils\TextFormat::GREEN."A new STABLE version of PocketMine-MP has been released!"); console("[NOTICE] ".TextFormat::GREEN."A new STABLE version of PocketMine-MP has been released!");
console("[NOTICE] ".Utils\TextFormat::GREEN."Version \"".$info[0]["name"]."\" #".$updateN); console("[NOTICE] ".TextFormat::GREEN."Version \"".$info[0]["name"]."\" #".$updateN);
console("[NOTICE] Get it at PocketMine.net or at ".$info[0]["zipball_url"]); console("[NOTICE] Get it at PocketMine.net or at ".$info[0]["zipball_url"]);
console("[NOTICE] This message will dissapear as soon as you update"); console("[NOTICE] This message will dissapear as soon as you update");
}else{ }else{
$this->setProperty("last-update", time()); $this->setProperty("last-update", time());
console("[INFO] ".Utils\TextFormat::AQUA."This is the latest STABLE version"); console("[INFO] ".TextFormat::AQUA."This is the latest STABLE version");
} }
} }
} }
@ -222,19 +235,19 @@ class ServerAPI{
public function checkTickUpdates(){ public function checkTickUpdates(){
//Update entities that need update //Update entities that need update
if(count(Entity\Entity::$needUpdate) > 0){ if(count(Entity::$needUpdate) > 0){
foreach(EntityEntity::$needUpdate as $id => $entity){ foreach(EntityEntity::$needUpdate as $id => $entity){
if($entity->onUpdate() === false){ if($entity->onUpdate() === false){
unset(Entity\Entity::$needUpdate[$id]); unset(Entity::$needUpdate[$id]);
} }
} }
} }
//Update tiles that need update //Update tiles that need update
if(count(Tile\Tile::$needUpdate) > 0){ if(count(Tile::$needUpdate) > 0){
foreach(Tile\Tile::$needUpdate as $id => $tile){ foreach(Tile::$needUpdate as $id => $tile){
if($tile->onUpdate() === false){ if($tile->onUpdate() === false){
unset(Tile\Tile::$needUpdate[$id]); unset(Tile::$needUpdate[$id]);
} }
} }
} }
@ -272,13 +285,13 @@ class ServerAPI{
"data" => array( "data" => array(
"serverid" => $this->server->serverID, "serverid" => $this->server->serverID,
"port" => $this->server->port, "port" => $this->server->port,
"os" => Utils\Utils::getOS(), "os" => Utils::getOS(),
"memory_total" => $this->getProperty("memory-limit"), "memory_total" => $this->getProperty("memory-limit"),
"memory_usage" => memory_get_usage(true), "memory_usage" => memory_get_usage(true),
"php_version" => PHP_VERSION, "php_version" => PHP_VERSION,
"version" => VERSION, "version" => VERSION,
"mc_version" => MINECRAFT_VERSION, "mc_version" => MINECRAFT_VERSION,
"protocol" => Network\Protocol\Info::CURRENT_PROTOCOL, "protocol" => Info::CURRENT_PROTOCOL,
"online" => count(Player::$list), "online" => count(Player::$list),
"max" => $this->server->maxClients, "max" => $this->server->maxClients,
"plugins" => $plist, "plugins" => $plist,
@ -342,7 +355,7 @@ class ServerAPI{
break; break;
case "server-id": case "server-id":
if($v !== false){ if($v !== false){
$v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils\Utils::readInt(substr(md5($v, true), 0, 4)):$v; $v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)):$v;
} }
break; break;
} }
@ -366,24 +379,24 @@ class ServerAPI{
$this->server->schedule(18000, array($this, "autoSave"), array(), true); $this->server->schedule(18000, array($this, "autoSave"), array(), true);
} }
if(!defined("NO_THREADS") and $this->getProperty("enable-rcon") === true){ if(!defined("NO_THREADS") and $this->getProperty("enable-rcon") === true){
$this->rcon = new Network\RCON\RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50)); $this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50));
} }
if($this->getProperty("enable-query") === true){ if($this->getProperty("enable-query") === true){
$this->query = new Network\Query\QueryHandler(); $this->query = new QueryHandler();
} }
Recipes\Crafting::init(); Crafting::init();
$this->schedule(2, array($this, "checkTickUpdates"), array(), true); $this->schedule(2, array($this, "checkTickUpdates"), array(), true);
$this->server->init(); $this->server->init();
unregister_tick_function(array($this->server, "tick")); unregister_tick_function(array($this->server, "tick"));
$this->console->__destruct(); $this->console->__destruct();
if($this->rcon instanceof Network\RCON\RCON){ if($this->rcon instanceof RCON){
$this->rcon->stop(); $this->rcon->stop();
} }
$this->__destruct(); $this->__destruct();
if($this->getProperty("upnp-forwarding") === true ){ if($this->getProperty("upnp-forwarding") === true ){
console("[INFO] [UPnP] Removing port forward..."); console("[INFO] [UPnP] Removing port forward...");
Network\UPnP\RemovePortForward($this->getProperty("server-port")); RemovePortForward($this->getProperty("server-port"));
} }
return $this->restart; return $this->restart;
} }

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
class TimeAPI{ class TimeAPI{
public static $phases = array( public static $phases = array(

View File

@ -21,8 +21,20 @@
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine; use PocketMine;
use PocketMine\Level\Position as Position;
use PocketMine\Level\Level as Level;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\Math\AxisAlignedBB as AxisAlignedBB;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\PMF\LevelFormat as LevelFormat;
use PocketMine\Player as Player;
use PocketMine\Event\EventHandler as EventHandler;
use PocketMine\Event\Entity\EntityLevelChangeEvent as EntityLevelChangeEvent;
use PocketMine\Event\Event as Event;
use PocketMine\Event\Entity\EntityMoveEvent as EntityMoveEvent;
use PocketMine\Event\Entity\EntityMotionEvent as EntityMotionEvent;
abstract class Entity extends Level\Position{ abstract class Entity extends Position{
public static $entityCount = 1; public static $entityCount = 1;
public static $list = array(); public static $list = array();
public static $needUpdate = array(); public static $needUpdate = array();
@ -84,16 +96,16 @@ abstract class Entity extends Level\Position{
} }
public function __construct(Level\Level $level, NBT\Tag\Compound $nbt){ public function __construct(Level $level, Compound $nbt){
$this->id = Entity::$entityCount++; $this->id = Entity::$entityCount++;
$this->justCreated = true; $this->justCreated = true;
$this->closed = false; $this->closed = false;
$this->namedtag = $nbt; $this->namedtag = $nbt;
$this->level = $level; $this->level = $level;
$this->boundingBox = new Math\AxisAlignedBB(0, 0, 0, 0, 0, 0); $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
$this->setPositionAndRotation(new Math\Vector3($this->namedtag->Pos[0], $this->namedtag->Pos[1], $this->namedtag->Pos[2]), $this->namedtag->Rotation[0], $this->namedtag->Rotation[1]); $this->setPositionAndRotation(new Vector3($this->namedtag->Pos[0], $this->namedtag->Pos[1], $this->namedtag->Pos[2]), $this->namedtag->Rotation[0], $this->namedtag->Rotation[1]);
$this->setMotion(new Math\Vector3($this->namedtag->Motion[0], $this->namedtag->Motion[1], $this->namedtag->Motion[2])); $this->setMotion(new Vector3($this->namedtag->Motion[0], $this->namedtag->Motion[1], $this->namedtag->Motion[2]));
$this->fallDistance = $this->namedtag->FallDistance; $this->fallDistance = $this->namedtag->FallDistance;
$this->fireTicks = $this->namedtag->Fire; $this->fireTicks = $this->namedtag->Fire;
@ -101,7 +113,7 @@ abstract class Entity extends Level\Position{
$this->onGround = $this->namedtag->OnGround > 0 ? true:false; $this->onGround = $this->namedtag->OnGround > 0 ? true:false;
$this->invulnerable = $this->namedtag->Invulnerable > 0 ? true:false; $this->invulnerable = $this->namedtag->Invulnerable > 0 ? true:false;
$index = PMF\LevelFormat::getIndex($this->x >> 4, $this->z >> 4); $index = LevelFormat::getIndex($this->x >> 4, $this->z >> 4);
$this->chunkIndex = $index; $this->chunkIndex = $index;
Entity::$list[$this->id] = $this; Entity::$list[$this->id] = $this;
$this->level->entities[$this->id] = $this; $this->level->entities[$this->id] = $this;
@ -299,9 +311,9 @@ abstract class Entity extends Level\Position{
} }
protected function switchLevel(Level\Level $targetLevel){ protected function switchLevel(Level $targetLevel){
if($this->level instanceof Level\Level){ if($this->level instanceof Level){
if(Event\EventHandler::callEvent(new Event\Entity\EntityLevelChangeEvent($this, $this->level, $targetLevel)) === Event\Event::DENY){ if(EventHandler::callEvent(new EntityLevelChangeEvent($this, $this->level, $targetLevel)) === Event::DENY){
return false; return false;
} }
unset($this->level->entities[$this->id]); unset($this->level->entities[$this->id]);
@ -312,7 +324,7 @@ abstract class Entity extends Level\Position{
if($Yndex !== 0xff){ if($Yndex !== 0xff){
$X = null; $X = null;
$Z = null; $Z = null;
PMF\LevelFormat::getXZ($index, $X, $Z); LevelFormat::getXZ($index, $X, $Z);
foreach($this->level->getChunkEntities($X, $Z) as $entity){ foreach($this->level->getChunkEntities($X, $Z) as $entity){
$entity->despawnFrom($this); $entity->despawnFrom($this);
} }
@ -335,10 +347,10 @@ abstract class Entity extends Level\Position{
} }
public function getPosition(){ public function getPosition(){
return new Level\Position($this->x, $this->y, $this->z, $this->level); return new Position($this->x, $this->y, $this->z, $this->level);
} }
public function move(Math\Vector3 $displacement){ public function move(Vector3 $displacement){
if($displacement->x == 0 and $displacement->y == 0 and $displacement->z == 0){ if($displacement->x == 0 and $displacement->y == 0 and $displacement->z == 0){
return; return;
} }
@ -349,7 +361,7 @@ abstract class Entity extends Level\Position{
$this->scheduleUpdate(); $this->scheduleUpdate();
} }
public function setPositionAndRotation(Math\Vector3 $pos, $yaw, $pitch){ public function setPositionAndRotation(Vector3 $pos, $yaw, $pitch){
if($this->setPosition($pos) === true){ if($this->setPosition($pos) === true){
$this->setRotation($yaw, $pitch); $this->setRotation($yaw, $pitch);
return true; return true;
@ -363,13 +375,13 @@ abstract class Entity extends Level\Position{
$this->scheduleUpdate(); $this->scheduleUpdate();
} }
public function setPosition(Math\Vector3 $pos){ public function setPosition(Vector3 $pos){
if($pos instanceof Level\Position and $pos->level instanceof Level\Level and $pos->level !== $this->level){ if($pos instanceof Position and $pos->level instanceof Level and $pos->level !== $this->level){
if($this->switchLevel($pos->level) === false){ if($this->switchLevel($pos->level) === false){
return false; return false;
} }
} }
if(Event\EventHandler::callEvent(new Event\Entity\EntityMoveEvent($this, $pos)) === Event\Event::DENY){ if(EventHandler::callEvent(new EntityMoveEvent($this, $pos)) === Event::DENY){
return false; return false;
} }
$this->x = $pos->x; $this->x = $pos->x;
@ -377,7 +389,7 @@ abstract class Entity extends Level\Position{
$this->z = $pos->z; $this->z = $pos->z;
$radius = $this->width / 2; $radius = $this->width / 2;
if(($index = PMF\LevelFormat::getIndex($this->x >> 4, $this->z >> 4)) !== $this->chunkIndex){ if(($index = LevelFormat::getIndex($this->x >> 4, $this->z >> 4)) !== $this->chunkIndex){
if($this->chunkIndex !== false){ if($this->chunkIndex !== false){
unset($this->level->chunkEntities[$this->chunkIndex][$this->id]); unset($this->level->chunkEntities[$this->chunkIndex][$this->id]);
} }
@ -405,11 +417,11 @@ abstract class Entity extends Level\Position{
} }
public function getMotion(){ public function getMotion(){
return new Math\Vector3($this->motionX, $this->motionY, $this->motionZ); return new Vector3($this->motionX, $this->motionY, $this->motionZ);
} }
public function setMotion(Math\Vector3 $motion){ public function setMotion(Vector3 $motion){
if(Event\EventHandler::callEvent(new Event\Entity\EntityMotionEvent($this, $motion)) === Event\Event::DENY){ if(EventHandler::callEvent(new EntityMotionEvent($this, $motion)) === Event::DENY){
return false; return false;
} }
$this->motionX = $motion->x; $this->motionX = $motion->x;
@ -430,8 +442,8 @@ abstract class Entity extends Level\Position{
return $this->level; return $this->level;
} }
public function teleport(Level\Position $pos, $yaw = false, $pitch = false){ public function teleport(Position $pos, $yaw = false, $pitch = false){
$this->setMotion(new Math\Vector3(0, 0, 0)); $this->setMotion(new Vector3(0, 0, 0));
if($this->setPositionAndRotation($pos, $yaw === false ? $this->yaw : $yaw, $pitch === false ? $this->pitch : $pitch) !== false){ if($this->setPositionAndRotation($pos, $yaw === false ? $this->yaw : $yaw, $pitch === false ? $this->pitch : $pitch) !== false){
if($this instanceof Player){ if($this instanceof Player){
$this->airTicks = 300; $this->airTicks = 300;

View File

@ -22,6 +22,14 @@
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item as Item;
use PocketMine\BlockAPI as BlockAPI;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\NBT\Tag\Byte as Byte;
use PocketMine\NBT\Tag\Short as Short;
use PocketMine\Event\EventHandler as EventHandler;
use PocketMine\Event\Entity\EntityArmorChangeEvent as EntityArmorChangeEvent;
use PocketMine\Event\Event as Event;
use PocketMine\Event\Entity\EntityInventoryChangeEvent as EntityInventoryChangeEvent;
class Human extends Creature implements ProjectileSource, InventorySource{ class Human extends Creature implements ProjectileSource, InventorySource{
@ -64,22 +72,22 @@ class Human extends Creature implements ProjectileSource, InventorySource{
if(isset($this->hotbar[$slot]) and $this->hotbar[$slot] !== -1){ if(isset($this->hotbar[$slot]) and $this->hotbar[$slot] !== -1){
$item = $this->getSlot($this->hotbar[$slot]); $item = $this->getSlot($this->hotbar[$slot]);
if($item->getID() !== AIR and $item->getCount() > 0){ if($item->getID() !== AIR and $item->getCount() > 0){
$this->namedtag->Inventory[$slot] = new NBT\Tag\Compound(false, array( $this->namedtag->Inventory[$slot] = new Compound(false, array(
"Count" => new NBT\Tag\Byte("Count", $item->getCount()), "Count" => new Byte("Count", $item->getCount()),
"Damage" => new NBT\Tag\Short("Damage", $item->getMetadata()), "Damage" => new Short("Damage", $item->getMetadata()),
"Slot" => new NBT\Tag\Byte("Slot", $slot), "Slot" => new Byte("Slot", $slot),
"TrueSlot" => new NBT\Tag\Byte("TrueSlot", $this->hotbar[$slot]), "TrueSlot" => new Byte("TrueSlot", $this->hotbar[$slot]),
"id" => new NBT\Tag\Short("id", $item->getID()), "id" => new Short("id", $item->getID()),
)); ));
continue; continue;
} }
} }
$this->namedtag->Inventory[$slot] = new NBT\Tag\Compound(false, array( $this->namedtag->Inventory[$slot] = new Compound(false, array(
"Count" => new NBT\Tag\Byte("Count", 0), "Count" => new Byte("Count", 0),
"Damage" => new NBT\Tag\Short("Damage", 0), "Damage" => new Short("Damage", 0),
"Slot" => new NBT\Tag\Byte("Slot", $slot), "Slot" => new Byte("Slot", $slot),
"TrueSlot" => new NBT\Tag\Byte("Slot", -1), "TrueSlot" => new Byte("Slot", -1),
"id" => new NBT\Tag\Short("id", 0), "id" => new Short("id", 0),
)); ));
} }
@ -87,11 +95,11 @@ class Human extends Creature implements ProjectileSource, InventorySource{
$slotCount = (($this->gamemode & 0x01) === 0 ? PLAYER_SURVIVAL_SLOTS:PLAYER_CREATIVE_SLOTS) + 9; $slotCount = (($this->gamemode & 0x01) === 0 ? PLAYER_SURVIVAL_SLOTS:PLAYER_CREATIVE_SLOTS) + 9;
for($slot = 9; $slot < $slotCount; ++$slot){ for($slot = 9; $slot < $slotCount; ++$slot){
$item = $this->getSlot($slot); $item = $this->getSlot($slot);
$this->namedtag->Inventory[$slot] = new NBT\Tag\Compound(false, array( $this->namedtag->Inventory[$slot] = new Compound(false, array(
"Count" => new NBT\Tag\Byte("Count", $item->getCount()), "Count" => new Byte("Count", $item->getCount()),
"Damage" => new NBT\Tag\Short("Damage", $item->getMetadata()), "Damage" => new Short("Damage", $item->getMetadata()),
"Slot" => new NBT\Tag\Byte("Slot", $slot), "Slot" => new Byte("Slot", $slot),
"id" => new NBT\Tag\Short("id", $item->getID()), "id" => new Short("id", $item->getID()),
)); ));
} }
@ -99,11 +107,11 @@ class Human extends Creature implements ProjectileSource, InventorySource{
for($slot = 100; $slot < 104; ++$slot){ for($slot = 100; $slot < 104; ++$slot){
$item = $this->armor[$slot - 100]; $item = $this->armor[$slot - 100];
if($item instanceof Item){ if($item instanceof Item){
$this->namedtag->Inventory[$slot] = new NBT\Tag\Compound(false, array( $this->namedtag->Inventory[$slot] = new Compound(false, array(
"Count" => new NBT\Tag\Byte("Count", $item->getCount()), "Count" => new Byte("Count", $item->getCount()),
"Damage" => new NBT\Tag\Short("Damage", $item->getMetadata()), "Damage" => new Short("Damage", $item->getMetadata()),
"Slot" => new NBT\Tag\Byte("Slot", $slot), "Slot" => new Byte("Slot", $slot),
"id" => new NBT\Tag\Short("id", $item->getID()), "id" => new Short("id", $item->getID()),
)); ));
} }
} }
@ -178,7 +186,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
} }
public function setArmorSlot($slot, Item $item){ public function setArmorSlot($slot, Item $item){
if(Event\EventHandler::callEvent($ev = new Event\Entity\EntityArmorChangeEvent($this, $this->getArmorSlot($slot), $item, $slot)) === Event\Event::DENY){ if(EventHandler::callEvent($ev = new EntityArmorChangeEvent($this, $this->getArmorSlot($slot), $item, $slot)) === Event::DENY){
return false; return false;
} }
$this->armor[(int) $slot] = $ev->getNewItem(); $this->armor[(int) $slot] = $ev->getNewItem();
@ -352,7 +360,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
} }
public function setSlot($slot, Item $item){ public function setSlot($slot, Item $item){
if(Event\EventHandler::callEvent($ev = new Event\Entity\EntityInventoryChangeEvent($this, $this->getSlot($slot), $item, $slot)) === Event\Event::DENY){ if(EventHandler::callEvent($ev = new EntityInventoryChangeEvent($this, $this->getSlot($slot), $item, $slot)) === Event::DENY){
return false; return false;
} }
$this->inventory[(int) $slot] = $ev->getNewItem(); $this->inventory[(int) $slot] = $ev->getNewItem();

View File

@ -21,6 +21,8 @@
namespace PocketMine\Event; namespace PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Event\EventPriority as EventPriority;
use PocketMine\Utils\Utils as Utils;
abstract class Event{ abstract class Event{
const ALLOW = 0; const ALLOW = 0;
@ -54,7 +56,7 @@ abstract class Event{
if($priority < EventPriority::MONITOR or $priority > EventPriority::LOWEST){ if($priority < EventPriority::MONITOR or $priority > EventPriority::LOWEST){
return false; return false;
} }
$identifier = Utils\Utils::getCallableIdentifier($handler); $identifier = Utils::getCallableIdentifier($handler);
if(isset(static::$handlers[$identifier])){ //Already registered if(isset(static::$handlers[$identifier])){ //Already registered
return false; return false;
}else{ }else{
@ -69,7 +71,7 @@ abstract class Event{
} }
public static function unregister(callable $handler, $priority = EventPriority::NORMAL){ public static function unregister(callable $handler, $priority = EventPriority::NORMAL){
$identifier = Utils\Utils::getCallableIdentifier($handler); $identifier = Utils::getCallableIdentifier($handler);
if(isset(static::$handlers[$identifier])){ if(isset(static::$handlers[$identifier])){
if(isset(static::$handlerPriority[(int) $priority][$identifier])){ if(isset(static::$handlerPriority[(int) $priority][$identifier])){
unset(static::$handlerPriority[(int) $priority][$identifier]); unset(static::$handlerPriority[(int) $priority][$identifier]);

View File

@ -21,6 +21,7 @@
namespace PocketMine\Event; namespace PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Event\Event as Event;
abstract class EventHandler{ abstract class EventHandler{

View File

@ -22,6 +22,8 @@
namespace PocketMine\Event\Entity; namespace PocketMine\Event\Entity;
use PocketMine\Event; use PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Entity\Entity as Entity;
use PocketMine\Item\Item as Item;
class EntityArmorChangeEvent extends EntityEvent implements CancellableEvent{ class EntityArmorChangeEvent extends EntityEvent implements CancellableEvent{
public static $handlers; public static $handlers;
@ -31,7 +33,7 @@ class EntityArmorChangeEvent extends EntityEvent implements CancellableEvent{
private $newItem; private $newItem;
private $slot; private $slot;
public function __construct(Entity\Entity $entity, Item\Item $oldItem, Item\Item $newItem, $slot){ public function __construct(Entity $entity, Item $oldItem, Item $newItem, $slot){
$this->entity = $entity; $this->entity = $entity;
$this->oldItem = $oldItem; $this->oldItem = $oldItem;
$this->newItem = $newItem; $this->newItem = $newItem;
@ -46,7 +48,7 @@ class EntityArmorChangeEvent extends EntityEvent implements CancellableEvent{
return $this->newItem; return $this->newItem;
} }
public function setNewItem(Item\Item $item){ public function setNewItem(Item $item){
$this->newItem = $item; $this->newItem = $item;
} }

View File

@ -22,6 +22,8 @@
namespace PocketMine\Event\Entity; namespace PocketMine\Event\Entity;
use PocketMine\Event; use PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Entity\Entity as Entity;
use PocketMine\Item\Item as Item;
class EntityInventoryChangeEvent extends EntityEvent implements CancellableEvent{ class EntityInventoryChangeEvent extends EntityEvent implements CancellableEvent{
public static $handlers; public static $handlers;
@ -31,7 +33,7 @@ class EntityInventoryChangeEvent extends EntityEvent implements CancellableEvent
private $newItem; private $newItem;
private $slot; private $slot;
public function __construct(Entity\Entity $entity, Item\Item $oldItem, Item\Item $newItem, $slot){ public function __construct(Entity $entity, Item $oldItem, Item $newItem, $slot){
$this->entity = $entity; $this->entity = $entity;
$this->oldItem = $oldItem; $this->oldItem = $oldItem;
$this->newItem = $newItem; $this->newItem = $newItem;
@ -46,7 +48,7 @@ class EntityInventoryChangeEvent extends EntityEvent implements CancellableEvent
return $this->newItem; return $this->newItem;
} }
public function setNewItem(Item\Item $item){ public function setNewItem(Item $item){
$this->newItem = $item; $this->newItem = $item;
} }

View File

@ -22,6 +22,8 @@
namespace PocketMine\Event\Entity; namespace PocketMine\Event\Entity;
use PocketMine\Event; use PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Entity\Entity as Entity;
use PocketMine\Level\Level as Level;
class EntityLevelChangeEvent extends EntityEvent implements CancellableEvent{ class EntityLevelChangeEvent extends EntityEvent implements CancellableEvent{
public static $handlers; public static $handlers;
@ -30,7 +32,7 @@ class EntityLevelChangeEvent extends EntityEvent implements CancellableEvent{
private $originLevel; private $originLevel;
private $targetLevel; private $targetLevel;
public function __construct(Entity\Entity $entity, Level\Level $originLevel, Level\Level $targetLevel){ public function __construct(Entity $entity, Level $originLevel, Level $targetLevel){
$this->entity = $entity; $this->entity = $entity;
$this->originLevel = $originLevel; $this->originLevel = $originLevel;
$this->targetLevel = $targetLevel; $this->targetLevel = $targetLevel;

View File

@ -22,6 +22,8 @@
namespace PocketMine\Event\Entity; namespace PocketMine\Event\Entity;
use PocketMine\Event; use PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Entity\Entity as Entity;
use PocketMine\Math\Vector3 as Vector3;
class EntityMotionEvent extends EntityEvent implements CancellableEvent{ class EntityMotionEvent extends EntityEvent implements CancellableEvent{
public static $handlers; public static $handlers;
@ -29,7 +31,7 @@ class EntityMotionEvent extends EntityEvent implements CancellableEvent{
private $mot; private $mot;
public function __construct(Entity\Entity $entity, Math\Vector3 $mot){ public function __construct(Entity $entity, Vector3 $mot){
$this->entity = $entity; $this->entity = $entity;
$this->mot = $mot; $this->mot = $mot;
} }

View File

@ -22,6 +22,8 @@
namespace PocketMine\Event\Entity; namespace PocketMine\Event\Entity;
use PocketMine\Event; use PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Entity\Entity as Entity;
use PocketMine\Math\Vector3 as Vector3;
class EntityMoveEvent extends EntityEvent implements CancellableEvent{ class EntityMoveEvent extends EntityEvent implements CancellableEvent{
public static $handlers; public static $handlers;
@ -29,7 +31,7 @@ class EntityMoveEvent extends EntityEvent implements CancellableEvent{
private $pos; private $pos;
public function __construct(Entity\Entity $entity, Math\Vector3 $pos){ public function __construct(Entity $entity, Vector3 $pos){
$this->entity = $entity; $this->entity = $entity;
$this->pos = $pos; $this->pos = $pos;
} }

View File

@ -22,6 +22,7 @@
namespace PocketMine\Event\Player; namespace PocketMine\Event\Player;
use PocketMine\Event; use PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item;
class PlayerEquipmentChangeEvent extends PlayerEvent implements CancellableEvent{ class PlayerEquipmentChangeEvent extends PlayerEvent implements CancellableEvent{
public static $handlers; public static $handlers;
@ -31,7 +32,7 @@ class PlayerEquipmentChangeEvent extends PlayerEvent implements CancellableEvent
private $slot; private $slot;
private $inventorySlot; private $inventorySlot;
public function __construct(Player $player, Item\Item $item, $inventorySlot, $slot){ public function __construct(Player $player, Item $item, $inventorySlot, $slot){
$this->player = $player; $this->player = $player;
$this->item = $item; $this->item = $item;
$this->inventorySlot = (int) $inventorySlot; $this->inventorySlot = (int) $inventorySlot;

View File

@ -22,6 +22,7 @@
namespace PocketMine\Event\Server; namespace PocketMine\Event\Server;
use PocketMine\Event; use PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\DataPacket as DataPacket;
class DataPacketReceiveEvent extends ServerEvent implements CancellableEvent{ class DataPacketReceiveEvent extends ServerEvent implements CancellableEvent{
public static $handlers; public static $handlers;
@ -30,7 +31,7 @@ class DataPacketReceiveEvent extends ServerEvent implements CancellableEvent{
private $packet; private $packet;
private $player; private $player;
public function __construct(Player $player, Network\Protocol\DataPacket $packet){ public function __construct(Player $player, DataPacket $packet){
$this->packet = $packet; $this->packet = $packet;
$this->player = $player; $this->player = $player;
} }

View File

@ -22,6 +22,7 @@
namespace PocketMine\Event\Server; namespace PocketMine\Event\Server;
use PocketMine\Event; use PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\DataPacket as DataPacket;
class DataPacketSendEvent extends ServerEvent implements CancellableEvent{ class DataPacketSendEvent extends ServerEvent implements CancellableEvent{
public static $handlers; public static $handlers;
@ -30,7 +31,7 @@ class DataPacketSendEvent extends ServerEvent implements CancellableEvent{
private $packet; private $packet;
private $player; private $player;
public function __construct(Player $player, Network\Protocol\DataPacket $packet){ public function __construct(Player $player, DataPacket $packet){
$this->packet = $packet; $this->packet = $packet;
$this->player = $player; $this->player = $player;
} }

View File

@ -22,6 +22,7 @@
namespace PocketMine\Event\Server; namespace PocketMine\Event\Server;
use PocketMine\Event; use PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Network\Packet as Packet;
class PacketReceiveEvent extends ServerEvent implements CancellableEvent{ class PacketReceiveEvent extends ServerEvent implements CancellableEvent{
public static $handlers; public static $handlers;
@ -30,7 +31,7 @@ class PacketReceiveEvent extends ServerEvent implements CancellableEvent{
private $packet; private $packet;
public function __construct(Network\Packet $packet){ public function __construct(Packet $packet){
$this->packet = $packet; $this->packet = $packet;
} }

View File

@ -22,6 +22,7 @@
namespace PocketMine\Event\Server; namespace PocketMine\Event\Server;
use PocketMine\Event; use PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Network\Packet as Packet;
class PacketSendEvent extends ServerEvent implements CancellableEvent{ class PacketSendEvent extends ServerEvent implements CancellableEvent{
public static $handlers; public static $handlers;
@ -30,7 +31,7 @@ class PacketSendEvent extends ServerEvent implements CancellableEvent{
private $packet; private $packet;
public function __construct(Network\Packet $packet){ public function __construct(Packet $packet){
$this->packet = $packet; $this->packet = $packet;
} }

View File

@ -22,6 +22,8 @@
namespace PocketMine\Event\Tile; namespace PocketMine\Event\Tile;
use PocketMine\Event; use PocketMine\Event;
use PocketMine; use PocketMine;
use PocketMine\Tile\Tile as Tile;
use PocketMine\Item\Item as Item;
class TileInventoryChangeEvent extends TileEvent implements CancellableEvent{ class TileInventoryChangeEvent extends TileEvent implements CancellableEvent{
public static $handlers; public static $handlers;
@ -31,7 +33,7 @@ class TileInventoryChangeEvent extends TileEvent implements CancellableEvent{
private $newItem; private $newItem;
private $slot; private $slot;
public function __construct(Tile\Tile $tile, Item\Item $oldItem, Item\Item $newItem, $slot){ public function __construct(Tile $tile, Item $oldItem, Item $newItem, $slot){
$this->tile = $tile; $this->tile = $tile;
$this->oldItem = $oldItem; $this->oldItem = $oldItem;
$this->newItem = $newItem; $this->newItem = $newItem;
@ -46,7 +48,7 @@ class TileInventoryChangeEvent extends TileEvent implements CancellableEvent{
return $this->newItem; return $this->newItem;
} }
public function setNewItem(Item\Item $item){ public function setNewItem(Item $item){
$this->newItem = $item; $this->newItem = $item;
} }

View File

@ -21,6 +21,12 @@
namespace PocketMine\Level; namespace PocketMine\Level;
use PocketMine; use PocketMine;
use PocketMine\Level\Position as Position;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\BlockAPI as BlockAPI;
use PocketMine\Block\TNT as TNT;
use PocketMine\Player as Player;
class Explosion{ class Explosion{
public static $specialDrops = array( public static $specialDrops = array(
@ -37,7 +43,7 @@ class Explosion{
public $affectedBlocks = array(); public $affectedBlocks = array();
public $stepLen = 0.3; public $stepLen = 0.3;
public function __construct(Level\Position $center, $size){ public function __construct(Position $center, $size){
$this->level = $center->level; $this->level = $center->level;
$this->source = $center; $this->source = $center;
$this->size = max($size, 0); $this->size = max($size, 0);
@ -58,7 +64,7 @@ class Explosion{
for($j = 0; $j < $this->rays; ++$j){ for($j = 0; $j < $this->rays; ++$j){
for($k = 0; $k < $this->rays; ++$k){ for($k = 0; $k < $this->rays; ++$k){
if($i == 0 or $i == $mRays or $j == 0 or $j == $mRays or $k == 0 or $k == $mRays){ if($i == 0 or $i == $mRays or $j == 0 or $j == $mRays or $k == 0 or $k == $mRays){
$vector = new Math\Vector3($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); //($i / $mRays) * 2 - 1 $vector = new Vector3($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); //($i / $mRays) * 2 - 1
$vector = $vector->normalize()->multiply($this->stepLen); $vector = $vector->normalize()->multiply($this->stepLen);
$pointer = clone $this->source; $pointer = clone $this->source;
@ -98,7 +104,7 @@ class Explosion{
foreach($this->affectedBlocks as $block){ foreach($this->affectedBlocks as $block){
if($block instanceof Block\TNT){ if($block instanceof TNT){
$data = array( $data = array(
"x" => $block->x + 0.5, "x" => $block->x + 0.5,
"y" => $block->y + 0.5, "y" => $block->y + 0.5,
@ -119,7 +125,7 @@ class Explosion{
} }
} }
$this->level->level->setBlockID($block->x, $block->y, $block->z, 0); $this->level->level->setBlockID($block->x, $block->y, $block->z, 0);
$send[] = new Math\Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z); $send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
} }
$pk = new Network\Protocol\ExplodePacket; $pk = new Network\Protocol\ExplodePacket;
$pk->x = $this->source->x; $pk->x = $this->source->x;

View File

@ -21,6 +21,22 @@
namespace PocketMine\Level; namespace PocketMine\Level;
use PocketMine; use PocketMine;
use PocketMine\PMF\LevelFormat as LevelFormat;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Level\Generator\Generator as Generator;
use PocketMine\Utils\Random as Random;
use PocketMine\Player as Player;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\NBT\Tag\Enum as Enum;
use PocketMine\BlockAPI as BlockAPI;
use PocketMine\Block\Block as Block;
use PocketMine\Utils\Cache as Cache;
use PocketMine\Tile\Tile as Tile;
use PocketMine\Tile\Chest as Chest;
use PocketMine\Tile\Furnace as Furnace;
use PocketMine\Tile\Sign as Sign;
use PocketMine\Block\Air as Air;
class Level{ class Level{
public $players = array(); public $players = array();
@ -35,7 +51,7 @@ class Level{
public $stopTime; public $stopTime;
private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $generator; private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $generator;
public function __construct(PMF\LevelFormat $level, $name){ public function __construct(LevelFormat $level, $name){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->level = $level; $this->level = $level;
$this->level->level = $this; $this->level->level = $this;
@ -49,9 +65,9 @@ class Level{
$this->usedChunks = array(); $this->usedChunks = array();
$this->changedBlocks = array(); $this->changedBlocks = array();
$this->changedCount = array(); $this->changedCount = array();
$gen = Generator\Generator::getGenerator($this->level->levelData["generator"]); $gen = Generator::getGenerator($this->level->levelData["generator"]);
$this->generator = new $gen((array) $this->level->levelData["generatorSettings"]); $this->generator = new $gen((array) $this->level->levelData["generatorSettings"]);
$this->generator->init($this, new Utils\Random($this->level->levelData["seed"])); $this->generator->init($this, new Random($this->level->levelData["seed"]));
} }
public function close(){ public function close(){
@ -59,12 +75,12 @@ class Level{
} }
public function getUsingChunk($X, $Z){ public function getUsingChunk($X, $Z){
$index = PMF\LevelFormat::getIndex($X, $Z); $index = LevelFormat::getIndex($X, $Z);
return isset($this->usedChunks[$index]) ? $this->usedChunks[$index]:array(); return isset($this->usedChunks[$index]) ? $this->usedChunks[$index]:array();
} }
public function useChunk($X, $Z, Player $player){ public function useChunk($X, $Z, Player $player){
$index = PMF\LevelFormat::getIndex($X, $Z); $index = LevelFormat::getIndex($X, $Z);
$this->loadChunk($X, $Z); $this->loadChunk($X, $Z);
$this->usedChunks[$index][$player->CID] = $player; $this->usedChunks[$index][$player->CID] = $player;
} }
@ -76,7 +92,7 @@ class Level{
} }
public function freeChunk($X, $Z, Player $player){ public function freeChunk($X, $Z, Player $player){
unset($this->usedChunks[PMF\LevelFormat::getIndex($X, $Z)][$player->CID]); unset($this->usedChunks[LevelFormat::getIndex($X, $Z)][$player->CID]);
} }
public function isChunkPopulated($X, $Z){ public function isChunkPopulated($X, $Z){
@ -148,11 +164,11 @@ class Level{
//Do chunk updates //Do chunk updates
foreach($this->usedChunks as $index => $p){ foreach($this->usedChunks as $index => $p){
PMF\LevelFormat::getXZ($index, $X, $Z); LevelFormat::getXZ($index, $X, $Z);
for($Y = 0; $Y < 8; ++$Y){ for($Y = 0; $Y < 8; ++$Y){
if(!$this->level->isMiniChunkEmpty($X, $Z, $Y)){ if(!$this->level->isMiniChunkEmpty($X, $Z, $Y)){
for($i = 0; $i < 3; ++$i){ for($i = 0; $i < 3; ++$i){
$block = $this->getBlockRaw(new Math\Vector3(($X << 4) + mt_rand(0, 15), ($Y << 4) + mt_rand(0, 15), ($Z << 4) + mt_rand(0, 15))); $block = $this->getBlockRaw(new Vector3(($X << 4) + mt_rand(0, 15), ($Y << 4) + mt_rand(0, 15), ($Z << 4) + mt_rand(0, 15)));
if($block instanceof Block){ if($block instanceof Block){
if($block->onUpdate(BLOCK_UPDATE_RANDOM) === BLOCK_UPDATE_NORMAL){ if($block->onUpdate(BLOCK_UPDATE_RANDOM) === BLOCK_UPDATE_NORMAL){
$this->server->api->block->blockUpdateAround($block, $this); $this->server->api->block->blockUpdateAround($block, $this);
@ -170,7 +186,7 @@ class Level{
foreach($this->usedChunks as $i => $c){ foreach($this->usedChunks as $i => $c){
if(count($c) === 0){ if(count($c) === 0){
unset($this->usedChunks[$i]); unset($this->usedChunks[$i]);
PMF\LevelFormat::getXZ($i, $X, $Z); LevelFormat::getXZ($i, $X, $Z);
if(!$this->isSpawnChunk($X, $Z)){ if(!$this->isSpawnChunk($X, $Z)){
$this->level->unloadChunk($X, $Z, $this->server->saveEnabled); $this->level->unloadChunk($X, $Z, $this->server->saveEnabled);
} }
@ -221,11 +237,11 @@ class Level{
protected function doSaveRoundExtra(){ protected function doSaveRoundExtra(){
foreach($this->usedChunks as $index => $d){ foreach($this->usedChunks as $index => $d){
PMF\LevelFormat::getXZ($index, $X, $Z); LevelFormat::getXZ($index, $X, $Z);
$nbt = new NBT(NBT\BIG_ENDIAN); $nbt = new NBT(NBT\BIG_ENDIAN);
$nbt->setData(new NBT\Tag\Compound("", array( $nbt->setData(new Compound("", array(
"Entities" => new NBT\Tag\Enum("Entities", array()), "Entities" => new Enum("Entities", array()),
"TileEntities" => new NBT\Tag\Enum("TileEntities", array()), "TileEntities" => new Enum("TileEntities", array()),
))); )));
$nbt->Entities->setTagType(NBT\TAG_Compound); $nbt->Entities->setTagType(NBT\TAG_Compound);
$nbt->TileEntities->setTagType(NBT\TAG_Compound); $nbt->TileEntities->setTagType(NBT\TAG_Compound);
@ -251,12 +267,12 @@ class Level{
} }
} }
public function getBlockRaw(Math\Vector3 $pos){ public function getBlockRaw(Vector3 $pos){
$b = $this->level->getBlock($pos->x, $pos->y, $pos->z); $b = $this->level->getBlock($pos->x, $pos->y, $pos->z);
return BlockAPI::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this)); return BlockAPI::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this));
} }
public function getBlock(Math\Vector3 $pos){ public function getBlock(Vector3 $pos){
if($pos instanceof Position and $pos->level !== $this){ if($pos instanceof Position and $pos->level !== $this){
return false; return false;
} }
@ -264,7 +280,7 @@ class Level{
return BlockAPI::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this)); return BlockAPI::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this));
} }
public function setBlockRaw(Math\Vector3 $pos, Block\Block $block, $direct = true, $send = true){ public function setBlockRaw(Vector3 $pos, Block $block, $direct = true, $send = true){
if(($ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata())) === true and $send !== false){ if(($ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata())) === true and $send !== false){
if($direct === true){ if($direct === true){
$pk = new Network\Protocol\UpdateBlockPacket; $pk = new Network\Protocol\UpdateBlockPacket;
@ -279,9 +295,9 @@ class Level{
$pos = new Position($pos->x, $pos->y, $pos->z, $this); $pos = new Position($pos->x, $pos->y, $pos->z, $this);
} }
$block->position($pos); $block->position($pos);
$index = PMF\LevelFormat::getIndex($pos->x >> 4, $pos->z >> 4); $index = LevelFormat::getIndex($pos->x >> 4, $pos->z >> 4);
if(ADVANCED_CACHE == true){ if(ADVANCED_CACHE == true){
Utils\Cache::remove("world:{$this->name}:{$index}"); Cache::remove("world:{$this->name}:{$index}");
} }
if(!isset($this->changedBlocks[$index])){ if(!isset($this->changedBlocks[$index])){
$this->changedBlocks[$index] = array(); $this->changedBlocks[$index] = array();
@ -298,7 +314,7 @@ class Level{
return $ret; return $ret;
} }
public function setBlock(Math\Vector3 $pos, Block\Block $block, $update = true, $tiles = false, $direct = false){ public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false){
if((($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){ if((($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){
return false; return false;
} }
@ -319,9 +335,9 @@ class Level{
$pk->meta = $block->getMetadata(); $pk->meta = $block->getMetadata();
Player::broadcastPacket($this->players, $pk); Player::broadcastPacket($this->players, $pk);
}else{ }else{
$index = PMF\LevelFormat::getIndex($pos->x >> 4, $pos->z >> 4); $index = LevelFormat::getIndex($pos->x >> 4, $pos->z >> 4);
if(ADVANCED_CACHE == true){ if(ADVANCED_CACHE == true){
Utils\Cache::remove("world:{$this->name}:{$index}"); Cache::remove("world:{$this->name}:{$index}");
} }
if(!isset($this->changedBlocks[$index])){ if(!isset($this->changedBlocks[$index])){
$this->changedBlocks[$index] = array(); $this->changedBlocks[$index] = array();
@ -339,7 +355,7 @@ class Level{
$this->server->api->block->blockUpdateAround($pos, BLOCK_UPDATE_NORMAL, 1); $this->server->api->block->blockUpdateAround($pos, BLOCK_UPDATE_NORMAL, 1);
} }
if($tiles === true){ if($tiles === true){
if($t = $this->getTile($pos) instanceof Tile\Tile){ if($t = $this->getTile($pos) instanceof Tile){
$t->close(); $t->close();
} }
} }
@ -367,7 +383,7 @@ class Level{
return $this->players; return $this->players;
} }
public function getTile(Math\Vector3 $pos){ public function getTile(Vector3 $pos){
if($pos instanceof Position and $pos->level !== $this){ if($pos instanceof Position and $pos->level !== $this){
return false; return false;
} }
@ -389,13 +405,13 @@ class Level{
public function setMiniChunk($X, $Z, $Y, $data){ public function setMiniChunk($X, $Z, $Y, $data){
$this->changedCount[$X.":".$Y.":".$Z] = 4096; $this->changedCount[$X.":".$Y.":".$Z] = 4096;
if(ADVANCED_CACHE == true){ if(ADVANCED_CACHE == true){
Utils\Cache::remove("world:{$this->name}:$X:$Z"); Cache::remove("world:{$this->name}:$X:$Z");
} }
return $this->level->setMiniChunk($X, $Z, $Y, $data); return $this->level->setMiniChunk($X, $Z, $Y, $data);
} }
public function getChunkEntities($X, $Z){ public function getChunkEntities($X, $Z){
$index = PMF\LevelFormat::getIndex($X, $Z); $index = LevelFormat::getIndex($X, $Z);
if(isset($this->usedChunks[$index]) or $this->loadChunk($X, $Z) === true){ if(isset($this->usedChunks[$index]) or $this->loadChunk($X, $Z) === true){
return $this->chunkEntities[$index]; return $this->chunkEntities[$index];
} }
@ -403,7 +419,7 @@ class Level{
} }
public function getChunkTiles($X, $Z){ public function getChunkTiles($X, $Z){
$index = PMF\LevelFormat::getIndex($X, $Z); $index = LevelFormat::getIndex($X, $Z);
if(isset($this->usedChunks[$index]) or $this->loadChunk($X, $Z) === true){ if(isset($this->usedChunks[$index]) or $this->loadChunk($X, $Z) === true){
return $this->chunkTiles[$index]; return $this->chunkTiles[$index];
} }
@ -413,7 +429,7 @@ class Level{
public function loadChunk($X, $Z){ public function loadChunk($X, $Z){
$index = PMF\LevelFormat::getIndex($X, $Z); $index = LevelFormat::getIndex($X, $Z);
if(isset($this->usedChunks[$index])){ if(isset($this->usedChunks[$index])){
return true; return true;
}elseif($this->level->loadChunk($X, $Z) !== false){ }elseif($this->level->loadChunk($X, $Z) !== false){
@ -427,14 +443,14 @@ class Level{
} }
foreach($this->level->getChunkNBT($X, $Z)->TileEntities as $nbt){ foreach($this->level->getChunkNBT($X, $Z)->TileEntities as $nbt){
switch($nbt->id){ switch($nbt->id){
case Tile\Tile::CHEST: case Tile::CHEST:
new Tile\Chest($this, $nbt); new Chest($this, $nbt);
break; break;
case Tile\Tile::FURNACE: case Tile::FURNACE:
new Tile\Furnace($this, $nbt); new Furnace($this, $nbt);
break; break;
case Tile\Tile::SIGN: case Tile::SIGN:
new Tile\Sign($this, $nbt); new Sign($this, $nbt);
break; break;
} }
} }
@ -454,7 +470,7 @@ class Level{
unset($this->usedChunks[$index]); unset($this->usedChunks[$index]);
unset($this->chunkEntities[$index]); unset($this->chunkEntities[$index]);
unset($this->chunkTiles[$index]); unset($this->chunkTiles[$index]);
Utils\Cache::remove("world:{$this->name}:$X:$Z"); Cache::remove("world:{$this->name}:$X:$Z");
return $this->level->unloadChunk($X, $Z, $this->server->saveEnabled); return $this->level->unloadChunk($X, $Z, $this->server->saveEnabled);
} }
@ -469,8 +485,8 @@ class Level{
return false; return false;
} }
if(ADVANCED_CACHE == true and $Yndex === 0xff){ if(ADVANCED_CACHE == true and $Yndex === 0xff){
$identifier = "world:{$this->name}:".PMF\LevelFormat::getIndex($X, $Z); $identifier = "world:{$this->name}:".LevelFormat::getIndex($X, $Z);
if(($cache = Utils\Cache::get($identifier)) !== false){ if(($cache = Cache::get($identifier)) !== false){
return $cache; return $cache;
} }
} }
@ -492,7 +508,7 @@ class Level{
} }
} }
if(ADVANCED_CACHE == true and $Yndex == 0xff){ if(ADVANCED_CACHE == true and $Yndex == 0xff){
Utils\Cache::add($identifier, $ordered, 60); Cache::add($identifier, $ordered, 60);
} }
return $ordered; return $ordered;
} }
@ -518,23 +534,23 @@ class Level{
if($spawn === false){ if($spawn === false){
$spawn = $this->getSpawn(); $spawn = $this->getSpawn();
} }
if($spawn instanceof Math\Vector3){ if($spawn instanceof Vector3){
$x = (int) round($spawn->x); $x = (int) round($spawn->x);
$y = (int) round($spawn->y); $y = (int) round($spawn->y);
$z = (int) round($spawn->z); $z = (int) round($spawn->z);
for(; $y > 0; --$y){ for(; $y > 0; --$y){
$v = new Math\Vector3($x, $y, $z); $v = new Vector3($x, $y, $z);
$b = $this->getBlock($v->getSide(0)); $b = $this->getBlock($v->getSide(0));
if($b === false){ if($b === false){
return $spawn; return $spawn;
}elseif(!($b instanceof Block\Air)){ }elseif(!($b instanceof Air)){
break; break;
} }
} }
for(; $y < 128; ++$y){ for(; $y < 128; ++$y){
$v = new Math\Vector3($x, $y, $z); $v = new Vector3($x, $y, $z);
if($this->getBlock($v->getSide(1)) instanceof Block\Air){ if($this->getBlock($v->getSide(1)) instanceof Air){
if($this->getBlock($v) instanceof Block\Air){ if($this->getBlock($v) instanceof Air){
return new Position($x, $y, $z, $this); return new Position($x, $y, $z, $this);
} }
}else{ }else{
@ -546,7 +562,7 @@ class Level{
return false; return false;
} }
public function setSpawn(Math\Vector3 $pos){ public function setSpawn(Vector3 $pos){
$this->level->setData("spawnX", $pos->x); $this->level->setData("spawnX", $pos->x);
$this->level->setData("spawnY", $pos->y); $this->level->setData("spawnY", $pos->y);
$this->level->setData("spawnZ", $pos->z); $this->level->setData("spawnZ", $pos->z);

View File

@ -21,6 +21,8 @@
namespace PocketMine\Level; namespace PocketMine\Level;
use PocketMine; use PocketMine;
use PocketMine\Utils\Config as Config;
use PocketMine\PMF\LevelFormat as LevelFormat;
class LevelImport{ class LevelImport{
private $path; private $path;
@ -32,9 +34,9 @@ class LevelImport{
if(file_exists($this->path."tileEntities.dat")){ //OldPM if(file_exists($this->path."tileEntities.dat")){ //OldPM
$level = unserialize(file_get_contents($this->path."level.dat")); $level = unserialize(file_get_contents($this->path."level.dat"));
console("[INFO] Importing OldPM level \"".$level["LevelName"]."\" to PMF format"); console("[INFO] Importing OldPM level \"".$level["LevelName"]."\" to PMF format");
$entities = new Utils\Config($this->path."entities.yml", Utils\Config::YAML, unserialize(file_get_contents($this->path."entities.dat"))); $entities = new Config($this->path."entities.yml", Config::YAML, unserialize(file_get_contents($this->path."entities.dat")));
$entities->save(); $entities->save();
$tiles = new Utils\Config($this->path."tiles.yml", Utils\Config::YAML, unserialize(file_get_contents($this->path."tileEntities.dat"))); $tiles = new Config($this->path."tiles.yml", Config::YAML, unserialize(file_get_contents($this->path."tileEntities.dat")));
$tiles->save(); $tiles->save();
}elseif(file_exists($this->path."chunks.dat") and file_exists($this->path."level.dat")){ //Pocket }elseif(file_exists($this->path."chunks.dat") and file_exists($this->path."level.dat")){ //Pocket
$nbt = new NBT(NBT\LITTLE_ENDIAN); $nbt = new NBT(NBT\LITTLE_ENDIAN);
@ -52,15 +54,15 @@ class LevelImport{
} }
$tiles = $entities->TileEntities; $tiles = $entities->TileEntities;
$entities = $entities->Entities; $entities = $entities->Entities;
$entities = new Utils\Config($this->path."entities.yml", Utils\Config::YAML, $entities); $entities = new Config($this->path."entities.yml", Config::YAML, $entities);
$entities->save(); $entities->save();
$tiles = new Utils\Config($this->path."tiles.yml", Utils\Config::YAML, $tiles); $tiles = new Config($this->path."tiles.yml", Config::YAML, $tiles);
$tiles->save(); $tiles->save();
}else{ }else{
return false; return false;
} }
$pmf = new PMF\LevelFormat($this->path."level.pmf", array( $pmf = new LevelFormat($this->path."level.pmf", array(
"name" => $level["LevelName"], "name" => $level["LevelName"],
"seed" => $level["RandomSeed"], "seed" => $level["RandomSeed"],
"time" => $level["Time"], "time" => $level["Time"],

View File

@ -21,6 +21,7 @@
namespace PocketMine\Level; namespace PocketMine\Level;
use PocketMine; use PocketMine;
use PocketMine\Utils\Utils as Utils;
/** /**
* WARNING: This code is old, and only supports the file format partially (reverse engineering) * WARNING: This code is old, and only supports the file format partially (reverse engineering)
@ -41,7 +42,7 @@ class PocketChunkParser{
$this->location = array(); $this->location = array();
console("[DEBUG] Loading Chunk Location table...", true, true, 2); console("[DEBUG] Loading Chunk Location table...", true, true, 2);
for($offset = 0; $offset < 0x1000; $offset += 4){ for($offset = 0; $offset < 0x1000; $offset += 4){
$data = Utils\Utils::readLInt(substr($this->raw, $offset, 4)); $data = Utils::readLInt(substr($this->raw, $offset, 4));
$sectors = $data & 0xff; $sectors = $data & 0xff;
if($sectors === 0){ if($sectors === 0){
continue; continue;
@ -99,14 +100,14 @@ class PocketChunkParser{
$chunk .= $data[$i]; $chunk .= $data[$i];
} }
} }
return Utils\Utils::writeLInt(strlen($chunk)).$chunk; return Utils::writeLInt(strlen($chunk)).$chunk;
} }
public function parseChunk($X, $Z){ public function parseChunk($X, $Z){
$X = (int) $X; $X = (int) $X;
$Z = (int) $Z; $Z = (int) $Z;
$offset = $this->getOffset($X, $Z); $offset = $this->getOffset($X, $Z);
$len = Utils\Utils::readLInt(substr($this->raw, $offset, 4)); $len = Utils::readLInt(substr($this->raw, $offset, 4));
$offset += 4; $offset += 4;
$chunk = array( $chunk = array(
0 => array(), //Block 0 => array(), //Block

View File

@ -21,12 +21,13 @@
namespace PocketMine\Level; namespace PocketMine\Level;
use PocketMine; use PocketMine;
use PocketMine\Math\Vector3 as Vector3;
class Position extends Math\Vector3{ class Position extends Vector3{
public $level; public $level;
public function __construct($x = 0, $y = 0, $z = 0, Level $level){ public function __construct($x = 0, $y = 0, $z = 0, Level $level){
if(($x instanceof Math\Vector3) === true){ if(($x instanceof Vector3) === true){
$this->__construct($x->x, $x->y, $x->z, $level); $this->__construct($x->x, $x->y, $x->z, $level);
}else{ }else{
$this->x = $x; $this->x = $x;

View File

@ -21,16 +21,21 @@
namespace PocketMine\Level; namespace PocketMine\Level;
use PocketMine; use PocketMine;
use PocketMine\Level\Generator\Generator as Generator;
use PocketMine\Utils\Utils as Utils;
use PocketMine\Utils\Random as Random;
use PocketMine\PMF\LevelFormat as LevelFormat;
use PocketMine\Utils\Config as Config;
class WorldGenerator{ class WorldGenerator{
private $seed, $level, $path, $random, $generator, $height; private $seed, $level, $path, $random, $generator, $height;
public function __construct(Generator\Generator $generator, $name, $seed = false, $height = 8){ public function __construct(Generator $generator, $name, $seed = false, $height = 8){
$this->seed = $seed !== false ? (int) $seed:Utils\Utils::readInt(Utils\Utils::getRandomBytes(4, false)); $this->seed = $seed !== false ? (int) $seed:Utils::readInt(Utils::getRandomBytes(4, false));
$this->random = new Utils\Random($this->seed); $this->random = new Random($this->seed);
$this->height = (int) $height; $this->height = (int) $height;
$this->path = \PocketMine\DATA."worlds/".$name."/"; $this->path = \PocketMine\DATA."worlds/".$name."/";
$this->generator = $generator; $this->generator = $generator;
$level = new PMF\LevelFormat($this->path."level.pmf", array( $level = new LevelFormat($this->path."level.pmf", array(
"name" => $name, "name" => $name,
"seed" => $this->seed, "seed" => $this->seed,
"time" => 0, "time" => 0,
@ -42,7 +47,7 @@ class WorldGenerator{
"generatorSettings" => $this->generator->getSettings(), "generatorSettings" => $this->generator->getSettings(),
"extra" => "" "extra" => ""
)); ));
$blockUpdates = new Utils\Config($this->path."bupdates.yml", Utils\Config::YAML); $blockUpdates = new Config($this->path."bupdates.yml", Config::YAML);
$this->level = new Level($level, $name); $this->level = new Level($level, $name);
} }

View File

@ -21,6 +21,20 @@
namespace PocketMine\Level\Generator; namespace PocketMine\Level\Generator;
use PocketMine; use PocketMine;
use PocketMine\Level\Generator\Populator\Ore as Ore;
use PocketMine\Block\CoalOre as CoalOre;
use PocketMine\Block\IronOre as IronOre;
use PocketMine\Block\RedstoneOre as RedstoneOre;
use PocketMine\Block\LapisOre as LapisOre;
use PocketMine\Block\GoldOre as GoldOre;
use PocketMine\Block\DiamondOre as DiamondOre;
use PocketMine\Block\Dirt as Dirt;
use PocketMine\Block\Gravel as Gravel;
use PocketMine\BlockAPI as BlockAPI;
use PocketMine\Level\Level as Level;
use PocketMine\Utils\Random as Random;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Level\Generator\Generator as Generator;
class Flat extends Generator{ class Flat extends Generator{
private $level, $random, $structure, $chunks, $options, $floorLevel, $preset, $populators = array(); private $level, $random, $structure, $chunks, $options, $floorLevel, $preset, $populators = array();
@ -42,16 +56,16 @@ class Flat extends Generator{
$this->parsePreset($this->preset); $this->parsePreset($this->preset);
} }
if(isset($this->options["decoration"])){ if(isset($this->options["decoration"])){
$ores = new Populator\Ore(); $ores = new Ore();
$ores->setOreTypes(array( $ores->setOreTypes(array(
new Object\Ore\Type(new Block\CoalOre(), 20, 16, 0, 128), new Object\Ore\Type(new CoalOre(), 20, 16, 0, 128),
new Object\Ore\Type(New Block\IronOre(), 20, 8, 0, 64), new Object\Ore\Type(New IronOre(), 20, 8, 0, 64),
new Object\Ore\Type(new Block\RedstoneOre(), 8, 7, 0, 16), new Object\Ore\Type(new RedstoneOre(), 8, 7, 0, 16),
new Object\Ore\Type(new Block\LapisOre(), 1, 6, 0, 32), new Object\Ore\Type(new LapisOre(), 1, 6, 0, 32),
new Object\Ore\Type(new Block\GoldOre(), 2, 8, 0, 32), new Object\Ore\Type(new GoldOre(), 2, 8, 0, 32),
new Object\Ore\Type(new Block\DiamondOre(), 1, 7, 0, 16), new Object\Ore\Type(new DiamondOre(), 1, 7, 0, 16),
new Object\Ore\Type(new Block\Dirt(), 20, 32, 0, 128), new Object\Ore\Type(new Dirt(), 20, 32, 0, 128),
new Object\Ore\Type(new Block\Gravel(), 10, 16, 0, 128), new Object\Ore\Type(new Gravel(), 10, 16, 0, 128),
)); ));
$this->populators[] = $ores; $this->populators[] = $ores;
} }
@ -121,7 +135,7 @@ class Flat extends Generator{
} }
} }
public function init(Level\Level $level, Utils\Random $random){ public function init(Level $level, Random $random){
$this->level = $level; $this->level = $level;
$this->random = $random; $this->random = $random;
} }
@ -140,7 +154,7 @@ class Flat extends Generator{
} }
public function getSpawn(){ public function getSpawn(){
return new Math\Vector3(128, $this->floorLevel, 128); return new Vector3(128, $this->floorLevel, 128);
} }
} }

View File

@ -21,6 +21,8 @@
namespace PocketMine\Level\Generator; namespace PocketMine\Level\Generator;
use PocketMine; use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Utils\Random as Random;
abstract class Generator{ abstract class Generator{
private static $list = array(); private static $list = array();
@ -42,7 +44,7 @@ abstract class Generator{
public abstract function __construct(array $settings = array()); public abstract function __construct(array $settings = array());
public abstract function init(Level\Level $level, Utils\Random $random); public abstract function init(Level $level, Random $random);
public abstract function generateChunk($chunkX, $chunkZ); public abstract function generateChunk($chunkX, $chunkZ);

View File

@ -21,6 +21,23 @@
namespace PocketMine\Level\Generator; namespace PocketMine\Level\Generator;
use PocketMine; use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Utils\Random as Random;
use PocketMine\Level\Generator\Noise\Simplex as Simplex;
use PocketMine\Level\Generator\Populator\Ore as Ore;
use PocketMine\Level\Generator\Object\OreType as OreType;
use PocketMine\Block\CoalOre as CoalOre;
use PocketMine\Block\IronOre as IronOre;
use PocketMine\Block\RedstoneOre as RedstoneOre;
use PocketMine\Block\LapisOre as LapisOre;
use PocketMine\Block\GoldOre as GoldOre;
use PocketMine\Block\DiamondOre as DiamondOre;
use PocketMine\Block\Dirt as Dirt;
use PocketMine\Block\Gravel as Gravel;
use PocketMine\Level\Generator\Populator\Tree as Tree;
use PocketMine\Level\Generator\Populator\TallGrass as TallGrass;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Level\Generator\Generator as Generator;
class Normal extends Generator{ class Normal extends Generator{
@ -46,35 +63,35 @@ class Normal extends Generator{
return array(); return array();
} }
public function init(Level\Level $level, Utils\Random $random){ public function init(Level $level, Random $random){
$this->level = $level; $this->level = $level;
$this->random = $random; $this->random = $random;
$this->random->setSeed($this->level->getSeed()); $this->random->setSeed($this->level->getSeed());
$this->noiseHills = new Noise\Simplex($this->random, 3); $this->noiseHills = new Simplex($this->random, 3);
$this->noisePatches = new Noise\Simplex($this->random, 2); $this->noisePatches = new Simplex($this->random, 2);
$this->noisePatchesSmall = new Noise\Simplex($this->random, 2); $this->noisePatchesSmall = new Simplex($this->random, 2);
$this->noiseBase = new Noise\Simplex($this->random, 16); $this->noiseBase = new Simplex($this->random, 16);
$ores = new Populator\Ore(); $ores = new Ore();
$ores->setOreTypes(array( $ores->setOreTypes(array(
new Object\OreType(new Block\CoalOre(), 20, 16, 0, 128), new OreType(new CoalOre(), 20, 16, 0, 128),
new Object\OreType(New Block\IronOre(), 20, 8, 0, 64), new OreType(New IronOre(), 20, 8, 0, 64),
new Object\OreType(new Block\RedstoneOre(), 8, 7, 0, 16), new OreType(new RedstoneOre(), 8, 7, 0, 16),
new Object\OreType(new Block\LapisOre(), 1, 6, 0, 32), new OreType(new LapisOre(), 1, 6, 0, 32),
new Object\OreType(new Block\GoldOre(), 2, 8, 0, 32), new OreType(new GoldOre(), 2, 8, 0, 32),
new Object\OreType(new Block\DiamondOre(), 1, 7, 0, 16), new OreType(new DiamondOre(), 1, 7, 0, 16),
new Object\OreType(new Block\Dirt(), 20, 32, 0, 128), new OreType(new Dirt(), 20, 32, 0, 128),
new Object\OreType(new Block\Gravel(), 10, 16, 0, 128), new OreType(new Gravel(), 10, 16, 0, 128),
)); ));
$this->populators[] = $ores; $this->populators[] = $ores;
$trees = new Populator\Tree(); $trees = new Tree();
$trees->setBaseAmount(3); $trees->setBaseAmount(3);
$trees->setRandomAmount(0); $trees->setRandomAmount(0);
$this->populators[] = $trees; $this->populators[] = $trees;
$tallGrass = new Populator\TallGrass(); $tallGrass = new TallGrass();
$tallGrass->setBaseAmount(5); $tallGrass->setBaseAmount(5);
$tallGrass->setRandomAmount(0); $tallGrass->setRandomAmount(0);
$this->populators[] = $tallGrass; $this->populators[] = $tallGrass;
@ -167,7 +184,7 @@ class Normal extends Generator{
} }
public function getSpawn(){ public function getSpawn(){
return $this->level->getSafeSpawn(new Math\Vector3(127.5, 128, 127.5)); return $this->level->getSafeSpawn(new Vector3(127.5, 128, 127.5));
} }
} }

View File

@ -21,6 +21,8 @@
namespace PocketMine\Level\Generator\Object; namespace PocketMine\Level\Generator\Object;
use PocketMine; use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Math\Vector3 as Vector3;
class BigTree extends Tree{ class BigTree extends Tree{
private $trunkHeightMultiplier = 0.618; private $trunkHeightMultiplier = 0.618;
@ -37,11 +39,11 @@ class BigTree extends Tree{
private $addLogVines = false; private $addLogVines = false;
private $addCocoaPlants = false; private $addCocoaPlants = false;
public function canPlaceObject(Level\Level $level, Math\Vector3 $pos){ public function canPlaceObject(Level $level, Vector3 $pos){
return false; return false;
} }
public function placeObject(Level\Level $level, Math\Vector3 $pos, $type){ public function placeObject(Level $level, Vector3 $pos, $type){
$this->trunkHeight = (int) ($this->totalHeight * $this->trunkHeightMultiplier); $this->trunkHeight = (int) ($this->totalHeight * $this->trunkHeightMultiplier);
$leaves = $this->getLeafGroupPoints($level, $pos); $leaves = $this->getLeafGroupPoints($level, $pos);

View File

@ -21,12 +21,16 @@
namespace PocketMine\Level\Generator\Object; namespace PocketMine\Level\Generator\Object;
use PocketMine; use PocketMine;
use PocketMine\Utils\Random as Random;
use PocketMine\Level\Level as Level;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Math\VectorMath as VectorMath;
class Ore{ class Ore{
private $random; private $random;
public $type; public $type;
public function __construct(Utils\Random $random, OreType $type){ public function __construct(Random $random, OreType $type){
$this->type = $type; $this->type = $type;
$this->random = $random; $this->random = $random;
} }
@ -35,14 +39,14 @@ class Ore{
return $this->type; return $this->type;
} }
public function canPlaceObject(Level\Level $level, $x, $y, $z){ public function canPlaceObject(Level $level, $x, $y, $z){
return ($level->level->getBlockID($x, $y, $z) != AIR); return ($level->level->getBlockID($x, $y, $z) != AIR);
} }
public function placeObject(Level\Level $level, Math\Vector3 $pos){ public function placeObject(Level $level, Vector3 $pos){
$clusterSize = (int) $this->type->clusterSize; $clusterSize = (int) $this->type->clusterSize;
$angle = $this->random->nextFloat() * M_PI; $angle = $this->random->nextFloat() * M_PI;
$offset = Math\VectorMath::getDirection2D($angle)->multiply($clusterSize)->divide(8); $offset = VectorMath::getDirection2D($angle)->multiply($clusterSize)->divide(8);
$x1 = $pos->x + 8 + $offset->x; $x1 = $pos->x + 8 + $offset->x;
$x2 = $pos->x + 8 - $offset->x; $x2 = $pos->x + 8 - $offset->x;
$z1 = $pos->z + 8 + $offset->y; $z1 = $pos->z + 8 + $offset->y;
@ -77,7 +81,7 @@ class Ore{
$sizeZ *= $sizeZ; $sizeZ *= $sizeZ;
if(($sizeX + $sizeY + $sizeZ) < 1 and $level->level->getBlockID($x, $y, $z) === STONE){ if(($sizeX + $sizeY + $sizeZ) < 1 and $level->level->getBlockID($x, $y, $z) === STONE){
$level->setBlockRaw(new Math\Vector3($x, $y, $z), $this->type->material); $level->setBlockRaw(new Vector3($x, $y, $z), $this->type->material);
} }
} }
} }

View File

@ -21,11 +21,12 @@
namespace PocketMine\Level\Generator\Object; namespace PocketMine\Level\Generator\Object;
use PocketMine; use PocketMine;
use PocketMine\Block\Block as Block;
class OreType{ class OreType{
public $material, $clusterCount, $clusterSize, $maxHeight, $minHeight; public $material, $clusterCount, $clusterSize, $maxHeight, $minHeight;
public function __construct(Block\Block $material, $clusterCount, $clusterSize, $minHeight, $maxHeight){ public function __construct(Block $material, $clusterCount, $clusterSize, $minHeight, $maxHeight){
$this->material = $material; $this->material = $material;
$this->clusterCount = (int) $clusterCount; $this->clusterCount = (int) $clusterCount;
$this->clusterSize = (int) $clusterSize; $this->clusterSize = (int) $clusterSize;

View File

@ -21,6 +21,12 @@
namespace PocketMine\Level\Generator\Object; namespace PocketMine\Level\Generator\Object;
use PocketMine; use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Utils\Random as Random;
use PocketMine\Block\Dirt as Dirt;
use PocketMine\Block\Leaves as Leaves;
use PocketMine\Block\Wood as Wood;
class PineTree extends Tree{ class PineTree extends Tree{
var $type = 1; var $type = 1;
@ -28,7 +34,7 @@ class PineTree extends Tree{
private $leavesSizeY = -1; private $leavesSizeY = -1;
private $leavesAbsoluteMaxRadius = -1; private $leavesAbsoluteMaxRadius = -1;
public function canPlaceObject(Level\Level $level, Math\Vector3 $pos, Random $random){ public function canPlaceObject(Level $level, Vector3 $pos, Random $random){
$this->findRandomLeavesSize($random); $this->findRandomLeavesSize($random);
$checkRadius = 0; $checkRadius = 0;
for($yy = 0; $yy < $this->totalHeight; ++$yy) { for($yy = 0; $yy < $this->totalHeight; ++$yy) {
@ -46,17 +52,17 @@ class PineTree extends Tree{
return true; return true;
} }
private function findRandomLeavesSize(Utils\Random $random){ private function findRandomLeavesSize(Random $random){
$this->totalHeight += $random->nextRange(-1, 2); $this->totalHeight += $random->nextRange(-1, 2);
$this->leavesSizeY = 1 + $random->nextRange(0, 2); $this->leavesSizeY = 1 + $random->nextRange(0, 2);
$this->leavesAbsoluteMaxRadius = 2 + $random->nextRange(0, 1); $this->leavesAbsoluteMaxRadius = 2 + $random->nextRange(0, 1);
} }
public function placeObject(Level\Level $level, Math\Vector3 $pos, Utils\Random $random){ public function placeObject(Level $level, Vector3 $pos, Random $random){
if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1) { if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1) {
$this->findRandomLeavesSize($random); $this->findRandomLeavesSize($random);
} }
$level->setBlockRaw(new Math\Vector3($pos->x, $pos->y - 1, $pos->z), new Block\Dirt()); $level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new Dirt());
$leavesRadius = 0; $leavesRadius = 0;
$leavesMaxRadius = 1; $leavesMaxRadius = 1;
$leavesBottomY = $this->totalHeight - $this->leavesSizeY; $leavesBottomY = $this->totalHeight - $this->leavesSizeY;
@ -66,7 +72,7 @@ class PineTree extends Tree{
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) { for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) {
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) { for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) {
if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) { if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) {
$level->setBlockRaw(new Math\Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz), new Block\Leaves($this->type)); $level->setBlockRaw(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz), new Leaves($this->type));
} }
} }
} }
@ -82,7 +88,7 @@ class PineTree extends Tree{
} }
$trunkHeightReducer = $random->nextRange(0, 3); $trunkHeightReducer = $random->nextRange(0, 3);
for($yy = 0; $yy < ($this->totalHeight - $trunkHeightReducer); ++$yy){ for($yy = 0; $yy < ($this->totalHeight - $trunkHeightReducer); ++$yy){
$level->setBlockRaw(new Math\Vector3($pos->x, $pos->y + $yy, $pos->z), new Block\Wood($this->type)); $level->setBlockRaw(new Vector3($pos->x, $pos->y + $yy, $pos->z), new Wood($this->type));
} }
} }

View File

@ -21,20 +21,24 @@
namespace PocketMine\Level\Generator\Object; namespace PocketMine\Level\Generator\Object;
use PocketMine; use PocketMine;
use PocketMine\Utils\Random as Random;
use PocketMine\Block\Block as Block;
use PocketMine\Level\Level as Level;
use PocketMine\Math\Vector3 as Vector3;
class Pond{ class Pond{
private $random; private $random;
public $type; public $type;
public function __construct(Utils\Random $random, Block\Block $type){ public function __construct(Random $random, Block $type){
$this->type = $type; $this->type = $type;
$this->random = $random; $this->random = $random;
} }
public function canPlaceObject(Level\Level $level, Math\Vector3 $pos){ public function canPlaceObject(Level $level, Vector3 $pos){
} }
public function placeObject(Level\Level $level, Math\Vector3 $pos){ public function placeObject(Level $level, Vector3 $pos){
} }
} }

View File

@ -21,6 +21,12 @@
namespace PocketMine\Level\Generator\Object; namespace PocketMine\Level\Generator\Object;
use PocketMine; use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Utils\Random as Random;
use PocketMine\Block\Dirt as Dirt;
use PocketMine\Block\Leaves as Leaves;
use PocketMine\Block\Wood as Wood;
class SmallTree extends Tree{ class SmallTree extends Tree{
public $type = 0; public $type = 0;
@ -32,7 +38,7 @@ class SmallTree extends Tree{
private $addLogVines = false; private $addLogVines = false;
private $addCocoaPlants = false; private $addCocoaPlants = false;
public function canPlaceObject(Level\Level $level, Math\Vector3 $pos, Utils\Random $random){ public function canPlaceObject(Level $level, Vector3 $pos, Random $random){
$radiusToCheck = 0; $radiusToCheck = 0;
for ($yy = 0; $yy < $this->trunkHeight + 3; ++$yy) { for ($yy = 0; $yy < $this->trunkHeight + 3; ++$yy) {
if($yy == 1 or $yy === $this->trunkHeight) { if($yy == 1 or $yy === $this->trunkHeight) {
@ -49,10 +55,10 @@ class SmallTree extends Tree{
return true; return true;
} }
public function placeObject(Level\Level $level, Math\Vector3 $pos, Utils\Random $random){ public function placeObject(Level $level, Vector3 $pos, Random $random){
// The base dirt block // The base dirt block
$dirtpos = new Math\Vector3( $pos->x, $pos->y - 1, $pos->z ); $dirtpos = new Vector3( $pos->x, $pos->y - 1, $pos->z );
$level->setBlockRaw( $dirtpos, new Block\Dirt() ); $level->setBlockRaw( $dirtpos, new Dirt() );
// Adjust the tree trunk's height randomly // Adjust the tree trunk's height randomly
// plot [-14:11] int( x / 8 ) + 5 // plot [-14:11] int( x / 8 ) + 5
@ -81,10 +87,10 @@ class SmallTree extends Tree{
{ {
if( sqrt(($xx * $xx) + ($zz * $zz)) <= $radius ) if( sqrt(($xx * $xx) + ($zz * $zz)) <= $radius )
{ {
$leafpos = new Math\Vector3( $pos->x + $xx, $leafpos = new Vector3( $pos->x + $xx,
$pos->y + $yy, $pos->y + $yy,
$pos->z + $zz ); $pos->z + $zz );
$level->setBlockRaw($leafpos, new Block\Leaves($this->type) ); $level->setBlockRaw($leafpos, new Leaves($this->type) );
} }
} }
} }
@ -94,8 +100,8 @@ class SmallTree extends Tree{
// Place the trunk last // Place the trunk last
if($leaflevel > 1) if($leaflevel > 1)
{ {
$trunkpos = new Math\Vector3( $pos->x, $pos->y + $yy, $pos->z ); $trunkpos = new Vector3( $pos->x, $pos->y + $yy, $pos->z );
$level->setBlockRaw($trunkpos, new Block\Wood($this->type)); $level->setBlockRaw($trunkpos, new Wood($this->type));
} }
} }
} }

View File

@ -21,6 +21,12 @@
namespace PocketMine\Level\Generator\Object; namespace PocketMine\Level\Generator\Object;
use PocketMine; use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Utils\Random as Random;
use PocketMine\Block\Dirt as Dirt;
use PocketMine\Block\Leaves as Leaves;
use PocketMine\Block\Wood as Wood;
class SpruceTree extends Tree{ class SpruceTree extends Tree{
var $type = 1; var $type = 1;
@ -28,7 +34,7 @@ class SpruceTree extends Tree{
private $leavesBottomY = -1; private $leavesBottomY = -1;
private $leavesMaxRadius = -1; private $leavesMaxRadius = -1;
public function canPlaceObject(Level\Level $level, Math\Vector3 $pos, Utils\Random $random){ public function canPlaceObject(Level $level, Vector3 $pos, Random $random){
$this->findRandomLeavesSize($random); $this->findRandomLeavesSize($random);
$checkRadius = 0; $checkRadius = 0;
for($yy = 0; $yy < $this->totalHeight + 2; ++$yy) { for($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
@ -46,23 +52,23 @@ class SpruceTree extends Tree{
return true; return true;
} }
private function findRandomLeavesSize(Utils\Random $random){ private function findRandomLeavesSize(Random $random){
$this->totalHeight += $random->nextRange(-1, 2); $this->totalHeight += $random->nextRange(-1, 2);
$this->leavesBottomY = (int) ($this->totalHeight - $random->nextRange(1, 2) - 3); $this->leavesBottomY = (int) ($this->totalHeight - $random->nextRange(1, 2) - 3);
$this->leavesMaxRadius = 1 + $random->nextRange(0, 1); $this->leavesMaxRadius = 1 + $random->nextRange(0, 1);
} }
public function placeObject(Level\Level $level, Math\Vector3 $pos, Utils\Random $random){ public function placeObject(Level $level, Vector3 $pos, Random $random){
if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) { if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) {
$this->findRandomLeavesSize($random); $this->findRandomLeavesSize($random);
} }
$level->setBlockRaw(new Math\Vector3($pos->x, $pos->y - 1, $pos->z), new Block\Dirt()); $level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new Dirt());
$leavesRadius = 0; $leavesRadius = 0;
for($yy = $this->totalHeight; $yy >= $this->leavesBottomY; --$yy){ for($yy = $this->totalHeight; $yy >= $this->leavesBottomY; --$yy){
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) { for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) {
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) { for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) {
if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) { if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) {
$level->setBlockRaw(new Math\Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz), new Block\Leaves($this->type)); $level->setBlockRaw(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz), new Leaves($this->type));
} }
} }
} }
@ -73,7 +79,7 @@ class SpruceTree extends Tree{
} }
} }
for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){ for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
$level->setBlockRaw(new Math\Vector3($pos->x, $pos->y + $yy, $pos->z), new Block\Wood($this->type)); $level->setBlockRaw(new Vector3($pos->x, $pos->y + $yy, $pos->z), new Wood($this->type));
} }
} }

View File

@ -22,9 +22,11 @@
namespace PocketMine\Level\Generator\Object; namespace PocketMine\Level\Generator\Object;
use PocketMine\Level; use PocketMine\Level;
use PocketMine; use PocketMine;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\BlockAPI as BlockAPI;
class TallGrass{ class TallGrass{
public static function growGrass(Level $level, Math\Vector3 $pos, Random $random, $count = 15, $radius = 10){ public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15, $radius = 10){
$arr = array( $arr = array(
BlockAPI::get(DANDELION, 0), BlockAPI::get(DANDELION, 0),
BlockAPI::get(CYAN_FLOWER, 0), BlockAPI::get(CYAN_FLOWER, 0),
@ -39,7 +41,7 @@ class TallGrass{
$z = $random->nextRange($pos->z - $radius, $pos->z + $radius); $z = $random->nextRange($pos->z - $radius, $pos->z + $radius);
if($level->level->getBlockID($x, $pos->y + 1, $z) === AIR and $level->level->getBlockID($x, $pos->y, $z) === GRASS){ if($level->level->getBlockID($x, $pos->y + 1, $z) === AIR and $level->level->getBlockID($x, $pos->y, $z) === GRASS){
$t = $arr[$random->nextRange(0, $arrC)]; $t = $arr[$random->nextRange(0, $arrC)];
$level->setBlockRaw(new Math\Vector3($x, $pos->y + 1, $z), $t); $level->setBlockRaw(new Vector3($x, $pos->y + 1, $z), $t);
} }
} }
} }

View File

@ -21,6 +21,9 @@
namespace PocketMine\Level\Generator\Object; namespace PocketMine\Level\Generator\Object;
use PocketMine; use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Block\Sapling as Sapling;
class Tree{ class Tree{
public $overridable = array( public $overridable = array(
@ -32,7 +35,7 @@ class Tree{
18 => true, 18 => true,
); );
public static function growTree(Level\Level $level, Math\Vector3 $pos, Level\Random $random, $type = 0){ public static function growTree(Level $level, Vector3 $pos, Level\Random $random, $type = 0){
switch($type & 0x03){ switch($type & 0x03){
case SaplingBlock::SPRUCE: case SaplingBlock::SPRUCE:
if($random->nextRange(0, 1) === 1){ if($random->nextRange(0, 1) === 1){
@ -43,11 +46,11 @@ class Tree{
break; break;
case SaplingBlock::BIRCH: case SaplingBlock::BIRCH:
$tree = new SmallTree(); $tree = new SmallTree();
$tree->type = Block\Sapling::BIRCH; $tree->type = Sapling::BIRCH;
break; break;
case SaplingBlock::JUNGLE: case SaplingBlock::JUNGLE:
$tree = new SmallTree(); $tree = new SmallTree();
$tree->type = Block\Sapling::JUNGLE; $tree->type = Sapling::JUNGLE;
break; break;
case SaplingBlock::OAK: case SaplingBlock::OAK:
default: default:

View File

@ -21,6 +21,8 @@
namespace PocketMine\Level\Generator\Populator; namespace PocketMine\Level\Generator\Populator;
use PocketMine; use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Utils\Random as Random;
class Mineshaft extends Populator{ class Mineshaft extends Populator{
private static $DISTANCE = 256; private static $DISTANCE = 256;
@ -29,7 +31,7 @@ class Mineshaft extends Populator{
private static $BASE_Y = 35; private static $BASE_Y = 35;
private static $RAND_Y = 11; private static $RAND_Y = 11;
public function populate(Level\Level $level, $chunkX, $chunkZ, Utils\Random $random){ public function populate(Level $level, $chunkX, $chunkZ, Random $random){
if($random->nextRange(0, self::$ODD) === 0){ if($random->nextRange(0, self::$ODD) === 0){
//$mineshaft = new Mineshaft($random); //$mineshaft = new Mineshaft($random);
} }

View File

@ -21,18 +21,22 @@
namespace PocketMine\Level\Generator\Populator; namespace PocketMine\Level\Generator\Populator;
use PocketMine; use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Utils\Random as Random;
use PocketMine\Level\Generator\Object\Ore as ObjectOre;
use PocketMine\Math\Vector3 as Vector3;
class Ore extends Populator{ class Ore extends Populator{
private $oreTypes = array(); private $oreTypes = array();
public function populate(Level\Level $level, $chunkX, $chunkZ, Utils\Random $random){ public function populate(Level $level, $chunkX, $chunkZ, Random $random){
foreach($this->oreTypes as $type){ foreach($this->oreTypes as $type){
$ore = new Level\Generator\Object\Ore($random, $type); $ore = new ObjectOre($random, $type);
for($i = 0; $i < $ore->type->clusterCount; ++$i){ for($i = 0; $i < $ore->type->clusterCount; ++$i){
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
$y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight); $y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight);
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15); $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
if($ore->canPlaceObject($level, $x, $y, $z)){ if($ore->canPlaceObject($level, $x, $y, $z)){
$ore->placeObject($level, new Math\Vector3($x, $y, $z)); $ore->placeObject($level, new Vector3($x, $y, $z));
} }
} }
} }

View File

@ -21,19 +21,23 @@
namespace PocketMine\Level\Generator\Populator; namespace PocketMine\Level\Generator\Populator;
use PocketMine; use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Utils\Random as Random;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Block\Water as Water;
class Pond extends Populator{ class Pond extends Populator{
private $waterOdd = 4; private $waterOdd = 4;
private $lavaOdd = 4; private $lavaOdd = 4;
private $lavaSurfaceOdd = 4; private $lavaSurfaceOdd = 4;
public function populate(Level\Level $level, $chunkX, $chunkZ, Utils\Random $random){ public function populate(Level $level, $chunkX, $chunkZ, Random $random){
if($random->nextRange(0, $this->waterOdd) === 0){ if($random->nextRange(0, $this->waterOdd) === 0){
$v = new Math\Vector3( $v = new Vector3(
$random->nextRange($chunkX << 4, ($chunkX << 4) + 16), $random->nextRange($chunkX << 4, ($chunkX << 4) + 16),
$random->nextRange(0, 128), $random->nextRange(0, 128),
$random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16) $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16)
); );
$pond = new Level\Genenerator\Object\Pond($random, new Block\Water()); $pond = new Level\Genenerator\Object\Pond($random, new Water());
if($pond->canPlaceObject($level, $v)){ if($pond->canPlaceObject($level, $v)){
$pond->placeObject($level, $v); $pond->placeObject($level, $v);
} }

View File

@ -21,7 +21,9 @@
namespace PocketMine\Level\Generator\Populator; namespace PocketMine\Level\Generator\Populator;
use PocketMine; use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Utils\Random as Random;
abstract class Populator{ abstract class Populator{
public abstract function populate(Level\Level $level, $chunkX, $chunkZ, Utils\Random $random); public abstract function populate(Level $level, $chunkX, $chunkZ, Random $random);
} }

View File

@ -21,6 +21,8 @@
namespace PocketMine\Level\Generator\Populator; namespace PocketMine\Level\Generator\Populator;
use PocketMine; use PocketMine;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Block\TallGrass as BlockTallGrass;
class TallGrass extends Populator{ class TallGrass extends Populator{
private $level; private $level;
@ -45,9 +47,9 @@ class TallGrass extends Populator{
$xx = $x - 7 + $random->nextRange(0, 15); $xx = $x - 7 + $random->nextRange(0, 15);
$zz = $z - 7 + $random->nextRange(0, 15); $zz = $z - 7 + $random->nextRange(0, 15);
$yy = $this->getHighestWorkableBlock($xx, $zz); $yy = $this->getHighestWorkableBlock($xx, $zz);
$vector = new Math\Vector3($xx, $yy, $zz); $vector = new Vector3($xx, $yy, $zz);
if($yy !== -1 and $this->canTallGrassStay($this->level->getBlockRaw($vector))){ if($yy !== -1 and $this->canTallGrassStay($this->level->getBlockRaw($vector))){
$this->level->setBlockRaw($vector, new Block\TallGrass(1)); $this->level->setBlockRaw($vector, new BlockTallGrass(1));
} }
} }
} }
@ -59,7 +61,7 @@ class TallGrass extends Populator{
private function getHighestWorkableBlock($x, $z){ private function getHighestWorkableBlock($x, $z){
for($y = 128; $y > 0; --$y){ for($y = 128; $y > 0; --$y){
$b = $this->level->getBlockRaw(new Math\Vector3($x, $y, $z)); $b = $this->level->getBlockRaw(new Vector3($x, $y, $z));
if($b->getID() === AIR or $b->getID() === LEAVES){ if($b->getID() === AIR or $b->getID() === LEAVES){
if(--$y <= 0){ if(--$y <= 0){
return -1; return -1;

View File

@ -21,6 +21,9 @@
namespace PocketMine\Level\Generator\Populator; namespace PocketMine\Level\Generator\Populator;
use PocketMine; use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Utils\Random as Random;
use PocketMine\Math\Vector3 as Vector3;
class Tree extends Populator{ class Tree extends Populator{
private $level; private $level;
@ -35,7 +38,7 @@ class Tree extends Populator{
$this->baseAmount = $amount; $this->baseAmount = $amount;
} }
public function populate(Level\Level $level, $chunkX, $chunkZ, Utils\Random $random){ public function populate(Level $level, $chunkX, $chunkZ, Random $random){
$this->level = $level; $this->level = $level;
$amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount; $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount;
for($i = 0; $i < $amount; ++$i){ for($i = 0; $i < $amount; ++$i){
@ -50,13 +53,13 @@ class Tree extends Populator{
}else{ }else{
$meta = SaplingBlock::OAK; $meta = SaplingBlock::OAK;
} }
TreeObject::growTree($this->level, new Math\Vector3($x, $y, $z), $random, $meta); TreeObject::growTree($this->level, new Vector3($x, $y, $z), $random, $meta);
} }
} }
private function getHighestWorkableBlock($x, $z){ private function getHighestWorkableBlock($x, $z){
for($y = 128; $y > 0; --$y){ for($y = 128; $y > 0; --$y){
$b = $this->level->getBlockRaw(new Math\Vector3($x, $y, $z)); $b = $this->level->getBlockRaw(new Vector3($x, $y, $z));
if($b->getID() !== DIRT and $b->getID() !== GRASS){ if($b->getID() !== DIRT and $b->getID() !== GRASS){
if(--$y <= 0){ if(--$y <= 0){
return -1; return -1;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Math; namespace PocketMine\Math;
use PocketMine; use PocketMine;
use PocketMine\Math\Vector3 as Vector3;
class AxisAlignedBB{ class AxisAlignedBB{
public $minX; public $minX;
@ -195,7 +196,7 @@ class AxisAlignedBB{
return $bb->maxZ > $this->minZ and $bb->minZ < $this->maxZ; return $bb->maxZ > $this->minZ and $bb->minZ < $this->maxZ;
} }
public function isVectorInside(Math\Vector3 $vector){ public function isVectorInside(Vector3 $vector){
if($vector->x <= $this->minX or $vector->x >= $this->maxX){ if($vector->x <= $this->minX or $vector->x >= $this->maxX){
return false; return false;
} }
@ -209,15 +210,15 @@ class AxisAlignedBB{
return ($this->maxX - $this->minX + $this->maxY - $this->minY + $this->maxZ - $this->minZ) / 3; return ($this->maxX - $this->minX + $this->maxY - $this->minY + $this->maxZ - $this->minZ) / 3;
} }
public function isVectorInYZ(Math\Vector3 $vector){ public function isVectorInYZ(Vector3 $vector){
return $vector->y >= $this->minY and $vector->y <= $this->maxY and $vector->z >= $this->minZ and $vector->z <= $this->maxZ; return $vector->y >= $this->minY and $vector->y <= $this->maxY and $vector->z >= $this->minZ and $vector->z <= $this->maxZ;
} }
public function isVectorInXZ(Math\Vector3 $vector){ public function isVectorInXZ(Vector3 $vector){
return $vector->x >= $this->minX and $vector->x <= $this->maxX and $vector->z >= $this->minZ and $vector->z <= $this->maxZ; return $vector->x >= $this->minX and $vector->x <= $this->maxX and $vector->z >= $this->minZ and $vector->z <= $this->maxZ;
} }
public function isVectorInXY(Math\Vector3 $vector){ public function isVectorInXY(Vector3 $vector){
return $vector->x >= $this->minX and $vector->x <= $this->maxX and $vector->y >= $this->minY and $vector->y <= $this->maxY; return $vector->x >= $this->minX and $vector->x <= $this->maxX and $vector->y >= $this->minY and $vector->y <= $this->maxY;
} }

View File

@ -21,6 +21,7 @@
namespace PocketMine\Math; namespace PocketMine\Math;
use PocketMine; use PocketMine;
use PocketMine\Math\Vector3 as Vector3;
class Vector2{ class Vector2{
public $x, $y; public $x, $y;
@ -52,7 +53,7 @@ class Vector2{
}else{ }else{
$this->x += $x; $this->x += $x;
$this->y += $y; $this->y += $y;
return new Math\Vector3($this->x + $x, $this->y + $y); return new Vector3($this->x + $x, $this->y + $y);
} }
} }

View File

@ -21,6 +21,7 @@
namespace PocketMine\Math; namespace PocketMine\Math;
use PocketMine; use PocketMine;
use PocketMine\Math\Vector3 as MathVector3;
class Vector3{ class Vector3{
public $x, $y, $z; public $x, $y, $z;
@ -76,15 +77,15 @@ class Vector3{
} }
public function add($x = 0, $y = 0, $z = 0){ public function add($x = 0, $y = 0, $z = 0){
if(($x instanceof Math\Vector3) === true){ if(($x instanceof MathVector3) === true){
return $this->add($x->x, $x->y, $x->z); return $this->add($x->x, $x->y, $x->z);
}else{ }else{
return new Math\Vector3($this->x + $x, $this->y + $y, $this->z + $z); return new MathVector3($this->x + $x, $this->y + $y, $this->z + $z);
} }
} }
public function subtract($x = 0, $y = 0, $z = 0){ public function subtract($x = 0, $y = 0, $z = 0){
if(($x instanceof Math\Vector3) === true){ if(($x instanceof MathVector3) === true){
return $this->add(-$x->x, -$x->y, -$x->z); return $this->add(-$x->x, -$x->y, -$x->z);
}else{ }else{
return $this->add(-$x, -$y, -$z); return $this->add(-$x, -$y, -$z);
@ -92,50 +93,50 @@ class Vector3{
} }
public function multiply($number){ public function multiply($number){
return new Math\Vector3($this->x * $number, $this->y * $number, $this->z * $number); return new MathVector3($this->x * $number, $this->y * $number, $this->z * $number);
} }
public function divide($number){ public function divide($number){
return new Math\Vector3($this->x / $number, $this->y / $number, $this->z / $number); return new MathVector3($this->x / $number, $this->y / $number, $this->z / $number);
} }
public function ceil(){ public function ceil(){
return new Math\Vector3((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1)); return new MathVector3((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1));
} }
public function floor(){ public function floor(){
return new Math\Vector3((int) $this->x, (int) $this->y, (int) $this->z); return new MathVector3((int) $this->x, (int) $this->y, (int) $this->z);
} }
public function round(){ public function round(){
return new Math\Vector3(round($this->x), round($this->y), round($this->z)); return new MathVector3(round($this->x), round($this->y), round($this->z));
} }
public function abs(){ public function abs(){
return new Math\Vector3(abs($this->x), abs($this->y), abs($this->z)); return new MathVector3(abs($this->x), abs($this->y), abs($this->z));
} }
public function getSide($side){ public function getSide($side){
switch((int) $side){ switch((int) $side){
case 0: case 0:
return new Math\Vector3($this->x, $this->y - 1, $this->z); return new MathVector3($this->x, $this->y - 1, $this->z);
case 1: case 1:
return new Math\Vector3($this->x, $this->y + 1, $this->z); return new MathVector3($this->x, $this->y + 1, $this->z);
case 2: case 2:
return new Math\Vector3($this->x, $this->y, $this->z - 1); return new MathVector3($this->x, $this->y, $this->z - 1);
case 3: case 3:
return new Math\Vector3($this->x, $this->y, $this->z + 1); return new MathVector3($this->x, $this->y, $this->z + 1);
case 4: case 4:
return new Math\Vector3($this->x - 1, $this->y, $this->z); return new MathVector3($this->x - 1, $this->y, $this->z);
case 5: case 5:
return new Math\Vector3($this->x + 1, $this->y, $this->z); return new MathVector3($this->x + 1, $this->y, $this->z);
default: default:
return $this; return $this;
} }
} }
public function distance($x = 0, $y = 0, $z = 0){ public function distance($x = 0, $y = 0, $z = 0){
if(($x instanceof Math\Vector3) === true){ if(($x instanceof MathVector3) === true){
return sqrt($this->distanceSquared($x->x, $x->y, $x->z)); return sqrt($this->distanceSquared($x->x, $x->y, $x->z));
}else{ }else{
return sqrt($this->distanceSquared($x, $y, $z)); return sqrt($this->distanceSquared($x, $y, $z));
@ -143,7 +144,7 @@ class Vector3{
} }
public function distanceSquared($x = 0, $y = 0, $z = 0){ public function distanceSquared($x = 0, $y = 0, $z = 0){
if(($x instanceof Math\Vector3) === true){ if(($x instanceof MathVector3) === true){
return $this->distanceSquared($x->x, $x->y, $x->z); return $this->distanceSquared($x->x, $x->y, $x->z);
}else{ }else{
return pow($this->x - $x, 2) + pow($this->y - $y, 2) + pow($this->z - $z, 2); return pow($this->x - $x, 2) + pow($this->y - $y, 2) + pow($this->z - $z, 2);
@ -151,7 +152,7 @@ class Vector3{
} }
public function maxPlainDistance($x = 0, $z = 0){ public function maxPlainDistance($x = 0, $z = 0){
if(($x instanceof Math\Vector3) === true){ if(($x instanceof MathVector3) === true){
return $this->maxPlainDistance($x->x, $x->z); return $this->maxPlainDistance($x->x, $x->z);
}else{ }else{
return max(abs($this->x - $x), abs($this->z - $z)); return max(abs($this->x - $x), abs($this->z - $z));
@ -171,15 +172,15 @@ class Vector3{
if($len != 0){ if($len != 0){
return $this->divide($len); return $this->divide($len);
} }
return new Math\Vector3(0, 0, 0); return new MathVector3(0, 0, 0);
} }
public function dot(Math\Vector3 $v){ public function dot(MathVector3 $v){
return $this->x * $v->x + $this->y * $v->y + $this->z * $v->z; return $this->x * $v->x + $this->y * $v->y + $this->z * $v->z;
} }
public function cross(Math\Vector3 $v){ public function cross(MathVector3 $v){
return new Math\Vector3( return new MathVector3(
$this->y * $v->z - $this->z * $v->y, $this->y * $v->z - $this->z * $v->y,
$this->z * $v->x - $this->x * $v->z, $this->z * $v->x - $this->x * $v->z,
$this->x * $v->y - $this->y * $v->x $this->x * $v->y - $this->y * $v->x

View File

@ -23,6 +23,19 @@ namespace PocketMine\NBT;
const LITTLE_ENDIAN = 0; const LITTLE_ENDIAN = 0;
const BIG_ENDIAN = 1; const BIG_ENDIAN = 1;
use PocketMine; use PocketMine;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\NBT\Tag\Byte as Byte;
use PocketMine\NBT\Tag\Short as Short;
use PocketMine\NBT\Tag\Int as Int;
use PocketMine\NBT\Tag\Long as Long;
use PocketMine\NBT\Tag\Float as Float;
use PocketMine\NBT\Tag\Double as Double;
use PocketMine\NBT\Tag\Byte_Array as Byte_Array;
use PocketMine\NBT\Tag\String as String;
use PocketMine\NBT\Tag\Enum as Enum;
use PocketMine\NBT\Tag\Int_Array as Int_Array;
use PocketMine\NBT\Tag\End as End;
use PocketMine\Utils\Utils as Utils;
class NBT implements \ArrayAccess{ class NBT implements \ArrayAccess{
private $buffer; private $buffer;
@ -67,7 +80,7 @@ class NBT implements \ArrayAccess{
public function write(){ public function write(){
$this->offset = 0; $this->offset = 0;
if($this->data instanceof NBT\Tag\Compound){ if($this->data instanceof Compound){
$this->writeTag($this->data); $this->writeTag($this->data);
return $this->buffer; return $this->buffer;
}else{ }else{
@ -78,57 +91,57 @@ class NBT implements \ArrayAccess{
public function readTag(){ public function readTag(){
switch($this->getByte()){ switch($this->getByte()){
case NBT\TAG_Byte: case NBT\TAG_Byte:
$tag = new NBT\Tag\Byte($this->getString()); $tag = new Byte($this->getString());
$tag->read($this); $tag->read($this);
break; break;
case NBT\TAG_Byte: case NBT\TAG_Byte:
$tag = new NBT\Tag\Byte($this->getString()); $tag = new Byte($this->getString());
$tag->read($this); $tag->read($this);
break; break;
case NBT\TAG_Short: case NBT\TAG_Short:
$tag = new NBT\Tag\Short($this->getString()); $tag = new Short($this->getString());
$tag->read($this); $tag->read($this);
break; break;
case NBT\TAG_Int: case NBT\TAG_Int:
$tag = new NBT\Tag\Int($this->getString()); $tag = new Int($this->getString());
$tag->read($this); $tag->read($this);
break; break;
case NBT\TAG_Long: case NBT\TAG_Long:
$tag = new NBT\Tag\Long($this->getString()); $tag = new Long($this->getString());
$tag->read($this); $tag->read($this);
break; break;
case NBT\TAG_Float: case NBT\TAG_Float:
$tag = new NBT\Tag\Float($this->getString()); $tag = new Float($this->getString());
$tag->read($this); $tag->read($this);
break; break;
case NBT\TAG_Double: case NBT\TAG_Double:
$tag = new NBT\Tag\Double($this->getString()); $tag = new Double($this->getString());
$tag->read($this); $tag->read($this);
break; break;
case NBT\TAG_Byte_Array: case NBT\TAG_Byte_Array:
$tag = new NBT\Tag\Byte_Array($this->getString()); $tag = new Byte_Array($this->getString());
$tag->read($this); $tag->read($this);
break; break;
case NBT\TAG_String: case NBT\TAG_String:
$tag = new NBT\Tag\String($this->getString()); $tag = new String($this->getString());
$tag->read($this); $tag->read($this);
break; break;
case NBT\TAG_Enum: case NBT\TAG_Enum:
$tag = new NBT\Tag\Enum($this->getString()); $tag = new Enum($this->getString());
$tag->read($this); $tag->read($this);
break; break;
case NBT\TAG_Compound: case NBT\TAG_Compound:
$tag = new NBT\Tag\Compound($this->getString()); $tag = new Compound($this->getString());
$tag->read($this); $tag->read($this);
break; break;
case NBT\TAG_Int_Array: case NBT\TAG_Int_Array:
$tag = new NBT\Tag\Int_Array($this->getString()); $tag = new Int_Array($this->getString());
$tag->read($this); $tag->read($this);
break; break;
case NBT\TAG_End: //No named tag case NBT\TAG_End: //No named tag
default: default:
$tag = new NBT\Tag\End; $tag = new End;
break; break;
} }
return $tag; return $tag;
@ -151,43 +164,43 @@ class NBT implements \ArrayAccess{
} }
public function getShort(){ public function getShort(){
return $this->endianness === self::BIG_ENDIAN ? Utils\Utils::readShort($this->get(2)) : Utils\Utils::readLShort($this->get(2)); return $this->endianness === self::BIG_ENDIAN ? Utils::readShort($this->get(2)) : Utils::readLShort($this->get(2));
} }
public function putShort($v){ public function putShort($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils\Utils::writeShort($v) : Utils\Utils::writeLShort($v); $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeShort($v) : Utils::writeLShort($v);
} }
public function getInt(){ public function getInt(){
return $this->endianness === self::BIG_ENDIAN ? Utils\Utils::readInt($this->get(4)) : Utils\Utils::readLInt($this->get(4)); return $this->endianness === self::BIG_ENDIAN ? Utils::readInt($this->get(4)) : Utils::readLInt($this->get(4));
} }
public function putInt($v){ public function putInt($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils\Utils::writeInt($v) : Utils\Utils::writeLInt($v); $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeInt($v) : Utils::writeLInt($v);
} }
public function getLong(){ public function getLong(){
return $this->endianness === self::BIG_ENDIAN ? Utils\Utils::readLong($this->get(8)) : Utils\Utils::readLLong($this->get(8)); return $this->endianness === self::BIG_ENDIAN ? Utils::readLong($this->get(8)) : Utils::readLLong($this->get(8));
} }
public function putLong($v){ public function putLong($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils\Utils::writeLong($v) : Utils\Utils::writeLLong($v); $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeLong($v) : Utils::writeLLong($v);
} }
public function getFloat(){ public function getFloat(){
return $this->endianness === self::BIG_ENDIAN ? Utils\Utils::readFloat($this->get(4)) : Utils\Utils::readLFloat($this->get(4)); return $this->endianness === self::BIG_ENDIAN ? Utils::readFloat($this->get(4)) : Utils::readLFloat($this->get(4));
} }
public function putFloat($v){ public function putFloat($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils\Utils::writeFloat($v) : Utils\Utils::writeLFloat($v); $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeFloat($v) : Utils::writeLFloat($v);
} }
public function getDouble(){ public function getDouble(){
return $this->endianness === self::BIG_ENDIAN ? Utils\Utils::readDouble($this->get(8)) : Utils\Utils::readLDouble($this->get(8)); return $this->endianness === self::BIG_ENDIAN ? Utils::readDouble($this->get(8)) : Utils::readLDouble($this->get(8));
} }
public function putDouble($v){ public function putDouble($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils\Utils::writeDouble($v) : Utils\Utils::writeLDouble($v); $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeDouble($v) : Utils::writeLDouble($v);
} }
public function getString(){ public function getString(){
@ -200,22 +213,22 @@ class NBT implements \ArrayAccess{
} }
public function &__get($name){ public function &__get($name){
$ret = $this->data instanceof NBT\Tag\Compound ? $this->data[$name] : false; $ret = $this->data instanceof Compound ? $this->data[$name] : false;
return $ret; return $ret;
} }
public function __set($name, $value){ public function __set($name, $value){
if($this->data instanceof NBT\Tag\Compound){ if($this->data instanceof Compound){
$this->data[$name] = $value; $this->data[$name] = $value;
} }
} }
public function __isset($name){ public function __isset($name){
return $this->data instanceof NBT\Tag\Compound ? isset($this->data[$name]) : false; return $this->data instanceof Compound ? isset($this->data[$name]) : false;
} }
public function __unset($name){ public function __unset($name){
if($this->data instanceof NBT\Tag\Compound){ if($this->data instanceof Compound){
unset($this->data[$name]); unset($this->data[$name]);
} }
} }
@ -240,7 +253,7 @@ class NBT implements \ArrayAccess{
return $this->data; return $this->data;
} }
public function setData(NBT\Tag\Compound $data){ public function setData(Compound $data){
$this->data = $data; $this->data = $data;
} }

View File

@ -22,6 +22,7 @@
namespace PocketMine\NBT\Tag; namespace PocketMine\NBT\Tag;
use PocketMine\NBT; use PocketMine\NBT;
use PocketMine; use PocketMine;
use PocketMine\NBT\Tag\End as End;
class Compound extends NamedNBTTag implements \ArrayAccess, \Iterator{ class Compound extends NamedNBTTag implements \ArrayAccess, \Iterator{
@ -101,18 +102,18 @@ class Compound extends NamedNBTTag implements \ArrayAccess, \Iterator{
$tag = $nbt->readTag(); $tag = $nbt->readTag();
if($tag instanceof NamedNBTTag and $tag->getName() !== ""){ if($tag instanceof NamedNBTTag and $tag->getName() !== ""){
$this->value[$tag->getName()] = $tag; $this->value[$tag->getName()] = $tag;
}elseif(!($tag instanceof NBT\Tag\End)){ }elseif(!($tag instanceof End)){
$this->value[] = $tag; $this->value[] = $tag;
} }
}while(!($tag instanceof NBT\Tag\End) and !$nbt->feof()); }while(!($tag instanceof End) and !$nbt->feof());
} }
public function write(NBT $nbt){ public function write(NBT $nbt){
foreach($this->value as $tag){ foreach($this->value as $tag){
if(!($tag instanceof NBT\Tag\End)){ if(!($tag instanceof End)){
$nbt->writeTag($tag); $nbt->writeTag($tag);
} }
} }
$nbt->writeTag(new NBT\Tag\End); $nbt->writeTag(new End);
} }
} }

View File

@ -22,6 +22,17 @@
namespace PocketMine\NBT\Tag; namespace PocketMine\NBT\Tag;
use PocketMine\NBT; use PocketMine\NBT;
use PocketMine; use PocketMine;
use PocketMine\NBT\Tag\Byte as Byte;
use PocketMine\NBT\Tag\Short as Short;
use PocketMine\NBT\Tag\Int as Int;
use PocketMine\NBT\Tag\Long as Long;
use PocketMine\NBT\Tag\Float as Float;
use PocketMine\NBT\Tag\Double as Double;
use PocketMine\NBT\Tag\Byte_Array as Byte_Array;
use PocketMine\NBT\Tag\String as String;
use PocketMine\NBT\Tag\Enum as TagEnum;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\NBT\Tag\Int_Array as Int_Array;
class Enum extends NamedNBTTag implements \ArrayAccess, \Iterator{ class Enum extends NamedNBTTag implements \ArrayAccess, \Iterator{
@ -108,62 +119,62 @@ class Enum extends NamedNBTTag implements \ArrayAccess, \Iterator{
for($i = 0; $i < $size and !$nbt->feof(); ++$i){ for($i = 0; $i < $size and !$nbt->feof(); ++$i){
switch($this->tagType){ switch($this->tagType){
case NBT\TAG_Byte: case NBT\TAG_Byte:
$tag = new NBT\Tag\Byte(false); $tag = new Byte(false);
$tag->read($nbt); $tag->read($nbt);
$this->value[] = $tag; $this->value[] = $tag;
break; break;
case NBT\TAG_Byte: case NBT\TAG_Byte:
$tag = new NBT\Tag\Byte(false); $tag = new Byte(false);
$tag->read($nbt); $tag->read($nbt);
$this->value[] = $tag; $this->value[] = $tag;
break; break;
case NBT\TAG_Short: case NBT\TAG_Short:
$tag = new NBT\Tag\Short(false); $tag = new Short(false);
$tag->read($nbt); $tag->read($nbt);
$this->value[] = $tag; $this->value[] = $tag;
break; break;
case NBT\TAG_Int: case NBT\TAG_Int:
$tag = new NBT\Tag\Int(false); $tag = new Int(false);
$tag->read($nbt); $tag->read($nbt);
$this->value[] = $tag; $this->value[] = $tag;
break; break;
case NBT\TAG_Long: case NBT\TAG_Long:
$tag = new NBT\Tag\Long(false); $tag = new Long(false);
$tag->read($nbt); $tag->read($nbt);
$this->value[] = $tag; $this->value[] = $tag;
break; break;
case NBT\TAG_Float: case NBT\TAG_Float:
$tag = new NBT\Tag\Float(false); $tag = new Float(false);
$tag->read($nbt); $tag->read($nbt);
$this->value[] = $tag; $this->value[] = $tag;
break; break;
case NBT\TAG_Double: case NBT\TAG_Double:
$tag = new NBT\Tag\Double(false); $tag = new Double(false);
$tag->read($nbt); $tag->read($nbt);
$this->value[] = $tag; $this->value[] = $tag;
break; break;
case NBT\TAG_Byte_Array: case NBT\TAG_Byte_Array:
$tag = new NBT\Tag\Byte_Array(false); $tag = new Byte_Array(false);
$tag->read($nbt); $tag->read($nbt);
$this->value[] = $tag; $this->value[] = $tag;
break; break;
case NBT\TAG_String: case NBT\TAG_String:
$tag = new NBT\Tag\String(false); $tag = new String(false);
$tag->read($nbt); $tag->read($nbt);
$this->value[] = $tag; $this->value[] = $tag;
break; break;
case NBT\TAG_Enum: case NBT\TAG_Enum:
$tag = new NBT\Tag\Enum(false); $tag = new TagEnum(false);
$tag->read($nbt); $tag->read($nbt);
$this->value[] = $tag; $this->value[] = $tag;
break; break;
case NBT\TAG_Compound: case NBT\TAG_Compound:
$tag = new NBT\Tag\Compound(false); $tag = new Compound(false);
$tag->read($nbt); $tag->read($nbt);
$this->value[] = $tag; $this->value[] = $tag;
break; break;
case NBT\TAG_Int_Array: case NBT\TAG_Int_Array:
$tag = new NBT\Tag\Int_Array(false); $tag = new Int_Array(false);
$tag->read($nbt); $tag->read($nbt);
$this->value[] = $tag; $this->value[] = $tag;
break; break;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network; namespace PocketMine\Network;
use PocketMine; use PocketMine;
use PocketMine\ServerAPI as ServerAPI;
class Handler{ class Handler{
public $bandwidth; public $bandwidth;

View File

@ -21,6 +21,8 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Utils\Utils as Utils;
use PocketMine\BlockAPI as BlockAPI;
abstract class DataPacket{ abstract class DataPacket{
private $offset = 0; private $offset = 0;
@ -75,52 +77,52 @@ abstract class DataPacket{
} }
protected function getLong($unsigned = false){ protected function getLong($unsigned = false){
return Utils\Utils::readLong($this->get(8), $unsigned); return Utils::readLong($this->get(8), $unsigned);
} }
protected function putLong($v){ protected function putLong($v){
$this->buffer .= Utils\Utils::writeLong($v); $this->buffer .= Utils::writeLong($v);
} }
protected function getInt(){ protected function getInt(){
return Utils\Utils::readInt($this->get(4)); return Utils::readInt($this->get(4));
} }
protected function putInt($v){ protected function putInt($v){
$this->buffer .= Utils\Utils::writeInt($v); $this->buffer .= Utils::writeInt($v);
} }
protected function getShort($unsigned = false){ protected function getShort($unsigned = false){
return Utils\Utils::readShort($this->get(2), $unsigned); return Utils::readShort($this->get(2), $unsigned);
} }
protected function putShort($v){ protected function putShort($v){
$this->buffer .= Utils\Utils::writeShort($v); $this->buffer .= Utils::writeShort($v);
} }
protected function getFloat(){ protected function getFloat(){
return Utils\Utils::readFloat($this->get(4)); return Utils::readFloat($this->get(4));
} }
protected function putFloat($v){ protected function putFloat($v){
$this->buffer .= Utils\Utils::writeFloat($v); $this->buffer .= Utils::writeFloat($v);
} }
protected function getTriad(){ protected function getTriad(){
return Utils\Utils::readTriad($this->get(3)); return Utils::readTriad($this->get(3));
} }
protected function putTriad($v){ protected function putTriad($v){
$this->buffer .= Utils\Utils::writeTriad($v); $this->buffer .= Utils::writeTriad($v);
} }
protected function getLTriad(){ protected function getLTriad(){
return Utils\Utils::readTriad(strrev($this->get(3))); return Utils::readTriad(strrev($this->get(3)));
} }
protected function putLTriad($v){ protected function putLTriad($v){
$this->buffer .= strrev(Utils\Utils::writeTriad($v)); $this->buffer .= strrev(Utils::writeTriad($v));
} }
protected function getByte(){ protected function getByte(){

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class AddEntityPacket extends DataPacket{ class AddEntityPacket extends DataPacket{
public $eid; public $eid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class AddItemEntityPacket extends DataPacket{ class AddItemEntityPacket extends DataPacket{
public $eid; public $eid;

View File

@ -21,6 +21,8 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
use PocketMine\Utils\Utils as Utils;
class AddMobPacket extends DataPacket{ class AddMobPacket extends DataPacket{
public $eid; public $eid;
@ -49,7 +51,7 @@ class AddMobPacket extends DataPacket{
$this->putFloat($this->z); $this->putFloat($this->z);
$this->putByte($this->yaw); $this->putByte($this->yaw);
$this->putByte($this->pitch); $this->putByte($this->pitch);
$this->put(Utils\Utils::writeMetadata($this->metadata)); $this->put(Utils::writeMetadata($this->metadata));
} }
} }

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class AddPaintingPacket extends DataPacket{ class AddPaintingPacket extends DataPacket{
public $eid; public $eid;

View File

@ -21,6 +21,8 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
use PocketMine\Utils\Utils as Utils;
class AddPlayerPacket extends DataPacket{ class AddPlayerPacket extends DataPacket{
public $clientID; public $clientID;
@ -55,7 +57,7 @@ class AddPlayerPacket extends DataPacket{
$this->putByte($this->pitch); $this->putByte($this->pitch);
$this->putShort($this->unknown1); $this->putShort($this->unknown1);
$this->putShort($this->unknown2); $this->putShort($this->unknown2);
$this->put(Utils\Utils::writeMetadata($this->metadata)); $this->put(Utils::writeMetadata($this->metadata));
} }
} }

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class AdventureSettingsPacket extends DataPacket{ class AdventureSettingsPacket extends DataPacket{
public $flags; public $flags;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class AnimatePacket extends DataPacket{ class AnimatePacket extends DataPacket{
public $action; public $action;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class ChatPacket extends DataPacket{ class ChatPacket extends DataPacket{
public $message; public $message;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class ChunkDataPacket extends DataPacket{ class ChunkDataPacket extends DataPacket{
public $chunkX; public $chunkX;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class ClientConnectPacket extends DataPacket{ class ClientConnectPacket extends DataPacket{
public $clientID; public $clientID;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class ClientHandshakePacket extends DataPacket{ class ClientHandshakePacket extends DataPacket{
public $cookie; public $cookie;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class ContainerClosePacket extends DataPacket{ class ContainerClosePacket extends DataPacket{
public $windowid; public $windowid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class ContainerOpenPacket extends DataPacket{ class ContainerOpenPacket extends DataPacket{
public $windowid; public $windowid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class ContainerSetContentPacket extends DataPacket{ class ContainerSetContentPacket extends DataPacket{
public $windowid; public $windowid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class ContainerSetDataPacket extends DataPacket{ class ContainerSetDataPacket extends DataPacket{
public $windowid; public $windowid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class ContainerSetSlotPacket extends DataPacket{ class ContainerSetSlotPacket extends DataPacket{
public $windowid; public $windowid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class DisconnectPacket extends DataPacket{ class DisconnectPacket extends DataPacket{
public function pid(){ public function pid(){

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class DropItemPacket extends DataPacket{ class DropItemPacket extends DataPacket{
public $eid; public $eid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class EntityDataPacket extends DataPacket{ class EntityDataPacket extends DataPacket{
public $x; public $x;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class EntityEventPacket extends DataPacket{ class EntityEventPacket extends DataPacket{
public $eid; public $eid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class ExplodePacket extends DataPacket{ class ExplodePacket extends DataPacket{
public $x; public $x;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class HurtArmorPacket extends DataPacket{ class HurtArmorPacket extends DataPacket{
public $health; public $health;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class InteractPacket extends DataPacket{ class InteractPacket extends DataPacket{
public $action; public $action;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class LevelEventPacket extends DataPacket{ class LevelEventPacket extends DataPacket{
public $evid; public $evid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class LoginPacket extends DataPacket{ class LoginPacket extends DataPacket{
public $username; public $username;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class LoginStatusPacket extends DataPacket{ class LoginStatusPacket extends DataPacket{
public $status; public $status;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class MessagePacket extends DataPacket{ class MessagePacket extends DataPacket{
public $source; public $source;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class MoveEntityPacket extends DataPacket{ class MoveEntityPacket extends DataPacket{

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class MoveEntityPacket_PosRot extends DataPacket{ class MoveEntityPacket_PosRot extends DataPacket{
public $eid; public $eid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class MovePlayerPacket extends DataPacket{ class MovePlayerPacket extends DataPacket{
public $eid; public $eid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class PingPacket extends DataPacket{ class PingPacket extends DataPacket{
public $time = 0; public $time = 0;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class PlayerActionPacket extends DataPacket{ class PlayerActionPacket extends DataPacket{
public $action; public $action;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class PlayerArmorEquipmentPacket extends DataPacket{ class PlayerArmorEquipmentPacket extends DataPacket{
public $eid; public $eid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class PlayerEquipmentPacket extends DataPacket{ class PlayerEquipmentPacket extends DataPacket{
public $eid; public $eid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class PongPacket extends DataPacket{ class PongPacket extends DataPacket{
public $time = 0; public $time = 0;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class ReadyPacket extends DataPacket{ class ReadyPacket extends DataPacket{
public $status; public $status;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class RemoveBlockPacket extends DataPacket{ class RemoveBlockPacket extends DataPacket{
public $eid; public $eid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class RemoveEntityPacket extends DataPacket{ class RemoveEntityPacket extends DataPacket{
public $eid; public $eid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class RemovePlayerPacket extends DataPacket{ class RemovePlayerPacket extends DataPacket{
public $eid; public $eid;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Network\Protocol; namespace PocketMine\Network\Protocol;
use PocketMine; use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class RequestChunkPacket extends DataPacket{ class RequestChunkPacket extends DataPacket{
public $chunkX; public $chunkX;

Some files were not shown because too many files have changed in this diff Show More