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;
use PocketMine\ServerAPI as ServerAPI;
abstract class Achievement{
public static $list = array(

View File

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

View File

@ -20,6 +20,16 @@
*/
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{
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])){
$classname = Block::$class[$id];
$b = new $classname($meta);
}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);
}
return $b;
@ -263,11 +273,11 @@ class BlockAPI{
public static function getItem($id, $meta = 0, $count = 1){
$id = (int) $id;
if(isset(Item\Item::$class[$id])){
$classname = Item\Item::$class[$id];
if(isset(Item::$class[$id])){
$classname = Item::$class[$id];
$i = new $classname($meta, $count);
}else{
$i = new Item\Item($id, $meta, $count);
$i = new Item($id, $meta, $count);
}
return $i;
}
@ -318,7 +328,7 @@ class BlockAPI{
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->x = $block->x;
$pk->y = $block->y;
@ -356,7 +366,7 @@ class BlockAPI{
return $this->cancelAction($target, $player, false);
}
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{
return $this->cancelAction($target, $player, false);
@ -453,16 +463,16 @@ class BlockAPI{
return $this->cancelAction($block, $player, false);
}
if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){
new Tile\Sign($player->level, new NBT\Tag\Compound(false, array(
"id" => new NBT\Tag\String("id", Tile::Sign),
"x" => new NBT\Tag\Int("x", $block->x),
"y" => new NBT\Tag\Int("y", $block->y),
"z" => new NBT\Tag\Int("z", $block->z),
"Text1" => new NBT\Tag\String("Text1", ""),
"Text2" => new NBT\Tag\String("Text2", ""),
"Text3" => new NBT\Tag\String("Text3", ""),
"Text4" => new NBT\Tag\String("Text4", ""),
"creator" => new NBT\Tag\String("creator", $player->getUsername())
new Sign($player->level, new Compound(false, array(
"id" => new String("id", Tile::Sign),
"x" => new Int("x", $block->x),
"y" => new Int("y", $block->y),
"z" => new Int("z", $block->z),
"Text1" => new String("Text1", ""),
"Text2" => new String("Text2", ""),
"Text3" => new String("Text3", ""),
"Text4" => new String("Text4", ""),
"creator" => new String("creator", $player->getUsername())
)));
}
@ -476,7 +486,7 @@ class BlockAPI{
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){
$this->scheduleBlockUpdate($pos->getSide(0), $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){
if(!($pos instanceof Block\Block)){
public function blockUpdate(Position $pos, $type = BLOCK_UPDATE_NORMAL){
if(!($pos instanceof Block)){
$block = $pos->level->getBlock($pos);
}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);
}
if($block === false){
@ -512,7 +522,7 @@ class BlockAPI{
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;
if($delay < 0){
return false;

View File

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

View File

@ -20,6 +20,9 @@
*/
namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Utils\TextFormat as TextFormat;
use PocketMine\Player as Player;
class ConsoleAPI{
private $loop, $server, $event, $help, $cmds, $alias;
@ -132,7 +135,7 @@ class ConsoleAPI{
$max = ceil(count($cmds) / 5);
$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;
foreach($cmds as $c => $h){
$curpage = (int) ceil($current / 5);
@ -179,9 +182,9 @@ class ConsoleAPI{
return $this->run($this->alias[$cmd] . ($params !== "" ? " " .$params:""), $issuer, $cmd);
}
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{
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){

View File

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

View File

@ -20,6 +20,27 @@
*/
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{
private $server, $levels, $default;
@ -94,12 +115,12 @@ class LevelAPI{
$generator = new $generator($options);
}else{
if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){
$generator = new Level\Generator\Flat($options);
$generator = new Flat($options);
}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->close();
return true;
@ -111,7 +132,7 @@ class LevelAPI{
}
$path = \PocketMine\DATA."worlds/".$name."/";
if($this->get($name) === false and !file_exists($path."level.pmf")){
$level = new Level\LevelImport($path);
$level = new LevelImport($path);
if($level->import() === false){
return false;
}
@ -119,7 +140,7 @@ class LevelAPI{
return true;
}
public function unloadLevel(Level\Level $level, $force = false){
public function unloadLevel(Level $level, $force = false){
$name = $level->getName();
if($name === $this->default and $force !== true){
return false;
@ -144,17 +165,17 @@ class LevelAPI{
}
$path = \PocketMine\DATA."worlds/".$name."/";
console("[INFO] Preparing level \"".$name."\"");
$level = new PMF\LevelFormat($path."level.pmf");
$level = new LevelFormat($path."level.pmf");
if(!$level->isLoaded){
console("[ERROR] Could not load level \"".$name."\"");
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")){
@rename($path."tileEntities.yml", $path."tiles.yml");
}
$blockUpdates = new Utils\Config($path."bupdates.yml", Utils\Config::YAML);
$this->levels[$name] = new Level\Level($level, $name);
$blockUpdates = new Config($path."bupdates.yml", Config::YAML);
$this->levels[$name] = new Level($level, $name);
/*foreach($entities->getAll() as $entity){
if(!isset($entity["id"])){
break;
@ -171,39 +192,39 @@ class LevelAPI{
));
}elseif($entity["id"] === FALLING_SAND){
$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"]);
}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->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);
}else{
$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"]);
}
}*/
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){
if(!isset($tile["id"])){
continue;
}
$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){
switch($index){
case "Items":
$tag = new NBT\Tag\Enum("Items", array());
$tag = new Enum("Items", array());
$tag->setTagType(NBT\TAG_Compound);
foreach($data as $slot => $fields){
$tag[(int) $slot] = new NBT\Tag\Compound(false, array(
"Count" => new NBT\Tag\Byte("Count", $fields["Count"]),
"Slot" => new NBT\Tag\Short("Slot", $fields["Slot"]),
"Damage" => new NBT\Tag\Short("Damage", $fields["Damage"]),
"id" => new NBT\Tag\String("id", $fields["id"])
$tag[(int) $slot] = new Compound(false, array(
"Count" => new Byte("Count", $fields["Count"]),
"Slot" => new Short("Slot", $fields["Slot"]),
"Damage" => new Short("Damage", $fields["Damage"]),
"id" => new String("id", $fields["id"])
));
}
$nbt["Items"] = $tag;
@ -214,7 +235,7 @@ class LevelAPI{
case "Text2":
case "Text3":
case "Text4":
$nbt[$index] = new NBT\Tag\String($index, $data);
$nbt[$index] = new String($index, $data);
break;
case "x":
@ -222,25 +243,25 @@ class LevelAPI{
case "z":
case "pairx":
case "pairz":
$nbt[$index] = new NBT\Tag\Int($index, $data);
$nbt[$index] = new Int($index, $data);
break;
case "BurnTime":
case "CookTime":
case "MaxTime":
$nbt[$index] = new NBT\Tag\Short($index, $data);
$nbt[$index] = new Short($index, $data);
break;
}
}
switch($tile["id"]){
case Tile\Tile::FURNACE:
new Tile\Furnace($this->levels[$name], $nbt);
case Tile::FURNACE:
new Furnace($this->levels[$name], $nbt);
break;
case Tile\Tile::CHEST:
new Tile\Chest($this->levels[$name], $nbt);
case Tile::CHEST:
new Chest($this->levels[$name], $nbt);
break;
case Tile\Tile::SIGN:
new Tile\Sign($this->levels[$name], $nbt);
case Tile::SIGN:
new Sign($this->levels[$name], $nbt);
break;
}
}
@ -249,7 +270,7 @@ class LevelAPI{
}
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;
}

View File

@ -20,8 +20,44 @@
*/
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();
private $recoveryQueue = array();
@ -113,44 +149,44 @@ class Player extends Entity\RealHuman{
$server = ServerAPI::request();
$iname = strtolower($name);
if(!file_exists(\PocketMine\DATA."players/".$iname.".dat")){
$nbt = new NBT\Tag\Compound(false, array(
"Pos" => new NBT\Tag\Enum("Pos", array(
0 => new NBT\Tag\Double(0, $server->spawn->x),
1 => new NBT\Tag\Double(1, $server->spawn->y),
2 => new NBT\Tag\Double(2, $server->spawn->z)
$nbt = new Compound(false, array(
"Pos" => new Enum("Pos", array(
0 => new Double(0, $server->spawn->x),
1 => new Double(1, $server->spawn->y),
2 => new Double(2, $server->spawn->z)
)),
"Level" => new NBT\Tag\String("Level", $server->spawn->level->getName()),
"SpawnLevel" => new NBT\Tag\String("SpawnLevel", $server->spawn->level->getName()),
"SpawnX" => new NBT\Tag\Int("SpawnX", (int) $server->spawn->x),
"SpawnY" => new NBT\Tag\Int("SpawnY", (int) $server->spawn->y),
"SpawnZ" => new NBT\Tag\Int("SpawnZ", (int) $server->spawn->z),
"SpawnForced" => new NBT\Tag\Byte("SpawnForced", 1), //TODO
"Inventory" => new NBT\Tag\Enum("Inventory", array()),
"Achievements" => new NBT\Tag\Compound("Achievements", array()),
"playerGameType" => new NBT\Tag\Int("playerGameType", $server->gamemode),
"Motion" => new NBT\Tag\Enum("Motion", array(
0 => new NBT\Tag\Double(0, 0.0),
1 => new NBT\Tag\Double(1, 0.0),
2 => new NBT\Tag\Double(2, 0.0)
"Level" => new String("Level", $server->spawn->level->getName()),
"SpawnLevel" => new String("SpawnLevel", $server->spawn->level->getName()),
"SpawnX" => new Int("SpawnX", (int) $server->spawn->x),
"SpawnY" => new Int("SpawnY", (int) $server->spawn->y),
"SpawnZ" => new Int("SpawnZ", (int) $server->spawn->z),
"SpawnForced" => new Byte("SpawnForced", 1), //TODO
"Inventory" => new Enum("Inventory", array()),
"Achievements" => new Compound("Achievements", array()),
"playerGameType" => new Int("playerGameType", $server->gamemode),
"Motion" => new Enum("Motion", array(
0 => new Double(0, 0.0),
1 => new Double(1, 0.0),
2 => new Double(2, 0.0)
)),
"Rotation" => new NBT\Tag\Enum("Rotation", array(
0 => new NBT\Tag\Float(0, 0.0),
1 => new NBT\Tag\Float(1, 0.0)
"Rotation" => new Enum("Rotation", array(
0 => new Float(0, 0.0),
1 => new Float(1, 0.0)
)),
"FallDistance" => new NBT\Tag\Float("FallDistance", 0.0),
"Fire" => new NBT\Tag\Short("Fire", 0),
"Air" => new NBT\Tag\Short("Air", 0),
"OnGround" => new NBT\Tag\Byte("OnGround", 1),
"Invulnerable" => new NBT\Tag\Byte("Invulnerable", 0),
"FallDistance" => new Float("FallDistance", 0.0),
"Fire" => new Short("Fire", 0),
"Air" => new Short("Air", 0),
"OnGround" => new Byte("OnGround", 1),
"Invulnerable" => new Byte("Invulnerable", 0),
"NameTag" => new NBT\Tag\String("NameTag", $name),
"NameTag" => new String("NameTag", $name),
));
$nbt->Pos->setTagType(NBT\TAG_Double);
$nbt->Inventory->setTagType(NBT\TAG_Compound);
$nbt->Motion->setTagType(NBT\TAG_Double);
$nbt->Rotation->setTagType(NBT\TAG_Float);
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->Level = $data->get("position")["level"];
$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");
foreach($data->get("inventory") as $slot => $item){
if(count($item) === 3){
$nbt->Inventory[$slot + 9] = new NBT\Tag\Compound(false, array(
"id" => new NBT\Tag\Short("id", $item[0]),
"Damage" => new NBT\Tag\Short("Damage", $item[1]),
"Count" => new NBT\Tag\Byte("Count", $item[2]),
"Slot" => new NBT\Tag\Byte("Slot", $slot + 9),
"TrueSlot" => new NBT\Tag\Byte("TrueSlot", $slot + 9)
$nbt->Inventory[$slot + 9] = new Compound(false, array(
"id" => new Short("id", $item[0]),
"Damage" => new Short("Damage", $item[1]),
"Count" => new Byte("Count", $item[2]),
"Slot" => new Byte("Slot", $slot + 9),
"TrueSlot" => new Byte("TrueSlot", $slot + 9)
));
}
}
foreach($data->get("hotbar") as $slot => $itemSlot){
if(isset($nbt->Inventory[$itemSlot + 9])){
$item = $nbt->Inventory[$itemSlot + 9];
$nbt->Inventory[$slot] = new NBT\Tag\Compound(false, array(
"id" => new NBT\Tag\Short("id", $item->id),
"Damage" => new NBT\Tag\Short("Damage", $item->Damage),
"Count" => new NBT\Tag\Byte("Count", $item->Count),
"Slot" => new NBT\Tag\Byte("Slot", $slot),
"TrueSlot" => new NBT\Tag\Byte("TrueSlot", $item->TrueSlot)
$nbt->Inventory[$slot] = new Compound(false, array(
"id" => new Short("id", $item->id),
"Damage" => new Short("Damage", $item->Damage),
"Count" => new Byte("Count", $item->Count),
"Slot" => new Byte("Slot", $slot),
"TrueSlot" => new Byte("TrueSlot", $item->TrueSlot)
));
}
}
foreach($data->get("armor") as $slot => $item){
if(count($item) === 2){
$nbt->Inventory[$slot + 100] = new NBT\Tag\Compound(false, array(
"id" => new NBT\Tag\Short("id", $item[0]),
"Damage" => new NBT\Tag\Short("Damage", $item[1]),
"Count" => new NBT\Tag\Byte("Count", 1),
"Slot" => new NBT\Tag\Byte("Slot", $slot + 100)
$nbt->Inventory[$slot + 100] = new Compound(false, array(
"id" => new Short("id", $item[0]),
"Damage" => new Short("Damage", $item[1]),
"Count" => new Byte("Count", 1),
"Slot" => new Byte("Slot", $slot + 100)
));
}
}
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");
}else{
@ -214,14 +250,14 @@ class Player extends Entity\RealHuman{
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);
$nbt = new NBT(NBT\BIG_ENDIAN);
$nbt->setData($nbtTag);
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){
$player->dataPacket(clone $packet);
}
@ -280,7 +316,7 @@ class Player extends Entity\RealHuman{
}
public function isSleeping(){
return $this->sleeping instanceof Math\Vector3;
return $this->sleeping instanceof Vector3;
}
public function setChunkIndex($index, $flags){
@ -314,7 +350,7 @@ class Player extends Entity\RealHuman{
$this->slot = 0;
$this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1);
$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->server->schedule(2, array($this, "handlePacketQueues"), 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){
if(!($pos instanceof Level\Position)){
public function setSpawn(Vector3 $pos){
if(!($pos instanceof Position)){
$level = $this->level;
}else{
$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->x = (int) $this->spawnPosition->x;
$pk->y = (int) $this->spawnPosition->y;
@ -359,7 +395,7 @@ class Player extends Entity\RealHuman{
for($X = $startX; $X <= $finalX; ++$X){
for($Z = $startZ; $Z <= $finalZ; ++$Z){
$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){
$newOrder[$index] = $distance;
}
@ -370,7 +406,7 @@ class Player extends Entity\RealHuman{
$this->chunksOrder = $newOrder;
$index = key($this->chunksOrder);
PMF\LevelFormat::getXZ($index, $X, $Z);
LevelFormat::getXZ($index, $X, $Z);
$this->level->loadChunk($X, $Z);
if(!$this->level->isChunkPopulated($X, $Z)){
$this->level->loadChunk($X - 1, $Z);
@ -387,7 +423,7 @@ class Player extends Entity\RealHuman{
if($Yndex !== 0xff){
$X = null;
$Z = null;
PMF\LevelFormat::getXZ($index, $X, $Z);
LevelFormat::getXZ($index, $X, $Z);
foreach($this->level->getChunkEntities($X, $Z) as $entity){
if($entity !== $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){
if($tile instanceof Tile\Spawnable){
if($tile instanceof Spawnable){
$tile->spawnTo($this);
}
}
@ -446,7 +482,7 @@ class Player extends Entity\RealHuman{
}
$X = null;
$Z = null;
PMF\LevelFormat::getXZ($index, $X, $Z);
LevelFormat::getXZ($index, $X, $Z);
if(!$this->level->isChunkPopulated($X, $Z)){
$this->orderChunks();
if($this->chunkScheduled === 0 or $force === true){
@ -493,7 +529,7 @@ class Player extends Entity\RealHuman{
$this->namedtag->SpawnZ = (int) $this->spawnPosition->z;
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;
@ -528,14 +564,14 @@ class Player extends Entity\RealHuman{
$this->receiveQueue = array();
$this->resendQueue = 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);
}
if($msg === true and $this->username != "" and $this->spawned !== false){
$this->server->api->chat->broadcast($this->username." left the game");
}
$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->armor = array();
$this->inventory = array();
@ -549,20 +585,20 @@ class Player extends Entity\RealHuman{
}
/**
* @param Math\Vector3 $pos
* @param Vector3 $pos
*
* @return boolean
*/
public function sleepOn(Math\Vector3 $pos){
public function sleepOn(Vector3 $pos){
foreach($this->level->getPlayers() as $p){
if($p->sleeping instanceof Math\Vector3){
if($p->sleeping instanceof Vector3){
if($pos->distance($p->sleeping) <= 0.1){
return false;
}
}
}
$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){
$this->updateMetadata();
}*/
@ -623,7 +659,7 @@ class Player extends Entity\RealHuman{
switch($event){
case "tile.update":
if($data->level === $this->level){
if($data instanceof Tile\Furnace){
if($data instanceof Furnace){
foreach($this->windows as $id => $w){
if($w === $data){
$pk = new Network\Protocol\ContainerSetDataPacket;
@ -758,7 +794,7 @@ class Player extends Entity\RealHuman{
if($m !== ""){
$pk = new Network\Protocol\MessagePacket;
$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);
}
}
@ -825,7 +861,7 @@ class Player extends Entity\RealHuman{
$craftItem = array(0, true, 0);
unset($craft[-1]);
foreach($craft as $slot => $item){
if($item instanceof Item\Item){
if($item instanceof Item){
$craftItem[0] = $item->getID();
if($item->getMetadata() !== $craftItem[1] and $craftItem[1] !== true){
$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){
$res2 = Recipes\Crafting::canCraft($craftItem, $recipeItems, 0);
$res2 = Crafting::canCraft($craftItem, $recipeItems, 0);
if(is_array($res2)){
$res = $res2;
}
@ -1023,7 +1059,7 @@ class Player extends Entity\RealHuman{
$safeCount = (int) (($this->MTU - 1) / 4);
$packetCnt = (int) ($ackCnt / $safeCount + 1);
for($p = 0; $p < $packetCnt; ++$p){
$pk = new Network\RakNet\Packet(Network\RakNet\Info::ACK);
$pk = new Packet(Info::ACK);
$pk->packets = array();
for($c = 0; $c < $safeCount; ++$c){
if(($k = array_pop($this->ackQueue)) === null){
@ -1041,7 +1077,7 @@ class Player extends Entity\RealHuman{
foreach($this->receiveQueue as $count => $packets){
unset($this->receiveQueue[$count]);
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($p->messageIndex > $this->receiveCount){
$this->receiveCount = $p->messageIndex;
@ -1051,12 +1087,12 @@ class Player extends Entity\RealHuman{
}
switch($p->pid()){
case 0x01:
case Network\Protocol\Info::PING_PACKET:
case Network\Protocol\Info::PONG_PACKET:
case Network\Protocol\Info::MOVE_PLAYER_PACKET:
case Network\Protocol\Info::REQUEST_CHUNK_PACKET:
case Network\Protocol\Info::ANIMATE_PACKET:
case Network\Protocol\Info::SET_HEALTH_PACKET:
case ProtocolInfo::PING_PACKET:
case ProtocolInfo::PONG_PACKET:
case ProtocolInfo::MOVE_PLAYER_PACKET:
case ProtocolInfo::REQUEST_CHUNK_PACKET:
case ProtocolInfo::ANIMATE_PACKET:
case ProtocolInfo::SET_HEALTH_PACKET:
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){
$this->timeout = microtime(true) + 20;
switch($packet->pid()){
case Network\RakNet\Info::NACK:
case Info::NACK:
foreach($packet->packets as $count){
if(isset($this->recoveryQueue[$count])){
$this->resendQueue[$count] =& $this->recoveryQueue[$count];
@ -1112,7 +1148,7 @@ class Player extends Entity\RealHuman{
}
break;
case Network\RakNet\Info::ACK:
case Info::ACK:
foreach($packet->packets as $count){
if(isset($this->recoveryQueue[$count])){
$this->lag[] = microtime(true) - $this->recoveryQueue[$count]->sendtime;
@ -1123,22 +1159,22 @@ class Player extends Entity\RealHuman{
}
break;
case Network\RakNet\Info::DATA_PACKET_0:
case Network\RakNet\Info::DATA_PACKET_1:
case Network\RakNet\Info::DATA_PACKET_2:
case Network\RakNet\Info::DATA_PACKET_3:
case Network\RakNet\Info::DATA_PACKET_4:
case Network\RakNet\Info::DATA_PACKET_5:
case Network\RakNet\Info::DATA_PACKET_6:
case Network\RakNet\Info::DATA_PACKET_7:
case Network\RakNet\Info::DATA_PACKET_8:
case Network\RakNet\Info::DATA_PACKET_9:
case Network\RakNet\Info::DATA_PACKET_A:
case Network\RakNet\Info::DATA_PACKET_B:
case Network\RakNet\Info::DATA_PACKET_C:
case Network\RakNet\Info::DATA_PACKET_D:
case Network\RakNet\Info::DATA_PACKET_E:
case Network\RakNet\Info::DATA_PACKET_F:
case Info::DATA_PACKET_0:
case Info::DATA_PACKET_1:
case Info::DATA_PACKET_2:
case Info::DATA_PACKET_3:
case Info::DATA_PACKET_4:
case Info::DATA_PACKET_5:
case Info::DATA_PACKET_6:
case Info::DATA_PACKET_7:
case Info::DATA_PACKET_8:
case Info::DATA_PACKET_9:
case Info::DATA_PACKET_A:
case Info::DATA_PACKET_B:
case Info::DATA_PACKET_C:
case Info::DATA_PACKET_D:
case Info::DATA_PACKET_E:
case Info::DATA_PACKET_F:
$this->ackQueue[] = $packet->seqNumber;
$this->receiveQueue[$packet->seqNumber] = array();
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){
return;
}
if(Event\EventHandler::callEvent(new Event\Server\DataPacketReceiveEvent($this, $packet)) === Event\Event::DENY){
if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === Event::DENY){
return;
}
switch($packet->pid()){
case 0x01:
break;
case Network\Protocol\Info::PONG_PACKET:
case ProtocolInfo::PONG_PACKET:
break;
case Network\Protocol\Info::PING_PACKET:
case ProtocolInfo::PING_PACKET:
$pk = new Network\Protocol\PongPacket;
$pk->ptime = $packet->time;
$pk->time = abs(microtime(true) * 1000);
$this->directDataPacket($pk);
break;
case Network\Protocol\Info::DISCONNECT_PACKET:
case ProtocolInfo::DISCONNECT_PACKET:
$this->close("client disconnect");
break;
case Network\Protocol\Info::CLIENT_CONNECT_PACKET:
case ProtocolInfo::CLIENT_CONNECT_PACKET:
if($this->loggedIn === true){
break;
}
$pk = new Network\Protocol\ServerHandshakePacket;
$pk->port = $this->port;
$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);
break;
case Network\Protocol\Info::CLIENT_HANDSHAKE_PACKET:
case ProtocolInfo::CLIENT_HANDSHAKE_PACKET:
if($this->loggedIn === true){
break;
}
break;
case Network\Protocol\Info::LOGIN_PACKET:
case ProtocolInfo::LOGIN_PACKET:
if($this->loggedIn === true){
break;
}
@ -1198,8 +1234,8 @@ class Player extends Entity\RealHuman{
$this->close("server is full!", false);
return;
}
if($packet->protocol1 !== Network\Protocol\Info::CURRENT_PROTOCOL){
if($packet->protocol1 < Network\Protocol\Info::CURRENT_PROTOCOL){
if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){
if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){
$pk = new Network\Protocol\LoginStatusPacket;
$pk->status = 1;
$this->directDataPacket($pk);
@ -1254,7 +1290,7 @@ class Player extends Entity\RealHuman{
return;
}
if(!($nbt instanceof NBT\Tag\Compound)){
if(!($nbt instanceof Compound)){
$this->close("no config created", false);
return;
}
@ -1292,7 +1328,7 @@ class Player extends Entity\RealHuman{
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->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->lastMeasure = microtime(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;
case Network\Protocol\Info::READY_PACKET:
case ProtocolInfo::READY_PACKET:
if($this->loggedIn === false){
break;
}
@ -1337,7 +1373,7 @@ class Player extends Entity\RealHuman{
$pk->started = $this->level->stopTime == false;
$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);
$this->teleport($pos);
$this->sendBuffer();
@ -1347,20 +1383,20 @@ class Player extends Entity\RealHuman{
break;
}
break;
case Network\Protocol\Info::ROTATE_HEAD_PACKET:
case ProtocolInfo::ROTATE_HEAD_PACKET:
if($this->spawned === false){
break;
}
$this->setRotation($packet->yaw, $this->pitch);
break;
case Network\Protocol\Info::MOVE_PLAYER_PACKET:
case ProtocolInfo::MOVE_PLAYER_PACKET:
if($this->spawned === false){
break;
}
if($packet->messageIndex > $this->lastMovement){
$this->lastMovement = $packet->messageIndex;
$newPos = new Math\Vector3($packet->x, $packet->y, $packet->z);
if($this->forceMovement instanceof Math\Vector3){
$newPos = new Vector3($packet->x, $packet->y, $packet->z);
if($this->forceMovement instanceof Vector3){
if($this->forceMovement->distance($newPos) <= 0.7){
$this->forceMovement = false;
}else{
@ -1369,7 +1405,7 @@ class Player extends Entity\RealHuman{
}
/*$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->lastCorrect instanceof Math\Vector3){
if($this->lastCorrect instanceof Vector3){
$this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false);
}
if($this->blocked !== true){
@ -1380,7 +1416,7 @@ class Player extends Entity\RealHuman{
//}
}
break;
case Network\Protocol\Info::PLAYER_EQUIPMENT_PACKET:
case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:
if($this->spawned === false){
break;
}
@ -1421,10 +1457,10 @@ class Player extends Entity\RealHuman{
//$this->entity->updateMetadata();
}
break;
case Network\Protocol\Info::REQUEST_CHUNK_PACKET:
case ProtocolInfo::REQUEST_CHUNK_PACKET:
break;
case Network\Protocol\Info::USE_ITEM_PACKET:
$blockVector = new Math\Vector3($packet->x, $packet->y, $packet->z);
case ProtocolInfo::USE_ITEM_PACKET:
$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){
$target = $this->level->getBlock($blockVector);
@ -1508,7 +1544,7 @@ class Player extends Entity\RealHuman{
//$this->updateMetadata();
}
break;
/*case Network\Protocol\Info::PLAYER_ACTION_PACKET:
/*case ProtocolInfo::PLAYER_ACTION_PACKET:
if($this->spawned === false or $this->blocked === true){
break;
}
@ -1584,8 +1620,8 @@ class Player extends Entity\RealHuman{
$this->stopSleep();
}
break;*/
case Network\Protocol\Info::REMOVE_BLOCK_PACKET:
$blockVector = new Math\Vector3($packet->x, $packet->y, $packet->z);
case ProtocolInfo::REMOVE_BLOCK_PACKET:
$blockVector = new Vector3($packet->x, $packet->y, $packet->z);
if($this->spawned === false or $this->blocked === true or $this->distance($blockVector) > 8){
$target = $this->level->getBlock($blockVector);
@ -1602,7 +1638,7 @@ class Player extends Entity\RealHuman{
$this->toCraft = array();
$this->server->api->block->playerBlockBreak($this, $blockVector);
break;
case Network\Protocol\Info::PLAYER_ARMOR_EQUIPMENT_PACKET:
case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET:
if($this->spawned === false or $this->blocked === true){
break;
}
@ -1650,7 +1686,7 @@ class Player extends Entity\RealHuman{
//$this->entity->updateMetadata();
}
break;
/*case Network\Protocol\Info::INTERACT_PACKET:
/*case ProtocolInfo::INTERACT_PACKET:
if($this->spawned === false){
break;
}
@ -1661,8 +1697,8 @@ class Player extends Entity\RealHuman{
$data["action"] = $packet->action;
$this->craftingItems = array();
$this->toCraft = array();
$target = Entity\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){
$target = Entity::get($packet->target);
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["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)){
@ -1739,14 +1775,14 @@ class Player extends Entity\RealHuman{
}
break;*/
/*case Network\Protocol\Info::ANIMATE_PACKET:
/*case ProtocolInfo::ANIMATE_PACKET:
if($this->spawned === false){
break;
}
$packet->eid = $this->id;
$this->server->api->dhandle("entity.animate", array("eid" => $packet->eid, "entity" => $this->entity, "action" => $packet->action));
break;*/
case Network\Protocol\Info::RESPAWN_PACKET:
case ProtocolInfo::RESPAWN_PACKET:
if($this->spawned === false){
break;
}
@ -1765,9 +1801,9 @@ class Player extends Entity\RealHuman{
$this->blocked = false;
$this->server->handle("player.respawn", $this);
break;
case Network\Protocol\Info::SET_HEALTH_PACKET: //Not used
case ProtocolInfo::SET_HEALTH_PACKET: //Not used
break;
/*case Network\Protocol\Info::ENTITY_EVENT_PACKET:
/*case ProtocolInfo::ENTITY_EVENT_PACKET:
if($this->spawned === false or $this->blocked === true){
break;
}
@ -1821,7 +1857,7 @@ class Player extends Entity\RealHuman{
break;
}
break;*/
/*case Network\Protocol\Info::DROP_ITEM_PACKET:
/*case ProtocolInfo::DROP_ITEM_PACKET:
if($this->spawned === false or $this->blocked === true){
break;
}
@ -1843,13 +1879,13 @@ class Player extends Entity\RealHuman{
$this->entity->updateMetadata();
}
break;*/
case Network\Protocol\Info::MESSAGE_PACKET:
case ProtocolInfo::MESSAGE_PACKET:
if($this->spawned === false){
break;
}
$this->craftingItems = 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){
$message = $packet->message;
if($message{0} === "/"){ //Command
@ -1866,7 +1902,7 @@ class Player extends Entity\RealHuman{
}
}
break;
case Network\Protocol\Info::CONTAINER_CLOSE_PACKET:
case ProtocolInfo::CONTAINER_CLOSE_PACKET:
if($this->spawned === false){
break;
}
@ -1899,7 +1935,7 @@ class Player extends Entity\RealHuman{
$pk->windowid = $packet->windowid;
$this->dataPacket($pk);
break;
case Network\Protocol\Info::CONTAINER_SET_SLOT_PACKET:
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if($this->spawned === false or $this->blocked === true){
break;
}
@ -1961,14 +1997,14 @@ class Player extends Entity\RealHuman{
if(is_array($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];
$slotn = $packet->slot;
$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];
$slotn = $packet->slot - Tile\Chest::SLOTS;
$offset = Tile\Chest::SLOTS;
$slotn = $packet->slot - Chest::SLOTS;
$offset = Chest::SLOTS;
}else{
break;
}
@ -2015,13 +2051,13 @@ class Player extends Entity\RealHuman{
}else{
$tile = $this->windows[$packet->windowid];
if(
!($tile instanceof Tile\Chest or $tile instanceof Tile\Furnace)
!($tile instanceof Chest or $tile instanceof Furnace)
or $packet->slot < 0
or (
$tile instanceof Tile\Chest
and $packet->slot >= Tile\Chest::SLOTS
$tile instanceof Chest
and $packet->slot >= Chest::SLOTS
) or (
$tile instanceof Tile\Furnace and $packet->slot >= Tile\Furnace::SLOTS
$tile instanceof Furnace and $packet->slot >= Furnace::SLOTS
)
){
break;
@ -2044,7 +2080,7 @@ class Player extends Entity\RealHuman{
break;
}
if($tile instanceof Tile\Furnace and $packet->slot == 2){
if($tile instanceof Furnace and $packet->slot == 2){
switch($slot->getID()){
case IRON_INGOT:
$this->grantAchievement("acquireIron");
@ -2075,25 +2111,25 @@ class Player extends Entity\RealHuman{
$tile->setSlot($packet->slot, $item);
}
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){
break;
}
break;
case Network\Protocol\Info::ENTITY_DATA_PACKET:
case ProtocolInfo::ENTITY_DATA_PACKET:
if($this->spawned === false or $this->blocked === true){
break;
}
$this->craftingItems = array();
$this->toCraft = array();
$t = $this->level->getTile(new Math\Vector3($packet->x, $packet->y, $packet->z));
if($t instanceof Tile\Sign){
$t = $this->level->getTile(new Vector3($packet->x, $packet->y, $packet->z));
if($t instanceof Sign){
if($t->namedtag->creator !== $this->username){
$t->spawnTo($this);
}else{
$nbt = new NBT\NBT(NBT\LITTLE_ENDIAN);
$nbt = new NBT(NBT\LITTLE_ENDIAN);
$nbt->read($packet->namedtag);
if($nbt->id !== Tile\Tile::SIGN){
if($nbt->id !== Tile::SIGN){
$t->spawnTo($this);
}else{
$t->setText($nbt->Text1, $nbt->Text2, $nbt->Text3, $nbt->Text4);
@ -2123,7 +2159,7 @@ class Player extends Entity\RealHuman{
$this->dataPacket($pk);
}
public function send(Network\RakNet\Packet $packet){
public function send(Packet $packet){
if($this->connected === true){
$packet->ip = $this->ip;
$packet->port = $this->port;
@ -2133,12 +2169,12 @@ class Player extends Entity\RealHuman{
public function sendBuffer(){
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->send($this->buffer);
}
$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->nextBuffer = microtime(true) + 0.1;
}
@ -2170,7 +2206,7 @@ class Player extends Entity\RealHuman{
$pk->buffer = $buf;
$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->seqNumber = $count;
$rk->sendtime = $sendtime;
@ -2185,11 +2221,11 @@ class Player extends Entity\RealHuman{
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();
}
$packet->encode();
$pk = new Network\RakNet\Packet(Network\RakNet\Info::DATA_PACKET_0);
$pk = new Packet(Info::DATA_PACKET_0);
$pk->data[] = $packet;
$pk->seqNumber = $this->counter[0]++;
$pk->sendtime = microtime(true);
@ -2212,7 +2248,7 @@ class Player extends Entity\RealHuman{
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;
}

View File

@ -20,6 +20,12 @@
*/
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{
private $server;
@ -52,7 +58,7 @@ class PlayerAPI{
$result = $this->server->preparedSQL->selectPlayersToHeal->execute();
if($result !== 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){
continue;
}
@ -65,8 +71,8 @@ class PlayerAPI{
break;
case "player.death":
if(is_numeric($data["cause"])){
$e = Entity\Entity::get($data["cause"]);
if($e instanceof Entity\Entity){
$e = Entity::get($data["cause"]);
if($e instanceof Entity){
switch($e->class){
case ENTITY_PLAYER:
$message = " was killed by ".$e->name;
@ -139,19 +145,19 @@ class PlayerAPI{
$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";
break;
}
if(count($params) === 3){
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{
$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{
$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);
@ -323,7 +329,7 @@ class PlayerAPI{
$x = $x{0} === "~" ? $player->entity->x + floatval(substr($x, 1)):floatval($x);
$y = $y{0} === "~" ? $player->entity->y + floatval(substr($y, 1)):floatval($y);
$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 false;

View File

@ -20,6 +20,12 @@
*/
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{
private $server;
@ -27,7 +33,7 @@ class PluginAPI extends \stdClass{
private $randomNonce;
public function __construct(){
$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("version", "", array($this, "commandHandler"));
$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";
break;
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)){
$output .= " (git ".GIT_COMMIT.")";
}
@ -79,7 +85,7 @@ class PluginAPI extends \stdClass{
return false;
}
if(strtolower(substr($file, -3)) === "pmf"){
$pmf = new PMF\Plugin($file);
$pmf = new PMFPlugin($file);
$info = $pmf->getPluginInfo();
}else{
$content = file_get_contents($file);
@ -113,7 +119,7 @@ class PluginAPI extends \stdClass{
console("[ERROR] Failed parsing of ".basename($file));
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"])){
console("[ERROR] Failed loading plugin: class already exists");
return false;
@ -193,7 +199,7 @@ class PluginAPI extends \stdClass{
return false;
}
$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();
return $path;
}

View File

@ -20,6 +20,16 @@
*/
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{
public $tCnt;
@ -32,14 +42,14 @@ class Server{
public $api;
private function load(){
$this->version = new Utils\VersionString();
$this->version = new VersionString();
if(defined("DEBUG") and DEBUG >= 0){
@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);
define("BOOTUP_RANDOM", Utils\Utils::getRandomBytes(16));
$this->serverID = $this->serverID === false ? Utils\Utils::readLong(substr(Utils\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;
define("BOOTUP_RANDOM", Utils::getRandomBytes(16));
$this->serverID = $this->serverID === false ? Utils::readLong(substr(Utils::getUniqueID(true, $this->serverip . $this->port), 8)):$this->serverID;
$this->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):$this->seed;
$this->startDatabase();
$this->api = false;
$this->tCnt = 1;
@ -62,7 +72,7 @@ class Server{
$this->whitelist = false;
$this->tickMeasure = array_fill(0, 40, 0);
$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->ticks = 0;
if(!defined("NO_THREADS")){
@ -154,7 +164,7 @@ class Server{
$info["tps"] = $this->getTPS();
$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["entities"] = count(Entity\Entity::$list);
$info["entities"] = count(Entity::$list);
$info["players"] = count(Player::$list);
$info["events"] = count($this->eventsID);
$info["handlers"] = $this->query("SELECT count(ID) as count FROM handlers;", true);
@ -213,25 +223,25 @@ class Server{
$type = (int) $type;
switch($type){
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;
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\Utils::writeShort(count($data["data"]));
$d .= Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
$d .= Utils::writeShort(count($data["data"]));
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;
case ASYNC_FUNCTION:
$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;
default:
return false;
}
$ID = $this->asyncID++;
$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;
}
@ -241,21 +251,21 @@ class Server{
}
if(isset($this->asyncThread->output{5})){
$offset = 0;
$ID = Utils\Utils::readInt(substr($this->asyncThread->output, $offset, 4));
$ID = Utils::readInt(substr($this->asyncThread->output, $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;
$data = array();
switch($type){
case ASYNC_CURL_GET:
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;
$data["result"] = substr($this->asyncThread->output, $offset, $len);
$offset += $len;
break;
case ASYNC_FUNCTION:
$len = Utils\Utils::readInt(substr($this->asyncThread->output, $offset, 4));
$len = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
$offset += 4;
$data["result"] = unserialize(substr($this->asyncThread->output, $offset, $len));
$offset += $len;
@ -426,13 +436,13 @@ class Server{
$dump .= "$line\r\n";
}
$dump .= "\r\n\r\n";
$version = new Utils\VersionString();
$dump .= "PocketMine-MP version: ".$version." #".$version->getNumber()." [Protocol ".Network\Protocol\Info::CURRENT_PROTOCOL."; API ".API_VERSION."]\r\n";
$version = new VersionString();
$dump .= "PocketMine-MP version: ".$version." #".$version->getNumber()." [Protocol ".Info::CURRENT_PROTOCOL."; API ".API_VERSION."]\r\n";
$dump .= "Git commit: ".GIT_COMMIT."\r\n";
$dump .= "uname -a: ".php_uname("a")."\r\n";
$dump .= "PHP Version: " .phpversion()."\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";
global $arguments;
$dump .= "Parameters: ".var_export($arguments, true)."\r\n\r\n\r\n";
@ -484,17 +494,17 @@ class Server{
//return $ip . ":" . $port;
}
public function packetHandler(Network\Packet $packet){
public function packetHandler(Packet $packet){
$data =& $packet;
$CID = Server::clientID($packet->ip, $packet->port);
if(isset(Player::$list[$CID])){
Player::$list[$CID]->handlePacket($packet);
}else{
switch($packet->pid()){
case Network\RakNet\Info::UNCONNECTED_PING:
case Network\RakNet\Info::UNCONNECTED_PING_OPEN_CONNECTIONS:
case RakNetInfo::UNCONNECTED_PING:
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
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->serverID = $this->serverID;
$pk->serverType = $this->serverType;
@ -512,7 +522,7 @@ class Server{
}
$txt = substr($this->description, $this->custom["times_".$CID], $ln);
$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->serverID = $this->serverID;
$pk->serverType = $this->serverType . $this->name . " [".count(Player::$list)."/".$this->maxClients."] ".$txt;
@ -521,16 +531,16 @@ class Server{
$this->send($pk);
$this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description);
break;
case Network\RakNet\Info::OPEN_CONNECTION_REQUEST_1:
if($packet->structure !== Network\RakNet\Info::STRUCTURE){
case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
if($packet->structure !== RakNetInfo::STRUCTURE){
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->ip = $packet->ip;
$pk->port = $packet->port;
$this->send($pk);
}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->mtuSize = strlen($packet->buffer);
$pk->ip = $packet->ip;
@ -538,13 +548,13 @@ class Server{
$this->send($pk);
}
break;
case Network\RakNet\Info::OPEN_CONNECTION_REQUEST_2:
case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
if($this->invisible === true){
break;
}
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->serverPort = $this->port;
$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);
}
@ -564,7 +574,7 @@ class Server{
$lastLoop = 0;
while($this->stop === false){
$packet = $this->interface->readPacket();
if($packet instanceof Network\Packet){
if($packet instanceof Packet){
$this->packetHandler($packet);
$lastLoop = 0;
}

View File

@ -20,6 +20,19 @@
*/
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{
public $restart = false;
@ -103,11 +116,11 @@ class ServerAPI{
}
}
$version = new Utils\VersionString();
console("[INFO] Starting Minecraft PE server version ".Utils\TextFormat::AQUA.MINECRAFT_VERSION);
$version = new VersionString();
console("[INFO] Starting Minecraft PE server version ".TextFormat::AQUA.MINECRAFT_VERSION);
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",
"description" => "Server made using PocketMine-MP",
"motd" => "Welcome @player to this server!",
@ -134,7 +147,7 @@ class ServerAPI{
"level-type" => "DEFAULT",
"enable-query" => true,
"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,
));
@ -149,52 +162,52 @@ class ServerAPI{
}
if($this->getProperty("upnp-forwarding") == true){
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->api = $this;
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);
if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){
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()){
$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])){
console("[ERROR] Github API error");
}else{
$last = new \DateTime($info[0]["commit"]["committer"]["date"]);
$last = $last->getTimestamp();
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] ".Utils\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."A new DEVELOPMENT version of PocketMine-MP has been released!");
console("[NOTICE] ".TextFormat::YELLOW."Commit \"".$info[0]["commit"]["message"]."\" [".substr($info[0]["sha"], 0, 10)."] by ".$info[0]["commit"]["committer"]["name"]);
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\"");
}else{
$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{
$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])){
console("[ERROR] Github API error");
}else{
$newest = new Utils\VersionString(VERSION);
$newest = new VersionString(VERSION);
$newestN = $newest->getNumber();
$update = new Utils\VersionString($info[0]["name"]);
$update = new VersionString($info[0]["name"]);
$updateN = $update->getNumber();
if($updateN > $newestN){
console("[NOTICE] ".Utils\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."A new STABLE version of PocketMine-MP has been released!");
console("[NOTICE] ".TextFormat::GREEN."Version \"".$info[0]["name"]."\" #".$updateN);
console("[NOTICE] Get it at PocketMine.net or at ".$info[0]["zipball_url"]);
console("[NOTICE] This message will dissapear as soon as you update");
}else{
$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(){
//Update entities that need update
if(count(Entity\Entity::$needUpdate) > 0){
if(count(Entity::$needUpdate) > 0){
foreach(EntityEntity::$needUpdate as $id => $entity){
if($entity->onUpdate() === false){
unset(Entity\Entity::$needUpdate[$id]);
unset(Entity::$needUpdate[$id]);
}
}
}
//Update tiles that need update
if(count(Tile\Tile::$needUpdate) > 0){
foreach(Tile\Tile::$needUpdate as $id => $tile){
if(count(Tile::$needUpdate) > 0){
foreach(Tile::$needUpdate as $id => $tile){
if($tile->onUpdate() === false){
unset(Tile\Tile::$needUpdate[$id]);
unset(Tile::$needUpdate[$id]);
}
}
}
@ -272,13 +285,13 @@ class ServerAPI{
"data" => array(
"serverid" => $this->server->serverID,
"port" => $this->server->port,
"os" => Utils\Utils::getOS(),
"os" => Utils::getOS(),
"memory_total" => $this->getProperty("memory-limit"),
"memory_usage" => memory_get_usage(true),
"php_version" => PHP_VERSION,
"version" => VERSION,
"mc_version" => MINECRAFT_VERSION,
"protocol" => Network\Protocol\Info::CURRENT_PROTOCOL,
"protocol" => Info::CURRENT_PROTOCOL,
"online" => count(Player::$list),
"max" => $this->server->maxClients,
"plugins" => $plist,
@ -342,7 +355,7 @@ class ServerAPI{
break;
case "server-id":
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;
}
@ -366,24 +379,24 @@ class ServerAPI{
$this->server->schedule(18000, array($this, "autoSave"), array(), 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){
$this->query = new Network\Query\QueryHandler();
$this->query = new QueryHandler();
}
Recipes\Crafting::init();
Crafting::init();
$this->schedule(2, array($this, "checkTickUpdates"), array(), true);
$this->server->init();
unregister_tick_function(array($this->server, "tick"));
$this->console->__destruct();
if($this->rcon instanceof Network\RCON\RCON){
if($this->rcon instanceof RCON){
$this->rcon->stop();
}
$this->__destruct();
if($this->getProperty("upnp-forwarding") === true ){
console("[INFO] [UPnP] Removing port forward...");
Network\UPnP\RemovePortForward($this->getProperty("server-port"));
RemovePortForward($this->getProperty("server-port"));
}
return $this->restart;
}

View File

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

View File

@ -21,8 +21,20 @@
namespace PocketMine\Entity;
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 $list = 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->justCreated = true;
$this->closed = false;
$this->namedtag = $nbt;
$this->level = $level;
$this->boundingBox = new Math\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->setMotion(new Math\Vector3($this->namedtag->Motion[0], $this->namedtag->Motion[1], $this->namedtag->Motion[2]));
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
$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 Vector3($this->namedtag->Motion[0], $this->namedtag->Motion[1], $this->namedtag->Motion[2]));
$this->fallDistance = $this->namedtag->FallDistance;
$this->fireTicks = $this->namedtag->Fire;
@ -101,7 +113,7 @@ abstract class Entity extends Level\Position{
$this->onGround = $this->namedtag->OnGround > 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;
Entity::$list[$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){
if($this->level instanceof Level\Level){
if(Event\EventHandler::callEvent(new Event\Entity\EntityLevelChangeEvent($this, $this->level, $targetLevel)) === Event\Event::DENY){
protected function switchLevel(Level $targetLevel){
if($this->level instanceof Level){
if(EventHandler::callEvent(new EntityLevelChangeEvent($this, $this->level, $targetLevel)) === Event::DENY){
return false;
}
unset($this->level->entities[$this->id]);
@ -312,7 +324,7 @@ abstract class Entity extends Level\Position{
if($Yndex !== 0xff){
$X = null;
$Z = null;
PMF\LevelFormat::getXZ($index, $X, $Z);
LevelFormat::getXZ($index, $X, $Z);
foreach($this->level->getChunkEntities($X, $Z) as $entity){
$entity->despawnFrom($this);
}
@ -335,10 +347,10 @@ abstract class Entity extends Level\Position{
}
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){
return;
}
@ -349,7 +361,7 @@ abstract class Entity extends Level\Position{
$this->scheduleUpdate();
}
public function setPositionAndRotation(Math\Vector3 $pos, $yaw, $pitch){
public function setPositionAndRotation(Vector3 $pos, $yaw, $pitch){
if($this->setPosition($pos) === true){
$this->setRotation($yaw, $pitch);
return true;
@ -363,13 +375,13 @@ abstract class Entity extends Level\Position{
$this->scheduleUpdate();
}
public function setPosition(Math\Vector3 $pos){
if($pos instanceof Level\Position and $pos->level instanceof Level\Level and $pos->level !== $this->level){
public function setPosition(Vector3 $pos){
if($pos instanceof Position and $pos->level instanceof Level and $pos->level !== $this->level){
if($this->switchLevel($pos->level) === 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;
}
$this->x = $pos->x;
@ -377,7 +389,7 @@ abstract class Entity extends Level\Position{
$this->z = $pos->z;
$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){
unset($this->level->chunkEntities[$this->chunkIndex][$this->id]);
}
@ -405,11 +417,11 @@ abstract class Entity extends Level\Position{
}
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){
if(Event\EventHandler::callEvent(new Event\Entity\EntityMotionEvent($this, $motion)) === Event\Event::DENY){
public function setMotion(Vector3 $motion){
if(EventHandler::callEvent(new EntityMotionEvent($this, $motion)) === Event::DENY){
return false;
}
$this->motionX = $motion->x;
@ -430,8 +442,8 @@ abstract class Entity extends Level\Position{
return $this->level;
}
public function teleport(Level\Position $pos, $yaw = false, $pitch = false){
$this->setMotion(new Math\Vector3(0, 0, 0));
public function teleport(Position $pos, $yaw = false, $pitch = false){
$this->setMotion(new Vector3(0, 0, 0));
if($this->setPositionAndRotation($pos, $yaw === false ? $this->yaw : $yaw, $pitch === false ? $this->pitch : $pitch) !== false){
if($this instanceof Player){
$this->airTicks = 300;

View File

@ -22,6 +22,14 @@
namespace PocketMine\Entity;
use PocketMine;
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{
@ -64,22 +72,22 @@ class Human extends Creature implements ProjectileSource, InventorySource{
if(isset($this->hotbar[$slot]) and $this->hotbar[$slot] !== -1){
$item = $this->getSlot($this->hotbar[$slot]);
if($item->getID() !== AIR and $item->getCount() > 0){
$this->namedtag->Inventory[$slot] = new NBT\Tag\Compound(false, array(
"Count" => new NBT\Tag\Byte("Count", $item->getCount()),
"Damage" => new NBT\Tag\Short("Damage", $item->getMetadata()),
"Slot" => new NBT\Tag\Byte("Slot", $slot),
"TrueSlot" => new NBT\Tag\Byte("TrueSlot", $this->hotbar[$slot]),
"id" => new NBT\Tag\Short("id", $item->getID()),
$this->namedtag->Inventory[$slot] = new Compound(false, array(
"Count" => new Byte("Count", $item->getCount()),
"Damage" => new Short("Damage", $item->getMetadata()),
"Slot" => new Byte("Slot", $slot),
"TrueSlot" => new Byte("TrueSlot", $this->hotbar[$slot]),
"id" => new Short("id", $item->getID()),
));
continue;
}
}
$this->namedtag->Inventory[$slot] = new NBT\Tag\Compound(false, array(
"Count" => new NBT\Tag\Byte("Count", 0),
"Damage" => new NBT\Tag\Short("Damage", 0),
"Slot" => new NBT\Tag\Byte("Slot", $slot),
"TrueSlot" => new NBT\Tag\Byte("Slot", -1),
"id" => new NBT\Tag\Short("id", 0),
$this->namedtag->Inventory[$slot] = new Compound(false, array(
"Count" => new Byte("Count", 0),
"Damage" => new Short("Damage", 0),
"Slot" => new Byte("Slot", $slot),
"TrueSlot" => new Byte("Slot", -1),
"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;
for($slot = 9; $slot < $slotCount; ++$slot){
$item = $this->getSlot($slot);
$this->namedtag->Inventory[$slot] = new NBT\Tag\Compound(false, array(
"Count" => new NBT\Tag\Byte("Count", $item->getCount()),
"Damage" => new NBT\Tag\Short("Damage", $item->getMetadata()),
"Slot" => new NBT\Tag\Byte("Slot", $slot),
"id" => new NBT\Tag\Short("id", $item->getID()),
$this->namedtag->Inventory[$slot] = new Compound(false, array(
"Count" => new Byte("Count", $item->getCount()),
"Damage" => new Short("Damage", $item->getMetadata()),
"Slot" => new Byte("Slot", $slot),
"id" => new Short("id", $item->getID()),
));
}
@ -99,11 +107,11 @@ class Human extends Creature implements ProjectileSource, InventorySource{
for($slot = 100; $slot < 104; ++$slot){
$item = $this->armor[$slot - 100];
if($item instanceof Item){
$this->namedtag->Inventory[$slot] = new NBT\Tag\Compound(false, array(
"Count" => new NBT\Tag\Byte("Count", $item->getCount()),
"Damage" => new NBT\Tag\Short("Damage", $item->getMetadata()),
"Slot" => new NBT\Tag\Byte("Slot", $slot),
"id" => new NBT\Tag\Short("id", $item->getID()),
$this->namedtag->Inventory[$slot] = new Compound(false, array(
"Count" => new Byte("Count", $item->getCount()),
"Damage" => new Short("Damage", $item->getMetadata()),
"Slot" => new Byte("Slot", $slot),
"id" => new Short("id", $item->getID()),
));
}
}
@ -178,7 +186,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
}
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;
}
$this->armor[(int) $slot] = $ev->getNewItem();
@ -352,7 +360,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
}
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;
}
$this->inventory[(int) $slot] = $ev->getNewItem();

View File

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

View File

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

View File

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

View File

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

View File

@ -22,6 +22,8 @@
namespace PocketMine\Event\Entity;
use PocketMine\Event;
use PocketMine;
use PocketMine\Entity\Entity as Entity;
use PocketMine\Level\Level as Level;
class EntityLevelChangeEvent extends EntityEvent implements CancellableEvent{
public static $handlers;
@ -30,7 +32,7 @@ class EntityLevelChangeEvent extends EntityEvent implements CancellableEvent{
private $originLevel;
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->originLevel = $originLevel;
$this->targetLevel = $targetLevel;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,6 +21,12 @@
namespace PocketMine\Level;
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{
public static $specialDrops = array(
@ -37,7 +43,7 @@ class Explosion{
public $affectedBlocks = array();
public $stepLen = 0.3;
public function __construct(Level\Position $center, $size){
public function __construct(Position $center, $size){
$this->level = $center->level;
$this->source = $center;
$this->size = max($size, 0);
@ -58,7 +64,7 @@ class Explosion{
for($j = 0; $j < $this->rays; ++$j){
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){
$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);
$pointer = clone $this->source;
@ -98,7 +104,7 @@ class Explosion{
foreach($this->affectedBlocks as $block){
if($block instanceof Block\TNT){
if($block instanceof TNT){
$data = array(
"x" => $block->x + 0.5,
"y" => $block->y + 0.5,
@ -119,7 +125,7 @@ class Explosion{
}
}
$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->x = $this->source->x;

View File

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

View File

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

View File

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

View File

@ -21,12 +21,13 @@
namespace PocketMine\Level;
use PocketMine;
use PocketMine\Math\Vector3 as Vector3;
class Position extends Math\Vector3{
class Position extends Vector3{
public $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);
}else{
$this->x = $x;

View File

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

View File

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

View File

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

View File

@ -21,12 +21,16 @@
namespace PocketMine\Level\Generator\Object;
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{
private $random;
public $type;
public function __construct(Utils\Random $random, OreType $type){
public function __construct(Random $random, OreType $type){
$this->type = $type;
$this->random = $random;
}
@ -35,14 +39,14 @@ class Ore{
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);
}
public function placeObject(Level\Level $level, Math\Vector3 $pos){
public function placeObject(Level $level, Vector3 $pos){
$clusterSize = (int) $this->type->clusterSize;
$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;
$x2 = $pos->x + 8 - $offset->x;
$z1 = $pos->z + 8 + $offset->y;
@ -77,7 +81,7 @@ class Ore{
$sizeZ *= $sizeZ;
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;
use PocketMine;
use PocketMine\Block\Block as Block;
class OreType{
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->clusterCount = (int) $clusterCount;
$this->clusterSize = (int) $clusterSize;

View File

@ -21,6 +21,12 @@
namespace PocketMine\Level\Generator\Object;
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{
var $type = 1;
@ -28,7 +34,7 @@ class PineTree extends Tree{
private $leavesSizeY = -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);
$checkRadius = 0;
for($yy = 0; $yy < $this->totalHeight; ++$yy) {
@ -46,17 +52,17 @@ class PineTree extends Tree{
return true;
}
private function findRandomLeavesSize(Utils\Random $random){
private function findRandomLeavesSize(Random $random){
$this->totalHeight += $random->nextRange(-1, 2);
$this->leavesSizeY = 1 + $random->nextRange(0, 2);
$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) {
$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;
$leavesMaxRadius = 1;
$leavesBottomY = $this->totalHeight - $this->leavesSizeY;
@ -66,7 +72,7 @@ class PineTree extends Tree{
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) {
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) {
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);
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;
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{
private $random;
public $type;
public function __construct(Utils\Random $random, Block\Block $type){
public function __construct(Random $random, Block $type){
$this->type = $type;
$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;
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{
public $type = 0;
@ -32,7 +38,7 @@ class SmallTree extends Tree{
private $addLogVines = 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;
for ($yy = 0; $yy < $this->trunkHeight + 3; ++$yy) {
if($yy == 1 or $yy === $this->trunkHeight) {
@ -49,10 +55,10 @@ class SmallTree extends Tree{
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
$dirtpos = new Math\Vector3( $pos->x, $pos->y - 1, $pos->z );
$level->setBlockRaw( $dirtpos, new Block\Dirt() );
$dirtpos = new Vector3( $pos->x, $pos->y - 1, $pos->z );
$level->setBlockRaw( $dirtpos, new Dirt() );
// Adjust the tree trunk's height randomly
// plot [-14:11] int( x / 8 ) + 5
@ -81,10 +87,10 @@ class SmallTree extends Tree{
{
if( sqrt(($xx * $xx) + ($zz * $zz)) <= $radius )
{
$leafpos = new Math\Vector3( $pos->x + $xx,
$leafpos = new Vector3( $pos->x + $xx,
$pos->y + $yy,
$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
if($leaflevel > 1)
{
$trunkpos = new Math\Vector3( $pos->x, $pos->y + $yy, $pos->z );
$level->setBlockRaw($trunkpos, new Block\Wood($this->type));
$trunkpos = new Vector3( $pos->x, $pos->y + $yy, $pos->z );
$level->setBlockRaw($trunkpos, new Wood($this->type));
}
}
}

View File

@ -21,6 +21,12 @@
namespace PocketMine\Level\Generator\Object;
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{
var $type = 1;
@ -28,7 +34,7 @@ class SpruceTree extends Tree{
private $leavesBottomY = -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);
$checkRadius = 0;
for($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
@ -46,23 +52,23 @@ class SpruceTree extends Tree{
return true;
}
private function findRandomLeavesSize(Utils\Random $random){
private function findRandomLeavesSize(Random $random){
$this->totalHeight += $random->nextRange(-1, 2);
$this->leavesBottomY = (int) ($this->totalHeight - $random->nextRange(1, 2) - 3);
$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) {
$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;
for($yy = $this->totalHeight; $yy >= $this->leavesBottomY; --$yy){
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) {
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) {
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){
$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;
use PocketMine\Level;
use PocketMine;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\BlockAPI as BlockAPI;
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(
BlockAPI::get(DANDELION, 0),
BlockAPI::get(CYAN_FLOWER, 0),
@ -39,7 +41,7 @@ class TallGrass{
$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){
$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;
use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Block\Sapling as Sapling;
class Tree{
public $overridable = array(
@ -32,7 +35,7 @@ class Tree{
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){
case SaplingBlock::SPRUCE:
if($random->nextRange(0, 1) === 1){
@ -43,11 +46,11 @@ class Tree{
break;
case SaplingBlock::BIRCH:
$tree = new SmallTree();
$tree->type = Block\Sapling::BIRCH;
$tree->type = Sapling::BIRCH;
break;
case SaplingBlock::JUNGLE:
$tree = new SmallTree();
$tree->type = Block\Sapling::JUNGLE;
$tree->type = Sapling::JUNGLE;
break;
case SaplingBlock::OAK:
default:

View File

@ -21,6 +21,8 @@
namespace PocketMine\Level\Generator\Populator;
use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Utils\Random as Random;
class Mineshaft extends Populator{
private static $DISTANCE = 256;
@ -29,7 +31,7 @@ class Mineshaft extends Populator{
private static $BASE_Y = 35;
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){
//$mineshaft = new Mineshaft($random);
}

View File

@ -21,18 +21,22 @@
namespace PocketMine\Level\Generator\Populator;
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{
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){
$ore = new Level\Generator\Object\Ore($random, $type);
$ore = new ObjectOre($random, $type);
for($i = 0; $i < $ore->type->clusterCount; ++$i){
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
$y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight);
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
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;
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{
private $waterOdd = 4;
private $lavaOdd = 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){
$v = new Math\Vector3(
$v = new Vector3(
$random->nextRange($chunkX << 4, ($chunkX << 4) + 16),
$random->nextRange(0, 128),
$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)){
$pond->placeObject($level, $v);
}

View File

@ -21,7 +21,9 @@
namespace PocketMine\Level\Generator\Populator;
use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Utils\Random as Random;
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;
use PocketMine;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Block\TallGrass as BlockTallGrass;
class TallGrass extends Populator{
private $level;
@ -45,9 +47,9 @@ class TallGrass extends Populator{
$xx = $x - 7 + $random->nextRange(0, 15);
$zz = $z - 7 + $random->nextRange(0, 15);
$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))){
$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){
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(--$y <= 0){
return -1;

View File

@ -21,6 +21,9 @@
namespace PocketMine\Level\Generator\Populator;
use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Utils\Random as Random;
use PocketMine\Math\Vector3 as Vector3;
class Tree extends Populator{
private $level;
@ -35,7 +38,7 @@ class Tree extends Populator{
$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;
$amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount;
for($i = 0; $i < $amount; ++$i){
@ -50,13 +53,13 @@ class Tree extends Populator{
}else{
$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){
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(--$y <= 0){
return -1;

View File

@ -21,6 +21,7 @@
namespace PocketMine\Math;
use PocketMine;
use PocketMine\Math\Vector3 as Vector3;
class AxisAlignedBB{
public $minX;
@ -195,7 +196,7 @@ class AxisAlignedBB{
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){
return false;
}
@ -209,15 +210,15 @@ class AxisAlignedBB{
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;
}
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;
}
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;
}

View File

@ -21,6 +21,7 @@
namespace PocketMine\Math;
use PocketMine;
use PocketMine\Math\Vector3 as Vector3;
class Vector2{
public $x, $y;
@ -52,7 +53,7 @@ class Vector2{
}else{
$this->x += $x;
$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;
use PocketMine;
use PocketMine\Math\Vector3 as MathVector3;
class Vector3{
public $x, $y, $z;
@ -76,15 +77,15 @@ class Vector3{
}
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);
}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){
if(($x instanceof Math\Vector3) === true){
if(($x instanceof MathVector3) === true){
return $this->add(-$x->x, -$x->y, -$x->z);
}else{
return $this->add(-$x, -$y, -$z);
@ -92,50 +93,50 @@ class Vector3{
}
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){
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(){
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(){
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(){
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(){
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){
switch((int) $side){
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:
return new Math\Vector3($this->x, $this->y + 1, $this->z);
return new MathVector3($this->x, $this->y + 1, $this->z);
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:
return new Math\Vector3($this->x, $this->y, $this->z + 1);
return new MathVector3($this->x, $this->y, $this->z + 1);
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:
return new Math\Vector3($this->x + 1, $this->y, $this->z);
return new MathVector3($this->x + 1, $this->y, $this->z);
default:
return $this;
}
}
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));
}else{
return sqrt($this->distanceSquared($x, $y, $z));
@ -143,7 +144,7 @@ class Vector3{
}
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);
}else{
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){
if(($x instanceof Math\Vector3) === true){
if(($x instanceof MathVector3) === true){
return $this->maxPlainDistance($x->x, $x->z);
}else{
return max(abs($this->x - $x), abs($this->z - $z));
@ -171,15 +172,15 @@ class Vector3{
if($len != 0){
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;
}
public function cross(Math\Vector3 $v){
return new Math\Vector3(
public function cross(MathVector3 $v){
return new MathVector3(
$this->y * $v->z - $this->z * $v->y,
$this->z * $v->x - $this->x * $v->z,
$this->x * $v->y - $this->y * $v->x

View File

@ -23,6 +23,19 @@ namespace PocketMine\NBT;
const LITTLE_ENDIAN = 0;
const BIG_ENDIAN = 1;
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{
private $buffer;
@ -67,7 +80,7 @@ class NBT implements \ArrayAccess{
public function write(){
$this->offset = 0;
if($this->data instanceof NBT\Tag\Compound){
if($this->data instanceof Compound){
$this->writeTag($this->data);
return $this->buffer;
}else{
@ -78,57 +91,57 @@ class NBT implements \ArrayAccess{
public function readTag(){
switch($this->getByte()){
case NBT\TAG_Byte:
$tag = new NBT\Tag\Byte($this->getString());
$tag = new Byte($this->getString());
$tag->read($this);
break;
case NBT\TAG_Byte:
$tag = new NBT\Tag\Byte($this->getString());
$tag = new Byte($this->getString());
$tag->read($this);
break;
case NBT\TAG_Short:
$tag = new NBT\Tag\Short($this->getString());
$tag = new Short($this->getString());
$tag->read($this);
break;
case NBT\TAG_Int:
$tag = new NBT\Tag\Int($this->getString());
$tag = new Int($this->getString());
$tag->read($this);
break;
case NBT\TAG_Long:
$tag = new NBT\Tag\Long($this->getString());
$tag = new Long($this->getString());
$tag->read($this);
break;
case NBT\TAG_Float:
$tag = new NBT\Tag\Float($this->getString());
$tag = new Float($this->getString());
$tag->read($this);
break;
case NBT\TAG_Double:
$tag = new NBT\Tag\Double($this->getString());
$tag = new Double($this->getString());
$tag->read($this);
break;
case NBT\TAG_Byte_Array:
$tag = new NBT\Tag\Byte_Array($this->getString());
$tag = new Byte_Array($this->getString());
$tag->read($this);
break;
case NBT\TAG_String:
$tag = new NBT\Tag\String($this->getString());
$tag = new String($this->getString());
$tag->read($this);
break;
case NBT\TAG_Enum:
$tag = new NBT\Tag\Enum($this->getString());
$tag = new Enum($this->getString());
$tag->read($this);
break;
case NBT\TAG_Compound:
$tag = new NBT\Tag\Compound($this->getString());
$tag = new Compound($this->getString());
$tag->read($this);
break;
case NBT\TAG_Int_Array:
$tag = new NBT\Tag\Int_Array($this->getString());
$tag = new Int_Array($this->getString());
$tag->read($this);
break;
case NBT\TAG_End: //No named tag
default:
$tag = new NBT\Tag\End;
$tag = new End;
break;
}
return $tag;
@ -151,43 +164,43 @@ class NBT implements \ArrayAccess{
}
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){
$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(){
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){
$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(){
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){
$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(){
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){
$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(){
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){
$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(){
@ -200,22 +213,22 @@ class NBT implements \ArrayAccess{
}
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;
}
public function __set($name, $value){
if($this->data instanceof NBT\Tag\Compound){
if($this->data instanceof Compound){
$this->data[$name] = $value;
}
}
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){
if($this->data instanceof NBT\Tag\Compound){
if($this->data instanceof Compound){
unset($this->data[$name]);
}
}
@ -240,7 +253,7 @@ class NBT implements \ArrayAccess{
return $this->data;
}
public function setData(NBT\Tag\Compound $data){
public function setData(Compound $data){
$this->data = $data;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,6 +21,8 @@
namespace PocketMine\Network\Protocol;
use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
use PocketMine\Utils\Utils as Utils;
class AddMobPacket extends DataPacket{
public $eid;
@ -49,7 +51,7 @@ class AddMobPacket extends DataPacket{
$this->putFloat($this->z);
$this->putByte($this->yaw);
$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;
use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class AddPaintingPacket extends DataPacket{
public $eid;

View File

@ -21,6 +21,8 @@
namespace PocketMine\Network\Protocol;
use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
use PocketMine\Utils\Utils as Utils;
class AddPlayerPacket extends DataPacket{
public $clientID;
@ -55,7 +57,7 @@ class AddPlayerPacket extends DataPacket{
$this->putByte($this->pitch);
$this->putShort($this->unknown1);
$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;
use PocketMine;
use PocketMine\Network\Protocol\Info as Info;
class AdventureSettingsPacket extends DataPacket{
public $flags;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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