diff --git a/src/Achievement.php b/src/Achievement.php index a6aa912d5..7f000b0ec 100644 --- a/src/Achievement.php +++ b/src/Achievement.php @@ -20,6 +20,7 @@ */ namespace PocketMine; +use PocketMine\ServerAPI as ServerAPI; abstract class Achievement{ public static $list = array( diff --git a/src/BanAPI.php b/src/BanAPI.php index 4c92213ac..65d8ade7a 100644 --- a/src/BanAPI.php +++ b/src/BanAPI.php @@ -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", " [IP|player]", array($this, "commandHandler")); $this->server->api->console->register("ban", " [username]", array($this, "commandHandler")); $this->server->api->console->register("kick", " [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"; diff --git a/src/BlockAPI.php b/src/BlockAPI.php index d2e0ffcbc..85c95e899 100644 --- a/src/BlockAPI.php +++ b/src/BlockAPI.php @@ -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; diff --git a/src/ChatAPI.php b/src/ChatAPI.php index 7cf20c9b0..38fbdf493 100644 --- a/src/ChatAPI.php +++ b/src/ChatAPI.php @@ -20,6 +20,8 @@ */ namespace PocketMine; +use PocketMine\ServerAPI as ServerAPI; +use PocketMine\Player as Player; class ChatAPI{ private $server; diff --git a/src/ConsoleAPI.php b/src/ConsoleAPI.php index fb9f6d4e4..36e91a231 100644 --- a/src/ConsoleAPI.php +++ b/src/ConsoleAPI.php @@ -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 ) ".Utils\TextFormat::RED."-".Utils\TextFormat::RESET."\n"; + $output .= TextFormat::RED."-".TextFormat::RESET." Showing help page $page of $max (/help ) ".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){ diff --git a/src/Deprecation.php b/src/Deprecation.php index f9fcdb31e..a760a4cd2 100644 --- a/src/Deprecation.php +++ b/src/Deprecation.php @@ -22,6 +22,7 @@ //TODO: REMOVE namespace PocketMine; +use PocketMine\ServerAPI as ServerAPI; class Deprecation{ public static $events = array( diff --git a/src/LevelAPI.php b/src/LevelAPI.php index 25ce46b65..17f910345 100644 --- a/src/LevelAPI.php +++ b/src/LevelAPI.php @@ -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; } diff --git a/src/Player.php b/src/Player.php index 4b947f9e9..c1e156519 100644 --- a/src/Player.php +++ b/src/Player.php @@ -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; } diff --git a/src/PlayerAPI.php b/src/PlayerAPI.php index f322824d4..8a9bd9355 100644 --- a/src/PlayerAPI.php +++ b/src/PlayerAPI.php @@ -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; diff --git a/src/PluginAPI.php b/src/PluginAPI.php index 7b801a71f..c12715fd2 100644 --- a/src/PluginAPI.php +++ b/src/PluginAPI.php @@ -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; } diff --git a/src/Server.php b/src/Server.php index 22ec3f67b..5c536186f 100644 --- a/src/Server.php +++ b/src/Server.php @@ -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; } diff --git a/src/ServerAPI.php b/src/ServerAPI.php index c15fce5a1..07a80d4bd 100644 --- a/src/ServerAPI.php +++ b/src/ServerAPI.php @@ -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; } diff --git a/src/TimeAPI.php b/src/TimeAPI.php index 378f23d03..c31fe771f 100644 --- a/src/TimeAPI.php +++ b/src/TimeAPI.php @@ -20,6 +20,7 @@ */ namespace PocketMine; +use PocketMine\ServerAPI as ServerAPI; class TimeAPI{ public static $phases = array( diff --git a/src/entity/Entity.php b/src/entity/Entity.php index f851ccf73..1f0de057e 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -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; diff --git a/src/entity/Human.php b/src/entity/Human.php index 18d70ed29..72d5b47fe 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -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(); diff --git a/src/event/Event.php b/src/event/Event.php index d5fefd40d..9eb3eb382 100644 --- a/src/event/Event.php +++ b/src/event/Event.php @@ -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]); diff --git a/src/event/EventHandler.php b/src/event/EventHandler.php index 6c57d2a2e..ce2034ef4 100644 --- a/src/event/EventHandler.php +++ b/src/event/EventHandler.php @@ -21,6 +21,7 @@ namespace PocketMine\Event; use PocketMine; +use PocketMine\Event\Event as Event; abstract class EventHandler{ diff --git a/src/event/entity/EntityArmorChangeEvent.php b/src/event/entity/EntityArmorChangeEvent.php index 7cb442dc0..3dfdee548 100644 --- a/src/event/entity/EntityArmorChangeEvent.php +++ b/src/event/entity/EntityArmorChangeEvent.php @@ -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; } diff --git a/src/event/entity/EntityInventoryChangeEvent.php b/src/event/entity/EntityInventoryChangeEvent.php index 550867d9b..5bf099257 100644 --- a/src/event/entity/EntityInventoryChangeEvent.php +++ b/src/event/entity/EntityInventoryChangeEvent.php @@ -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; } diff --git a/src/event/entity/EntityLevelChangeEvent.php b/src/event/entity/EntityLevelChangeEvent.php index fd06bf236..fba9012fe 100644 --- a/src/event/entity/EntityLevelChangeEvent.php +++ b/src/event/entity/EntityLevelChangeEvent.php @@ -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; diff --git a/src/event/entity/EntityMotionEvent.php b/src/event/entity/EntityMotionEvent.php index c2e22357e..8457ed4e8 100644 --- a/src/event/entity/EntityMotionEvent.php +++ b/src/event/entity/EntityMotionEvent.php @@ -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; } diff --git a/src/event/entity/EntityMoveEvent.php b/src/event/entity/EntityMoveEvent.php index 0c0ec6e33..de45a2db3 100644 --- a/src/event/entity/EntityMoveEvent.php +++ b/src/event/entity/EntityMoveEvent.php @@ -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; } diff --git a/src/event/player/PlayerEquipmentChangeEvent.php b/src/event/player/PlayerEquipmentChangeEvent.php index c07adbf8c..8e10ca376 100644 --- a/src/event/player/PlayerEquipmentChangeEvent.php +++ b/src/event/player/PlayerEquipmentChangeEvent.php @@ -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; diff --git a/src/event/server/DataPacketReceiveEvent.php b/src/event/server/DataPacketReceiveEvent.php index 876ee8589..a2f0cd3de 100644 --- a/src/event/server/DataPacketReceiveEvent.php +++ b/src/event/server/DataPacketReceiveEvent.php @@ -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; } diff --git a/src/event/server/DataPacketSendEvent.php b/src/event/server/DataPacketSendEvent.php index 003e251f1..0bfdbbcc8 100644 --- a/src/event/server/DataPacketSendEvent.php +++ b/src/event/server/DataPacketSendEvent.php @@ -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; } diff --git a/src/event/server/PacketReceiveEvent.php b/src/event/server/PacketReceiveEvent.php index ca9de31fd..fdb643f3d 100644 --- a/src/event/server/PacketReceiveEvent.php +++ b/src/event/server/PacketReceiveEvent.php @@ -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; } diff --git a/src/event/server/PacketSendEvent.php b/src/event/server/PacketSendEvent.php index 3ec3de94f..8841e698e 100644 --- a/src/event/server/PacketSendEvent.php +++ b/src/event/server/PacketSendEvent.php @@ -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; } diff --git a/src/event/tile/TileInventoryChangeEvent.php b/src/event/tile/TileInventoryChangeEvent.php index cf1083943..ff53ed710 100644 --- a/src/event/tile/TileInventoryChangeEvent.php +++ b/src/event/tile/TileInventoryChangeEvent.php @@ -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; } diff --git a/src/level/Explosion.php b/src/level/Explosion.php index 3b1e07b99..c55175bc0 100644 --- a/src/level/Explosion.php +++ b/src/level/Explosion.php @@ -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; diff --git a/src/level/Level.php b/src/level/Level.php index a7ce7c83f..852cb26fe 100644 --- a/src/level/Level.php +++ b/src/level/Level.php @@ -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); diff --git a/src/level/LevelImport.php b/src/level/LevelImport.php index ddcee751b..b06f742b4 100644 --- a/src/level/LevelImport.php +++ b/src/level/LevelImport.php @@ -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"], diff --git a/src/level/PocketChunkParser.php b/src/level/PocketChunkParser.php index d1976245d..821633975 100644 --- a/src/level/PocketChunkParser.php +++ b/src/level/PocketChunkParser.php @@ -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 diff --git a/src/level/Position.php b/src/level/Position.php index 9799eb4b0..ea040a24d 100644 --- a/src/level/Position.php +++ b/src/level/Position.php @@ -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; diff --git a/src/level/WorldGenerator.php b/src/level/WorldGenerator.php index 0f8da5587..2862d46b1 100644 --- a/src/level/WorldGenerator.php +++ b/src/level/WorldGenerator.php @@ -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); } diff --git a/src/level/generator/Flat.php b/src/level/generator/Flat.php index 0770e68c5..f64ae6012 100644 --- a/src/level/generator/Flat.php +++ b/src/level/generator/Flat.php @@ -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); } } diff --git a/src/level/generator/Generator.php b/src/level/generator/Generator.php index f51d4b66c..8a93a00c2 100644 --- a/src/level/generator/Generator.php +++ b/src/level/generator/Generator.php @@ -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); diff --git a/src/level/generator/Normal.php b/src/level/generator/Normal.php index 92db6bc15..888b48838 100644 --- a/src/level/generator/Normal.php +++ b/src/level/generator/Normal.php @@ -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)); } } diff --git a/src/level/generator/object/BigTree.php b/src/level/generator/object/BigTree.php index c05d755a3..a11307a57 100644 --- a/src/level/generator/object/BigTree.php +++ b/src/level/generator/object/BigTree.php @@ -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); diff --git a/src/level/generator/object/Ore.php b/src/level/generator/object/Ore.php index 72021718d..9a4a8a69b 100644 --- a/src/level/generator/object/Ore.php +++ b/src/level/generator/object/Ore.php @@ -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); } } } diff --git a/src/level/generator/object/OreType.php b/src/level/generator/object/OreType.php index 9ad38c50b..fb379ac5d 100644 --- a/src/level/generator/object/OreType.php +++ b/src/level/generator/object/OreType.php @@ -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; diff --git a/src/level/generator/object/PineTree.php b/src/level/generator/object/PineTree.php index 59bc0c999..a9f266d59 100644 --- a/src/level/generator/object/PineTree.php +++ b/src/level/generator/object/PineTree.php @@ -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)); } } diff --git a/src/level/generator/object/Pond.php b/src/level/generator/object/Pond.php index 4eb8feb44..e75045c3b 100644 --- a/src/level/generator/object/Pond.php +++ b/src/level/generator/object/Pond.php @@ -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){ } } \ No newline at end of file diff --git a/src/level/generator/object/SmallTree.php b/src/level/generator/object/SmallTree.php index e3509a174..c635d912f 100644 --- a/src/level/generator/object/SmallTree.php +++ b/src/level/generator/object/SmallTree.php @@ -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)); } } } diff --git a/src/level/generator/object/SpruceTree.php b/src/level/generator/object/SpruceTree.php index 4c8afcb4a..91d5f31ad 100644 --- a/src/level/generator/object/SpruceTree.php +++ b/src/level/generator/object/SpruceTree.php @@ -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)); } } diff --git a/src/level/generator/object/TallGrass.php b/src/level/generator/object/TallGrass.php index 6a9dd45d3..d2568bfb9 100644 --- a/src/level/generator/object/TallGrass.php +++ b/src/level/generator/object/TallGrass.php @@ -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); } } } diff --git a/src/level/generator/object/Tree.php b/src/level/generator/object/Tree.php index e6110876f..b6d239df2 100644 --- a/src/level/generator/object/Tree.php +++ b/src/level/generator/object/Tree.php @@ -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: diff --git a/src/level/generator/populator/Mineshaft.php b/src/level/generator/populator/Mineshaft.php index 9f582f526..bdad84782 100644 --- a/src/level/generator/populator/Mineshaft.php +++ b/src/level/generator/populator/Mineshaft.php @@ -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); } diff --git a/src/level/generator/populator/Ore.php b/src/level/generator/populator/Ore.php index d96783166..5cf3292e5 100644 --- a/src/level/generator/populator/Ore.php +++ b/src/level/generator/populator/Ore.php @@ -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)); } } } diff --git a/src/level/generator/populator/Pond.php b/src/level/generator/populator/Pond.php index 1ab9c9aee..562218a0c 100644 --- a/src/level/generator/populator/Pond.php +++ b/src/level/generator/populator/Pond.php @@ -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); } diff --git a/src/level/generator/populator/Populator.php b/src/level/generator/populator/Populator.php index 6a84e3edd..72c23c233 100644 --- a/src/level/generator/populator/Populator.php +++ b/src/level/generator/populator/Populator.php @@ -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); } \ No newline at end of file diff --git a/src/level/generator/populator/TallGrass.php b/src/level/generator/populator/TallGrass.php index 30d1707ae..26476afb6 100644 --- a/src/level/generator/populator/TallGrass.php +++ b/src/level/generator/populator/TallGrass.php @@ -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; diff --git a/src/level/generator/populator/Tree.php b/src/level/generator/populator/Tree.php index f707cb7d7..0a6ea71f7 100644 --- a/src/level/generator/populator/Tree.php +++ b/src/level/generator/populator/Tree.php @@ -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; diff --git a/src/math/AxisAlignedBB.php b/src/math/AxisAlignedBB.php index ccc18fa14..b4e6ad4c9 100644 --- a/src/math/AxisAlignedBB.php +++ b/src/math/AxisAlignedBB.php @@ -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; } diff --git a/src/math/Vector2.php b/src/math/Vector2.php index 5e92685bf..173b42c61 100644 --- a/src/math/Vector2.php +++ b/src/math/Vector2.php @@ -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); } } diff --git a/src/math/Vector3.php b/src/math/Vector3.php index 726a97926..c77267a97 100644 --- a/src/math/Vector3.php +++ b/src/math/Vector3.php @@ -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 diff --git a/src/nbt/NBT.php b/src/nbt/NBT.php index ed5fb12ab..313793365 100644 --- a/src/nbt/NBT.php +++ b/src/nbt/NBT.php @@ -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; } diff --git a/src/nbt/tag/Compound.php b/src/nbt/tag/Compound.php index fb34dc74b..8339c6dec 100644 --- a/src/nbt/tag/Compound.php +++ b/src/nbt/tag/Compound.php @@ -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); } } \ No newline at end of file diff --git a/src/nbt/tag/Enum.php b/src/nbt/tag/Enum.php index 8c52bb667..75f42f4fb 100644 --- a/src/nbt/tag/Enum.php +++ b/src/nbt/tag/Enum.php @@ -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; diff --git a/src/network/Handler.php b/src/network/Handler.php index c94f16347..0bda9b37a 100644 --- a/src/network/Handler.php +++ b/src/network/Handler.php @@ -21,6 +21,7 @@ namespace PocketMine\Network; use PocketMine; +use PocketMine\ServerAPI as ServerAPI; class Handler{ public $bandwidth; diff --git a/src/network/protocol/DataPacket.php b/src/network/protocol/DataPacket.php index 9851dc953..f134bd7b8 100644 --- a/src/network/protocol/DataPacket.php +++ b/src/network/protocol/DataPacket.php @@ -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(){ diff --git a/src/network/protocol/packet/AddEntityPacket.php b/src/network/protocol/packet/AddEntityPacket.php index d893b71dc..315a336a2 100644 --- a/src/network/protocol/packet/AddEntityPacket.php +++ b/src/network/protocol/packet/AddEntityPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class AddEntityPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/AddItemEntityPacket.php b/src/network/protocol/packet/AddItemEntityPacket.php index 5fe765508..9cd487221 100644 --- a/src/network/protocol/packet/AddItemEntityPacket.php +++ b/src/network/protocol/packet/AddItemEntityPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class AddItemEntityPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/AddMobPacket.php b/src/network/protocol/packet/AddMobPacket.php index e5056ee5d..3c6efcc2f 100644 --- a/src/network/protocol/packet/AddMobPacket.php +++ b/src/network/protocol/packet/AddMobPacket.php @@ -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)); } } \ No newline at end of file diff --git a/src/network/protocol/packet/AddPaintingPacket.php b/src/network/protocol/packet/AddPaintingPacket.php index 250eef130..b631785f1 100644 --- a/src/network/protocol/packet/AddPaintingPacket.php +++ b/src/network/protocol/packet/AddPaintingPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class AddPaintingPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/AddPlayerPacket.php b/src/network/protocol/packet/AddPlayerPacket.php index 4b049ef26..9aa09d2f5 100644 --- a/src/network/protocol/packet/AddPlayerPacket.php +++ b/src/network/protocol/packet/AddPlayerPacket.php @@ -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)); } } \ No newline at end of file diff --git a/src/network/protocol/packet/AdventureSettingsPacket.php b/src/network/protocol/packet/AdventureSettingsPacket.php index cb182d954..d36c3f890 100644 --- a/src/network/protocol/packet/AdventureSettingsPacket.php +++ b/src/network/protocol/packet/AdventureSettingsPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class AdventureSettingsPacket extends DataPacket{ public $flags; diff --git a/src/network/protocol/packet/AnimatePacket.php b/src/network/protocol/packet/AnimatePacket.php index e4f32b652..99bc3c1d9 100644 --- a/src/network/protocol/packet/AnimatePacket.php +++ b/src/network/protocol/packet/AnimatePacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class AnimatePacket extends DataPacket{ public $action; diff --git a/src/network/protocol/packet/ChatPacket.php b/src/network/protocol/packet/ChatPacket.php index ac3b90836..a14719c65 100644 --- a/src/network/protocol/packet/ChatPacket.php +++ b/src/network/protocol/packet/ChatPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class ChatPacket extends DataPacket{ public $message; diff --git a/src/network/protocol/packet/ChunkDataPacket.php b/src/network/protocol/packet/ChunkDataPacket.php index 395ead10c..dbbe593c2 100644 --- a/src/network/protocol/packet/ChunkDataPacket.php +++ b/src/network/protocol/packet/ChunkDataPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class ChunkDataPacket extends DataPacket{ public $chunkX; diff --git a/src/network/protocol/packet/ClientConnectPacket.php b/src/network/protocol/packet/ClientConnectPacket.php index 6dab6efcd..f82ffda5b 100644 --- a/src/network/protocol/packet/ClientConnectPacket.php +++ b/src/network/protocol/packet/ClientConnectPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class ClientConnectPacket extends DataPacket{ public $clientID; diff --git a/src/network/protocol/packet/ClientHandshakePacket.php b/src/network/protocol/packet/ClientHandshakePacket.php index 7df3531c5..5dc019c3a 100644 --- a/src/network/protocol/packet/ClientHandshakePacket.php +++ b/src/network/protocol/packet/ClientHandshakePacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class ClientHandshakePacket extends DataPacket{ public $cookie; diff --git a/src/network/protocol/packet/ContainerClosePacket.php b/src/network/protocol/packet/ContainerClosePacket.php index c028204b6..556662166 100644 --- a/src/network/protocol/packet/ContainerClosePacket.php +++ b/src/network/protocol/packet/ContainerClosePacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class ContainerClosePacket extends DataPacket{ public $windowid; diff --git a/src/network/protocol/packet/ContainerOpenPacket.php b/src/network/protocol/packet/ContainerOpenPacket.php index 4257b857c..bbec1245e 100644 --- a/src/network/protocol/packet/ContainerOpenPacket.php +++ b/src/network/protocol/packet/ContainerOpenPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class ContainerOpenPacket extends DataPacket{ public $windowid; diff --git a/src/network/protocol/packet/ContainerSetContentPacket.php b/src/network/protocol/packet/ContainerSetContentPacket.php index 32d5d59c0..9566b4c0c 100644 --- a/src/network/protocol/packet/ContainerSetContentPacket.php +++ b/src/network/protocol/packet/ContainerSetContentPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class ContainerSetContentPacket extends DataPacket{ public $windowid; diff --git a/src/network/protocol/packet/ContainerSetDataPacket.php b/src/network/protocol/packet/ContainerSetDataPacket.php index 89db6c787..aa0f6917c 100644 --- a/src/network/protocol/packet/ContainerSetDataPacket.php +++ b/src/network/protocol/packet/ContainerSetDataPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class ContainerSetDataPacket extends DataPacket{ public $windowid; diff --git a/src/network/protocol/packet/ContainerSetSlotPacket.php b/src/network/protocol/packet/ContainerSetSlotPacket.php index be88a50af..fe60df87b 100644 --- a/src/network/protocol/packet/ContainerSetSlotPacket.php +++ b/src/network/protocol/packet/ContainerSetSlotPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class ContainerSetSlotPacket extends DataPacket{ public $windowid; diff --git a/src/network/protocol/packet/DisconnectPacket.php b/src/network/protocol/packet/DisconnectPacket.php index 68afafc85..1d928d76e 100644 --- a/src/network/protocol/packet/DisconnectPacket.php +++ b/src/network/protocol/packet/DisconnectPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class DisconnectPacket extends DataPacket{ public function pid(){ diff --git a/src/network/protocol/packet/DropItemPacket.php b/src/network/protocol/packet/DropItemPacket.php index 3338327f2..01b064e91 100644 --- a/src/network/protocol/packet/DropItemPacket.php +++ b/src/network/protocol/packet/DropItemPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class DropItemPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/EntityDataPacket.php b/src/network/protocol/packet/EntityDataPacket.php index 7ad892e38..33713b680 100644 --- a/src/network/protocol/packet/EntityDataPacket.php +++ b/src/network/protocol/packet/EntityDataPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class EntityDataPacket extends DataPacket{ public $x; diff --git a/src/network/protocol/packet/EntityEventPacket.php b/src/network/protocol/packet/EntityEventPacket.php index d666633e0..d70359094 100644 --- a/src/network/protocol/packet/EntityEventPacket.php +++ b/src/network/protocol/packet/EntityEventPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class EntityEventPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/ExplodePacket.php b/src/network/protocol/packet/ExplodePacket.php index f4823c621..4c9e12a40 100644 --- a/src/network/protocol/packet/ExplodePacket.php +++ b/src/network/protocol/packet/ExplodePacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class ExplodePacket extends DataPacket{ public $x; diff --git a/src/network/protocol/packet/HurtArmorPacket.php b/src/network/protocol/packet/HurtArmorPacket.php index 62c2be85a..45ea037b1 100644 --- a/src/network/protocol/packet/HurtArmorPacket.php +++ b/src/network/protocol/packet/HurtArmorPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class HurtArmorPacket extends DataPacket{ public $health; diff --git a/src/network/protocol/packet/InteractPacket.php b/src/network/protocol/packet/InteractPacket.php index 7a3fe0c8b..b9660da72 100644 --- a/src/network/protocol/packet/InteractPacket.php +++ b/src/network/protocol/packet/InteractPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class InteractPacket extends DataPacket{ public $action; diff --git a/src/network/protocol/packet/LevelEventPacket.php b/src/network/protocol/packet/LevelEventPacket.php index f682612fa..1ecce05ec 100644 --- a/src/network/protocol/packet/LevelEventPacket.php +++ b/src/network/protocol/packet/LevelEventPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class LevelEventPacket extends DataPacket{ public $evid; diff --git a/src/network/protocol/packet/LoginPacket.php b/src/network/protocol/packet/LoginPacket.php index bf1e48d34..51250e920 100644 --- a/src/network/protocol/packet/LoginPacket.php +++ b/src/network/protocol/packet/LoginPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class LoginPacket extends DataPacket{ public $username; diff --git a/src/network/protocol/packet/LoginStatusPacket.php b/src/network/protocol/packet/LoginStatusPacket.php index 4450f27c8..0e58cf2ea 100644 --- a/src/network/protocol/packet/LoginStatusPacket.php +++ b/src/network/protocol/packet/LoginStatusPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class LoginStatusPacket extends DataPacket{ public $status; diff --git a/src/network/protocol/packet/MessagePacket.php b/src/network/protocol/packet/MessagePacket.php index e1ba9688e..a91a76e8f 100644 --- a/src/network/protocol/packet/MessagePacket.php +++ b/src/network/protocol/packet/MessagePacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class MessagePacket extends DataPacket{ public $source; diff --git a/src/network/protocol/packet/MoveEntityPacket.php b/src/network/protocol/packet/MoveEntityPacket.php index 65b76e9ce..badeaf1c2 100644 --- a/src/network/protocol/packet/MoveEntityPacket.php +++ b/src/network/protocol/packet/MoveEntityPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class MoveEntityPacket extends DataPacket{ diff --git a/src/network/protocol/packet/MoveEntityPacket_PosRot.php b/src/network/protocol/packet/MoveEntityPacket_PosRot.php index 2d36e8f2f..2577b62cd 100644 --- a/src/network/protocol/packet/MoveEntityPacket_PosRot.php +++ b/src/network/protocol/packet/MoveEntityPacket_PosRot.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class MoveEntityPacket_PosRot extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/MovePlayerPacket.php b/src/network/protocol/packet/MovePlayerPacket.php index dff525ae0..99096372f 100644 --- a/src/network/protocol/packet/MovePlayerPacket.php +++ b/src/network/protocol/packet/MovePlayerPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class MovePlayerPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/PingPacket.php b/src/network/protocol/packet/PingPacket.php index 30752f435..956c6eabb 100644 --- a/src/network/protocol/packet/PingPacket.php +++ b/src/network/protocol/packet/PingPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class PingPacket extends DataPacket{ public $time = 0; diff --git a/src/network/protocol/packet/PlayerActionPacket.php b/src/network/protocol/packet/PlayerActionPacket.php index 85792bb99..6c4abcadf 100644 --- a/src/network/protocol/packet/PlayerActionPacket.php +++ b/src/network/protocol/packet/PlayerActionPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class PlayerActionPacket extends DataPacket{ public $action; diff --git a/src/network/protocol/packet/PlayerArmorEquipmentPacket.php b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php index 0ae0d9136..061683837 100644 --- a/src/network/protocol/packet/PlayerArmorEquipmentPacket.php +++ b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class PlayerArmorEquipmentPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/PlayerEquipmentPacket.php b/src/network/protocol/packet/PlayerEquipmentPacket.php index 488b2e406..9f0949b1f 100644 --- a/src/network/protocol/packet/PlayerEquipmentPacket.php +++ b/src/network/protocol/packet/PlayerEquipmentPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class PlayerEquipmentPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/PongPacket.php b/src/network/protocol/packet/PongPacket.php index ec5928425..7558ac5aa 100644 --- a/src/network/protocol/packet/PongPacket.php +++ b/src/network/protocol/packet/PongPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class PongPacket extends DataPacket{ public $time = 0; diff --git a/src/network/protocol/packet/ReadyPacket.php b/src/network/protocol/packet/ReadyPacket.php index 71422bb4e..73c43e692 100644 --- a/src/network/protocol/packet/ReadyPacket.php +++ b/src/network/protocol/packet/ReadyPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class ReadyPacket extends DataPacket{ public $status; diff --git a/src/network/protocol/packet/RemoveBlockPacket.php b/src/network/protocol/packet/RemoveBlockPacket.php index 2e6c6e51d..287a86a76 100644 --- a/src/network/protocol/packet/RemoveBlockPacket.php +++ b/src/network/protocol/packet/RemoveBlockPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class RemoveBlockPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/RemoveEntityPacket.php b/src/network/protocol/packet/RemoveEntityPacket.php index 37c570268..ae9f6b19d 100644 --- a/src/network/protocol/packet/RemoveEntityPacket.php +++ b/src/network/protocol/packet/RemoveEntityPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class RemoveEntityPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/RemovePlayerPacket.php b/src/network/protocol/packet/RemovePlayerPacket.php index 70356f8d9..04ce0832e 100644 --- a/src/network/protocol/packet/RemovePlayerPacket.php +++ b/src/network/protocol/packet/RemovePlayerPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class RemovePlayerPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/RequestChunkPacket.php b/src/network/protocol/packet/RequestChunkPacket.php index 83b8e0138..bd85891d8 100644 --- a/src/network/protocol/packet/RequestChunkPacket.php +++ b/src/network/protocol/packet/RequestChunkPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class RequestChunkPacket extends DataPacket{ public $chunkX; diff --git a/src/network/protocol/packet/RespawnPacket.php b/src/network/protocol/packet/RespawnPacket.php index b73637dc0..e03d46e54 100644 --- a/src/network/protocol/packet/RespawnPacket.php +++ b/src/network/protocol/packet/RespawnPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class RespawnPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/RotateHeadPacket.php b/src/network/protocol/packet/RotateHeadPacket.php index 4227c7b33..e8b7a5f2a 100644 --- a/src/network/protocol/packet/RotateHeadPacket.php +++ b/src/network/protocol/packet/RotateHeadPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class RotateHeadPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/SendInventoryPacket.php b/src/network/protocol/packet/SendInventoryPacket.php index 0ec0f6513..d1840c914 100644 --- a/src/network/protocol/packet/SendInventoryPacket.php +++ b/src/network/protocol/packet/SendInventoryPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class SendInventoryPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/ServerHandshakePacket.php b/src/network/protocol/packet/ServerHandshakePacket.php index 10f7172bd..239041984 100644 --- a/src/network/protocol/packet/ServerHandshakePacket.php +++ b/src/network/protocol/packet/ServerHandshakePacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class ServerHandshakePacket extends DataPacket{ public $port; diff --git a/src/network/protocol/packet/SetEntityDataPacket.php b/src/network/protocol/packet/SetEntityDataPacket.php index b72e160b4..554f7ac75 100644 --- a/src/network/protocol/packet/SetEntityDataPacket.php +++ b/src/network/protocol/packet/SetEntityDataPacket.php @@ -21,6 +21,8 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; +use PocketMine\Utils\Utils as Utils; class SetEntityDataPacket extends DataPacket{ public $eid; @@ -37,7 +39,7 @@ class SetEntityDataPacket extends DataPacket{ public function encode(){ $this->reset(); $this->putInt($this->eid); - $this->put(Utils\Utils::writeMetadata($this->metadata)); + $this->put(Utils::writeMetadata($this->metadata)); } } \ No newline at end of file diff --git a/src/network/protocol/packet/SetEntityMotionPacket.php b/src/network/protocol/packet/SetEntityMotionPacket.php index 85b69bb61..e1944c135 100644 --- a/src/network/protocol/packet/SetEntityMotionPacket.php +++ b/src/network/protocol/packet/SetEntityMotionPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class SetEntityMotionPacket extends DataPacket{ public $eid; diff --git a/src/network/protocol/packet/SetHealthPacket.php b/src/network/protocol/packet/SetHealthPacket.php index 13cec73dd..80326c6f8 100644 --- a/src/network/protocol/packet/SetHealthPacket.php +++ b/src/network/protocol/packet/SetHealthPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class SetHealthPacket extends DataPacket{ public $health; diff --git a/src/network/protocol/packet/SetSpawnPositionPacket.php b/src/network/protocol/packet/SetSpawnPositionPacket.php index 454f2ffdc..cc9278b98 100644 --- a/src/network/protocol/packet/SetSpawnPositionPacket.php +++ b/src/network/protocol/packet/SetSpawnPositionPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class SetSpawnPositionPacket extends DataPacket{ public $x; diff --git a/src/network/protocol/packet/SetTimePacket.php b/src/network/protocol/packet/SetTimePacket.php index 7304c3bfd..7217c5419 100644 --- a/src/network/protocol/packet/SetTimePacket.php +++ b/src/network/protocol/packet/SetTimePacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class SetTimePacket extends DataPacket{ public $time; diff --git a/src/network/protocol/packet/StartGamePacket.php b/src/network/protocol/packet/StartGamePacket.php index e35b238ed..22d21bc85 100644 --- a/src/network/protocol/packet/StartGamePacket.php +++ b/src/network/protocol/packet/StartGamePacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class StartGamePacket extends DataPacket{ public $seed; diff --git a/src/network/protocol/packet/TakeItemEntityPacket.php b/src/network/protocol/packet/TakeItemEntityPacket.php index 68543da6f..d349481ea 100644 --- a/src/network/protocol/packet/TakeItemEntityPacket.php +++ b/src/network/protocol/packet/TakeItemEntityPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class TakeItemEntityPacket extends DataPacket{ public $target; diff --git a/src/network/protocol/packet/TileEventPacket.php b/src/network/protocol/packet/TileEventPacket.php index e275d05d1..0aa229bec 100644 --- a/src/network/protocol/packet/TileEventPacket.php +++ b/src/network/protocol/packet/TileEventPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class TileEventPacket extends DataPacket{ public $x; diff --git a/src/network/protocol/packet/UpdateBlockPacket.php b/src/network/protocol/packet/UpdateBlockPacket.php index 69e0e6ec1..c83f63dd5 100644 --- a/src/network/protocol/packet/UpdateBlockPacket.php +++ b/src/network/protocol/packet/UpdateBlockPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class UpdateBlockPacket extends DataPacket{ public $x; diff --git a/src/network/protocol/packet/UseItemPacket.php b/src/network/protocol/packet/UseItemPacket.php index fc8f56496..6a7982884 100644 --- a/src/network/protocol/packet/UseItemPacket.php +++ b/src/network/protocol/packet/UseItemPacket.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\Protocol; use PocketMine; +use PocketMine\Network\Protocol\Info as Info; class UseItemPacket extends DataPacket{ public $x; diff --git a/src/network/query/QueryHandler.php b/src/network/query/QueryHandler.php index 247b5aa2f..38a22046e 100644 --- a/src/network/query/QueryHandler.php +++ b/src/network/query/QueryHandler.php @@ -21,6 +21,10 @@ namespace PocketMine\Network\Query; use PocketMine; +use PocketMine\ServerAPI as ServerAPI; +use PocketMine\Player as Player; +use PocketMine\Utils\Utils as Utils; +use PocketMine\Network\Query\QueryPacket as QueryPacket; /* Implementation of the UT3 Query Protocol (GameSpot) @@ -94,11 +98,11 @@ class QueryHandler{ public function regenerateToken(){ $this->lastToken = $this->token; - $this->token = Utils\Utils::getRandomBytes(16, false); + $this->token = Utils::getRandomBytes(16, false); } public static function getTokenString($token, $salt){ - return Utils\Utils::readInt(substr(hash("sha512", $salt . ":". $token, true), 7, 4)); + return Utils::readInt(substr(hash("sha512", $salt . ":". $token, true), 7, 4)); } public function handle(QueryPacket $packet){ @@ -115,7 +119,7 @@ class QueryHandler{ $this->server->send($pk); break; case QueryPacket::STATISTICS: //Stat - $token = Utils\Utils::readInt(substr($packet->payload, 0, 4)); + $token = Utils::readInt(substr($packet->payload, 0, 4)); if($token !== self::getTokenString($this->token, $packet->ip) and $token !== self::getTokenString($this->lastToken, $packet->ip)){ break; } @@ -130,7 +134,7 @@ class QueryHandler{ } $pk->payload = $this->longData; }else{ - $pk->payload = $this->server->name."\x00".(($this->server->gamemode & 0x01) === 0 ? "SMP":"CMP")."\x00".$this->server->api->level->getDefault()->getName()."\x00".count(Player::$list)."\x00".$this->server->maxClients."\x00".Utils\Utils::writeLShort($this->server->api->getProperty("server-port")).$this->server->api->getProperty("server-ip", "0.0.0.0")."\x00"; + $pk->payload = $this->server->name."\x00".(($this->server->gamemode & 0x01) === 0 ? "SMP":"CMP")."\x00".$this->server->api->level->getDefault()->getName()."\x00".count(Player::$list)."\x00".$this->server->maxClients."\x00".Utils::writeLShort($this->server->api->getProperty("server-port")).$this->server->api->getProperty("server-ip", "0.0.0.0")."\x00"; } $pk->encode(); $this->server->send($pk); diff --git a/src/network/query/QueryPacket.php b/src/network/query/QueryPacket.php index 5bdb6438a..f186e5123 100644 --- a/src/network/query/QueryPacket.php +++ b/src/network/query/QueryPacket.php @@ -21,8 +21,10 @@ namespace PocketMine\Network\Query; use PocketMine; +use PocketMine\Network\Packet as Packet; +use PocketMine\Utils\Utils as Utils; -class QueryPacket extends Network\Packet{ +class QueryPacket extends Packet{ const HANDSHAKE = 9; const STATISTICS = 0; @@ -32,13 +34,13 @@ class QueryPacket extends Network\Packet{ public function decode(){ $this->packetType = ord($this->buffer{2}); - $this->sessionID = Utils\Utils::readInt(substr($this->buffer, 3, 4)); + $this->sessionID = Utils::readInt(substr($this->buffer, 3, 4)); $this->payload = substr($this->buffer, 7); } public function encode(){ $this->buffer .= chr($this->packetType); - $this->buffer .= Utils\Utils::writeInt($this->sessionID); + $this->buffer .= Utils::writeInt($this->sessionID); $this->buffer .= $this->payload; } } \ No newline at end of file diff --git a/src/network/raknet/Packet.php b/src/network/raknet/Packet.php index a4b87fe9d..a91959f5c 100644 --- a/src/network/raknet/Packet.php +++ b/src/network/raknet/Packet.php @@ -21,8 +21,12 @@ namespace PocketMine\Network\RakNet; use PocketMine; +use PocketMine\Network\Packet as NetworkPacket; +use PocketMine\Utils\Utils as Utils; +use PocketMine\Network\RakNet\Info as Info; +use PocketMine\Network\Protocol\Info as ProtocolInfo; -class Packet extends Network\Packet{ +class Packet extends NetworkPacket{ private $packetID; private $offset = 1; public $data = array(); @@ -51,19 +55,19 @@ class Packet extends Network\Packet{ } private function getLong($unsigned = false){ - return Utils\Utils::readLong($this->get(8), $unsigned); + return Utils::readLong($this->get(8), $unsigned); } private function getInt(){ - return Utils\Utils::readInt($this->get(4)); + return Utils::readInt($this->get(4)); } private function getShort($unsigned = false){ - return Utils\Utils::readShort($this->get(2), $unsigned); + return Utils::readShort($this->get(2), $unsigned); } private function getLTriad(){ - return Utils\Utils::readTriad(strrev($this->get(3))); + return Utils::readTriad(strrev($this->get(3))); } private function getByte(){ @@ -187,163 +191,163 @@ class Packet extends Network\Packet{ return false; } switch($pid){ - case Network\Protocol\Info::PING_PACKET: + case ProtocolInfo::PING_PACKET: $data = new PingPacket; break; - case Network\Protocol\Info::PONG_PACKET: + case ProtocolInfo::PONG_PACKET: $data = new PongPacket; break; - case Network\Protocol\Info::CLIENT_CONNECT_PACKET: + case ProtocolInfo::CLIENT_CONNECT_PACKET: $data = new ClientConnectPacket; break; - case Network\Protocol\Info::SERVER_HANDSHAKE_PACKET: + case ProtocolInfo::SERVER_HANDSHAKE_PACKET: $data = new ServerHandshakePacket; break; - case Network\Protocol\Info::DISCONNECT_PACKET: + case ProtocolInfo::DISCONNECT_PACKET: $data = new DisconnectPacket; break; - case Network\Protocol\Info::LOGIN_PACKET: + case ProtocolInfo::LOGIN_PACKET: $data = new LoginPacket; break; - case Network\Protocol\Info::LOGIN_STATUS_PACKET: + case ProtocolInfo::LOGIN_STATUS_PACKET: $data = new LoginStatusPacket; break; - case Network\Protocol\Info::READY_PACKET: + case ProtocolInfo::READY_PACKET: $data = new ReadyPacket; break; - case Network\Protocol\Info::MESSAGE_PACKET: + case ProtocolInfo::MESSAGE_PACKET: $data = new MessagePacket; break; - case Network\Protocol\Info::SET_TIME_PACKET: + case ProtocolInfo::SET_TIME_PACKET: $data = new SetTimePacket; break; - case Network\Protocol\Info::START_GAME_PACKET: + case ProtocolInfo::START_GAME_PACKET: $data = new StartGamePacket; break; - case Network\Protocol\Info::ADD_MOB_PACKET: + case ProtocolInfo::ADD_MOB_PACKET: $data = new AddMobPacket; break; - case Network\Protocol\Info::ADD_PLAYER_PACKET: + case ProtocolInfo::ADD_PLAYER_PACKET: $data = new AddPlayerPacket; break; - case Network\Protocol\Info::REMOVE_PLAYER_PACKET: + case ProtocolInfo::REMOVE_PLAYER_PACKET: $data = new RemovePlayerPacket; break; - case Network\Protocol\Info::ADD_ENTITY_PACKET: + case ProtocolInfo::ADD_ENTITY_PACKET: $data = new AddEntityPacket; break; - case Network\Protocol\Info::REMOVE_ENTITY_PACKET: + case ProtocolInfo::REMOVE_ENTITY_PACKET: $data = new RemoveEntityPacket; break; - case Network\Protocol\Info::ADD_ITEM_ENTITY_PACKET: + case ProtocolInfo::ADD_ITEM_ENTITY_PACKET: $data = new AddItemEntityPacket; break; - case Network\Protocol\Info::TAKE_ITEM_ENTITY_PACKET: + case ProtocolInfo::TAKE_ITEM_ENTITY_PACKET: $data = new TakeItemEntityPacket; break; - case Network\Protocol\Info::MOVE_ENTITY_PACKET: + case ProtocolInfo::MOVE_ENTITY_PACKET: $data = new MoveEntityPacket; break; - case Network\Protocol\Info::MOVE_ENTITY_PACKET_POSROT: + case ProtocolInfo::MOVE_ENTITY_PACKET_POSROT: $data = new MoveEntityPacket_PosRot; break; - case Network\Protocol\Info::ROTATE_HEAD_PACKET: + case ProtocolInfo::ROTATE_HEAD_PACKET: $data = new RotateHeadPacket; break; - case Network\Protocol\Info::MOVE_PLAYER_PACKET: + case ProtocolInfo::MOVE_PLAYER_PACKET: $data = new MovePlayerPacket; break; - case Network\Protocol\Info::REMOVE_BLOCK_PACKET: + case ProtocolInfo::REMOVE_BLOCK_PACKET: $data = new RemoveBlockPacket; break; - case Network\Protocol\Info::UPDATE_BLOCK_PACKET: + case ProtocolInfo::UPDATE_BLOCK_PACKET: $data = new UpdateBlockPacket; break; - case Network\Protocol\Info::ADD_PAINTING_PACKET: + case ProtocolInfo::ADD_PAINTING_PACKET: $data = new AddPaintingPacket; break; - case Network\Protocol\Info::EXPLODE_PACKET: + case ProtocolInfo::EXPLODE_PACKET: $data = new ExplodePacket; break; - case Network\Protocol\Info::LEVEL_EVENT_PACKET: + case ProtocolInfo::LEVEL_EVENT_PACKET: $data = new LevelEventPacket; break; - case Network\Protocol\Info::TILE_EVENT_PACKET: + case ProtocolInfo::TILE_EVENT_PACKET: $data = new TileEventPacket; break; - case Network\Protocol\Info::ENTITY_EVENT_PACKET: + case ProtocolInfo::ENTITY_EVENT_PACKET: $data = new EntityEventPacket; break; - case Network\Protocol\Info::REQUEST_CHUNK_PACKET: + case ProtocolInfo::REQUEST_CHUNK_PACKET: $data = new RequestChunkPacket; break; - case Network\Protocol\Info::CHUNK_DATA_PACKET: + case ProtocolInfo::CHUNK_DATA_PACKET: $data = new ChunkDataPacket; break; - case Network\Protocol\Info::PLAYER_EQUIPMENT_PACKET: + case ProtocolInfo::PLAYER_EQUIPMENT_PACKET: $data = new PlayerEquipmentPacket; break; - case Network\Protocol\Info::PLAYER_ARMOR_EQUIPMENT_PACKET: + case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET: $data = new PlayerArmorEquipmentPacket; break; - case Network\Protocol\Info::INTERACT_PACKET: + case ProtocolInfo::INTERACT_PACKET: $data = new InteractPacket; break; - case Network\Protocol\Info::USE_ITEM_PACKET: + case ProtocolInfo::USE_ITEM_PACKET: $data = new UseItemPacket; break; - case Network\Protocol\Info::PLAYER_ACTION_PACKET: + case ProtocolInfo::PLAYER_ACTION_PACKET: $data = new PlayerActionPacket; break; - case Network\Protocol\Info::HURT_ARMOR_PACKET: + case ProtocolInfo::HURT_ARMOR_PACKET: $data = new HurtArmorPacket; break; - case Network\Protocol\Info::SET_ENTITY_DATA_PACKET: + case ProtocolInfo::SET_ENTITY_DATA_PACKET: $data = new SetEntityDataPacket; break; - case Network\Protocol\Info::SET_ENTITY_MOTION_PACKET: + case ProtocolInfo::SET_ENTITY_MOTION_PACKET: $data = new SetEntityMotionPacket; break; - case Network\Protocol\Info::SET_HEALTH_PACKET: + case ProtocolInfo::SET_HEALTH_PACKET: $data = new SetHealthPacket; break; - case Network\Protocol\Info::SET_SPAWN_POSITION_PACKET: + case ProtocolInfo::SET_SPAWN_POSITION_PACKET: $data = new SetSpawnPositionPacket; break; - case Network\Protocol\Info::ANIMATE_PACKET: + case ProtocolInfo::ANIMATE_PACKET: $data = new AnimatePacket; break; - case Network\Protocol\Info::RESPAWN_PACKET: + case ProtocolInfo::RESPAWN_PACKET: $data = new RespawnPacket; break; - case Network\Protocol\Info::SEND_INVENTORY_PACKET: + case ProtocolInfo::SEND_INVENTORY_PACKET: $data = new SendInventoryPacket; break; - case Network\Protocol\Info::DROP_ITEM_PACKET: + case ProtocolInfo::DROP_ITEM_PACKET: $data = new DropItemPacket; break; - case Network\Protocol\Info::CONTAINER_OPEN_PACKET: + case ProtocolInfo::CONTAINER_OPEN_PACKET: $data = new ContainerOpenPacket; break; - case Network\Protocol\Info::CONTAINER_CLOSE_PACKET: + case ProtocolInfo::CONTAINER_CLOSE_PACKET: $data = new ContainerClosePacket; break; - case Network\Protocol\Info::CONTAINER_SET_SLOT_PACKET: + case ProtocolInfo::CONTAINER_SET_SLOT_PACKET: $data = new ContainerSetSlotPacket; break; - case Network\Protocol\Info::CONTAINER_SET_DATA_PACKET: + case ProtocolInfo::CONTAINER_SET_DATA_PACKET: $data = new ContainerSetDataPacket; break; - case Network\Protocol\Info::CONTAINER_SET_CONTENT_PACKET: + case ProtocolInfo::CONTAINER_SET_CONTENT_PACKET: $data = new ContainerSetContentPacket; break; - case Network\Protocol\Info::CHAT_PACKET: + case ProtocolInfo::CHAT_PACKET: $data = new ChatPacket; break; - case Network\Protocol\Info::ADVENTURE_SETTINGS_PACKET: + case ProtocolInfo::ADVENTURE_SETTINGS_PACKET: $data = new AdventureSettingsPacket; break; - case Network\Protocol\Info::ENTITY_DATA_PACKET: + case ProtocolInfo::ENTITY_DATA_PACKET: $data = new EntityDataPacket; break; default: @@ -442,11 +446,11 @@ class Packet extends Network\Packet{ ++$pointer; if($type === false){ $payload .= "\x00"; - $payload .= strrev(Utils\Utils::writeTriad($start)); - $payload .= strrev(Utils\Utils::writeTriad($end)); + $payload .= strrev(Utils::writeTriad($start)); + $payload .= strrev(Utils::writeTriad($end)); }else{ - $payload .= Utils\Utils::writeBool(true); - $payload .= strrev(Utils\Utils::writeTriad($start)); + $payload .= Utils::writeBool(true); + $payload .= strrev(Utils::writeTriad($start)); } ++$records; } @@ -492,23 +496,23 @@ class Packet extends Network\Packet{ } protected function putLong($v){ - $this->buffer .= Utils\Utils::writeLong($v); + $this->buffer .= Utils::writeLong($v); } protected function putInt($v){ - $this->buffer .= Utils\Utils::writeInt($v); + $this->buffer .= Utils::writeInt($v); } protected function putShort($v){ - $this->buffer .= Utils\Utils::writeShort($v); + $this->buffer .= Utils::writeShort($v); } protected function putTriad($v){ - $this->buffer .= Utils\Utils::writeTriad($v); + $this->buffer .= Utils::writeTriad($v); } protected function putLTriad($v){ - $this->buffer .= strrev(Utils\Utils::writeTriad($v)); + $this->buffer .= strrev(Utils::writeTriad($v)); } protected function putByte($v){ diff --git a/src/network/rcon/RCON.php b/src/network/rcon/RCON.php index 377e4f7b1..b0b4f878a 100644 --- a/src/network/rcon/RCON.php +++ b/src/network/rcon/RCON.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\RCON; use PocketMine; +use PocketMine\ServerAPI as ServerAPI; /* Implementation of the Source RCON Protocol to allow remote console commands diff --git a/src/network/rcon/RCONInstance.php b/src/network/rcon/RCONInstance.php index 567c05498..69c6663ba 100644 --- a/src/network/rcon/RCONInstance.php +++ b/src/network/rcon/RCONInstance.php @@ -21,6 +21,7 @@ namespace PocketMine\Network\RCON; use PocketMine; +use PocketMine\Utils\Utils as Utils; class RCONInstance extends \Thread{ public $stop; @@ -46,11 +47,11 @@ class RCONInstance extends \Thread{ } private function writePacket($client, $requestID, $packetType, $payload){ - $pk = Utils\Utils::writeLInt((int) $requestID) - . Utils\Utils::writeLInt((int) $packetType) + $pk = Utils::writeLInt((int) $requestID) + . Utils::writeLInt((int) $packetType) . $payload . "\x00\x00"; //Terminate payload and packet - return socket_write($client, Utils\Utils::writeLInt(strlen($pk)).$pk); + return socket_write($client, Utils::writeLInt(strlen($pk)).$pk); } private function readPacket($client, &$size, &$requestID, &$packetType, &$payload){ @@ -64,12 +65,12 @@ class RCONInstance extends \Thread{ return false; } @socket_set_block($client); - $size = Utils\Utils::readLInt($d); + $size = Utils::readLInt($d); if($size < 0 or $size > 65535){ return false; } - $requestID = Utils\Utils::readLInt(socket_read($client, 4)); - $packetType = Utils\Utils::readLInt(socket_read($client, 4)); + $requestID = Utils::readLInt(socket_read($client, 4)); + $packetType = Utils::readLInt(socket_read($client, 4)); $payload = rtrim(socket_read($client, $size + 2)); //Strip two null bytes return true; } diff --git a/src/network/upnp/PortForward.php b/src/network/upnp/PortForward.php index 73a8e59cd..dabeff8dc 100644 --- a/src/network/upnp/PortForward.php +++ b/src/network/upnp/PortForward.php @@ -21,12 +21,13 @@ namespace PocketMine\Network\UPnP; use PocketMine; +use PocketMine\Utils\Utils as Utils; function PortForward($port){ - if(Utils\Utils::$online === false){ + if(Utils::$online === false){ return false; } - if(Utils\Utils::getOS() != "win" or !class_exists("COM")){ + if(Utils::getOS() != "win" or !class_exists("COM")){ return false; } $port = (int) $port; @@ -44,10 +45,10 @@ function PortForward($port){ } function RemovePortForward($port){ - if(Utils\Utils::$online === false){ + if(Utils::$online === false){ return false; } - if(Utils\Utils::getOS() != "win" or !class_exists("COM")){ + if(Utils::getOS() != "win" or !class_exists("COM")){ return false; } $port = (int) $port; diff --git a/src/network/upnp/RemovePortForward.php b/src/network/upnp/RemovePortForward.php index 9c5df4ebf..3e4d9bd1f 100644 --- a/src/network/upnp/RemovePortForward.php +++ b/src/network/upnp/RemovePortForward.php @@ -21,12 +21,13 @@ namespace PocketMine\Network\UPnP; use PocketMine; +use PocketMine\Utils\Utils as Utils; function RemovePortForward($port){ - if(Utils\Utils::$online === false){ + if(Utils::$online === false){ return false; } - if(Utils\Utils::getOS() != "win" or !class_exists("COM")){ + if(Utils::getOS() != "win" or !class_exists("COM")){ return false; } $port = (int) $port; diff --git a/src/pmf/LevelFormat.php b/src/pmf/LevelFormat.php index cc786a83c..cb0aa10e6 100644 --- a/src/pmf/LevelFormat.php +++ b/src/pmf/LevelFormat.php @@ -21,6 +21,10 @@ namespace PocketMine\PMF; use PocketMine; +use PocketMine\Utils\Utils as Utils; +use PocketMine\NBT\Tag\Compound as Compound; +use PocketMine\NBT\Tag\Enum as Enum; +use PocketMine\Level\Level as Level; class LevelFormat extends PMF{ const VERSION = 2; @@ -84,18 +88,18 @@ class LevelFormat extends PMF{ @ftruncate($this->fp, 5); $this->seek(5); $this->write(chr($this->levelData["version"])); - $this->write(Utils\Utils::writeShort(strlen($this->levelData["name"])).$this->levelData["name"]); - $this->write(Utils\Utils::writeInt($this->levelData["seed"])); - $this->write(Utils\Utils::writeInt($this->levelData["time"])); - $this->write(Utils\Utils::writeFloat($this->levelData["spawnX"])); - $this->write(Utils\Utils::writeFloat($this->levelData["spawnY"])); - $this->write(Utils\Utils::writeFloat($this->levelData["spawnZ"])); + $this->write(Utils::writeShort(strlen($this->levelData["name"])).$this->levelData["name"]); + $this->write(Utils::writeInt($this->levelData["seed"])); + $this->write(Utils::writeInt($this->levelData["time"])); + $this->write(Utils::writeFloat($this->levelData["spawnX"])); + $this->write(Utils::writeFloat($this->levelData["spawnY"])); + $this->write(Utils::writeFloat($this->levelData["spawnZ"])); $this->write(chr($this->levelData["height"])); - $this->write(Utils\Utils::writeShort(strlen($this->levelData["generator"])).$this->levelData["generator"]); + $this->write(Utils::writeShort(strlen($this->levelData["generator"])).$this->levelData["generator"]); $settings = serialize($this->levelData["generatorSettings"]); - $this->write(Utils\Utils::writeShort(strlen($settings)).$settings); + $this->write(Utils::writeShort(strlen($settings)).$settings); $extra = zlib_encode($this->levelData["extra"], self::ZLIB_ENCODING, self::ZLIB_LEVEL); - $this->write(Utils\Utils::writeShort(strlen($extra)).$extra); + $this->write(Utils::writeShort(strlen($extra)).$extra); } private function createBlank(){ @@ -113,12 +117,12 @@ class LevelFormat extends PMF{ console("[ERROR] New unsupported PMF Level format version #".$this->levelData["version"].", current version is #".self::VERSION); return false; } - $this->levelData["name"] = $this->read(Utils\Utils::readShort($this->read(2), false)); - $this->levelData["seed"] = Utils\Utils::readInt($this->read(4)); - $this->levelData["time"] = Utils\Utils::readInt($this->read(4)); - $this->levelData["spawnX"] = Utils\Utils::readFloat($this->read(4)); - $this->levelData["spawnY"] = Utils\Utils::readFloat($this->read(4)); - $this->levelData["spawnZ"] = Utils\Utils::readFloat($this->read(4)); + $this->levelData["name"] = $this->read(Utils::readShort($this->read(2), false)); + $this->levelData["seed"] = Utils::readInt($this->read(4)); + $this->levelData["time"] = Utils::readInt($this->read(4)); + $this->levelData["spawnX"] = Utils::readFloat($this->read(4)); + $this->levelData["spawnY"] = Utils::readFloat($this->read(4)); + $this->levelData["spawnZ"] = Utils::readFloat($this->read(4)); if($this->levelData["version"] === 0){ $this->read(1); $this->levelData["height"] = ord($this->read(1)); @@ -127,11 +131,11 @@ class LevelFormat extends PMF{ if($this->levelData["height"] !== 8){ return false; } - $this->levelData["generator"] = $this->read(Utils\Utils::readShort($this->read(2), false)); - $this->levelData["generatorSettings"] = unserialize($this->read(Utils\Utils::readShort($this->read(2), false))); + $this->levelData["generator"] = $this->read(Utils::readShort($this->read(2), false)); + $this->levelData["generatorSettings"] = unserialize($this->read(Utils::readShort($this->read(2), false))); } - $this->levelData["extra"] = @zlib_decode($this->read(Utils\Utils::readShort($this->read(2), false))); + $this->levelData["extra"] = @zlib_decode($this->read(Utils::readShort($this->read(2), false))); $upgrade = false; if($this->levelData["version"] === 0){ @@ -154,7 +158,7 @@ class LevelFormat extends PMF{ $X = $index & 0x0F; $Z = $index >> 4; - $bitflags = Utils\Utils::readShort($this->read(2)); + $bitflags = Utils::readShort($this->read(2)); $oldPath = dirname($this->file)."/chunks/".$Z.".".$X.".pmc"; $chunkOld = gzopen($oldPath, "rb"); $newPath = dirname($this->file)."/chunks/".(($X ^ $Z) & 0xff)."/".$Z.".".$X.".pmc"; @@ -176,14 +180,14 @@ class LevelFormat extends PMF{ private function upgrade_From1_To2(){ console("[NOTICE] Old PMF Level format version #1 detected, upgrading to version #2"); $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); $namedtag = $nbt->write(); - $namedtag = Utils\Utils::writeInt(strlen($namedtag)) . $namedtag; + $namedtag = Utils::writeInt(strlen($namedtag)) . $namedtag; foreach(glob(dirname($this->file)."/chunks/*/*.*.pmc") as $chunkFile){ $oldChunk = zlib_decode(file_get_contents($chunkFile)); $newChunk = substr($oldChunk, 0, 5); @@ -215,7 +219,7 @@ class LevelFormat extends PMF{ @mkdir(dirname($path), 0755); } $this->initCleanChunk($X, $Z); - if($this->level instanceof Level\Level){ + if($this->level instanceof Level){ $ret = $this->level->generateChunk($X, $Z); $this->saveChunk($X, $Z); $this->populateChunk($X - 1, $Z); @@ -231,7 +235,7 @@ class LevelFormat extends PMF{ } public function populateChunk($X, $Z){ - if($this->level instanceof Level\Level){ + if($this->level instanceof Level){ if($this->isGenerating === 0 and $this->isChunkLoaded($X, $Z) and !$this->isPopulated($X, $Z) and @@ -274,10 +278,10 @@ class LevelFormat extends PMF{ $this->chunkInfo[$index] = array( 0 => ord($chunk{0}), - 1 => Utils\Utils::readInt(substr($chunk, 1, 4)), + 1 => Utils::readInt(substr($chunk, 1, 4)), ); $offset += 5; - $len = Utils\Utils::readInt(substr($chunk, $offset, 4)); + $len = Utils::readInt(substr($chunk, $offset, 4)); $offset += 4; $nbt = new NBT(NBT\BIG_ENDIAN); $nbt->read(substr($chunk, $offset, $len)); @@ -397,9 +401,9 @@ class LevelFormat extends PMF{ 7 => 8192, ); $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); @@ -671,9 +675,9 @@ class LevelFormat extends PMF{ $this->chunkChange[$index][-1] = false; $chunk = b""; $chunk .= chr($bitmap); - $chunk .= Utils\Utils::writeInt($this->chunkInfo[$index][1]); + $chunk .= Utils::writeInt($this->chunkInfo[$index][1]); $namedtag = $this->chunkInfo[$index][2]->write(); - $chunk .= Utils\Utils::writeInt(strlen($namedtag)).$namedtag; + $chunk .= Utils::writeInt(strlen($namedtag)).$namedtag; $chunk .= $this->chunkInfo[$index][3]; //biomes for($Y = 0; $Y < 8; ++$Y){ $t = 1 << $Y; diff --git a/src/pmf/Plugin.php b/src/pmf/Plugin.php index 0bc4adef1..91642cf04 100644 --- a/src/pmf/Plugin.php +++ b/src/pmf/Plugin.php @@ -21,6 +21,7 @@ namespace PocketMine\PMF; use PocketMine; +use PocketMine\Utils\Utils as Utils; class Plugin extends PMF{ const VERSION = 0x02; @@ -45,18 +46,18 @@ class Plugin extends PMF{ if($this->pluginData["fversion"] > PMFPlugin::VERSION){ return false; } - $this->pluginData["name"] = $this->read(Utils\Utils::readShort($this->read(2), false)); - $this->pluginData["version"] = $this->read(Utils\Utils::readShort($this->read(2), false)); - $this->pluginData["author"] = $this->read(Utils\Utils::readShort($this->read(2), false)); + $this->pluginData["name"] = $this->read(Utils::readShort($this->read(2), false)); + $this->pluginData["version"] = $this->read(Utils::readShort($this->read(2), false)); + $this->pluginData["author"] = $this->read(Utils::readShort($this->read(2), false)); if($this->pluginData["fversion"] >= 0x01){ - $this->pluginData["apiversion"] = $this->read(Utils\Utils::readShort($this->read(2), false)); + $this->pluginData["apiversion"] = $this->read(Utils::readShort($this->read(2), false)); }else{ - $this->pluginData["apiversion"] = Utils\Utils::readShort($this->read(2), false); + $this->pluginData["apiversion"] = Utils::readShort($this->read(2), false); } - $this->pluginData["class"] = $this->read(Utils\Utils::readShort($this->read(2), false)); - $this->pluginData["identifier"] = $this->read(Utils\Utils::readShort($this->read(2), false)); //Will be used to check for updates + $this->pluginData["class"] = $this->read(Utils::readShort($this->read(2), false)); + $this->pluginData["identifier"] = $this->read(Utils::readShort($this->read(2), false)); //Will be used to check for updates if($this->pluginData["fversion"] >= 0x02){ - $data = explode(";", gzinflate($this->read(Utils\Utils::readInt($this->read(4))))); + $data = explode(";", gzinflate($this->read(Utils::readInt($this->read(4))))); $this->pluginData["extra"] = array(); foreach($data as $v){ $v = trim($v); @@ -68,7 +69,7 @@ class Plugin extends PMF{ } }else{ - $this->pluginData["extra"] = gzinflate($this->read(Utils\Utils::readShort($this->read(2), false))); + $this->pluginData["extra"] = gzinflate($this->read(Utils::readShort($this->read(2), false))); } $this->pluginData["code"] = ""; while(!feof($this->fp)){ diff --git a/src/recipes/Crafting.php b/src/recipes/Crafting.php index 27aef3406..fecb844c3 100644 --- a/src/recipes/Crafting.php +++ b/src/recipes/Crafting.php @@ -21,6 +21,8 @@ namespace PocketMine\Recipes; use PocketMine; +use PocketMine\BlockAPI as BlockAPI; +use PocketMine\ServerAPI as ServerAPI; abstract class Crafting{ private static $small = array(//Probably means craftable on crafting bench and in inventory. Name it better! diff --git a/src/tile/Chest.php b/src/tile/Chest.php index 4efcd7c4e..650567bb4 100644 --- a/src/tile/Chest.php +++ b/src/tile/Chest.php @@ -21,13 +21,19 @@ namespace PocketMine\Tile; use PocketMine; +use PocketMine\Level\Level as Level; +use PocketMine\NBT\Tag\Compound as Compound; +use PocketMine\Tile\Tile as Tile; +use PocketMine\Math\Vector3 as Vector3; +use PocketMine\NBT\Tag\String as String; +use PocketMine\NBT\Tag\Int as Int; class Chest extends Spawnable{ use Container; const SLOTS = 27; - public function __construct(Level\Level $level, NBT\Tag\Compound $nbt){ + public function __construct(Level $level, Compound $nbt){ $nbt->id = Tile::CHEST; parent::__construct($level, $nbt); } @@ -41,7 +47,7 @@ class Chest extends Spawnable{ public function getPair(){ if($this->isPaired()){ - return $this->level->getTile(new Math\Vector3((int) $this->namedtag->pairx, $this->y, (int) $this->namedtag->pairz)); + return $this->level->getTile(new Vector3((int) $this->namedtag->pairx, $this->y, (int) $this->namedtag->pairz)); } return false; } @@ -86,20 +92,20 @@ class Chest extends Spawnable{ $nbt = new NBT(NBT\LITTLE_ENDIAN); if($this->isPaired()){ - $nbt->setData(new NBT\Tag\Compound("", array( - new NBT\Tag\String("id", Tile::CHEST), - new NBT\Tag\Int("x", (int) $this->x), - new NBT\Tag\Int("y", (int) $this->y), - new NBT\Tag\Int("z", (int) $this->z), - new NBT\Tag\Int("pairx", (int) $this->namedtag->pairx), - new NBT\Tag\Int("pairz", (int) $this->namedtag->pairz) + $nbt->setData(new Compound("", array( + new String("id", Tile::CHEST), + new Int("x", (int) $this->x), + new Int("y", (int) $this->y), + new Int("z", (int) $this->z), + new Int("pairx", (int) $this->namedtag->pairx), + new Int("pairz", (int) $this->namedtag->pairz) ))); }else{ - $nbt->setData(new NBT\Tag\Compound("", array( - new NBT\Tag\String("id", Tile::CHEST), - new NBT\Tag\Int("x", (int) $this->x), - new NBT\Tag\Int("y", (int) $this->y), - new NBT\Tag\Int("z", (int) $this->z) + $nbt->setData(new Compound("", array( + new String("id", Tile::CHEST), + new Int("x", (int) $this->x), + new Int("y", (int) $this->y), + new Int("z", (int) $this->z) ))); } diff --git a/src/tile/Container.php b/src/tile/Container.php index ae8a18ce4..daf054808 100644 --- a/src/tile/Container.php +++ b/src/tile/Container.php @@ -21,6 +21,17 @@ namespace PocketMine\Tile; use PocketMine; +use PocketMine\Tile\Chest as Chest; +use PocketMine\Player as Player; +use PocketMine\BlockAPI as BlockAPI; +use PocketMine\Tile\Furnace as Furnace; +use PocketMine\Item\Item as Item; +use PocketMine\Event\EventHandler as EventHandler; +use PocketMine\Event\Tile\TileInventoryChangeEvent as TileInventoryChangeEvent; +use PocketMine\Event\Event as Event; +use PocketMine\NBT\Tag\Compound as Compound; +use PocketMine\NBT\Tag\Byte as Byte; +use PocketMine\NBT\Tag\Short as Short; trait Container{ public function openInventory(Player $player){ @@ -144,19 +155,19 @@ trait Container{ } } - public function setSlot($s, Item\Item $item, $update = true, $offset = 0){ + public function setSlot($s, Item $item, $update = true, $offset = 0){ $i = $this->getSlotIndex($s); - if($i === false or Event\EventHandler::callEvent($ev = new Event\Tile\TileInventoryChangeEvent($this, $this->getSlot($s), $item, $s, $offset)) === Event\Event::DENY){ + if($i === false or EventHandler::callEvent($ev = new TileInventoryChangeEvent($this, $this->getSlot($s), $item, $s, $offset)) === Event::DENY){ return false; } $item = $ev->getNewItem(); - $d = new NBT\Tag\Compound(false, array( - "Count" => new NBT\Tag\Byte("Count", $item->getCount()), - "Slot" => new NBT\Tag\Byte("Slot", $s), - "id" => new NBT\Tag\Short("id", $item->getID()), - "Damage" => new NBT\Tag\Short("Damage", $item->getMetadata()), + $d = new Compound(false, array( + "Count" => new Byte("Count", $item->getCount()), + "Slot" => new Byte("Slot", $s), + "id" => new Short("id", $item->getID()), + "Damage" => new Short("Damage", $item->getMetadata()), )); if($item->getID() === AIR or $item->getCount() <= 0){ diff --git a/src/tile/Furnace.php b/src/tile/Furnace.php index c29ba12f2..1232b61dd 100644 --- a/src/tile/Furnace.php +++ b/src/tile/Furnace.php @@ -21,13 +21,17 @@ namespace PocketMine\Tile; use PocketMine; +use PocketMine\Level\Level as Level; +use PocketMine\NBT\Tag\Compound as Compound; +use PocketMine\Tile\Tile as Tile; +use PocketMine\BlockAPI as BlockAPI; class Furnace extends Tile{ use Container; const SLOTS = 3; - public function __construct(Level\Level $level, NBT\Tag\Compound $nbt){ + public function __construct(Level $level, Compound $nbt){ $nbt->id = Tile::FURNACE; parent::__construct($level, $nbt); if(!isset($this->namedtag->BurnTime) or $this->namedtag->BurnTime < 0){ diff --git a/src/tile/Sign.php b/src/tile/Sign.php index 1787a46c3..d63543ba4 100644 --- a/src/tile/Sign.php +++ b/src/tile/Sign.php @@ -21,10 +21,15 @@ namespace PocketMine\Tile; use PocketMine; +use PocketMine\NBT\Tag\Compound as Compound; +use PocketMine\Tile\Tile as Tile; +use PocketMine\NBT\NBT as NBT; +use PocketMine\NBT\Tag\String as String; +use PocketMine\NBT\Tag\Int as Int; class Sign extends Spawnable{ - public function __construct(Level $level, NBT\Tag\Compound $nbt){ + public function __construct(Level $level, Compound $nbt){ $nbt->id = Tile::SIGN; parent::__construct($level, $nbt); } @@ -53,16 +58,16 @@ class Sign extends Spawnable{ return false; } - $nbt = new NBT\NBT(NBT\LITTLE_ENDIAN); - $nbt->setData(new NBT\Tag\Compound("", array( - new NBT\Tag\String("Text1", $this->namedtag->Text1), - new NBT\Tag\String("Text2", $this->namedtag->Text2), - new NBT\Tag\String("Text3", $this->namedtag->Text3), - new NBT\Tag\String("Text4", $this->namedtag->Text4), - new NBT\Tag\String("id", Tile::SIGN), - new NBT\Tag\Int("x", (int) $this->x), - new NBT\Tag\Int("y", (int) $this->y), - new NBT\Tag\Int("z", (int) $this->z) + $nbt = new NBT(NBT\LITTLE_ENDIAN); + $nbt->setData(new Compound("", array( + new String("Text1", $this->namedtag->Text1), + new String("Text2", $this->namedtag->Text2), + new String("Text3", $this->namedtag->Text3), + new String("Text4", $this->namedtag->Text4), + new String("id", Tile::SIGN), + new Int("x", (int) $this->x), + new Int("y", (int) $this->y), + new Int("z", (int) $this->z) ))); $pk = new Network\Protocol\EntityDataPacket; $pk->x = $this->x; diff --git a/src/tile/Tile.php b/src/tile/Tile.php index 95a669d3e..5a9a54678 100644 --- a/src/tile/Tile.php +++ b/src/tile/Tile.php @@ -21,6 +21,10 @@ namespace PocketMine\Tile; use PocketMine; +use PocketMine\Level\Level as Level; +use PocketMine\NBT\Tag\Compound as Compound; +use PocketMine\ServerAPI as ServerAPI; +use PocketMine\PMF\LevelFormat as LevelFormat; abstract class Tile extends Position{ const SIGN = "Sign"; @@ -57,7 +61,7 @@ abstract class Tile extends Position{ } - public function __construct(Level\Level $level, NBT\Tag\Compound $nbt){ + public function __construct(Level $level, Compound $nbt){ $this->server = ServerAPI::request(); $this->level = $level; $this->namedtag = $nbt; @@ -70,7 +74,7 @@ abstract class Tile extends Position{ $this->y = (int) $this->namedtag->y; $this->z = (int) $this->namedtag->z; - $index = PMF\LevelFormat::getIndex($this->x >> 4, $this->z >> 4); + $index = LevelFormat::getIndex($this->x >> 4, $this->z >> 4); $this->chunkIndex = $index; $this->level->tiles[$this->id] = $this; $this->level->chunkTiles[$this->chunkIndex][$this->id] = $this; diff --git a/src/utils/Random.php b/src/utils/Random.php index dc3b82fa3..cdce58b35 100644 --- a/src/utils/Random.php +++ b/src/utils/Random.php @@ -21,6 +21,7 @@ namespace PocketMine\Utils; use PocketMine; +use PocketMine\Utils\Utils as Utils; //Unsecure, not used for "Real Randomness" class Random{ diff --git a/src/utils/Utils.php b/src/utils/Utils.php index c6ce3d03c..7db864768 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -21,6 +21,7 @@ namespace PocketMine\Utils; use PocketMine; +use PocketMine\BlockAPI as BlockAPI; class Utils{ const BIG_ENDIAN = 0x00; diff --git a/src/wizard/Installer.php b/src/wizard/Installer.php index 1c157a4d7..e65946031 100644 --- a/src/wizard/Installer.php +++ b/src/wizard/Installer.php @@ -21,6 +21,8 @@ namespace PocketMine\Wizard; use PocketMine\Utils\Config as Config; +use PocketMine\Wizard\InstallerLang as InstallerLang; +use PocketMine\Utils\Utils as Utils; use PocketMine; class Installer{ @@ -84,7 +86,7 @@ LICENSE; } private function generateBaseConfig(){ - $config = new Utils\Config(\PocketMine\DATA . "server.properties", Utils\Config::PROPERTIES); + $config = new UtilsConfig(\PocketMine\DATA . "server.properties", UtilsConfig::PROPERTIES); echo "[?] ".$this->lang->name_your_server." (".self::DEFAULT_NAME."): "; $config->set("server-name", $this->getInput(self::DEFAULT_NAME)); echo "[*] ".$this->lang->port_warning."\n"; @@ -124,13 +126,13 @@ LICENSE; if($op === ""){ echo "[!] ".$this->lang->op_warning."\n"; }else{ - $ops = new Utils\Config(\PocketMine\DATA."ops.txt", Utils\Config::ENUM); + $ops = new UtilsConfig(\PocketMine\DATA."ops.txt", UtilsConfig::ENUM); $ops->set($op, true); $ops->save(); } echo "[*] ".$this->lang->whitelist_info."\n"; echo "[?] ".$this->lang->whitelist_enable." (y/N): "; - $config = new Utils\Config(\PocketMine\DATA . "server.properties", Utils\Config::PROPERTIES); + $config = new UtilsConfig(\PocketMine\DATA . "server.properties", UtilsConfig::PROPERTIES); if(strtolower($this->getInput("n")) === "y"){ echo "[!] ".$this->lang->whitelist_warning."\n"; $config->set("white-list", true); @@ -141,7 +143,7 @@ LICENSE; } private function networkFunctions(){ - $config = new Utils\Config(\PocketMine\DATA . "server.properties", Utils\Config::PROPERTIES); + $config = new UtilsConfig(\PocketMine\DATA . "server.properties", UtilsConfig::PROPERTIES); echo "[!] ".$this->lang->query_warning1."\n"; echo "[!] ".$this->lang->query_warning2."\n"; echo "[?] ".$this->lang->query_disable." (y/N): "; @@ -155,7 +157,7 @@ LICENSE; echo "[?] ".$this->lang->rcon_enable." (y/N): "; if(strtolower($this->getInput("n")) === "y"){ $config->set("enable-rcon", true); - $password = substr(base64_encode(Utils\Utils::getRandomBytes(20, false)), 3, 10); + $password = substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10); $config->set("rcon.password", $password); echo "[*] ".$this->lang->rcon_password.": ".$password."\n"; }else{ @@ -174,7 +176,7 @@ LICENSE; echo "[*] ".$this->lang->ip_get."\n"; - $externalIP = Utils\Utils::getIP(); + $externalIP = Utils::getIP(); $internalIP = gethostbyname(trim(`hostname`)); echo "[!] ".$this->lang->get("ip_warning", array("{{EXTERNAL_IP}}", "{{INTERNAL_IP}}"), array($externalIP, $internalIP))."\n";