Removed code remove comments

This commit is contained in:
Shoghi Cervantes 2014-03-06 13:16:44 +01:00
parent bbd66e6ad1
commit c08bf3ef86
350 changed files with 6317 additions and 5559 deletions

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI; use PocketMine\ServerAPI as ServerAPI;
abstract class Achievement{ abstract class Achievement{
@ -30,8 +31,7 @@ abstract class Achievement{
),*/ ),*/
"mineWood" => array( "mineWood" => array(
"name" => "Getting Wood", "name" => "Getting Wood",
"requires" => array( "requires" => array(//"openInventory",
//"openInventory",
), ),
), ),
"buildWorkBench" => array( "buildWorkBench" => array(
@ -103,13 +103,15 @@ abstract class Achievement{
$result = ServerAPI::request()->api->dhandle("achievement.broadcast", array("player" => $player, "achievementId" => $achievementId)); $result = ServerAPI::request()->api->dhandle("achievement.broadcast", array("player" => $player, "achievementId" => $achievementId));
if($result !== false and $result !== true){ if($result !== false and $result !== true){
if(ServerAPI::request()->api->getProperty("announce-player-achievements") == true){ if(ServerAPI::request()->api->getProperty("announce-player-achievements") == true){
ServerAPI::request()->api->chat->broadcast($player->getUsername()." has just earned the achievement ".Achievement::$list[$achievementId]["name"]); ServerAPI::request()->api->chat->broadcast($player->getUsername() . " has just earned the achievement " . Achievement::$list[$achievementId]["name"]);
}else{ } else{
$player->sendChat("You have just earned the achievement ".Achievement::$list[$achievementId]["name"]); $player->sendChat("You have just earned the achievement " . Achievement::$list[$achievementId]["name"]);
} }
} }
return true; return true;
} }
return false; return false;
} }
@ -119,8 +121,10 @@ abstract class Achievement{
"name" => $achievementName, "name" => $achievementName,
"requires" => $requires, "requires" => $requires,
); );
return true; return true;
} }
return false; return false;
} }

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI; use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Utils\Config as Config; use PocketMine\Utils\Config as Config;
use PocketMine\Player as Player; use PocketMine\Player as Player;
@ -37,16 +38,16 @@ class BanAPI{
private $ops; private $ops;
/** @var Config */ /** @var Config */
private $bannedIPs; private $bannedIPs;
private $cmdWhitelist = array();//Command WhiteList private $cmdWhitelist = array(); //Command WhiteList
function __construct(){ function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
public function init(){ public function init(){
$this->whitelist = new Config(\PocketMine\DATA."white-list.txt", Config::ENUM);//Open whitelist list file $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->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->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->ops = new Config(\PocketMine\DATA . "ops.txt", Config::ENUM); //Open list of OPs
$this->server->api->console->register("banip", "<add|remove|list|reload> [IP|player]", array($this, "commandHandler")); $this->server->api->console->register("banip", "<add|remove|list|reload> [IP|player]", array($this, "commandHandler"));
$this->server->api->console->register("ban", "<add|remove|list|reload> [username]", array($this, "commandHandler")); $this->server->api->console->register("ban", "<add|remove|list|reload> [username]", array($this, "commandHandler"));
$this->server->api->console->register("kick", "<player> [reason ...]", array($this, "commandHandler")); $this->server->api->console->register("kick", "<player> [reason ...]", array($this, "commandHandler"));
@ -58,16 +59,16 @@ class BanAPI{
$this->server->api->console->alias("banlist", "ban list"); $this->server->api->console->alias("banlist", "ban list");
$this->server->api->console->alias("pardon", "ban remove"); $this->server->api->console->alias("pardon", "ban remove");
$this->server->api->console->alias("pardon-ip", "banip remove"); $this->server->api->console->alias("pardon-ip", "banip remove");
$this->server->addHandler("console.command", array($this, "permissionsCheck"), 1);//Event handler when commands are issued. Used to check permissions of commands that go through the server. $this->server->addHandler("console.command", array($this, "permissionsCheck"), 1); //Event handler when commands are issued. Used to check permissions of commands that go through the server.
$this->server->addHandler("player.block.break", array($this, "permissionsCheck"), 1);//Event handler for blocks $this->server->addHandler("player.block.break", array($this, "permissionsCheck"), 1); //Event handler for blocks
$this->server->addHandler("player.block.place", array($this, "permissionsCheck"), 1);//Event handler for blocks $this->server->addHandler("player.block.place", array($this, "permissionsCheck"), 1); //Event handler for blocks
$this->server->addHandler("player.flying", array($this, "permissionsCheck"), 1);//Flying Event $this->server->addHandler("player.flying", array($this, "permissionsCheck"), 1); //Flying Event
} }
/** /**
* @param string $cmd Command to Whitelist * @param string $cmd Command to Whitelist
*/ */
public function cmdWhitelist($cmd){//Whitelists a CMD so everyone can issue it - Even non OPs. public function cmdWhitelist($cmd){ //Whitelists a CMD so everyone can issue it - Even non OPs.
$this->cmdWhitelist[strtolower(trim($cmd))] = true; $this->cmdWhitelist[strtolower(trim($cmd))] = true;
} }
@ -76,13 +77,14 @@ class BanAPI{
* *
* @return boolean * @return boolean
*/ */
public function isOp($username){//Is a player op? public function isOp($username){ //Is a player op?
$username = strtolower($username); $username = strtolower($username);
if($this->server->api->dhandle("op.check", $username) === true){ if($this->server->api->dhandle("op.check", $username) === true){
return true; return true;
}elseif($this->ops->exists($username)){ } elseif($this->ops->exists($username)){
return true; return true;
} }
return false; return false;
} }
@ -94,22 +96,23 @@ class BanAPI{
*/ */
public function permissionsCheck($data, $event){ public function permissionsCheck($data, $event){
switch($event){ switch($event){
case "player.flying"://OPs can fly around the server. case "player.flying": //OPs can fly around the server.
if($this->isOp($data->getUsername())){ if($this->isOp($data->getUsername())){
return true; return true;
} }
break; break;
case "player.block.break": case "player.block.break":
case "player.block.place"://Spawn protection detection. Allows OPs to place/break blocks in the spawn area. case "player.block.place": //Spawn protection detection. Allows OPs to place/break blocks in the spawn area.
if(!$this->isOp($data["player"]->getUsername())){ if(!$this->isOp($data["player"]->getUsername())){
$t = new Vector2($data["target"]->x, $data["target"]->z); $t = new Vector2($data["target"]->x, $data["target"]->z);
$s = new Vector2($this->server->spawn->x, $this->server->spawn->z); $s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event.".spawn", $data) !== true){ if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){
return false; return false;
} }
} }
return; return;
case "console.command"://Checks if a command is allowed with the current user permissions. case "console.command": //Checks if a command is allowed with the current user permissions.
if(isset($this->cmdWhitelist[$data["cmd"]])){ if(isset($this->cmdWhitelist[$data["cmd"]])){
return; return;
} }
@ -118,9 +121,10 @@ class BanAPI{
if($this->server->api->handle("console.check", $data) === true or $this->isOp($data["issuer"]->getUsername())){ if($this->server->api->handle("console.check", $data) === true or $this->isOp($data["issuer"]->getUsername())){
return; return;
} }
}elseif($data["issuer"] === "console" or $data["issuer"] === "rcon"){ } elseif($data["issuer"] === "console" or $data["issuer"] === "rcon"){
return; return;
} }
return false; return false;
} }
} }
@ -144,11 +148,11 @@ class BanAPI{
break; break;
} }
$this->server->api->console->run(implode(" ", $params), $player); $this->server->api->console->run(implode(" ", $params), $player);
$output .= "Command ran as ".$player->getUsername().".\n"; $output .= "Command ran as " . $player->getUsername() . ".\n";
break; break;
case "op": case "op":
$user = strtolower($params[0]); $user = strtolower($params[0]);
if($user == NULL){ if($user == null){
$output .= "Usage: /op <player>\n"; $output .= "Usage: /op <player>\n";
break; break;
} }
@ -156,12 +160,12 @@ class BanAPI{
if(!($player instanceof Player)){ if(!($player instanceof Player)){
$this->ops->set($user); $this->ops->set($user);
$this->ops->save(); $this->ops->save();
$output .= $user." is now op\n"; $output .= $user . " is now op\n";
break; break;
} }
$this->ops->set(strtolower($player->getUsername())); $this->ops->set(strtolower($player->getUsername()));
$this->ops->save(); $this->ops->save();
$output .= $player->getUsername()." is now op\n"; $output .= $player->getUsername() . " is now op\n";
$this->server->api->chat->sendTo(false, "You are now op.", $player->getUsername()); $this->server->api->chat->sendTo(false, "You are now op.", $player->getUsername());
break; break;
case "deop": case "deop":
@ -170,32 +174,32 @@ class BanAPI{
if(!($player instanceof Player)){ if(!($player instanceof Player)){
$this->ops->remove($user); $this->ops->remove($user);
$this->ops->save(); $this->ops->save();
$output .= $user." is no longer op\n"; $output .= $user . " is no longer op\n";
break; break;
} }
$this->ops->remove(strtolower($player->getUsername())); $this->ops->remove(strtolower($player->getUsername()));
$this->ops->save(); $this->ops->save();
$output .= $player->getUsername()." is no longer op\n"; $output .= $player->getUsername() . " is no longer op\n";
$this->server->api->chat->sendTo(false, "You are no longer op.", $player->getUsername()); $this->server->api->chat->sendTo(false, "You are no longer op.", $player->getUsername());
break; break;
case "kick": case "kick":
if(!isset($params[0])){ if(!isset($params[0])){
$output .= "Usage: /kick <player> [reason ...]\n"; $output .= "Usage: /kick <player> [reason ...]\n";
}else{ } else{
$name = strtolower(array_shift($params)); $name = strtolower(array_shift($params));
$player = Player::get($name); $player = Player::get($name);
if($player === false){ if($player === false){
$output .= "Player \"".$name."\" does not exist\n"; $output .= "Player \"" . $name . "\" does not exist\n";
}else{ } else{
$reason = implode(" ", $params); $reason = implode(" ", $params);
$reason = $reason == "" ? "No reason":$reason; $reason = $reason == "" ? "No reason" : $reason;
$this->server->schedule(60, array($player, "close"), "You have been kicked: ".$reason); //Forces a kick $this->server->schedule(60, array($player, "close"), "You have been kicked: " . $reason); //Forces a kick
$player->blocked = true; $player->blocked = true;
if($issuer instanceof Player){ if($issuer instanceof Player){
$this->server->api->chat->broadcast($player->getUsername()." has been kicked by ".$issuer->getUsername().": $reason\n"); $this->server->api->chat->broadcast($player->getUsername() . " has been kicked by " . $issuer->getUsername() . ": $reason\n");
}else{ } else{
$this->server->api->chat->broadcast($player->getUsername()." has been kicked: $reason\n"); $this->server->api->chat->broadcast($player->getUsername() . " has been kicked: $reason\n");
} }
} }
} }
@ -216,10 +220,10 @@ class BanAPI{
$output .= "Player \"$user\" added to white-list\n"; $output .= "Player \"$user\" added to white-list\n";
break; break;
case "reload": case "reload":
$this->whitelist = new Config(\PocketMine\DATA."white-list.txt", Config::ENUM); $this->whitelist = new Config(\PocketMine\DATA . "white-list.txt", Config::ENUM);
break; break;
case "list": case "list":
$output .= "White-list: ".implode(", ", $this->whitelist->getAll(true))."\n"; $output .= "White-list: " . implode(", ", $this->whitelist->getAll(true)) . "\n";
break; break;
case "on": case "on":
case "true": case "true":
@ -261,10 +265,10 @@ class BanAPI{
$output .= "IP \"$ip\" added to ban list\n"; $output .= "IP \"$ip\" added to ban list\n";
break; break;
case "reload": case "reload":
$this->bannedIPs = new Config(\PocketMine\DATA."banned-ips.txt", Config::ENUM); $this->bannedIPs = new Config(\PocketMine\DATA . "banned-ips.txt", Config::ENUM);
break; break;
case "list": case "list":
$output .= "IP ban list: ".implode(", ", $this->bannedIPs->getAll(true))."\n"; $output .= "IP ban list: " . implode(", ", $this->bannedIPs->getAll(true)) . "\n";
break; break;
default: default:
$output .= "Usage: /banip <add|remove|list|reload> [IP|player]\n"; $output .= "Usage: /banip <add|remove|list|reload> [IP|player]\n";
@ -291,18 +295,18 @@ class BanAPI{
$player->close("You have been banned"); $player->close("You have been banned");
} }
if($issuer instanceof Player){ if($issuer instanceof Player){
$this->server->api->chat->broadcast($user." has been banned by ".$issuer->getUsername()."\n"); $this->server->api->chat->broadcast($user . " has been banned by " . $issuer->getUsername() . "\n");
}else{ } else{
$this->server->api->chat->broadcast($user." has been banned\n"); $this->server->api->chat->broadcast($user . " has been banned\n");
} }
$this->kick($user, "Banned"); $this->kick($user, "Banned");
$output .= "Player \"$user\" added to ban list\n"; $output .= "Player \"$user\" added to ban list\n";
break; break;
case "reload": case "reload":
$this->banned = new Config(\PocketMine\DATA."banned.txt", Config::ENUM); $this->banned = new Config(\PocketMine\DATA . "banned.txt", Config::ENUM);
break; break;
case "list": case "list":
$output .= "Ban list: ".implode(", ", $this->banned->getAll(true))."\n"; $output .= "Ban list: " . implode(", ", $this->banned->getAll(true)) . "\n";
break; break;
default: default:
$output .= "Usage: /ban <add|remove|list|reload> [username]\n"; $output .= "Usage: /ban <add|remove|list|reload> [username]\n";
@ -310,6 +314,7 @@ class BanAPI{
} }
break; break;
} }
return $output; return $output;
} }
@ -363,9 +368,9 @@ class BanAPI{
public function isIPBanned($ip){ public function isIPBanned($ip){
if($this->server->api->dhandle("api.ban.ip.check", $ip) === false){ if($this->server->api->dhandle("api.ban.ip.check", $ip) === false){
return true; return true;
}elseif($this->bannedIPs->exists($ip, true)){ } elseif($this->bannedIPs->exists($ip, true)){
return true; return true;
}else{ } else{
return false; return false;
} }
} }
@ -379,9 +384,9 @@ class BanAPI{
$username = strtolower($username); $username = strtolower($username);
if($this->server->api->dhandle("api.ban.check", $username) === false){ if($this->server->api->dhandle("api.ban.check", $username) === false){
return true; return true;
}elseif($this->banned->exists($username, true)){ } elseif($this->banned->exists($username, true)){
return true; return true;
}else{ } else{
return false; return false;
} }
} }
@ -395,11 +400,12 @@ class BanAPI{
$username = strtolower($username); $username = strtolower($username);
if($this->isOp($username)){ if($this->isOp($username)){
return true; return true;
}elseif($this->server->api->dhandle("api.ban.whitelist.check", $username) === false){ } elseif($this->server->api->dhandle("api.ban.whitelist.check", $username) === false){
return true; return true;
}elseif($this->whitelist->exists($username, true)){ } elseif($this->whitelist->exists($username, true)){
return true; return true;
} }
return false; return false;
} }
} }

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\Level\Position as Position; use PocketMine\Level\Position as Position;
use PocketMine\Block\GenericBlock as GenericBlock; use PocketMine\Block\GenericBlock as GenericBlock;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item as Item;
@ -234,15 +235,16 @@ class BlockAPI{
public static function fromString($str, $multiple = false){ public static function fromString($str, $multiple = false){
if($multiple === true){ if($multiple === true){
$blocks = array(); $blocks = array();
foreach(explode(",",$str) as $b){ foreach(explode(",", $str) as $b){
$blocks[] = BlockAPI::fromString($b, false); $blocks[] = BlockAPI::fromString($b, false);
} }
return $blocks; return $blocks;
}else{ } else{
$b = explode(":", str_replace(" ", "_", trim($str))); $b = explode(":", str_replace(" ", "_", trim($str)));
if(!isset($b[1])){ if(!isset($b[1])){
$meta = 0; $meta = 0;
}else{ } else{
$meta = ((int) $b[1]) & 0xFFFF; $meta = ((int) $b[1]) & 0xFFFF;
} }
@ -251,9 +253,10 @@ class BlockAPI{
if($item->getID() === AIR and strtoupper($b[0]) !== "AIR"){ if($item->getID() === AIR and strtoupper($b[0]) !== "AIR"){
$item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta); $item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta);
} }
}else{ } else{
$item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta); $item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta);
} }
return $item; return $item;
} }
} }
@ -262,12 +265,13 @@ class BlockAPI{
if(isset(Block::$class[$id])){ if(isset(Block::$class[$id])){
$classname = Block::$class[$id]; $classname = Block::$class[$id];
$b = new $classname($meta); $b = new $classname($meta);
}else{ } else{
$b = new GenericBlock((int) $id, $meta); $b = new GenericBlock((int) $id, $meta);
} }
if($v instanceof Position){ if($v instanceof Position){
$b->position($v); $b->position($v);
} }
return $b; return $b;
} }
@ -276,9 +280,10 @@ class BlockAPI{
if(isset(Item::$class[$id])){ if(isset(Item::$class[$id])){
$classname = Item::$class[$id]; $classname = Item::$class[$id];
$i = new $classname($meta, $count); $i = new $classname($meta, $count);
}else{ } else{
$i = new Item($id, $meta, $count); $i = new Item($id, $meta, $count);
} }
return $i; return $i;
} }
@ -304,7 +309,7 @@ class BlockAPI{
if(!isset($params[2])){ if(!isset($params[2])){
$item->setCount($item->getMaxStackSize()); $item->setCount($item->getMaxStackSize());
}else{ } else{
$item->setCount((int) $params[2]); $item->setCount((int) $params[2]);
} }
@ -313,18 +318,19 @@ class BlockAPI{
$output .= "Player is in creative mode.\n"; $output .= "Player is in creative mode.\n";
break; break;
} }
if($item->getID() == 0) { if($item->getID() == 0){
$output .= "You cannot give an air block to a player.\n"; $output .= "You cannot give an air block to a player.\n";
break; break;
} }
$player->addItem($item); $player->addItem($item);
$output .= "Giving ".$item->getCount()." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->getUsername()."\n"; $output .= "Giving " . $item->getCount() . " of " . $item->getName() . " (" . $item->getID() . ":" . $item->getMetadata() . ") to " . $player->getUsername() . "\n";
}else{ } else{
$output .= "Unknown player.\n"; $output .= "Unknown player.\n";
} }
break; break;
} }
return $output; return $output;
} }
@ -339,6 +345,7 @@ class BlockAPI{
if($send === true){ if($send === true){
$player->sendInventorySlot($player->slot); $player->sendInventorySlot($player->slot);
} }
return false; return false;
} }
@ -368,7 +375,7 @@ class BlockAPI{
if(($player->gamemode & 0x01) === 0 and $item->useOn($target) and $item->getMetadata() >= $item->getMaxDurability()){ if(($player->gamemode & 0x01) === 0 and $item->useOn($target) and $item->getMetadata() >= $item->getMaxDurability()){
$player->setSlot($player->slot, new Item(AIR, 0, 0)); $player->setSlot($player->slot, new Item(AIR, 0, 0));
} }
}else{ } else{
return $this->cancelAction($target, $player, false); return $this->cancelAction($target, $player, false);
} }
@ -379,6 +386,7 @@ class BlockAPI{
//$this->server->api->entity->drop(new Position($target->x + 0.5, $target->y, $target->z + 0.5, $target->level), BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2])); //$this->server->api->entity->drop(new Position($target->x + 0.5, $target->y, $target->z + 0.5, $target->level), BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2]));
} }
} }
return false; return false;
} }
@ -391,13 +399,14 @@ class BlockAPI{
$block = $target->getSide($face); $block = $target->getSide($face);
if(($player->getGamemode() & 0x01) === 0){ if(($player->getGamemode() & 0x01) === 0){
$item = $player->getSlot($player->slot); $item = $player->getSlot($player->slot);
}else{ } else{
$item = BlockAPI::getItem(BlockAPI::$creative[$player->slot][0], BlockAPI::$creative[$player->slot][1], 1); $item = BlockAPI::getItem(BlockAPI::$creative[$player->slot][0], BlockAPI::$creative[$player->slot][1], 1);
} }
if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ //If no block exists or not allowed in CREATIVE if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ //If no block exists or not allowed in CREATIVE
if($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ if($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){
$this->cancelAction($target, $player); $this->cancelAction($target, $player);
return $this->cancelAction($block, $player); return $this->cancelAction($block, $player);
} }
} }
@ -429,16 +438,18 @@ class BlockAPI{
if($item->getCount() <= 0){ if($item->getCount() <= 0){
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0)); $player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0));
} }
return false; return false;
} }
if($item->isPlaceable()){ if($item->isPlaceable()){
$hand = $item->getBlock(); $hand = $item->getBlock();
$hand->position($block); $hand->position($block);
}elseif($block->getID() === FIRE){ } elseif($block->getID() === FIRE){
$player->level->setBlock($block, new Block\AirBlock(), true, false, true); $player->level->setBlock($block, new Block\AirBlock(), true, false, true);
return false; return false;
}else{ } else{
return $this->cancelAction($block, $player, false); return $this->cancelAction($block, $player, false);
} }
@ -459,7 +470,7 @@ class BlockAPI{
if($this->server->api->dhandle("player.block.place", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) === false){ if($this->server->api->dhandle("player.block.place", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) === false){
return $this->cancelAction($block, $player); return $this->cancelAction($block, $player);
}elseif($hand->place($item, $player, $block, $target, $face, $fx, $fy, $fz) === false){ } elseif($hand->place($item, $player, $block, $target, $face, $fx, $fy, $fz) === false){
return $this->cancelAction($block, $player, false); return $this->cancelAction($block, $player, false);
} }
if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){ if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){
@ -494,7 +505,7 @@ class BlockAPI{
$this->scheduleBlockUpdate($pos->getSide(3), $delay, $type); $this->scheduleBlockUpdate($pos->getSide(3), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(4), $delay, $type); $this->scheduleBlockUpdate($pos->getSide(4), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(5), $delay, $type); $this->scheduleBlockUpdate($pos->getSide(5), $delay, $type);
}else{ } else{
$this->blockUpdate($pos->getSide(0), $type); $this->blockUpdate($pos->getSide(0), $type);
$this->blockUpdate($pos->getSide(1), $type); $this->blockUpdate($pos->getSide(1), $type);
$this->blockUpdate($pos->getSide(2), $type); $this->blockUpdate($pos->getSide(2), $type);
@ -507,7 +518,7 @@ class BlockAPI{
public function blockUpdate(Position $pos, $type = BLOCK_UPDATE_NORMAL){ public function blockUpdate(Position $pos, $type = BLOCK_UPDATE_NORMAL){
if(!($pos instanceof Block)){ if(!($pos instanceof Block)){
$block = $pos->level->getBlock($pos); $block = $pos->level->getBlock($pos);
}else{ } else{
$pos = new Position($pos->x, $pos->y, $pos->z, $pos->level); $pos = new Position($pos->x, $pos->y, $pos->z, $pos->level);
$block = $pos->level->getBlock($pos); $block = $pos->level->getBlock($pos);
} }
@ -519,6 +530,7 @@ class BlockAPI{
if($level === BLOCK_UPDATE_NORMAL){ if($level === BLOCK_UPDATE_NORMAL){
$this->blockUpdateAround($block, $level); $this->blockUpdateAround($block, $level);
} }
return $level; return $level;
} }
@ -528,30 +540,32 @@ class BlockAPI{
return false; return false;
} }
$index = $pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".$type; $index = $pos->x . "." . $pos->y . "." . $pos->z . "." . $pos->level->getName() . "." . $type;
$delay = microtime(true) + $delay * 0.05; $delay = microtime(true) + $delay * 0.05;
if(!isset($this->scheduledUpdates[$index])){ if(!isset($this->scheduledUpdates[$index])){
$this->scheduledUpdates[$index] = $pos; $this->scheduledUpdates[$index] = $pos;
$this->server->query("INSERT INTO blockUpdates (x, y, z, level, type, delay) VALUES (".$pos->x.", ".$pos->y.", ".$pos->z.", '".$pos->level->getName()."', ".$type.", ".$delay.");"); $this->server->query("INSERT INTO blockUpdates (x, y, z, level, type, delay) VALUES (" . $pos->x . ", " . $pos->y . ", " . $pos->z . ", '" . $pos->level->getName() . "', " . $type . ", " . $delay . ");");
return true; return true;
} }
return false; return false;
} }
public function blockUpdateTick(){ public function blockUpdateTick(){
$time = microtime(true); $time = microtime(true);
if(count($this->scheduledUpdates) > 0){ if(count($this->scheduledUpdates) > 0){
$update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE delay <= ".$time.";"); $update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE delay <= " . $time . ";");
if($update instanceof \SQLite3Result){ if($update instanceof \SQLite3Result){
$upp = array(); $upp = array();
while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){ while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){
$index = $up["x"].".".$up["y"].".".$up["z"].".".$up["level"].".".$up["type"]; $index = $up["x"] . "." . $up["y"] . "." . $up["z"] . "." . $up["level"] . "." . $up["type"];
if(isset($this->scheduledUpdates[$index])){ if(isset($this->scheduledUpdates[$index])){
$upp[] = array((int) $up["type"], $this->scheduledUpdates[$index]); $upp[] = array((int) $up["type"], $this->scheduledUpdates[$index]);
unset($this->scheduledUpdates[$index]); unset($this->scheduledUpdates[$index]);
} }
} }
$this->server->query("DELETE FROM blockUpdates WHERE delay <= ".$time.";"); $this->server->query("DELETE FROM blockUpdates WHERE delay <= " . $time . ";");
foreach($upp as $b){ foreach($upp as $b){
$this->blockUpdate($b[1], $b[0]); $this->blockUpdate($b[1], $b[0]);
} }

View File

@ -20,11 +20,13 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI; use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Player as Player; use PocketMine\Player as Player;
class ChatAPI{ class ChatAPI{
private $server; private $server;
function __construct(){ function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
@ -55,20 +57,20 @@ class ChatAPI{
$output .= "Usage: /say <message>\n"; $output .= "Usage: /say <message>\n";
break; break;
} }
$sender = ($issuer instanceof Player) ? "Server":ucfirst($issuer); $sender = ($issuer instanceof Player) ? "Server" : ucfirst($issuer);
$this->server->api->chat->broadcast("[$sender] ".$s); $this->server->api->chat->broadcast("[$sender] " . $s);
break; break;
case "me": case "me":
if(!($issuer instanceof Player)){ if(!($issuer instanceof Player)){
if($issuer === "rcon"){ if($issuer === "rcon"){
$sender = "Rcon"; $sender = "Rcon";
}else{ } else{
$sender = ucfirst($issuer); $sender = ucfirst($issuer);
} }
}else{ } else{
$sender = $issuer->getUsername(); $sender = $issuer->getUsername();
} }
$this->broadcast("* $sender ".implode(" ", $params)); $this->broadcast("* $sender " . implode(" ", $params));
break; break;
case "tell": case "tell":
if(!isset($params[0]) or !isset($params[1])){ if(!isset($params[0]) or !isset($params[1])){
@ -77,29 +79,30 @@ class ChatAPI{
} }
if(!($issuer instanceof Player)){ if(!($issuer instanceof Player)){
$sender = ucfirst($issuer); $sender = ucfirst($issuer);
}else{ } else{
$sender = $issuer->getUsername(); $sender = $issuer->getUsername();
} }
$n = array_shift($params); $n = array_shift($params);
$target = Player::get($n); $target = Player::get($n);
if($target instanceof Player){ if($target instanceof Player){
$target = $target->getUsername(); $target = $target->getUsername();
}else{ } else{
$target = strtolower($n); $target = strtolower($n);
if($target === "server" or $target === "console" or $target === "rcon"){ if($target === "server" or $target === "console" or $target === "rcon"){
$target = "Console"; $target = "Console";
} }
} }
$mes = implode(" ", $params); $mes = implode(" ", $params);
$output .= "[me -> ".$target."] ".$mes."\n"; $output .= "[me -> " . $target . "] " . $mes . "\n";
if($target !== "Console" and $target !== "Rcon"){ if($target !== "Console" and $target !== "Rcon"){
$this->sendTo(false, "[".$sender." -> me] ".$mes, $target); $this->sendTo(false, "[" . $sender . " -> me] " . $mes, $target);
} }
if($target === "Console" or $sender === "Console"){ if($target === "Console" or $sender === "Console"){
console("[INFO] [".$sender." -> ".$target."] ".$mes); console("[INFO] [" . $sender . " -> " . $target . "] " . $mes);
} }
break; break;
} }
return $output; return $output;
} }
@ -133,14 +136,14 @@ class ChatAPI{
if($owner !== false){ if($owner !== false){
if($owner instanceof Player){ if($owner instanceof Player){
if($whitelist === false){ if($whitelist === false){
console("[INFO] <".$owner->getUsername()."> ".$text); console("[INFO] <" . $owner->getUsername() . "> " . $text);
} }
}else{ } else{
if($whitelist === false){ if($whitelist === false){
console("[INFO] <".$owner."> ".$text); console("[INFO] <" . $owner . "> " . $text);
} }
} }
}else{ } else{
if($whitelist === false){ if($whitelist === false){
console("[INFO] $text"); console("[INFO] $text");
} }

View File

@ -20,12 +20,14 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI; use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Utils\TextFormat as TextFormat; use PocketMine\Utils\TextFormat as TextFormat;
use PocketMine\Player as Player; use PocketMine\Player as Player;
class ConsoleAPI{ class ConsoleAPI{
private $loop, $server, $event, $help, $cmds, $alias; private $loop, $server, $event, $help, $cmds, $alias;
function __construct(){ function __construct(){
$this->help = array(); $this->help = array();
$this->cmds = array(); $this->cmds = array();
@ -83,14 +85,14 @@ class ConsoleAPI{
break; break;
} }
$this->server->api->setProperty("gamemode", $gms[strtolower($params[0])]); $this->server->api->setProperty("gamemode", $gms[strtolower($params[0])]);
$output .= "Default Gamemode is now ".strtoupper($this->server->getGamemode()).".\n"; $output .= "Default Gamemode is now " . strtoupper($this->server->getGamemode()) . ".\n";
break; break;
case "status": case "status":
if(!($issuer instanceof Player) and $issuer === "console"){ if(!($issuer instanceof Player) and $issuer === "console"){
$this->server->debugInfo(true); $this->server->debugInfo(true);
} }
$info = $this->server->debugInfo(); $info = $this->server->debugInfo();
$output .= "TPS: ".$info["tps"].", Memory usage: ".$info["memory_usage"]." (Peak ".$info["memory_peak_usage"].")\n"; $output .= "TPS: " . $info["tps"] . ", Memory usage: " . $info["memory_usage"] . " (Peak " . $info["memory_peak_usage"] . ")\n";
break; break;
case "update-done": case "update-done":
$this->server->api->setProperty("last-update", time()); $this->server->api->setProperty("last-update", time());
@ -107,7 +109,7 @@ class ConsoleAPI{
break; break;
} }
$this->server->api->setProperty("difficulty", (int) $s); $this->server->api->setProperty("difficulty", (int) $s);
$output .= "Difficulty changed to ".$this->server->difficulty."\n"; $output .= "Difficulty changed to " . $this->server->difficulty . "\n";
break; break;
case "?": case "?":
if($issuer !== "console" and $issuer !== "rcon"){ if($issuer !== "console" and $issuer !== "rcon"){
@ -118,30 +120,30 @@ class ConsoleAPI{
$c = trim(strtolower($params[0])); $c = trim(strtolower($params[0]));
if(isset($this->help[$c]) or isset($this->alias[$c])){ if(isset($this->help[$c]) or isset($this->alias[$c])){
$c = isset($this->help[$c]) ? $c : $this->alias[$c]; $c = isset($this->help[$c]) ? $c : $this->alias[$c];
if($this->server->api->dhandle("console.command.".$c, array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false or $this->server->api->dhandle("console.command", array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false){ if($this->server->api->dhandle("console.command." . $c, array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false or $this->server->api->dhandle("console.command", array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false){
break; break;
} }
$output .= "Usage: /$c ".$this->help[$c]."\n"; $output .= "Usage: /$c " . $this->help[$c] . "\n";
break; break;
} }
} }
$cmds = array(); $cmds = array();
foreach($this->help as $c => $h){ foreach($this->help as $c => $h){
if($this->server->api->dhandle("console.command.".$c, array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false or $this->server->api->dhandle("console.command", array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false){ if($this->server->api->dhandle("console.command." . $c, array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false or $this->server->api->dhandle("console.command", array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false){
continue; continue;
} }
$cmds[$c] = $h; $cmds[$c] = $h;
} }
$max = ceil(count($cmds) / 5); $max = ceil(count($cmds) / 5);
$page = (int) (isset($params[0]) ? min($max, max(1, intval($params[0]))):1); $page = (int) (isset($params[0]) ? min($max, max(1, intval($params[0]))) : 1);
$output .= TextFormat::RED."-".TextFormat::RESET." Showing help page $page of $max (/help <page>) ".TextFormat::RED."-".TextFormat::RESET."\n"; $output .= TextFormat::RED . "-" . TextFormat::RESET . " Showing help page $page of $max (/help <page>) " . TextFormat::RED . "-" . TextFormat::RESET . "\n";
$current = 1; $current = 1;
foreach($cmds as $c => $h){ foreach($cmds as $c => $h){
$curpage = (int) ceil($current / 5); $curpage = (int) ceil($current / 5);
if($curpage === $page){ if($curpage === $page){
$output .= "/$c ".$h."\n"; $output .= "/$c " . $h . "\n";
}elseif($curpage > $page){ } elseif($curpage > $page){
break; break;
} }
++$current; ++$current;
@ -151,11 +153,13 @@ class ConsoleAPI{
$output .= "Command doesn't exist! Use /help\n"; $output .= "Command doesn't exist! Use /help\n";
break; break;
} }
return $output; return $output;
} }
public function alias($alias, $cmd){ public function alias($alias, $cmd){
$this->alias[strtolower(trim($alias))] = trim($cmd); $this->alias[strtolower(trim($alias))] = trim($cmd);
return true; return true;
} }
@ -179,12 +183,12 @@ class ConsoleAPI{
$cmd = strtolower(substr($line, 0, $end)); $cmd = strtolower(substr($line, 0, $end));
$params = (string) substr($line, $end + 1); $params = (string) substr($line, $end + 1);
if(isset($this->alias[$cmd])){ if(isset($this->alias[$cmd])){
return $this->run($this->alias[$cmd] . ($params !== "" ? " " .$params:""), $issuer, $cmd); return $this->run($this->alias[$cmd] . ($params !== "" ? " " . $params : ""), $issuer, $cmd);
} }
if($issuer instanceof Player){ if($issuer instanceof Player){
console("[DEBUG] ".TextFormat::AQUA.$issuer->getUsername().TextFormat::RESET." issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2); console("[DEBUG] " . TextFormat::AQUA . $issuer->getUsername() . TextFormat::RESET . " issued server command: " . ltrim("$alias ") . "/$cmd " . $params, true, true, 2);
}else{ } else{
console("[DEBUG] ".TextFormat::YELLOW."*".$issuer.TextFormat::RESET." issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2); console("[DEBUG] " . TextFormat::YELLOW . "*" . $issuer . TextFormat::RESET . " issued server command: " . ltrim("$alias ") . "/$cmd " . $params, true, true, 2);
} }
if(preg_match_all('#@([@a-z]{1,})#', $params, $matches, PREG_OFFSET_CAPTURE) > 0){ if(preg_match_all('#@([@a-z]{1,})#', $params, $matches, PREG_OFFSET_CAPTURE) > 0){
@ -199,13 +203,13 @@ class ConsoleAPI{
case "u": case "u":
case "player": case "player":
case "username": case "username":
$p = ($issuer instanceof Player) ? $issuer->getUsername():$issuer; $p = ($issuer instanceof Player) ? $issuer->getUsername() : $issuer;
$params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1); $params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1);
$offsetshift -= strlen($selector[0]) - strlen($p) + 1; $offsetshift -= strlen($selector[0]) - strlen($p) + 1;
break; break;
case "w": case "w":
case "world": case "world":
$p = ($issuer instanceof Player) ? $issuer->level->getName():$this->server->api->level->getDefault()->getName(); $p = ($issuer instanceof Player) ? $issuer->level->getName() : $this->server->api->level->getDefault()->getName();
$params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1); $params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1);
$offsetshift -= strlen($selector[0]) - strlen($p) + 1; $offsetshift -= strlen($selector[0]) - strlen($p) + 1;
break; break;
@ -215,17 +219,18 @@ class ConsoleAPI{
if($this->server->api->ban->isOp($issuer->getUsername())){ if($this->server->api->ban->isOp($issuer->getUsername())){
$output = ""; $output = "";
foreach(Player::getAll() as $p){ foreach(Player::getAll() as $p){
$output .= $this->run($cmd . " ". substr_replace($params, $p->getUsername(), $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias); $output .= $this->run($cmd . " " . substr_replace($params, $p->getUsername(), $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias);
} }
}else{ } else{
$issuer->sendChat("You don't have permissions to use this command.\n"); $issuer->sendChat("You don't have permissions to use this command.\n");
} }
}else{ } else{
$output = ""; $output = "";
foreach(Player::getAll() as $p){ foreach(Player::getAll() as $p){
$output .= $this->run($cmd . " ". substr_replace($params, $p->getUsername(), $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias); $output .= $this->run($cmd . " " . substr_replace($params, $p->getUsername(), $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias);
} }
} }
return $output; return $output;
case "r": case "r":
case "random": case "random":
@ -251,13 +256,14 @@ class ConsoleAPI{
$params = array(); $params = array();
} }
if(($d1 = $this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false if(($d1 = $this->server->api->dhandle("console.command." . $cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false
or ($d2 = $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false){ or ($d2 = $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false
){
$output = "You don't have permissions to use this command.\n"; $output = "You don't have permissions to use this command.\n";
}elseif($d1 !== true and (!isset($d2) or $d2 !== true)){ } elseif($d1 !== true and (!isset($d2) or $d2 !== true)){
if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){ if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){
$output = @call_user_func($this->cmds[$cmd], $cmd, $params, $issuer, $alias); $output = @call_user_func($this->cmds[$cmd], $cmd, $params, $issuer, $alias);
}elseif($this->server->api->dhandle("console.command.unknown", array("cmd" => $cmd, "params" => $params, "issuer" => $issuer, "alias" => $alias)) !== false){ } elseif($this->server->api->dhandle("console.command.unknown", array("cmd" => $cmd, "params" => $params, "issuer" => $issuer, "alias" => $alias)) !== false){
$output = $this->defaultCommands($cmd, $params, $issuer, $alias); $output = $this->defaultCommands($cmd, $params, $issuer, $alias);
} }
} }
@ -265,6 +271,7 @@ class ConsoleAPI{
if($output != "" and ($issuer instanceof Player)){ if($output != "" and ($issuer instanceof Player)){
$issuer->sendChat(trim($output)); $issuer->sendChat(trim($output));
} }
return $output; return $output;
} }
} }
@ -280,10 +287,10 @@ class ConsoleAPI{
if($output != ""){ if($output != ""){
$mes = explode("\n", trim($output)); $mes = explode("\n", trim($output));
foreach($mes as $m){ foreach($mes as $m){
console("[CMD] ".$m); console("[CMD] " . $m);
} }
} }
}else{ } else{
$this->loop->notify(); $this->loop->notify();
} }
} }
@ -296,6 +303,7 @@ class ConsoleLoop extends \Thread{
public $base; public $base;
public $ev; public $ev;
public $fp; public $fp;
public function __construct(){ public function __construct(){
$this->line = false; $this->line = false;
$this->stop = false; $this->stop = false;
@ -309,12 +317,13 @@ class ConsoleLoop extends \Thread{
private function readLine(){ private function readLine(){
if($this->fp){ if($this->fp){
$line = trim(fgets($this->fp)); $line = trim(fgets($this->fp));
}else{ } else{
$line = trim(readline("")); $line = trim(readline(""));
if($line != ""){ if($line != ""){
readline_add_history( $line ); readline_add_history($line);
} }
} }
return $line; return $line;
} }

View File

@ -20,10 +20,12 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine; use PocketMine;
class Container{ class Container{
private $payload = "", $whitelist = false, $blacklist = false; private $payload = "", $whitelist = false, $blacklist = false;
public function __construct($payload = "", $whitelist = false, $blacklist = false){ public function __construct($payload = "", $whitelist = false, $blacklist = false){
$this->payload = $payload; $this->payload = $payload;
if(is_array($whitelist)){ if(is_array($whitelist)){
@ -46,7 +48,7 @@ class Container{
if(in_array($target, $this->whitelist, true)){ if(in_array($target, $this->whitelist, true)){
$w = true; $w = true;
} }
}else{ } else{
$w = true; $w = true;
} }
if($this->blacklist !== false){ if($this->blacklist !== false){
@ -54,12 +56,13 @@ class Container{
if(in_array($target, $this->blacklist, true)){ if(in_array($target, $this->blacklist, true)){
$b = true; $b = true;
} }
}else{ } else{
$b = false; $b = false;
} }
if($w === false or $b === true){ if($w === false or $b === true){
return false; return false;
} }
return true; return true;
} }

View File

@ -22,6 +22,7 @@
//TODO: REMOVE //TODO: REMOVE
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI; use PocketMine\ServerAPI as ServerAPI;
class Deprecation{ class Deprecation{

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI; use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Level\Generator\Flat as Flat; use PocketMine\Level\Generator\Flat as Flat;
use PocketMine\Level\Generator\Normal as Normal; use PocketMine\Level\Generator\Normal as Normal;
@ -44,6 +45,7 @@ use PocketMine\Level\Position as Position;
class LevelAPI{ class LevelAPI{
private $server, $levels, $default; private $server, $levels, $default;
public function __construct(){ public function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->levels = array(); $this->levels = array();
@ -53,6 +55,7 @@ class LevelAPI{
if(isset($this->levels[$name])){ if(isset($this->levels[$name])){
return $this->levels[$name]; return $this->levels[$name];
} }
return false; return false;
} }
@ -90,15 +93,16 @@ class LevelAPI{
break; break;
case "seed": case "seed":
if(!isset($params[0]) and ($issuer instanceof Player)){ if(!isset($params[0]) and ($issuer instanceof Player)){
$output .= "Seed: ".$issuer->level->getSeed()."\n"; $output .= "Seed: " . $issuer->level->getSeed() . "\n";
}elseif(isset($params[0])){ } elseif(isset($params[0])){
if(($lv = $this->server->api->level->get(trim(implode(" ", $params)))) !== false){ if(($lv = $this->server->api->level->get(trim(implode(" ", $params)))) !== false){
$output .= "Seed: ".$lv->getSeed()."\n"; $output .= "Seed: " . $lv->getSeed() . "\n";
} }
}else{ } else{
$output .= "Seed: ".$this->server->api->level->getDefault()->getSeed()."\n"; $output .= "Seed: " . $this->server->api->level->getDefault()->getSeed() . "\n";
} }
} }
return $output; return $output;
} }
@ -113,16 +117,17 @@ class LevelAPI{
if($generator !== false and class_exists($generator)){ if($generator !== false and class_exists($generator)){
$generator = new $generator($options); $generator = new $generator($options);
}else{ } else{
if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){ if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){
$generator = new Flat($options); $generator = new Flat($options);
}else{ } else{
$generator = new Normal($options); $generator = new Normal($options);
} }
} }
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):(int) $seed); $gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed);
$gen->generate(); $gen->generate();
$gen->close(); $gen->close();
return true; return true;
} }
@ -130,13 +135,14 @@ class LevelAPI{
if($name === ""){ if($name === ""){
return false; return false;
} }
$path = \PocketMine\DATA."worlds/".$name."/"; $path = \PocketMine\DATA . "worlds/" . $name . "/";
if($this->get($name) === false and !file_exists($path."level.pmf")){ if($this->get($name) === false and !file_exists($path . "level.pmf")){
$level = new LevelImport($path); $level = new LevelImport($path);
if($level->import() === false){ if($level->import() === false){
return false; return false;
} }
} }
return true; return true;
} }
@ -145,7 +151,7 @@ class LevelAPI{
if($name === $this->default and $force !== true){ if($name === $this->default and $force !== true){
return false; return false;
} }
console("[INFO] Unloading level \"".$name."\""); console("[INFO] Unloading level \"" . $name . "\"");
$level->nextSave = PHP_INT_MAX; $level->nextSave = PHP_INT_MAX;
$level->save(); $level->save();
foreach($level->getPlayers() as $player){ foreach($level->getPlayers() as $player){
@ -153,28 +159,31 @@ class LevelAPI{
} }
$level->close(); $level->close();
unset($this->levels[$name]); unset($this->levels[$name]);
return true; return true;
} }
public function loadLevel($name){ public function loadLevel($name){
if($this->get($name) !== false){ if($this->get($name) !== false){
return true; return true;
}elseif($this->levelExists($name) === false){ } elseif($this->levelExists($name) === false){
console("[NOTICE] Level \"".$name."\" not found"); console("[NOTICE] Level \"" . $name . "\" not found");
return false; return false;
} }
$path = \PocketMine\DATA."worlds/".$name."/"; $path = \PocketMine\DATA . "worlds/" . $name . "/";
console("[INFO] Preparing level \"".$name."\""); console("[INFO] Preparing level \"" . $name . "\"");
$level = new LevelFormat($path."level.pmf"); $level = new LevelFormat($path . "level.pmf");
if(!$level->isLoaded){ if(!$level->isLoaded){
console("[ERROR] Could not load level \"".$name."\""); console("[ERROR] Could not load level \"" . $name . "\"");
return false; return false;
} }
//$entities = new Config($path."entities.yml", Config::YAML); //$entities = new Config($path."entities.yml", Config::YAML);
if(file_exists($path."tileEntities.yml")){ if(file_exists($path . "tileEntities.yml")){
@rename($path."tileEntities.yml", $path."tiles.yml"); @rename($path . "tileEntities.yml", $path . "tiles.yml");
} }
$blockUpdates = new Config($path."bupdates.yml", Config::YAML); $blockUpdates = new Config($path . "bupdates.yml", Config::YAML);
$this->levels[$name] = new Level($level, $name); $this->levels[$name] = new Level($level, $name);
/*foreach($entities->getAll() as $entity){ /*foreach($entities->getAll() as $entity){
if(!isset($entity["id"])){ if(!isset($entity["id"])){
@ -205,8 +214,8 @@ class LevelAPI{
} }
}*/ }*/
if(file_exists($path ."tiles.yml")){ if(file_exists($path . "tiles.yml")){
$tiles = new Config($path."tiles.yml", Config::YAML); $tiles = new Config($path . "tiles.yml", Config::YAML);
foreach($tiles->getAll() as $tile){ foreach($tiles->getAll() as $tile){
if(!isset($tile["id"])){ if(!isset($tile["id"])){
continue; continue;
@ -265,13 +274,14 @@ class LevelAPI{
break; break;
} }
} }
unlink($path ."tiles.yml"); unlink($path . "tiles.yml");
$this->levels[$name]->save(true, true); $this->levels[$name]->save(true, true);
} }
foreach($blockUpdates->getAll() as $bupdate){ foreach($blockUpdates->getAll() as $bupdate){
$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"]); $this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"], (int) $bupdate["y"], (int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
} }
return true; return true;
} }

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\Entity\RealHuman as RealHuman; use PocketMine\Entity\RealHuman as RealHuman;
use PocketMine\ServerAPI as ServerAPI; use PocketMine\ServerAPI as ServerAPI;
use PocketMine\NBT\Tag\Compound as Compound; use PocketMine\NBT\Tag\Compound as Compound;
@ -125,7 +126,7 @@ class Player extends RealHuman{
foreach(Player::$list as $player){ foreach(Player::$list as $player){
if($multiple === false and $player->iusername === $name){ if($multiple === false and $player->iusername === $name){
return $player; return $player;
}elseif(strpos($player->iusername, $name) !== false){ } elseif(strpos($player->iusername, $name) !== false){
$players[$player->CID] = $player; $players[$player->CID] = $player;
} }
} }
@ -133,10 +134,10 @@ class Player extends RealHuman{
if($multiple === false){ if($multiple === false){
if(count($players) > 0){ if(count($players) > 0){
return array_shift($players); return array_shift($players);
}else{ } else{
return false; return false;
} }
}else{ } else{
return $players; return $players;
} }
} }
@ -148,7 +149,7 @@ class Player extends RealHuman{
public static function getOffline($name){ public static function getOffline($name){
$server = ServerAPI::request(); $server = ServerAPI::request();
$iname = strtolower($name); $iname = strtolower($name);
if(!file_exists(\PocketMine\DATA."players/".$iname.".dat")){ if(!file_exists(\PocketMine\DATA . "players/" . $iname . ".dat")){
$nbt = new Compound(false, array( $nbt = new Compound(false, array(
"Pos" => new Enum("Pos", array( "Pos" => new Enum("Pos", array(
0 => new Double(0, $server->spawn->x), 0 => new Double(0, $server->spawn->x),
@ -185,8 +186,8 @@ class Player extends RealHuman{
$nbt->Inventory->setTagType(NBT\TAG_Compound); $nbt->Inventory->setTagType(NBT\TAG_Compound);
$nbt->Motion->setTagType(NBT\TAG_Double); $nbt->Motion->setTagType(NBT\TAG_Double);
$nbt->Rotation->setTagType(NBT\TAG_Float); $nbt->Rotation->setTagType(NBT\TAG_Float);
if(file_exists(\PocketMine\DATA."players/".$iname.".yml")){ if(file_exists(\PocketMine\DATA . "players/" . $iname . ".yml")){
$data = new Config(\PocketMine\DATA."players/".$iname.".yml", Config::YAML, array()); $data = new Config(\PocketMine\DATA . "players/" . $iname . ".yml", Config::YAML, array());
$nbt->playerGameType = (int) $data->get("gamemode"); $nbt->playerGameType = (int) $data->get("gamemode");
$nbt->Level = $data->get("position")["level"]; $nbt->Level = $data->get("position")["level"];
$nbt->Pos[0] = $data->get("position")["x"]; $nbt->Pos[0] = $data->get("position")["x"];
@ -196,7 +197,7 @@ class Player extends RealHuman{
$nbt->SpawnX = (int) $data->get("spawn")["x"]; $nbt->SpawnX = (int) $data->get("spawn")["x"];
$nbt->SpawnY = (int) $data->get("spawn")["y"]; $nbt->SpawnY = (int) $data->get("spawn")["y"];
$nbt->SpawnZ = (int) $data->get("spawn")["z"]; $nbt->SpawnZ = (int) $data->get("spawn")["z"];
console("[NOTICE] Old Player data found for \"".$iname."\", upgrading profile"); console("[NOTICE] Old Player data found for \"" . $iname . "\", upgrading profile");
foreach($data->get("inventory") as $slot => $item){ foreach($data->get("inventory") as $slot => $item){
if(count($item) === 3){ if(count($item) === 3){
$nbt->Inventory[$slot + 9] = new Compound(false, array( $nbt->Inventory[$slot + 9] = new Compound(false, array(
@ -231,17 +232,17 @@ class Player extends RealHuman{
} }
} }
foreach($data->get("achievements") as $achievement => $status){ foreach($data->get("achievements") as $achievement => $status){
$nbt->Achievements[$achievement] = new Byte($achievement, $status == true ? 1:0); $nbt->Achievements[$achievement] = new Byte($achievement, $status == true ? 1 : 0);
} }
unlink(\PocketMine\DATA."players/".$iname.".yml"); unlink(\PocketMine\DATA . "players/" . $iname . ".yml");
}else{ } else{
console("[NOTICE] Player data not found for \"".$iname."\", creating new profile"); console("[NOTICE] Player data not found for \"" . $iname . "\", creating new profile");
Player::saveOffline($name, $nbt); Player::saveOffline($name, $nbt);
} }
}else{ } else{
$nbt = new NBT(NBT\BIG_ENDIAN); $nbt = new NBT(NBT\BIG_ENDIAN);
$nbt->read(file_get_contents(\PocketMine\DATA."players/".$iname.".dat")); $nbt->read(file_get_contents(\PocketMine\DATA . "players/" . $iname . ".dat"));
$nbt = $nbt->getData(); $nbt = $nbt->getData();
} }
@ -254,7 +255,7 @@ class Player extends RealHuman{
ServerAPI::request()->handle("player.offline.save", $nbtTag); ServerAPI::request()->handle("player.offline.save", $nbtTag);
$nbt = new NBT(NBT\BIG_ENDIAN); $nbt = new NBT(NBT\BIG_ENDIAN);
$nbt->setData($nbtTag); $nbt->setData($nbtTag);
file_put_contents(\PocketMine\DATA."players/".strtolower($name).".dat", $nbt->write()); file_put_contents(\PocketMine\DATA . "players/" . strtolower($name) . ".dat", $nbt->write());
} }
public static function broadcastPacket(array $players, DataPacket $packet){ public static function broadcastPacket(array $players, DataPacket $packet){
@ -273,23 +274,27 @@ class Player extends RealHuman{
if($this->server->api->dhandle("achievement.grant", array("player" => $this, "achievementId" => $achievementId)) !== false){ if($this->server->api->dhandle("achievement.grant", array("player" => $this, "achievementId" => $achievementId)) !== false){
$this->achievements[$achievementId] = true; $this->achievements[$achievementId] = true;
Achievement::broadcast($this, $achievementId); Achievement::broadcast($this, $achievementId);
return true; return true;
}else{ } else{
return false; return false;
} }
} }
return false; return false;
} }
public function hasAchievement($achievementId){ public function hasAchievement($achievementId){
if(!isset(Achievement::$list[$achievementId]) or !isset($this->achievements)){ if(!isset(Achievement::$list[$achievementId]) or !isset($this->achievements)){
$this->achievements = array(); $this->achievements = array();
return false; return false;
} }
if(!isset($this->achievements[$achievementId]) or $this->achievements[$achievementId] == false){ if(!isset($this->achievements[$achievementId]) or $this->achievements[$achievementId] == false){
return false; return false;
} }
return true; return true;
} }
@ -349,13 +354,13 @@ class Player extends RealHuman{
$this->viewDistance = (int) $this->server->api->getProperty("view-distance"); $this->viewDistance = (int) $this->server->api->getProperty("view-distance");
$this->slot = 0; $this->slot = 0;
$this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1); $this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1);
$this->packetStats = array(0,0); $this->packetStats = array(0, 0);
$this->buffer = new Packet(Info::DATA_PACKET_0); $this->buffer = new Packet(Info::DATA_PACKET_0);
$this->buffer->data = array(); $this->buffer->data = array();
$this->server->schedule(2, array($this, "handlePacketQueues"), array(), true); $this->server->schedule(2, array($this, "handlePacketQueues"), array(), true);
$this->server->schedule(20 * 60, array($this, "clearQueue"), array(), true); $this->server->schedule(20 * 60, array($this, "clearQueue"), array(), true);
$this->evid[] = $this->server->event("server.close", array($this, "close")); $this->evid[] = $this->server->event("server.close", array($this, "close"));
console("[DEBUG] New Session started with ".$ip.":".$port.". MTU ".$this->MTU.", Client ID ".$this->clientID, true, true, 2); console("[DEBUG] New Session started with " . $ip . ":" . $port . ". MTU " . $this->MTU . ", Client ID " . $this->clientID, true, true, 2);
} }
public function getSpawn(){ public function getSpawn(){
@ -368,7 +373,7 @@ class Player extends RealHuman{
public function setSpawn(Vector3 $pos){ public function setSpawn(Vector3 $pos){
if(!($pos instanceof Position)){ if(!($pos instanceof Position)){
$level = $this->level; $level = $this->level;
}else{ } else{
$level = $pos->level; $level = $pos->level;
} }
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level); $this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level);
@ -452,8 +457,9 @@ class Player extends RealHuman{
$this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk")); $this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk"));
++$this->chunkScheduled; ++$this->chunkScheduled;
} }
return; return;
}else{ } else{
unset($this->chunkCount[$count]); unset($this->chunkCount[$count]);
} }
} }
@ -478,6 +484,7 @@ class Player extends RealHuman{
if($this->chunkScheduled === 0){ if($this->chunkScheduled === 0){
$this->server->schedule(40, array($this, "getNextChunk")); $this->server->schedule(40, array($this, "getNextChunk"));
} }
return false; return false;
} }
$X = null; $X = null;
@ -489,6 +496,7 @@ class Player extends RealHuman{
$this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk")); $this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk"));
++$this->chunkScheduled; ++$this->chunkScheduled;
} }
return false; return false;
} }
unset($this->chunksOrder[$index]); unset($this->chunksOrder[$index]);
@ -529,7 +537,7 @@ class Player extends RealHuman{
$this->namedtag->SpawnZ = (int) $this->spawnPosition->z; $this->namedtag->SpawnZ = (int) $this->spawnPosition->z;
foreach($this->achievements as $achievement => $status){ foreach($this->achievements as $achievement => $status){
$this->namedtag->Achievements[$achievement] = new Byte($achievement, $status === true ? 1:0); $this->namedtag->Achievements[$achievement] = new Byte($achievement, $status === true ? 1 : 0);
} }
$this->namedtag->playerGameType = $this->gamemode; $this->namedtag->playerGameType = $this->gamemode;
@ -550,8 +558,8 @@ class Player extends RealHuman{
$this->server->api->handle("player.quit", $this); $this->server->api->handle("player.quit", $this);
$this->save(); $this->save();
} }
$reason = $reason == "" ? "server stop":$reason; $reason = $reason == "" ? "server stop" : $reason;
$this->sendChat("You have been kicked. Reason: ".$reason."\n"); $this->sendChat("You have been kicked. Reason: " . $reason . "\n");
$this->sendBuffer(); $this->sendBuffer();
$this->directDataPacket(new Network\Protocol\DisconnectPacket); $this->directDataPacket(new Network\Protocol\DisconnectPacket);
unset(Player::$list[$this->CID]); unset(Player::$list[$this->CID]);
@ -568,10 +576,10 @@ class Player extends RealHuman{
Player::saveOffline($this->username, $this->namedtag); Player::saveOffline($this->username, $this->namedtag);
} }
if($msg === true and $this->username != "" and $this->spawned !== false){ if($msg === true and $this->username != "" and $this->spawned !== false){
$this->server->api->chat->broadcast($this->username." left the game"); $this->server->api->chat->broadcast($this->username . " left the game");
} }
$this->spawned = false; $this->spawned = false;
console("[INFO] ".TextFormat::AQUA.$this->username.TextFormat::RESET."[/".$this->ip.":".$this->port."] logged out due to ".$reason); console("[INFO] " . TextFormat::AQUA . $this->username . TextFormat::RESET . "[/" . $this->ip . ":" . $this->port . "] logged out due to " . $reason);
$this->windows = array(); $this->windows = array();
$this->armor = array(); $this->armor = array();
$this->inventory = array(); $this->inventory = array();
@ -604,6 +612,7 @@ class Player extends RealHuman{
}*/ }*/
$this->setSpawn($pos); $this->setSpawn($pos);
$this->server->schedule(60, array($this, "checkSleep")); $this->server->schedule(60, array($this, "checkSleep"));
return true; return true;
} }
@ -632,7 +641,8 @@ class Player extends RealHuman{
public function sendInventorySlot($s){ public function sendInventorySlot($s){
$this->sendInventory(); $this->sendInventory();
return;
return; //TODO: Check if Mojang adds this
$s = (int) $s; $s = (int) $s;
if(!isset($this->inventory[$s])){ if(!isset($this->inventory[$s])){
$pk = new Network\Protocol\ContainerSetSlotPacket; $pk = new Network\Protocol\ContainerSetSlotPacket;
@ -648,6 +658,7 @@ class Player extends RealHuman{
$pk->slot = (int) $s; $pk->slot = (int) $s;
$pk->item = $slot; $pk->item = $slot;
$this->dataPacket($pk); $this->dataPacket($pk);
return true; return true;
} }
@ -684,7 +695,7 @@ class Player extends RealHuman{
if($w === $data["tile"]){ if($w === $data["tile"]){
$pk = new Network\Protocol\ContainerSetSlotPacket; $pk = new Network\Protocol\ContainerSetSlotPacket;
$pk->windowid = $id; $pk->windowid = $id;
$pk->slot = $data["slot"] + (isset($data["offset"]) ? $data["offset"]:0); $pk->slot = $data["slot"] + (isset($data["offset"]) ? $data["offset"] : 0);
$pk->item = $data["slotdata"]; $pk->item = $data["slotdata"];
$this->dataPacket($pk); $this->dataPacket($pk);
} }
@ -709,7 +720,7 @@ class Player extends RealHuman{
$this->grantAchievement("diamond"); $this->grantAchievement("diamond");
break; break;
} }
}elseif($data["entity"]->level === $this->level){ } elseif($data["entity"]->level === $this->level){
$pk = new Network\Protocol\TakeItemEntityPacket; $pk = new Network\Protocol\TakeItemEntityPacket;
$pk->eid = $data["eid"]; $pk->eid = $data["eid"];
$pk->target = $data["entity"]->getID(); $pk->target = $data["entity"]->getID();
@ -728,7 +739,7 @@ class Player extends RealHuman{
case "entity.metadata": case "entity.metadata":
if($data->getID() === $this->id){ if($data->getID() === $this->id){
$eid = 0; $eid = 0;
}else{ } else{
$eid = $data->getID(); $eid = $data->getID();
} }
if($data->level === $this->level){ if($data->level === $this->level){
@ -741,7 +752,7 @@ class Player extends RealHuman{
case "entity.event": case "entity.event":
if($data["entity"]->getID() === $this->id){ if($data["entity"]->getID() === $this->id){
$eid = 0; $eid = 0;
}else{ } else{
$eid = $data["entity"]->getID(); $eid = $data["entity"]->getID();
} }
if($data["entity"]->level === $this->level){ if($data["entity"]->level === $this->level){
@ -755,11 +766,11 @@ class Player extends RealHuman{
if(($data instanceof Container) === true){ if(($data instanceof Container) === true){
if(!$data->check($this->username) and !$data->check($this->iusername)){ if(!$data->check($this->username) and !$data->check($this->iusername)){
return; return;
}else{ } else{
$message = $data->get(); $message = $data->get();
$this->sendChat($message["message"], $message["player"]); $this->sendChat($message["message"], $message["player"]);
} }
}else{ } else{
$this->sendChat((string) $data); $this->sendChat((string) $data);
} }
break; break;
@ -793,7 +804,7 @@ class Player extends RealHuman{
if($m !== ""){ if($m !== ""){
$pk = new Network\Protocol\MessagePacket; $pk = new Network\Protocol\MessagePacket;
$pk->source = ($author instanceof Player) ? $author->username:$author; $pk->source = ($author instanceof Player) ? $author->username : $author;
$pk->message = TextFormat::clean($m); //Colors not implemented :( $pk->message = TextFormat::clean($m); //Colors not implemented :(
$this->dataPacket($pk); $this->dataPacket($pk);
} }
@ -865,7 +876,7 @@ class Player extends RealHuman{
$craftItem[0] = $item->getID(); $craftItem[0] = $item->getID();
if($item->getMetadata() !== $craftItem[1] and $craftItem[1] !== true){ if($item->getMetadata() !== $craftItem[1] and $craftItem[1] !== true){
$craftItem[1] = false; $craftItem[1] = false;
}else{ } else{
$craftItem[1] = $item->getMetadata(); $craftItem[1] = $item->getMetadata();
} }
$craftItem[2] += $item->getCount(); $craftItem[2] += $item->getCount();
@ -877,7 +888,7 @@ class Player extends RealHuman{
foreach($recipe as $slot => $item){ foreach($recipe as $slot => $item){
if(!isset($recipeItems[$item->getID()])){ if(!isset($recipeItems[$item->getID()])){
$recipeItems[$item->getID()] = array($item->getID(), $item->getMetadata(), $item->getCount()); $recipeItems[$item->getID()] = array($item->getID(), $item->getMetadata(), $item->getCount());
}else{ } else{
if($item->getMetadata() !== $recipeItems[$item->getID()][1]){ if($item->getMetadata() !== $recipeItems[$item->getID()][1]){
$recipeItems[$item->getID()][1] = false; $recipeItems[$item->getID()][1] = false;
} }
@ -910,7 +921,7 @@ class Player extends RealHuman{
$s = $this->getSlot($slot); $s = $this->getSlot($slot);
if($s->getCount() <= 0 or $s->getID() === AIR){ if($s->getCount() <= 0 or $s->getID() === AIR){
$this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $item->getCount())); $this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $item->getCount()));
}else{ } else{
$this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $s->getCount() + $item->getCount())); $this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $s->getCount() + $item->getCount()));
} }
@ -952,6 +963,7 @@ class Player extends RealHuman{
} }
} }
} }
return $res; return $res;
} }
@ -984,16 +996,17 @@ class Player extends RealHuman{
$inv =& $this->inventory; $inv =& $this->inventory;
if(($this->gamemode & 0x01) === ($gm & 0x01)){ if(($this->gamemode & 0x01) === ($gm & 0x01)){
$this->gamemode = $gm; $this->gamemode = $gm;
$this->sendChat("Your gamemode has been changed to ".$this->getGamemode().".\n"); $this->sendChat("Your gamemode has been changed to " . $this->getGamemode() . ".\n");
}else{ } else{
$this->blocked = true; $this->blocked = true;
$this->gamemode = $gm; $this->gamemode = $gm;
$this->sendChat("Your gamemode has been changed to ".$this->getGamemode().", you've to do a forced reconnect.\n"); $this->sendChat("Your gamemode has been changed to " . $this->getGamemode() . ", you've to do a forced reconnect.\n");
$this->server->schedule(30, array($this, "close"), "gamemode change"); //Forces a kick $this->server->schedule(30, array($this, "close"), "gamemode change"); //Forces a kick
} }
$this->inventory = $inv; $this->inventory = $inv;
$this->sendSettings(); $this->sendSettings();
$this->sendInventory(); $this->sendInventory();
return true; return true;
} }
@ -1003,7 +1016,7 @@ class Player extends RealHuman{
} }
if($this->packetStats[1] > 2){ if($this->packetStats[1] > 2){
$this->packetLoss = $this->packetStats[1] / max(1, $this->packetStats[0] + $this->packetStats[1]); $this->packetLoss = $this->packetStats[1] / max(1, $this->packetStats[0] + $this->packetStats[1]);
}else{ } else{
$this->packetLoss = 0; $this->packetLoss = 0;
} }
$this->packetStats = array(0, 0); $this->packetStats = array(0, 0);
@ -1051,6 +1064,7 @@ class Player extends RealHuman{
$time = microtime(true); $time = microtime(true);
if($time > $this->timeout){ if($time > $this->timeout){
$this->close("timeout"); $this->close("timeout");
return false; return false;
} }
@ -1081,7 +1095,7 @@ class Player extends RealHuman{
if(isset($p->messageIndex) and $p->messageIndex !== false){ if(isset($p->messageIndex) and $p->messageIndex !== false){
if($p->messageIndex > $this->receiveCount){ if($p->messageIndex > $this->receiveCount){
$this->receiveCount = $p->messageIndex; $this->receiveCount = $p->messageIndex;
}elseif($p->messageIndex !== 0){ } elseif($p->messageIndex !== 0){
if(isset($this->received[$p->messageIndex])){ if(isset($this->received[$p->messageIndex])){
continue; continue;
} }
@ -1232,6 +1246,7 @@ class Player extends RealHuman{
$this->loginData = array("clientId" => $packet->clientId, "loginData" => $packet->loginData); $this->loginData = array("clientId" => $packet->clientId, "loginData" => $packet->loginData);
if(count(Player::$list) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)){ if(count(Player::$list) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)){
$this->close("server is full!", false); $this->close("server is full!", false);
return; return;
} }
if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){
@ -1239,28 +1254,33 @@ class Player extends RealHuman{
$pk = new Network\Protocol\LoginStatusPacket; $pk = new Network\Protocol\LoginStatusPacket;
$pk->status = 1; $pk->status = 1;
$this->directDataPacket($pk); $this->directDataPacket($pk);
}else{ } else{
$pk = new Network\Protocol\LoginStatusPacket; $pk = new Network\Protocol\LoginStatusPacket;
$pk->status = 2; $pk->status = 2;
$this->directDataPacket($pk); $this->directDataPacket($pk);
} }
$this->close("Incorrect protocol #".$packet->protocol1, false); $this->close("Incorrect protocol #" . $packet->protocol1, false);
return; return;
} }
if(preg_match('#^[a-zA-Z0-9_]{3,16}$#', $this->username) == 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console"){ if(preg_match('#^[a-zA-Z0-9_]{3,16}$#', $this->username) == 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console"){
$this->close("Bad username", false); $this->close("Bad username", false);
return; return;
} }
if($this->server->api->handle("player.connect", $this) === false){ if($this->server->api->handle("player.connect", $this) === false){
$this->close("Unknown reason", false); $this->close("Unknown reason", false);
return; return;
} }
if($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)){ if($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)){
$this->close("Server is white-listed", false); $this->close("Server is white-listed", false);
return; return;
}elseif($this->server->api->ban->isBanned($this->iusername) or $this->server->api->ban->isIPBanned($this->ip)){ } elseif($this->server->api->ban->isBanned($this->iusername) or $this->server->api->ban->isIPBanned($this->ip)){
$this->close("You are banned!", false); $this->close("You are banned!", false);
return; return;
} }
$this->loggedIn = true; $this->loggedIn = true;
@ -1287,11 +1307,13 @@ class Player extends RealHuman{
if($this->server->api->handle("player.join", $this) === false){ if($this->server->api->handle("player.join", $this) === false){
$this->close("join cancelled", false); $this->close("join cancelled", false);
return; return;
} }
if(!($nbt instanceof Compound)){ if(!($nbt instanceof Compound)){
$this->close("no config created", false); $this->close("no config created", false);
return; return;
} }
@ -1312,7 +1334,7 @@ class Player extends RealHuman{
if(($this->gamemode & 0x01) === 0x01){ if(($this->gamemode & 0x01) === 0x01){
$this->slot = 0; $this->slot = 0;
$this->hotbar[0] = 0; $this->hotbar[0] = 0;
}else{ } else{
$this->slot = $this->hotbar[0]; $this->slot = $this->hotbar[0];
} }
@ -1346,7 +1368,7 @@ class Player extends RealHuman{
$this->evid[] = $this->server->event("tile.update", array($this, "eventHandler")); $this->evid[] = $this->server->event("tile.update", array($this, "eventHandler"));
$this->lastMeasure = microtime(true); $this->lastMeasure = microtime(true);
$this->server->schedule(50, array($this, "measureLag"), array(), true); $this->server->schedule(50, array($this, "measureLag"), array(), true);
console("[INFO] ".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).")"); console("[INFO] " . TextFormat::AQUA . $this->username . TextFormat::RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->id . " at (" . $this->level->getName() . ", " . round($this->x, 4) . ", " . round($this->y, 4) . ", " . round($this->z, 4) . ")");
break; break;
case ProtocolInfo::READY_PACKET: case ProtocolInfo::READY_PACKET:
if($this->loggedIn === false){ if($this->loggedIn === false){
@ -1360,7 +1382,7 @@ class Player extends RealHuman{
//$this->heal($this->data->get("health"), "spawn", true); //$this->heal($this->data->get("health"), "spawn", true);
$this->spawned = true; $this->spawned = true;
$this->spawnToAll(); $this->spawnToAll();
$this->sendChat($this->server->motd."\n"); $this->sendChat($this->server->motd . "\n");
$this->sendInventory(); $this->sendInventory();
$this->sendSettings(); $this->sendSettings();
@ -1379,7 +1401,7 @@ class Player extends RealHuman{
$this->sendBuffer(); $this->sendBuffer();
$this->server->handle("player.spawn", $this); $this->server->handle("player.spawn", $this);
break; break;
case 2://Chunk loaded? case 2: //Chunk loaded?
break; break;
} }
break; break;
@ -1399,7 +1421,7 @@ class Player extends RealHuman{
if($this->forceMovement instanceof Vector3){ if($this->forceMovement instanceof Vector3){
if($this->forceMovement->distance($newPos) <= 0.7){ if($this->forceMovement->distance($newPos) <= 0.7){
$this->forceMovement = false; $this->forceMovement = false;
}else{ } else{
$this->setPosition($this->forceMovement); $this->setPosition($this->forceMovement);
} }
} }
@ -1423,7 +1445,7 @@ class Player extends RealHuman{
if($packet->slot === 0x28 or $packet->slot === 0){ //0 for 0.8.0 compatibility if($packet->slot === 0x28 or $packet->slot === 0){ //0 for 0.8.0 compatibility
$packet->slot = -1; //Air $packet->slot = -1; //Air
}else{ } else{
$packet->slot -= 9; $packet->slot -= 9;
} }
@ -1436,13 +1458,13 @@ class Player extends RealHuman{
break; break;
} }
} }
}else{ } else{
$item = $this->getSlot($packet->slot); $item = $this->getSlot($packet->slot);
} }
if($packet->slot === false or EventHandler::callEvent(new PlayerEquipmentChangeEvent($this, $item, $packet->slot, 0)) === Event::DENY){ if($packet->slot === false or EventHandler::callEvent(new PlayerEquipmentChangeEvent($this, $item, $packet->slot, 0)) === Event::DENY){
$this->sendInventorySlot($packet->slot); $this->sendInventorySlot($packet->slot);
}else{ } else{
$this->setEquipmentSlot(0, $packet->slot); $this->setEquipmentSlot(0, $packet->slot);
$this->setCurrentEquipmentSlot(0); $this->setCurrentEquipmentSlot(0);
if(($this->gamemode & 0x01) === SURVIVAL){ if(($this->gamemode & 0x01) === SURVIVAL){
@ -1510,12 +1532,12 @@ class Player extends RealHuman{
if($this->blocked === true or $blockVector->distance($this) > 10){ if($this->blocked === true or $blockVector->distance($this) > 10){
}elseif(($this->gamemode & 0x01) === 1 and isset(BlockAPI::$creative[$this->slot]) and $packet->item === BlockAPI::$creative[$this->slot][0] and $packet->meta === BlockAPI::$creative[$this->slot][1]){ } elseif(($this->gamemode & 0x01) === 1 and isset(BlockAPI::$creative[$this->slot]) and $packet->item === BlockAPI::$creative[$this->slot][0] and $packet->meta === BlockAPI::$creative[$this->slot][1]){
$this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->fx, $packet->fy, $packet->fz); $this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->fx, $packet->fy, $packet->fz);
break; break;
}elseif($this->getSlot($this->slot)->getID() !== $packet->item or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $packet->meta)){ } elseif($this->getSlot($this->slot)->getID() !== $packet->item or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $packet->meta)){
$this->sendInventorySlot($this->slot); $this->sendInventorySlot($this->slot);
}else{ } else{
$this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->fx, $packet->fy, $packet->fz); $this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->fx, $packet->fy, $packet->fz);
break; break;
} }
@ -1538,7 +1560,7 @@ class Player extends RealHuman{
$pk->meta = $block->getMetadata(); $pk->meta = $block->getMetadata();
$this->dataPacket($pk); $this->dataPacket($pk);
break; break;
}elseif($packet->face === 0xff and $this->server->handle("player.action", $data) !== false){ } elseif($packet->face === 0xff and $this->server->handle("player.action", $data) !== false){
$this->inAction = true; $this->inAction = true;
$this->startAction = microtime(true); $this->startAction = microtime(true);
//$this->updateMetadata(); //$this->updateMetadata();
@ -1649,7 +1671,7 @@ class Player extends RealHuman{
$s = $packet->slots[$i]; $s = $packet->slots[$i];
if($s === 0 or $s === 255){ if($s === 0 or $s === 255){
$s = BlockAPI::getItem(AIR, 0, 0); $s = BlockAPI::getItem(AIR, 0, 0);
}else{ } else{
$s = BlockAPI::getItem($s + 256, 0, 1); $s = BlockAPI::getItem($s + 256, 0, 1);
} }
$slot = $this->getArmorSlot($i); $slot = $this->getArmorSlot($i);
@ -1657,25 +1679,25 @@ class Player extends RealHuman{
if($this->setArmorSlot($i, BlockAPI::getItem(AIR, 0, 0)) === false){ if($this->setArmorSlot($i, BlockAPI::getItem(AIR, 0, 0)) === false){
$this->sendArmor(); $this->sendArmor();
$this->sendInventory(); $this->sendInventory();
}else{ } else{
$this->addItem($slot); $this->addItem($slot);
$packet->slots[$i] = 255; $packet->slots[$i] = 255;
} }
}elseif($s->getID() !== AIR and $slot->getID() === AIR and ($sl = $this->hasItem($s->getID())) !== false){ } elseif($s->getID() !== AIR and $slot->getID() === AIR and ($sl = $this->hasItem($s->getID())) !== false){
if($this->setArmorSlot($i, $this->getSlot($sl)) === false){ if($this->setArmorSlot($i, $this->getSlot($sl)) === false){
$this->sendArmor(); $this->sendArmor();
$this->sendInventory(); $this->sendInventory();
}else{ } else{
$this->setSlot($sl, BlockAPI::getItem(AIR, 0, 0)); $this->setSlot($sl, BlockAPI::getItem(AIR, 0, 0));
} }
}elseif($s->getID() !== AIR and $slot->getID() !== AIR and ($slot->getID() !== $s->getID() or $slot->getMetadata() !== $s->getMetadata()) and ($sl = $this->hasItem($s->getID())) !== false){ } elseif($s->getID() !== AIR and $slot->getID() !== AIR and ($slot->getID() !== $s->getID() or $slot->getMetadata() !== $s->getMetadata()) and ($sl = $this->hasItem($s->getID())) !== false){
if($this->setArmorSlot($i, $this->getSlot($sl)) === false){ if($this->setArmorSlot($i, $this->getSlot($sl)) === false){
$this->sendArmor(); $this->sendArmor();
$this->sendInventory(); $this->sendInventory();
}else{ } else{
$this->setSlot($sl, $slot); $this->setSlot($sl, $slot);
} }
}else{ } else{
$packet->slots[$i] = 255; $packet->slots[$i] = 255;
} }
@ -1890,12 +1912,12 @@ class Player extends RealHuman{
$message = $packet->message; $message = $packet->message;
if($message{0} === "/"){ //Command if($message{0} === "/"){ //Command
$this->server->api->console->run(substr($message, 1), $this); $this->server->api->console->run(substr($message, 1), $this);
}else{ } else{
$data = array("player" => $this, "message" => $message); $data = array("player" => $this, "message" => $message);
if($this->server->api->handle("player.chat", $data) !== false){ if($this->server->api->handle("player.chat", $data) !== false){
if(isset($data["message"])){ if(isset($data["message"])){
$this->server->api->chat->send($this, $data["message"]); $this->server->api->chat->send($this, $data["message"]);
}else{ } else{
$this->server->api->chat->send($this, $message); $this->server->api->chat->send($this, $message);
} }
} }
@ -1919,7 +1941,7 @@ class Player extends RealHuman{
$pk->case2 = 0; $pk->case2 = 0;
Player::broadcastPacket($this->level->players, $pk); Player::broadcastPacket($this->level->players, $pk);
} }
}elseif($this->windows[$packet->windowid] instanceof Chest){ } elseif($this->windows[$packet->windowid] instanceof Chest){
$pk = new Network\Protocol\TileEventPacket; $pk = new Network\Protocol\TileEventPacket;
$pk->x = $this->windows[$packet->windowid]->x; $pk->x = $this->windows[$packet->windowid]->x;
$pk->y = $this->windows[$packet->windowid]->y; $pk->y = $this->windows[$packet->windowid]->y;
@ -1943,7 +1965,7 @@ class Player extends RealHuman{
if($this->lastCraft <= (microtime(true) - 1)){ if($this->lastCraft <= (microtime(true) - 1)){
if(isset($this->toCraft[-1])){ if(isset($this->toCraft[-1])){
$this->toCraft = array(-1 => $this->toCraft[-1]); $this->toCraft = array(-1 => $this->toCraft[-1]);
}else{ } else{
$this->toCraft = array(); $this->toCraft = array();
} }
$this->craftingItems = array(); $this->craftingItems = array();
@ -1956,14 +1978,14 @@ class Player extends RealHuman{
$use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->getCount() - $packet->item->getCount()); $use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->getCount() - $packet->item->getCount());
$this->craftingItems[$packet->slot] = $use; $this->craftingItems[$packet->slot] = $use;
$craft = true; $craft = true;
}elseif($slot->getCount() <= $packet->item->getCount() and ($slot->getID() === AIR or ($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()))){ //Crafting final } elseif($slot->getCount() <= $packet->item->getCount() and ($slot->getID() === AIR or ($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()))){ //Crafting final
$craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount() - $slot->getCount()); $craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount() - $slot->getCount());
if(count($this->toCraft) === 0){ if(count($this->toCraft) === 0){
$this->toCraft[-1] = 0; $this->toCraft[-1] = 0;
} }
$this->toCraft[$packet->slot] = $craftItem; $this->toCraft[$packet->slot] = $craftItem;
$craft = true; $craft = true;
}elseif(((count($this->toCraft) === 1 and isset($this->toCraft[-1])) or count($this->toCraft) === 0) and $slot->getCount() > 0 and $slot->getID() > AIR and ($slot->getID() !== $packet->item->getID() or $slot->getMetadata() !== $packet->item->getMetadata())){ //Crafting final } elseif(((count($this->toCraft) === 1 and isset($this->toCraft[-1])) or count($this->toCraft) === 0) and $slot->getCount() > 0 and $slot->getID() > AIR and ($slot->getID() !== $packet->item->getID() or $slot->getMetadata() !== $packet->item->getMetadata())){ //Crafting final
$craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount()); $craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
if(count($this->toCraft) === 0){ if(count($this->toCraft) === 0){
$this->toCraft[-1] = 0; $this->toCraft[-1] = 0;
@ -1982,12 +2004,12 @@ class Player extends RealHuman{
if($recipe === false){ if($recipe === false){
$this->sendInventory(); $this->sendInventory();
$this->toCraft = array(); $this->toCraft = array();
}else{ } else{
$this->toCraft = array(-1 => $this->toCraft[-1]); $this->toCraft = array(-1 => $this->toCraft[-1]);
} }
$this->craftingItems = array(); $this->craftingItems = array();
} }
}else{ } else{
$this->toCraft = array(); $this->toCraft = array();
$this->craftingItems = array(); $this->craftingItems = array();
} }
@ -2001,11 +2023,11 @@ class Player extends RealHuman{
$tile = $tiles[0]; $tile = $tiles[0];
$slotn = $packet->slot; $slotn = $packet->slot;
$offset = 0; $offset = 0;
}elseif($packet->slot >= Chest::SLOTS and $packet->slot <= (Chest::SLOTS << 1)){ } elseif($packet->slot >= Chest::SLOTS and $packet->slot <= (Chest::SLOTS << 1)){
$tile = $tiles[1]; $tile = $tiles[1];
$slotn = $packet->slot - Chest::SLOTS; $slotn = $packet->slot - Chest::SLOTS;
$offset = Chest::SLOTS; $offset = Chest::SLOTS;
}else{ } else{
break; break;
} }
@ -2019,7 +2041,8 @@ class Player extends RealHuman{
"slotdata" => $slot, "slotdata" => $slot,
"itemdata" => $item, "itemdata" => $item,
"player" => $this, "player" => $this,
)) === false){ )) === false
){
$pk = new Network\Protocol\ContainerSetSlotPacket; $pk = new Network\Protocol\ContainerSetSlotPacket;
$pk->windowid = $packet->windowid; $pk->windowid = $packet->windowid;
$pk->slot = $packet->slot; $pk->slot = $packet->slot;
@ -2035,12 +2058,12 @@ class Player extends RealHuman{
$this->sendInventory(); $this->sendInventory();
break; break;
} }
}elseif($slot->getCount() > $item->getCount()){ } elseif($slot->getCount() > $item->getCount()){
$it = clone $item; $it = clone $item;
$it->setCount($slot->getCount() - $item->getCount()); $it->setCount($slot->getCount() - $item->getCount());
$this->addItem($it); $this->addItem($it);
} }
}else{ } else{
if($this->removeItem($item) === false){ if($this->removeItem($item) === false){
$this->sendInventory(); $this->sendInventory();
break; break;
@ -2048,7 +2071,7 @@ class Player extends RealHuman{
$this->addItem($slot); $this->addItem($slot);
} }
$tile->setSlot($slotn, $item, true, $offset); $tile->setSlot($slotn, $item, true, $offset);
}else{ } else{
$tile = $this->windows[$packet->windowid]; $tile = $this->windows[$packet->windowid];
if( if(
!($tile instanceof Chest or $tile instanceof Furnace) !($tile instanceof Chest or $tile instanceof Furnace)
@ -2071,7 +2094,8 @@ class Player extends RealHuman{
"slotdata" => $slot, "slotdata" => $slot,
"itemdata" => $item, "itemdata" => $item,
"player" => $this, "player" => $this,
)) === false){ )) === false
){
$pk = new Network\Protocol\ContainerSetSlotPacket; $pk = new Network\Protocol\ContainerSetSlotPacket;
$pk->windowid = $packet->windowid; $pk->windowid = $packet->windowid;
$pk->slot = $packet->slot; $pk->slot = $packet->slot;
@ -2096,12 +2120,12 @@ class Player extends RealHuman{
$this->sendInventory(); $this->sendInventory();
break; break;
} }
}elseif($slot->getCount() > $item->getCount()){ } elseif($slot->getCount() > $item->getCount()){
$it = clone $item; $it = clone $item;
$it->setCount($slot->count - $item->count); $it->setCount($slot->count - $item->count);
$this->addItem($it); $this->addItem($it);
} }
}else{ } else{
if($this->removeItem($item) === false){ if($this->removeItem($item) === false){
$this->sendInventory(); $this->sendInventory();
break; break;
@ -2126,19 +2150,19 @@ class Player extends RealHuman{
if($t instanceof Sign){ if($t instanceof Sign){
if($t->namedtag->creator !== $this->username){ if($t->namedtag->creator !== $this->username){
$t->spawnTo($this); $t->spawnTo($this);
}else{ } else{
$nbt = new NBT(NBT\LITTLE_ENDIAN); $nbt = new NBT(NBT\LITTLE_ENDIAN);
$nbt->read($packet->namedtag); $nbt->read($packet->namedtag);
if($nbt->id !== Tile::SIGN){ if($nbt->id !== Tile::SIGN){
$t->spawnTo($this); $t->spawnTo($this);
}else{ } else{
$t->setText($nbt->Text1, $nbt->Text2, $nbt->Text3, $nbt->Text4); $t->setText($nbt->Text1, $nbt->Text2, $nbt->Text3, $nbt->Text4);
} }
} }
} }
break; break;
default: default:
console("[DEBUG] Unhandled 0x".dechex($packet->pid())." data packet for ".$this->username." (".$this->clientID."): ".print_r($packet, true), true, true, 2); console("[DEBUG] Unhandled 0x" . dechex($packet->pid()) . " data packet for " . $this->username . " (" . $this->clientID . "): " . print_r($packet, true), true, true, 2);
break; break;
} }
} }
@ -2213,6 +2237,7 @@ class Player extends RealHuman{
$this->recoveryQueue[$count] = $rk; $this->recoveryQueue[$count] = $rk;
$this->send($rk); $this->send($rk);
} }
return $cnts; return $cnts;
} }
@ -2234,6 +2259,7 @@ class Player extends RealHuman{
} }
$this->send($pk); $this->send($pk);
return array($pk->seqNumber); return array($pk->seqNumber);
} }
@ -2267,6 +2293,7 @@ class Player extends RealHuman{
$packet->reliability = 2; $packet->reliability = 2;
@$this->buffer->data[] = $packet; @$this->buffer->data[] = $packet;
$this->bufferLen += 6 + $len; $this->bufferLen += 6 + $len;
return array(); return array();
} }

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI; use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Entity\Entity as Entity; use PocketMine\Entity\Entity as Entity;
use PocketMine\Player as Player; use PocketMine\Player as Player;
@ -29,6 +30,7 @@ use PocketMine\Level\Position as Position;
class PlayerAPI{ class PlayerAPI{
private $server; private $server;
function __construct(){ function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
@ -75,14 +77,14 @@ class PlayerAPI{
if($e instanceof Entity){ if($e instanceof Entity){
switch($e->class){ switch($e->class){
case ENTITY_PLAYER: case ENTITY_PLAYER:
$message = " was killed by ".$e->name; $message = " was killed by " . $e->name;
break; break;
default: default:
$message = " was killed"; $message = " was killed";
break; break;
} }
} }
}else{ } else{
switch($data["cause"]){ switch($data["cause"]){
case "cactus": case "cactus":
$message = " was pricked to death"; $message = " was pricked to death";
@ -117,8 +119,10 @@ class PlayerAPI{
} }
} }
$this->server->api->chat->broadcast($data["player"]->getUsername() . $message); $this->server->api->chat->broadcast($data["player"]->getUsername() . $message);
return true; return true;
} }
return;
} }
public function commandHandler($cmd, $params, $issuer, $alias){ public function commandHandler($cmd, $params, $issuer, $alias){
@ -138,10 +142,10 @@ class PlayerAPI{
$tg = array_shift($params); $tg = array_shift($params);
if(count($params) === 3 and substr($tg, 0, 2) === "w:"){ if(count($params) === 3 and substr($tg, 0, 2) === "w:"){
$target = $this->server->api->level->get(substr($tg, 2)); $target = $this->server->api->level->get(substr($tg, 2));
}else{ } else{
$target = Player::get($tg); $target = Player::get($tg);
} }
}else{ } else{
$target = $issuer; $target = $issuer;
} }
@ -153,19 +157,19 @@ class PlayerAPI{
if(count($params) === 3){ if(count($params) === 3){
if($target instanceof Level){ if($target instanceof Level){
$spawn = new Vector3(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params))); $spawn = new Vector3(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)));
}else{ } else{
$spawn = new Position(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)), $issuer->level); $spawn = new Position(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)), $issuer->level);
} }
}else{ } else{
$spawn = new Position($issuer->entity->x, $issuer->entity->y, $issuer->entity->z, $issuer->entity->level); $spawn = new Position($issuer->entity->x, $issuer->entity->y, $issuer->entity->z, $issuer->entity->level);
} }
$target->setSpawn($spawn); $target->setSpawn($spawn);
if($target instanceof Level){ if($target instanceof Level){
$output .= "Spawnpoint of world ".$target->getName()." set correctly!\n"; $output .= "Spawnpoint of world " . $target->getName() . " set correctly!\n";
}elseif($target !== $issuer){ } elseif($target !== $issuer){
$output .= "Spawnpoint of ".$target->getUsername()." set correctly!\n"; $output .= "Spawnpoint of " . $target->getUsername() . " set correctly!\n";
}else{ } else{
$output .= "Spawnpoint set correctly!\n"; $output .= "Spawnpoint set correctly!\n";
} }
break; break;
@ -181,7 +185,7 @@ class PlayerAPI{
$output .= "Please run this command in-game.\n"; $output .= "Please run this command in-game.\n";
break; break;
} }
$output .= "ping ".round($issuer->getLag(), 2)."ms, packet loss ".round($issuer->getPacketLoss() * 100, 2)."%, ".round($issuer->getBandwidth() / 1024, 2)." KB/s\n"; $output .= "ping " . round($issuer->getLag(), 2) . "ms, packet loss " . round($issuer->getPacketLoss() * 100, 2) . "%, " . round($issuer->getBandwidth() / 1024, 2) . " KB/s\n";
break; break;
case "gamemode": case "gamemode":
$player = false; $player = false;
@ -206,14 +210,14 @@ class PlayerAPI{
if(Player::get($params[1]) instanceof Player){ if(Player::get($params[1]) instanceof Player){
$player = Player::get($params[1]); $player = Player::get($params[1]);
$setgm = $params[0]; $setgm = $params[0];
}elseif(Player::get($params[0]) instanceof Player){ } elseif(Player::get($params[0]) instanceof Player){
$player = Player::get($params[0]); $player = Player::get($params[0]);
$setgm = $params[1]; $setgm = $params[1];
}else{ } else{
$output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n"; $output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n";
break; break;
} }
}elseif(isset($params[0])){ } elseif(isset($params[0])){
if(!(Player::get($params[0]) instanceof Player)){ if(!(Player::get($params[0]) instanceof Player)){
if($issuer instanceof Player){ if($issuer instanceof Player){
$setgm = $params[0]; $setgm = $params[0];
@ -227,7 +231,7 @@ class PlayerAPI{
break; break;
} }
if($player->setGamemode($gms[strtolower($setgm)])){ if($player->setGamemode($gms[strtolower($setgm)])){
$output .= "Gamemode of ".$player->getUsername()." changed to ".$player->getGamemode()."\n"; $output .= "Gamemode of " . $player->getUsername() . " changed to " . $player->getGamemode() . "\n";
} }
break; break;
case "tp": case "tp":
@ -235,36 +239,36 @@ class PlayerAPI{
if((!isset($params[1]) or substr($params[0], 0, 2) === "w:") and isset($params[0]) and ($issuer instanceof Player)){ if((!isset($params[1]) or substr($params[0], 0, 2) === "w:") and isset($params[0]) and ($issuer instanceof Player)){
$name = $issuer->getUsername(); $name = $issuer->getUsername();
$target = implode(" ", $params); $target = implode(" ", $params);
}elseif(isset($params[1]) and isset($params[0])){ } elseif(isset($params[1]) and isset($params[0])){
$name = array_shift($params); $name = array_shift($params);
$target = implode(" ", $params); $target = implode(" ", $params);
}else{ } else{
$output .= "Usage: /$cmd [target player] <destination player | w:world>\n"; $output .= "Usage: /$cmd [target player] <destination player | w:world>\n";
break; break;
} }
if($this->teleport($name, $target) !== false){ if($this->teleport($name, $target) !== false){
$output .= "\"$name\" teleported to \"$target\"\n"; $output .= "\"$name\" teleported to \"$target\"\n";
}else{ } else{
$output .= "Couldn't teleport.\n"; $output .= "Couldn't teleport.\n";
} }
}else{ } else{
if(!isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0]) and ($issuer instanceof Player)){ if(!isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0]) and ($issuer instanceof Player)){
$name = $issuer->getUsername(); $name = $issuer->getUsername();
$x = $params[0]; $x = $params[0];
$y = $params[1]; $y = $params[1];
$z = $params[2]; $z = $params[2];
}elseif(isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0])){ } elseif(isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0])){
$name = $params[0]; $name = $params[0];
$x = $params[1]; $x = $params[1];
$y = $params[2]; $y = $params[2];
$z = $params[3]; $z = $params[3];
}else{ } else{
$output .= "Usage: /$cmd [player] <x> <y> <z>\n"; $output .= "Usage: /$cmd [player] <x> <y> <z>\n";
break; break;
} }
if($this->tppos($name, $x, $y, $z)){ if($this->tppos($name, $x, $y, $z)){
$output .= "\"$name\" teleported to ($x, $y, $z)\n"; $output .= "\"$name\" teleported to ($x, $y, $z)\n";
}else{ } else{
$output .= "Couldn't teleport.\n"; $output .= "Couldn't teleport.\n";
} }
} }
@ -273,27 +277,28 @@ class PlayerAPI{
case "suicide": case "suicide":
if(!isset($params[0]) and ($issuer instanceof Player)){ if(!isset($params[0]) and ($issuer instanceof Player)){
$player = $issuer; $player = $issuer;
}else{ } else{
$player = Player::get($params[0]); $player = Player::get($params[0]);
} }
if($player instanceof Player){ if($player instanceof Player){
$player->entity->harm(1000, "console", true); $player->entity->harm(1000, "console", true);
$player->sendChat("Ouch. That looks like it hurt.\n"); $player->sendChat("Ouch. That looks like it hurt.\n");
}else{ } else{
$output .= "Usage: /$cmd [player]\n"; $output .= "Usage: /$cmd [player]\n";
} }
break; break;
case "list": case "list":
$output .= "There are ".count(Player::$list)."/".$this->server->maxClients." players online:\n"; $output .= "There are " . count(Player::$list) . "/" . $this->server->maxClients . " players online:\n";
if(count(Player::$list) == 0){ if(count(Player::$list) == 0){
break; break;
} }
foreach(Player::$list as $c){ foreach(Player::$list as $c){
$output .= $c->getUsername().", "; $output .= $c->getUsername() . ", ";
} }
$output = substr($output, 0, -2)."\n"; $output = substr($output, 0, -2) . "\n";
break; break;
} }
return $output; return $output;
} }
@ -304,9 +309,10 @@ class PlayerAPI{
$origin = Player::get($name); $origin = Player::get($name);
if($origin instanceof Player){ if($origin instanceof Player){
$name = $origin->getUsername(); $name = $origin->getUsername();
return $origin->teleport($lv->getSafeSpawn()); return $origin->teleport($lv->getSafeSpawn());
} }
}else{ } else{
return false; return false;
} }
} }
@ -316,9 +322,11 @@ class PlayerAPI{
$origin = Player::get($name); $origin = Player::get($name);
if($origin instanceof Player){ if($origin instanceof Player){
$name = $origin->getUsername(); $name = $origin->getUsername();
return $origin->teleport($player->entity); return $origin->teleport($player->entity);
} }
} }
return false; return false;
} }
@ -326,12 +334,14 @@ class PlayerAPI{
$player = Player::get($name); $player = Player::get($name);
if($player instanceof Player and $player->spawned === true){ if($player instanceof Player and $player->spawned === true){
$name = $player->getUsername(); $name = $player->getUsername();
$x = $x{0} === "~" ? $player->entity->x + floatval(substr($x, 1)):floatval($x); $x = $x{0} === "~" ? $player->entity->x + floatval(substr($x, 1)) : floatval($x);
$y = $y{0} === "~" ? $player->entity->y + floatval(substr($y, 1)):floatval($y); $y = $y{0} === "~" ? $player->entity->y + floatval(substr($y, 1)) : floatval($y);
$z = $z{0} === "~" ? $player->entity->z + floatval(substr($z, 1)):floatval($z); $z = $z{0} === "~" ? $player->entity->z + floatval(substr($z, 1)) : floatval($z);
$player->teleport(new Vector3($x, $y, $z)); $player->teleport(new Vector3($x, $y, $z));
return true; return true;
} }
return false; return false;
} }
} }

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI; use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Utils\Utils as Utils; use PocketMine\Utils\Utils as Utils;
use PocketMine\Network\Protocol\Info as Info; use PocketMine\Network\Protocol\Info as Info;
@ -31,6 +32,7 @@ class PluginAPI extends \stdClass{
private $server; private $server;
private $plugins = array(); private $plugins = array();
private $randomNonce; private $randomNonce;
public function __construct(){ public function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->randomNonce = Utils::getRandomBytes(16, false); $this->randomNonce = Utils::getRandomBytes(16, false);
@ -45,18 +47,19 @@ class PluginAPI extends \stdClass{
case "plugins": case "plugins":
$output = "Plugins: "; $output = "Plugins: ";
foreach($this->getList() as $plugin){ foreach($this->getList() as $plugin){
$output .= $plugin["name"] . ": ".$plugin["version"] .", "; $output .= $plugin["name"] . ": " . $plugin["version"] . ", ";
} }
$output = $output === "Plugins: " ? "No plugins installed.\n" : substr($output, 0, -2)."\n"; $output = $output === "Plugins: " ? "No plugins installed.\n" : substr($output, 0, -2) . "\n";
break; break;
case "version": case "version":
$output = "PocketMine-MP ".VERSION."".CODENAME."」 API #".API_VERSION." for Minecraft: PE ".MINECRAFT_VERSION." protocol #".Info::CURRENT_PROTOCOL; $output = "PocketMine-MP " . VERSION . "" . CODENAME . "」 API #" . API_VERSION . " for Minecraft: PE " . MINECRAFT_VERSION . " protocol #" . Info::CURRENT_PROTOCOL;
if(GIT_COMMIT !== str_repeat("00", 20)){ if(GIT_COMMIT !== str_repeat("00", 20)){
$output .= " (git ".GIT_COMMIT.")"; $output .= " (git " . GIT_COMMIT . ")";
} }
$output .= "\n"; $output .= "\n";
break; break;
} }
return $output; return $output;
} }
@ -72,6 +75,7 @@ class PluginAPI extends \stdClass{
foreach($this->plugins as $p){ foreach($this->plugins as $p){
$list[] = $p[1]; $list[] = $p[1];
} }
return $list; return $list;
} }
@ -81,18 +85,20 @@ class PluginAPI extends \stdClass{
public function load($file){ public function load($file){
if(is_link($file) or is_dir($file) or !file_exists($file)){ if(is_link($file) or is_dir($file) or !file_exists($file)){
console("[ERROR] ".basename($file)." is not a file"); console("[ERROR] " . basename($file) . " is not a file");
return false; return false;
} }
if(strtolower(substr($file, -3)) === "pmf"){ if(strtolower(substr($file, -3)) === "pmf"){
$pmf = new PMFPlugin($file); $pmf = new PMFPlugin($file);
$info = $pmf->getPluginInfo(); $info = $pmf->getPluginInfo();
}else{ } else{
$content = file_get_contents($file); $content = file_get_contents($file);
$info = strstr($content, "*/", true); $info = strstr($content, "*/", true);
$content = str_repeat(PHP_EOL, substr_count($info, "\n")).substr(strstr($content, "*/"),2); $content = str_repeat(PHP_EOL, substr_count($info, "\n")) . substr(strstr($content, "*/"), 2);
if(preg_match_all('#([a-zA-Z0-9\-_]*)=([^\r\n]*)#u', $info, $matches) == 0){ //false or 0 matches if(preg_match_all('#([a-zA-Z0-9\-_]*)=([^\r\n]*)#u', $info, $matches) == 0){ //false or 0 matches
console("[ERROR] Failed parsing of ".basename($file)); console("[ERROR] Failed parsing of " . basename($file));
return false; return false;
} }
$info = array(); $info = array();
@ -116,23 +122,26 @@ class PluginAPI extends \stdClass{
$info["class"] = trim(strtolower($info["class"])); $info["class"] = trim(strtolower($info["class"]));
} }
if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"]) or !isset($info["author"])){ if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"]) or !isset($info["author"])){
console("[ERROR] Failed parsing of ".basename($file)); console("[ERROR] Failed parsing of " . basename($file));
return false; return false;
} }
console("[INFO] Loading plugin \"".TextFormat::GREEN.$info["name"].TextFormat::RESET."\" ".TextFormat::AQUA.$info["version"].TextFormat::RESET." by ".TextFormat::AQUA.$info["author"].TextFormat::RESET); console("[INFO] Loading plugin \"" . TextFormat::GREEN . $info["name"] . TextFormat::RESET . "\" " . TextFormat::AQUA . $info["version"] . TextFormat::RESET . " by " . TextFormat::AQUA . $info["author"] . TextFormat::RESET);
if($info["class"] !== "none" and class_exists($info["class"])){ if($info["class"] !== "none" and class_exists($info["class"])){
console("[ERROR] Failed loading plugin: class already exists"); console("[ERROR] Failed loading plugin: class already exists");
return false; return false;
} }
if(((!isset($pmf) and (include $file) === false) or (isset($pmf) and eval($info["code"]) === false)) and $info["class"] !== "none" and !class_exists($info["class"])){ if(((!isset($pmf) and (include $file) === false) or (isset($pmf) and eval($info["code"]) === false)) and $info["class"] !== "none" and !class_exists($info["class"])){
console("[ERROR] Failed loading {$info['name']}: evaluation error"); console("[ERROR] Failed loading {$info['name']}: evaluation error");
return false; return false;
} }
$className = $info["class"]; $className = $info["class"];
$apiversion = array_map("intval", explode(",", (string) $info["apiversion"])); $apiversion = array_map("intval", explode(",", (string) $info["apiversion"]));
if(!in_array(API_VERSION, $apiversion)){ if(!in_array(API_VERSION, $apiversion)){
console("[WARNING] Plugin \"".$info["name"]."\" may not be compatible with the API (".$info["apiversion"]." != ".API_VERSION.")! It can crash or corrupt the server!"); console("[WARNING] Plugin \"" . $info["name"] . "\" may not be compatible with the API (" . $info["apiversion"] . " != " . API_VERSION . ")! It can crash or corrupt the server!");
} }
$identifier = $this->getIdentifier($info["name"], $info["author"]); $identifier = $this->getIdentifier($info["name"], $info["author"]);
@ -140,18 +149,19 @@ class PluginAPI extends \stdClass{
if($info["class"] !== "none"){ if($info["class"] !== "none"){
$object = new $className($this->server->api, false); $object = new $className($this->server->api, false);
if(!($object instanceof Plugin)){ if(!($object instanceof Plugin)){
console("[ERROR] Plugin \"".$info["name"]."\" doesn't use the Plugin Interface"); console("[ERROR] Plugin \"" . $info["name"] . "\" doesn't use the Plugin Interface");
if(method_exists($object, "__destruct")){ if(method_exists($object, "__destruct")){
$object->__destruct(); $object->__destruct();
} }
$object = null; $object = null;
unset($object); unset($object);
}else{ } else{
$this->plugins[$identifier] = array($object, $info); $this->plugins[$identifier] = array($object, $info);
} }
}else{ } else{
$this->plugins[$identifier] = array(new DummyPlugin($this->server->api, false), $info); $this->plugins[$identifier] = array(new DummyPlugin($this->server->api, false), $info);
} }
return true; return true;
} }
@ -166,17 +176,20 @@ class PluginAPI extends \stdClass{
return $p; return $p;
} }
} }
return false; return false;
} }
if(isset($this->plugins[$identifier])){ if(isset($this->plugins[$identifier])){
return $this->plugins[$identifier]; return $this->plugins[$identifier];
} }
return false; return false;
} }
public function pluginsPath(){ public function pluginsPath(){
$path = join(DIRECTORY_SEPARATOR, array(\PocketMine\DATA."plugins", "")); $path = join(DIRECTORY_SEPARATOR, array(\PocketMine\DATA . "plugins", ""));
@mkdir($path); @mkdir($path);
return $path; return $path;
} }
@ -190,6 +203,7 @@ class PluginAPI extends \stdClass{
$path = $this->pluginsPath() . $p[1]["name"] . DIRECTORY_SEPARATOR; $path = $this->pluginsPath() . $p[1]["name"] . DIRECTORY_SEPARATOR;
$this->plugins[$identifier][1]["path"] = $path; $this->plugins[$identifier][1]["path"] = $path;
@mkdir($path); @mkdir($path);
return $path; return $path;
} }
@ -199,8 +213,9 @@ class PluginAPI extends \stdClass{
return false; return false;
} }
$path = $this->configPath($plugin); $path = $this->configPath($plugin);
$cnf = new Config($path."config.yml", Config::YAML, $default); $cnf = new Config($path . "config.yml", Config::YAML, $default);
$cnf->save(); $cnf->save();
return $path; return $path;
} }
@ -240,7 +255,9 @@ class PluginAPI extends \stdClass{
interface Plugin{ interface Plugin{
public function __construct(ServerAPI $api, $server = false); public function __construct(ServerAPI $api, $server = false);
public function init(); public function init();
public function __destruct(); public function __destruct();
} }

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\Utils\VersionString as VersionString; use PocketMine\Utils\VersionString as VersionString;
use PocketMine\Utils\Utils as Utils; use PocketMine\Utils\Utils as Utils;
use PocketMine\Network\Handler as Handler; use PocketMine\Network\Handler as Handler;
@ -44,12 +45,12 @@ class Server{
private function load(){ private function load(){
$this->version = new VersionString(); $this->version = new VersionString();
if(defined("DEBUG") and DEBUG >= 0){ if(defined("DEBUG") and DEBUG >= 0){
@cli_set_process_title("PocketMine-MP ".MAJOR_VERSION); @cli_set_process_title("PocketMine-MP " . MAJOR_VERSION);
} }
console("[INFO] Starting Minecraft PE server on ".($this->serverip === "0.0.0.0" ? "*":$this->serverip).":".$this->port); console("[INFO] Starting Minecraft PE server on " . ($this->serverip === "0.0.0.0" ? "*" : $this->serverip) . ":" . $this->port);
define("BOOTUP_RANDOM", Utils::getRandomBytes(16)); 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->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->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : $this->seed;
$this->startDatabase(); $this->startDatabase();
$this->api = false; $this->api = false;
$this->tCnt = 1; $this->tCnt = 1;
@ -85,7 +86,7 @@ class Server{
$this->doTick = true; $this->doTick = true;
$this->gamemode = (int) $gamemode; $this->gamemode = (int) $gamemode;
$this->name = $name; $this->name = $name;
$this->motd = "Welcome to ".$name; $this->motd = "Welcome to " . $name;
$this->serverID = false; $this->serverID = false;
$this->seed = $seed; $this->seed = $seed;
$this->serverip = $serverip; $this->serverip = $serverip;
@ -98,13 +99,14 @@ class Server{
public function getTPS(){ public function getTPS(){
$v = array_values($this->tickMeasure); $v = array_values($this->tickMeasure);
$tps = 40 / ($v[39] - $v[0]); $tps = 40 / ($v[39] - $v[0]);
return round($tps, 4); return round($tps, 4);
} }
public function titleTick(){ public function titleTick(){
$time = microtime(true); $time = microtime(true);
if(defined("DEBUG") and DEBUG >= 0 and ANSI === true){ if(defined("DEBUG") and DEBUG >= 0 and ANSI === true){
echo "\x1b]0;PocketMine-MP ".VERSION." | Online ". count(Player::$list)."/".$this->maxClients." | RAM ".round((memory_get_usage() / 1024) / 1024, 2)."MB | U ".round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2)." D ".round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2)." kB/s | TPS ".$this->getTPS()."\x07"; echo "\x1b]0;PocketMine-MP " . VERSION . " | Online " . count(Player::$list) . "/" . $this->maxClients . " | RAM " . round((memory_get_usage() / 1024) / 1024, 2) . "MB | U " . round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " D " . round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " kB/s | TPS " . $this->getTPS() . "\x07";
} }
$this->interface->bandwidth = array(0, 0, $time); $this->interface->bandwidth = array(0, 0, $time);
} }
@ -127,7 +129,7 @@ class Server{
public function checkMemory(){ public function checkMemory(){
$info = $this->debugInfo(); $info = $this->debugInfo();
$data = $info["memory_usage"].",".$info["players"].",".$info["entities"]; $data = $info["memory_usage"] . "," . $info["players"] . "," . $info["entities"];
$i = count($this->memoryStats) - 1; $i = count($this->memoryStats) - 1;
if($i < 0 or $this->memoryStats[$i] !== $data){ if($i < 0 or $this->memoryStats[$i] !== $data){
$this->memoryStats[] = $data; $this->memoryStats[] = $data;
@ -152,18 +154,19 @@ class Server{
} }
public function query($sql, $fetch = false){ public function query($sql, $fetch = false){
$result = $this->database->query($sql) or console("[ERROR] [SQL Error] ".$this->database->lastErrorMsg().". Query: ".$sql, true, true, 0); $result = $this->database->query($sql) or console("[ERROR] [SQL Error] " . $this->database->lastErrorMsg() . ". Query: " . $sql, true, true, 0);
if($fetch === true and ($result instanceof \SQLite3Result)){ if($fetch === true and ($result instanceof \SQLite3Result)){
$result = $result->fetchArray(SQLITE3_ASSOC); $result = $result->fetchArray(SQLITE3_ASSOC);
} }
return $result; return $result;
} }
public function debugInfo($console = false){ public function debugInfo($console = false){
$info = array(); $info = array();
$info["tps"] = $this->getTPS(); $info["tps"] = $this->getTPS();
$info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2)."MB"; $info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2) . "MB";
$info["memory_peak_usage"] = round((memory_get_peak_usage() / 1024) / 1024, 2)."MB"; $info["memory_peak_usage"] = round((memory_get_peak_usage() / 1024) / 1024, 2) . "MB";
$info["entities"] = count(Entity::$list); $info["entities"] = count(Entity::$list);
$info["players"] = count(Player::$list); $info["players"] = count(Player::$list);
$info["events"] = count($this->eventsID); $info["events"] = count($this->eventsID);
@ -174,8 +177,9 @@ class Server{
$info["garbage"] = gc_collect_cycles(); $info["garbage"] = gc_collect_cycles();
$this->handle("server.debug", $info); $this->handle("server.debug", $info);
if($console === true){ if($console === true){
console("[DEBUG] TPS: ".$info["tps"].", Memory usage: ".$info["memory_usage"]." (Peak ".$info["memory_peak_usage"]."), Entities: ".$info["entities"].", Events: ".$info["events"].", Handlers: ".$info["handlers"].", Actions: ".$info["actions"].", Garbage: ".$info["garbage"], true, true, 2); console("[DEBUG] TPS: " . $info["tps"] . ", Memory usage: " . $info["memory_usage"] . " (Peak " . $info["memory_peak_usage"] . "), Entities: " . $info["entities"] . ", Events: " . $info["events"] . ", Handlers: " . $info["handlers"] . ", Actions: " . $info["actions"] . ", Garbage: " . $info["garbage"], true, true, 2);
} }
return $info; return $info;
} }
@ -223,25 +227,26 @@ class Server{
$type = (int) $type; $type = (int) $type;
switch($type){ switch($type){
case ASYNC_CURL_GET: case ASYNC_CURL_GET:
$d .= Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10)); $d .= Utils::writeShort(strlen($data["url"])) . $data["url"] . (isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
break; break;
case ASYNC_CURL_POST: case ASYNC_CURL_POST:
$d .= Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10)); $d .= Utils::writeShort(strlen($data["url"])) . $data["url"] . (isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
$d .= Utils::writeShort(count($data["data"])); $d .= Utils::writeShort(count($data["data"]));
foreach($data["data"] as $key => $value){ foreach($data["data"] as $key => $value){
$d .= Utils::writeShort(strlen($key)).$key . Utils::writeInt(strlen($value)).$value; $d .= Utils::writeShort(strlen($key)) . $key . Utils::writeInt(strlen($value)) . $value;
} }
break; break;
case ASYNC_FUNCTION: case ASYNC_FUNCTION:
$params = serialize($data["arguments"]); $params = serialize($data["arguments"]);
$d .= Utils::writeShort(strlen($data["function"])).$data["function"] . Utils::writeInt(strlen($params)) . $params; $d .= Utils::writeShort(strlen($data["function"])) . $data["function"] . Utils::writeInt(strlen($params)) . $params;
break; break;
default: default:
return false; return false;
} }
$ID = $this->asyncID++; $ID = $this->asyncID++;
$this->async[$ID] = $callable; $this->async[$ID] = $callable;
$this->asyncThread->input .= Utils::writeInt($ID).Utils::writeShort($type).$d; $this->asyncThread->input .= Utils::writeInt($ID) . Utils::writeShort($type) . $d;
return $ID; return $ID;
} }
@ -276,7 +281,7 @@ class Server{
if(is_array($this->async[$ID])){ if(is_array($this->async[$ID])){
$method = $this->async[$ID][1]; $method = $this->async[$ID][1];
$result = $this->async[$ID][0]->$method($data, $type, $ID); $result = $this->async[$ID][0]->$method($data, $type, $ID);
}else{ } else{
$result = $this->async[$ID]($data, $type, $ID); $result = $this->async[$ID]($data, $type, $ID);
} }
} }
@ -291,21 +296,22 @@ class Server{
* *
* @return boolean * @return boolean
*/ */
public function addHandler($event,callable $callable, $priority = 5){ public function addHandler($event, callable $callable, $priority = 5){
if(!is_callable($callable)){ if(!is_callable($callable)){
return false; return false;
}elseif(isset(Deprecation::$events[$event])){ } elseif(isset(Deprecation::$events[$event])){
$sub = ""; $sub = "";
if(Deprecation::$events[$event] !== false){ if(Deprecation::$events[$event] !== false){
$sub = " Substitute \"".Deprecation::$events[$event]."\" found."; $sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
} }
console("[ERROR] Event \"$event\" has been deprecated.$sub [Adding handle to ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)."]"); console("[ERROR] Event \"$event\" has been deprecated.$sub [Adding handle to " . (is_array($callable) ? get_class($callable[0]) . "::" . $callable[1] : $callable) . "]");
} }
$priority = (int) $priority; $priority = (int) $priority;
$hnid = $this->handCnt++; $hnid = $this->handCnt++;
$this->handlers[$hnid] = $callable; $this->handlers[$hnid] = $callable;
$this->query("INSERT INTO handlers (ID, name, priority) VALUES (".$hnid.", '".str_replace("'", "\\'", $event)."', ".$priority.");"); $this->query("INSERT INTO handlers (ID, name, priority) VALUES (" . $hnid . ", '" . str_replace("'", "\\'", $event) . "', " . $priority . ");");
console("[INTERNAL] New handler ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)." to special event ".$event." (ID ".$hnid.")", true, true, 3); console("[INTERNAL] New handler " . (is_array($callable) ? get_class($callable[0]) . "::" . $callable[1] : $callable) . " to special event " . $event . " (ID " . $hnid . ")", true, true, 3);
return $hnid; return $hnid;
} }
@ -331,17 +337,17 @@ class Server{
if(is_array($handler)){ if(is_array($handler)){
$method = $handler[1]; $method = $handler[1];
$result = $handler[0]->$method($data, $event); $result = $handler[0]->$method($data, $event);
}else{ } else{
$result = $handler($data, $event); $result = $handler($data, $event);
} }
}else{ } else{
break; break;
} }
} }
}elseif(isset(Deprecation::$events[$event])){ } elseif(isset(Deprecation::$events[$event])){
$sub = ""; $sub = "";
if(Deprecation::$events[$event] !== false){ if(Deprecation::$events[$event] !== false){
$sub = " Substitute \"".Deprecation::$events[$event]."\" found."; $sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
} }
console("[ERROR] Event \"$event\" has been deprecated.$sub [Handler]"); console("[ERROR] Event \"$event\" has been deprecated.$sub [Handler]");
} }
@ -349,6 +355,7 @@ class Server{
if($result !== false){ if($result !== false){
$this->trigger($event, $data); $this->trigger($event, $data);
} }
return $result; return $result;
} }
@ -375,10 +382,9 @@ class Server{
} }
public function init(){ public function init(){
register_tick_function(array($this, "tick")); register_tick_function(array($this, "tick"));
declare(ticks=5000); //Minimum TPS for main thread locks declare(ticks = 5000); //Minimum TPS for main thread locks
$this->loadEvents(); $this->loadEvents();
register_shutdown_function(array($this, "dumpError")); register_shutdown_function(array($this, "dumpError"));
@ -388,9 +394,9 @@ class Server{
pcntl_signal(SIGINT, array($this, "close")); pcntl_signal(SIGINT, array($this, "close"));
pcntl_signal(SIGHUP, array($this, "close")); pcntl_signal(SIGHUP, array($this, "close"));
} }
console("[INFO] Default game type: ".strtoupper($this->getGamemode())); console("[INFO] Default game type: " . strtoupper($this->getGamemode()));
$this->trigger("server.start", microtime(true)); $this->trigger("server.start", microtime(true));
console('[INFO] Done ('.round(microtime(true) - START_TIME, 3).'s)! For help, type "help" or "?"'); console('[INFO] Done (' . round(microtime(true) - START_TIME, 3) . 's)! For help, type "help" or "?"');
$this->process(); $this->process();
} }
@ -400,7 +406,7 @@ class Server{
} }
ini_set("memory_limit", "-1"); //Fix error dump not dumped on memory problems ini_set("memory_limit", "-1"); //Fix error dump not dumped on memory problems
console("[SEVERE] An unrecovereable has ocurred and the server has crashed. Creating an error dump"); console("[SEVERE] An unrecovereable has ocurred and the server has crashed. Creating an error dump");
$dump = "```\r\n# PocketMine-MP Error Dump ".date("D M j H:i:s T Y")."\r\n"; $dump = "```\r\n# PocketMine-MP Error Dump " . date("D M j H:i:s T Y") . "\r\n";
$er = error_get_last(); $er = error_get_last();
$errorConversion = array( $errorConversion = array(
E_ERROR => "E_ERROR", E_ERROR => "E_ERROR",
@ -419,8 +425,8 @@ class Server{
E_DEPRECATED => "E_DEPRECATED", E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED",
); );
$er["type"] = isset($errorConversion[$er["type"]]) ? $errorConversion[$er["type"]]:$er["type"]; $er["type"] = isset($errorConversion[$er["type"]]) ? $errorConversion[$er["type"]] : $er["type"];
$dump .= "Error: ".var_export($er, true)."\r\n\r\n"; $dump .= "Error: " . var_export($er, true) . "\r\n\r\n";
if(stripos($er["file"], "plugin") !== false){ if(stripos($er["file"], "plugin") !== false){
$dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n"; $dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n";
} }
@ -428,7 +434,7 @@ class Server{
$dump .= "Code: \r\n"; $dump .= "Code: \r\n";
$file = @file($er["file"], FILE_IGNORE_NEW_LINES); $file = @file($er["file"], FILE_IGNORE_NEW_LINES);
for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l){ for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l){
$dump .= "[".($l + 1)."] ".@$file[$l]."\r\n"; $dump .= "[" . ($l + 1) . "] " . @$file[$l] . "\r\n";
} }
$dump .= "\r\n\r\n"; $dump .= "\r\n\r\n";
$dump .= "Backtrace: \r\n"; $dump .= "Backtrace: \r\n";
@ -437,25 +443,25 @@ class Server{
} }
$dump .= "\r\n\r\n"; $dump .= "\r\n\r\n";
$version = new VersionString(); $version = new VersionString();
$dump .= "PocketMine-MP version: ".$version." #".$version->getNumber()." [Protocol ".Info::CURRENT_PROTOCOL."; API ".API_VERSION."]\r\n"; $dump .= "PocketMine-MP version: " . $version . " #" . $version->getNumber() . " [Protocol " . Info::CURRENT_PROTOCOL . "; API " . API_VERSION . "]\r\n";
$dump .= "Git commit: ".GIT_COMMIT."\r\n"; $dump .= "Git commit: " . GIT_COMMIT . "\r\n";
$dump .= "uname -a: ".php_uname("a")."\r\n"; $dump .= "uname -a: " . php_uname("a") . "\r\n";
$dump .= "PHP Version: " .phpversion()."\r\n"; $dump .= "PHP Version: " . phpversion() . "\r\n";
$dump .= "Zend version: ".zend_version()."\r\n"; $dump .= "Zend version: " . zend_version() . "\r\n";
$dump .= "OS : " .PHP_OS.", ".Utils::getOS()."\r\n"; $dump .= "OS : " . PHP_OS . ", " . Utils::getOS() . "\r\n";
$dump .= "Debug Info: ".var_export($this->debugInfo(false), true)."\r\n\r\n\r\n"; $dump .= "Debug Info: " . var_export($this->debugInfo(false), true) . "\r\n\r\n\r\n";
global $arguments; global $arguments;
$dump .= "Parameters: ".var_export($arguments, true)."\r\n\r\n\r\n"; $dump .= "Parameters: " . var_export($arguments, true) . "\r\n\r\n\r\n";
$p = $this->api->getProperties(); $p = $this->api->getProperties();
if($p["rcon.password"] != ""){ if($p["rcon.password"] != ""){
$p["rcon.password"] = "******"; $p["rcon.password"] = "******";
} }
$dump .= "server.properties: ".var_export($p, true)."\r\n\r\n\r\n"; $dump .= "server.properties: " . var_export($p, true) . "\r\n\r\n\r\n";
if($this->api->plugin instanceof PluginAPI){ if($this->api->plugin instanceof PluginAPI){
$plist = $this->api->plugin->getList(); $plist = $this->api->plugin->getList();
$dump .= "Loaded plugins:\r\n"; $dump .= "Loaded plugins:\r\n";
foreach($plist as $p){ foreach($plist as $p){
$dump .= $p["name"]." ".$p["version"]." by ".$p["author"]."\r\n"; $dump .= $p["name"] . " " . $p["version"] . " by " . $p["author"] . "\r\n";
} }
$dump .= "\r\n\r\n"; $dump .= "\r\n\r\n";
} }
@ -465,15 +471,15 @@ class Server{
$extensions[$ext] = phpversion($ext); $extensions[$ext] = phpversion($ext);
} }
$dump .= "Loaded Modules: ".var_export($extensions, true)."\r\n"; $dump .= "Loaded Modules: " . var_export($extensions, true) . "\r\n";
$this->checkMemory(); $this->checkMemory();
$dump .= "Memory Usage Tracking: \r\n".chunk_split(base64_encode(gzdeflate(implode(";", $this->memoryStats), 9)))."\r\n"; $dump .= "Memory Usage Tracking: \r\n" . chunk_split(base64_encode(gzdeflate(implode(";", $this->memoryStats), 9))) . "\r\n";
ob_start(); ob_start();
phpinfo(); phpinfo();
$dump .= "\r\nphpinfo(): \r\n".chunk_split(base64_encode(gzdeflate(ob_get_contents(), 9)))."\r\n"; $dump .= "\r\nphpinfo(): \r\n" . chunk_split(base64_encode(gzdeflate(ob_get_contents(), 9))) . "\r\n";
ob_end_clean(); ob_end_clean();
$dump .= "\r\n```"; $dump .= "\r\n```";
$name = "Error_Dump_".date("D_M_j-H.i.s-T_Y"); $name = "Error_Dump_" . date("D_M_j-H.i.s-T_Y");
logg($dump, $name, true, 0, true); logg($dump, $name, true, 0, true);
console("[SEVERE] Please submit the \"{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0); console("[SEVERE] Please submit the \"{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0);
} }
@ -484,8 +490,10 @@ class Server{
$this->tickMeasure[] = $this->lastTick = $time; $this->tickMeasure[] = $this->lastTick = $time;
unset($this->tickMeasure[key($this->tickMeasure)]); unset($this->tickMeasure[key($this->tickMeasure)]);
++$this->ticks; ++$this->ticks;
return $this->tickerFunction($time); return $this->tickerFunction($time);
} }
return 0; return 0;
} }
@ -499,7 +507,7 @@ class Server{
$CID = Server::clientID($packet->ip, $packet->port); $CID = Server::clientID($packet->ip, $packet->port);
if(isset(Player::$list[$CID])){ if(isset(Player::$list[$CID])){
Player::$list[$CID]->handlePacket($packet); Player::$list[$CID]->handlePacket($packet);
}else{ } else{
switch($packet->pid()){ switch($packet->pid()){
case RakNetInfo::UNCONNECTED_PING: case RakNetInfo::UNCONNECTED_PING:
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS: case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
@ -513,33 +521,33 @@ class Server{
$this->send($pk); $this->send($pk);
break; break;
} }
if(!isset($this->custom["times_".$CID])){ if(!isset($this->custom["times_" . $CID])){
$this->custom["times_".$CID] = 0; $this->custom["times_" . $CID] = 0;
} }
$ln = 15; $ln = 15;
if($this->description == "" or substr($this->description, -1) != " "){ if($this->description == "" or substr($this->description, -1) != " "){
$this->description .= " "; $this->description .= " ";
} }
$txt = substr($this->description, $this->custom["times_".$CID], $ln); $txt = substr($this->description, $this->custom["times_" . $CID], $ln);
$txt .= substr($this->description, 0, $ln - strlen($txt)); $txt .= substr($this->description, 0, $ln - strlen($txt));
$pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG); $pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
$pk->pingID = $packet->pingID; $pk->pingID = $packet->pingID;
$pk->serverID = $this->serverID; $pk->serverID = $this->serverID;
$pk->serverType = $this->serverType . $this->name . " [".count(Player::$list)."/".$this->maxClients."] ".$txt; $pk->serverType = $this->serverType . $this->name . " [" . count(Player::$list) . "/" . $this->maxClients . "] " . $txt;
$pk->ip = $packet->ip; $pk->ip = $packet->ip;
$pk->port = $packet->port; $pk->port = $packet->port;
$this->send($pk); $this->send($pk);
$this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description); $this->custom["times_" . $CID] = ($this->custom["times_" . $CID] + 1) % strlen($this->description);
break; break;
case RakNetInfo::OPEN_CONNECTION_REQUEST_1: case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
if($packet->structure !== RakNetInfo::STRUCTURE){ if($packet->structure !== RakNetInfo::STRUCTURE){
console("[DEBUG] Incorrect structure #".$packet->structure." from ".$packet->ip.":".$packet->port, true, true, 2); console("[DEBUG] Incorrect structure #" . $packet->structure . " from " . $packet->ip . ":" . $packet->port, true, true, 2);
$pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION); $pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION);
$pk->serverID = $this->serverID; $pk->serverID = $this->serverID;
$pk->ip = $packet->ip; $pk->ip = $packet->ip;
$pk->port = $packet->port; $pk->port = $packet->port;
$this->send($pk); $this->send($pk);
}else{ } else{
$pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1); $pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1);
$pk->serverID = $this->serverID; $pk->serverID = $this->serverID;
$pk->mtuSize = strlen($packet->buffer); $pk->mtuSize = strlen($packet->buffer);
@ -580,15 +588,15 @@ class Server{
} }
if($this->tick() > 0){ if($this->tick() > 0){
$lastLoop = 0; $lastLoop = 0;
}else{ } else{
++$lastLoop; ++$lastLoop;
if($lastLoop < 64){ if($lastLoop < 64){
}elseif($lastLoop < 256){ } elseif($lastLoop < 256){
usleep(100); usleep(100);
}elseif($lastLoop < 512){ } elseif($lastLoop < 512){
usleep(512); usleep(512);
}else{ } else{
usleep(5000); usleep(5000);
} }
} }
@ -605,14 +613,14 @@ class Server{
if(is_array($ev)){ if(is_array($ev)){
$method = $ev[1]; $method = $ev[1];
$ev[0]->$method($data, $event); $ev[0]->$method($data, $event);
}else{ } else{
$ev($data, $event); $ev($data, $event);
} }
} }
}elseif(isset(Deprecation::$events[$event])){ } elseif(isset(Deprecation::$events[$event])){
$sub = ""; $sub = "";
if(Deprecation::$events[$event] !== false){ if(Deprecation::$events[$event] !== false){
$sub = " Substitute \"".Deprecation::$events[$event]."\" found."; $sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
} }
console("[ERROR] Event \"$event\" has been deprecated.$sub [Trigger]"); console("[ERROR] Event \"$event\" has been deprecated.$sub [Trigger]");
} }
@ -624,7 +632,8 @@ class Server{
} }
$chcnt = $this->scheduleCnt++; $chcnt = $this->scheduleCnt++;
$this->schedule[$chcnt] = array($callback, $data, $eventName); $this->schedule[$chcnt] = array($callback, $data, $eventName);
$this->query("INSERT INTO actions (ID, interval, last, repeat) VALUES(".$chcnt.", ".($ticks / 20).", ".microtime(true).", ".(((bool) $repeat) === true ? 1:0).");"); $this->query("INSERT INTO actions (ID, interval, last, repeat) VALUES(" . $chcnt . ", " . ($ticks / 20) . ", " . microtime(true) . ", " . (((bool) $repeat) === true ? 1 : 0) . ");");
return $chcnt; return $chcnt;
} }
@ -644,31 +653,32 @@ class Server{
$this->preparedSQL->updateAction->execute(); $this->preparedSQL->updateAction->execute();
if(!@is_callable($this->schedule[$cid][0])){ if(!@is_callable($this->schedule[$cid][0])){
$return = false; $return = false;
}else{ } else{
++$actionCount; ++$actionCount;
$return = call_user_func($this->schedule[$cid][0], $this->schedule[$cid][1], $this->schedule[$cid][2]); $return = call_user_func($this->schedule[$cid][0], $this->schedule[$cid][1], $this->schedule[$cid][2]);
} }
if($action["repeat"] == 0 or $return === false){ if($action["repeat"] == 0 or $return === false){
$this->query("DELETE FROM actions WHERE ID = ".$action["ID"].";"); $this->query("DELETE FROM actions WHERE ID = " . $action["ID"] . ";");
$this->schedule[$cid] = null; $this->schedule[$cid] = null;
unset($this->schedule[$cid]); unset($this->schedule[$cid]);
} }
} }
$actions->finalize(); $actions->finalize();
} }
return $actionCount; return $actionCount;
} }
public function event($event,callable $func){ public function event($event, callable $func){
if(!is_callable($func)){ if(!is_callable($func)){
return false; return false;
}elseif(isset(Deprecation::$events[$event])){ } elseif(isset(Deprecation::$events[$event])){
$sub = ""; $sub = "";
if(Deprecation::$events[$event] !== false){ if(Deprecation::$events[$event] !== false){
$sub = " Substitute \"".Deprecation::$events[$event]."\" found."; $sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
} }
console("[ERROR] Event \"$event\" has been deprecated.$sub [Attach to ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)."]"); console("[ERROR] Event \"$event\" has been deprecated.$sub [Attach to " . (is_array($func) ? get_class($func[0]) . "::" . $func[1] : $func) . "]");
} }
$evid = $this->evCnt++; $evid = $this->evCnt++;
if(!isset($this->events[$event])){ if(!isset($this->events[$event])){
@ -676,7 +686,8 @@ class Server{
} }
$this->events[$event][$evid] = $func; $this->events[$event][$evid] = $func;
$this->eventsID[$evid] = $event; $this->eventsID[$evid] = $event;
console("[INTERNAL] Attached ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)." to event ".$event." (ID ".$evid.")", true, true, 3); console("[INTERNAL] Attached " . (is_array($func) ? get_class($func[0]) . "::" . $func[1] : $func) . " to event " . $event . " (ID " . $evid . ")", true, true, 3);
return $evid; return $evid;
} }

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\Utils\VersionString as VersionString; use PocketMine\Utils\VersionString as VersionString;
use PocketMine\Utils\TextFormat as TextFormat; use PocketMine\Utils\TextFormat as TextFormat;
use PocketMine\Utils\Config as Config; use PocketMine\Utils\Config as Config;
@ -101,13 +102,14 @@ class ServerAPI{
public function run(){ public function run(){
$this->load(); $this->load();
return $this->init(); return $this->init();
} }
public function load(){ public function load(){
@mkdir(\PocketMine\DATA."players/", 0755); @mkdir(\PocketMine\DATA . "players/", 0755);
@mkdir(\PocketMine\DATA."worlds/", 0755); @mkdir(\PocketMine\DATA . "worlds/", 0755);
@mkdir(\PocketMine\DATA."plugins/", 0755); @mkdir(\PocketMine\DATA . "plugins/", 0755);
//Init all the events //Init all the events
foreach(get_declared_classes() as $class){ foreach(get_declared_classes() as $class){
@ -117,7 +119,7 @@ class ServerAPI{
} }
$version = new VersionString(); $version = new VersionString();
console("[INFO] Starting Minecraft PE server version ".TextFormat::AQUA.MINECRAFT_VERSION); console("[INFO] Starting Minecraft PE server version " . TextFormat::AQUA . MINECRAFT_VERSION);
console("[INFO] Loading properties..."); console("[INFO] Loading properties...");
$this->config = new Config(\PocketMine\DATA . "server.properties", Config::PROPERTIES, array( $this->config = new Config(\PocketMine\DATA . "server.properties", Config::PROPERTIES, array(
@ -165,49 +167,49 @@ class ServerAPI{
PortForward($this->getProperty("server-port")); PortForward($this->getProperty("server-port"));
} }
$this->server = new Server($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed:false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0"); $this->server = new Server($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed : false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip : "0.0.0.0");
$this->server->api = $this; $this->server->api = $this;
self::$serverRequest = $this->server; self::$serverRequest = $this->server;
console("[INFO] This server is running PocketMine-MP version ".($version->isDev() ? TextFormat::YELLOW:"").VERSION.TextFormat::RESET." \"".CODENAME."\" (MCPE: ".MINECRAFT_VERSION.") (API ".API_VERSION.")", true, true, 0); console("[INFO] This server is running PocketMine-MP version " . ($version->isDev() ? TextFormat::YELLOW : "") . VERSION . TextFormat::RESET . " \"" . CODENAME . "\" (MCPE: " . MINECRAFT_VERSION . ") (API " . API_VERSION . ")", true, true, 0);
console("[INFO] PocketMine-MP is distributed under the LGPL License", true, true, 0); console("[INFO] PocketMine-MP is distributed under the LGPL License", true, true, 0);
if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){ if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){
console("[INFO] Checking for new server version"); console("[INFO] Checking for new server version");
console("[INFO] Last check: ".TextFormat::AQUA.date("Y-m-d H:i:s", $this->getProperty("last-update"))."\x1b[0m"); console("[INFO] Last check: " . TextFormat::AQUA . date("Y-m-d H:i:s", $this->getProperty("last-update")) . "\x1b[0m");
if($this->server->version->isDev()){ if($this->server->version->isDev()){
$info = json_decode(Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/commits"), true); $info = json_decode(Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/commits"), true);
if($info === false or !isset($info[0])){ if($info === false or !isset($info[0])){
console("[ERROR] Github API error"); console("[ERROR] Github API error");
}else{ } else{
$last = new \DateTime($info[0]["commit"]["committer"]["date"]); $last = new \DateTime($info[0]["commit"]["committer"]["date"]);
$last = $last->getTimestamp(); $last = $last->getTimestamp();
if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false and GIT_COMMIT != $info[0]["sha"]){ if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false and GIT_COMMIT != $info[0]["sha"]){
console("[NOTICE] ".TextFormat::YELLOW."A new DEVELOPMENT version of PocketMine-MP has been released!"); console("[NOTICE] " . TextFormat::YELLOW . "A new DEVELOPMENT version of PocketMine-MP has been released!");
console("[NOTICE] ".TextFormat::YELLOW."Commit \"".$info[0]["commit"]["message"]."\" [".substr($info[0]["sha"], 0, 10)."] by ".$info[0]["commit"]["committer"]["name"]); console("[NOTICE] " . TextFormat::YELLOW . "Commit \"" . $info[0]["commit"]["message"] . "\" [" . substr($info[0]["sha"], 0, 10) . "] by " . $info[0]["commit"]["committer"]["name"]);
console("[NOTICE] ".TextFormat::YELLOW."Get it at PocketMine.net or at https://github.com/PocketMine/PocketMine-MP/archive/".$info[0]["sha"].".zip"); console("[NOTICE] " . TextFormat::YELLOW . "Get it at PocketMine.net or at https://github.com/PocketMine/PocketMine-MP/archive/" . $info[0]["sha"] . ".zip");
console("[NOTICE] This message will dissapear after issuing the command \"/update-done\""); console("[NOTICE] This message will dissapear after issuing the command \"/update-done\"");
}else{ } else{
$this->setProperty("last-update", time()); $this->setProperty("last-update", time());
console("[INFO] ".TextFormat::AQUA."This is the latest DEVELOPMENT version"); console("[INFO] " . TextFormat::AQUA . "This is the latest DEVELOPMENT version");
} }
} }
}else{ } else{
$info = json_decode(Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/tags"), true); $info = json_decode(Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/tags"), true);
if($info === false or !isset($info[0])){ if($info === false or !isset($info[0])){
console("[ERROR] Github API error"); console("[ERROR] Github API error");
}else{ } else{
$newest = new VersionString(VERSION); $newest = new VersionString(VERSION);
$newestN = $newest->getNumber(); $newestN = $newest->getNumber();
$update = new VersionString($info[0]["name"]); $update = new VersionString($info[0]["name"]);
$updateN = $update->getNumber(); $updateN = $update->getNumber();
if($updateN > $newestN){ if($updateN > $newestN){
console("[NOTICE] ".TextFormat::GREEN."A new STABLE version of PocketMine-MP has been released!"); console("[NOTICE] " . TextFormat::GREEN . "A new STABLE version of PocketMine-MP has been released!");
console("[NOTICE] ".TextFormat::GREEN."Version \"".$info[0]["name"]."\" #".$updateN); console("[NOTICE] " . TextFormat::GREEN . "Version \"" . $info[0]["name"] . "\" #" . $updateN);
console("[NOTICE] Get it at PocketMine.net or at ".$info[0]["zipball_url"]); console("[NOTICE] Get it at PocketMine.net or at " . $info[0]["zipball_url"]);
console("[NOTICE] This message will dissapear as soon as you update"); console("[NOTICE] This message will dissapear as soon as you update");
}else{ } else{
$this->setProperty("last-update", time()); $this->setProperty("last-update", time());
console("[INFO] ".TextFormat::AQUA."This is the latest STABLE version"); console("[INFO] " . TextFormat::AQUA . "This is the latest STABLE version");
} }
} }
} }
@ -257,7 +259,8 @@ class ServerAPI{
public function async(callable $callable, $params = array(), $remove = false){ public function async(callable $callable, $params = array(), $remove = false){
$cnt = $this->asyncCnt++; $cnt = $this->asyncCnt++;
$this->asyncCalls[$cnt] = new \Async($callable, $params); $this->asyncCalls[$cnt] = new \Async($callable, $params);
return $remove === true ? $this->getAsync($cnt):$cnt;
return $remove === true ? $this->getAsync($cnt) : $cnt;
} }
public function getAsync($id){ public function getAsync($id){
@ -266,8 +269,10 @@ class ServerAPI{
} }
$ob = $this->asyncCalls[$id]; $ob = $this->asyncCalls[$id];
unset($this->asyncCalls[$id]); unset($this->asyncCalls[$id]);
return $ob; return $ob;
} }
public function autoSave(){ public function autoSave(){
console("[DEBUG] Saving....", true, true, 2); console("[DEBUG] Saving....", true, true, 2);
$this->server->api->level->saveAll(); $this->server->api->level->saveAll();
@ -277,7 +282,7 @@ class ServerAPI{
console("[DEBUG] Sending usage data...", true, true, 2); console("[DEBUG] Sending usage data...", true, true, 2);
$plist = ""; $plist = "";
foreach($this->plugin->getList() as $p){ foreach($this->plugin->getList() as $p){
$plist .= str_replace(array(";", ":"), "", $p["name"]).":".str_replace(array(";", ":"), "", $p["version"]).";"; $plist .= str_replace(array(";", ":"), "", $p["name"]) . ":" . str_replace(array(";", ":"), "", $p["version"]) . ";";
} }
$this->asyncOperation(ASYNC_CURL_POST, array( $this->asyncOperation(ASYNC_CURL_POST, array(
@ -296,7 +301,7 @@ class ServerAPI{
"max" => $this->server->maxClients, "max" => $this->server->maxClients,
"plugins" => $plist, "plugins" => $plist,
), ),
), NULL); ), null);
} }
public function __destruct(){ public function __destruct(){
@ -317,7 +322,7 @@ class ServerAPI{
console("[WARNING] PocketMine-MP may not work right with less than 128MB of RAM", true, true, 0); console("[WARNING] PocketMine-MP may not work right with less than 128MB of RAM", true, true, 0);
} }
@ini_set("memory_limit", $memory); @ini_set("memory_limit", $memory);
}else{ } else{
$this->setProperty("memory-limit", "128M"); $this->setProperty("memory-limit", "128M");
} }
@ -342,7 +347,7 @@ class ServerAPI{
case "last-update": case "last-update":
if($v === false){ if($v === false){
$v = time(); $v = time();
}else{ } else{
$v = (int) $v; $v = (int) $v;
} }
break; break;
@ -355,7 +360,7 @@ class ServerAPI{
break; break;
case "server-id": case "server-id":
if($v !== false){ if($v !== false){
$v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)):$v; $v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)) : $v;
} }
break; break;
} }
@ -379,7 +384,7 @@ class ServerAPI{
$this->server->schedule(18000, array($this, "autoSave"), array(), true); $this->server->schedule(18000, array($this, "autoSave"), array(), true);
} }
if(!defined("NO_THREADS") and $this->getProperty("enable-rcon") === true){ if(!defined("NO_THREADS") and $this->getProperty("enable-rcon") === true){
$this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50)); $this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip : "0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50));
} }
if($this->getProperty("enable-query") === true){ if($this->getProperty("enable-query") === true){
@ -394,10 +399,11 @@ class ServerAPI{
$this->rcon->stop(); $this->rcon->stop();
} }
$this->__destruct(); $this->__destruct();
if($this->getProperty("upnp-forwarding") === true ){ if($this->getProperty("upnp-forwarding") === true){
console("[INFO] [UPnP] Removing port forward..."); console("[INFO] [UPnP] Removing port forward...");
RemovePortForward($this->getProperty("server-port")); RemovePortForward($this->getProperty("server-port"));
} }
return $this->restart; return $this->restart;
} }
@ -460,7 +466,7 @@ class ServerAPI{
case "last-update": case "last-update":
if($v === false){ if($v === false){
$v = time(); $v = time();
}else{ } else{
$v = (int) $v; $v = (int) $v;
} }
break; break;
@ -472,9 +478,11 @@ class ServerAPI{
$v = (int) $v; $v = (int) $v;
break; break;
} }
return $v; return $v;
} }
return ($this->config->exists($name) ? $this->config->get($name):$default);
return ($this->config->exists($name) ? $this->config->get($name) : $default);
} }
public function setProperty($name, $value, $save = true){ public function setProperty($name, $value, $save = true){

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI; use PocketMine\ServerAPI as ServerAPI;
class TimeAPI{ class TimeAPI{
@ -30,6 +31,7 @@ class TimeAPI{
"sunrise" => 17800, "sunrise" => 17800,
); );
private $server; private $server;
function __construct(){ function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
@ -49,19 +51,19 @@ class TimeAPI{
$p = strtolower(array_shift($params)); $p = strtolower(array_shift($params));
switch($p){ switch($p){
case "check": case "check":
$output .= "Time: ".$this->getDate($level).", ".$this->getPhase($level)." (".$this->get(true, $level).")\n"; $output .= "Time: " . $this->getDate($level) . ", " . $this->getPhase($level) . " (" . $this->get(true, $level) . ")\n";
break; break;
case "add": case "add":
$output .= "Set the time to ".$this->add(array_shift($params), $level)."\n"; $output .= "Set the time to " . $this->add(array_shift($params), $level) . "\n";
break; break;
case "set": case "set":
$output .= "Set the time to ".$this->set(array_shift($params), $level)."\n"; $output .= "Set the time to " . $this->set(array_shift($params), $level) . "\n";
break; break;
case "sunrise": case "sunrise":
case "day": case "day":
case "sunset": case "sunset":
case "night": case "night":
$output .= "Set the time to ".$this->set($p, $level)."\n"; $output .= "Set the time to " . $this->set($p, $level) . "\n";
break; break;
default: default:
$output .= "Usage: /time <check|set|add> [time]\n"; $output .= "Usage: /time <check|set|add> [time]\n";
@ -69,18 +71,22 @@ class TimeAPI{
} }
break; break;
} }
return $output; return $output;
} }
public function night(){ public function night(){
return $this->set("night"); return $this->set("night");
} }
public function day(){ public function day(){
return $this->set("day"); return $this->set("day");
} }
public function sunrise(){ public function sunrise(){
return $this->set("sunrise"); return $this->set("sunrise");
} }
public function sunset(){ public function sunset(){
return $this->set("sunset"); return $this->set("sunset");
} }
@ -89,7 +95,8 @@ class TimeAPI{
if(!($level instanceof Level)){ if(!($level instanceof Level)){
$level = $this->server->api->level->getDefault(); $level = $this->server->api->level->getDefault();
} }
return $raw === true ? $level->getTime():abs($level->getTime()) % 19200;
return $raw === true ? $level->getTime() : abs($level->getTime()) % 19200;
} }
public function add($time, $level = false){ public function add($time, $level = false){
@ -100,21 +107,23 @@ class TimeAPI{
} }
public function getDate($time = false){ public function getDate($time = false){
$time = !is_integer($time) ? $this->get(false, $time):$time; $time = !is_integer($time) ? $this->get(false, $time) : $time;
return str_pad(strval((floor($time /800) + 6) % 24), 2, "0", STR_PAD_LEFT).":".str_pad(strval(floor(($time % 800) / 13.33)), 2, "0", STR_PAD_LEFT);
return str_pad(strval((floor($time / 800) + 6) % 24), 2, "0", STR_PAD_LEFT) . ":" . str_pad(strval(floor(($time % 800) / 13.33)), 2, "0", STR_PAD_LEFT);
} }
public function getPhase($time = false){ public function getPhase($time = false){
$time = !is_integer($time) ? $this->get(false, $time):$time; $time = !is_integer($time) ? $this->get(false, $time) : $time;
if($time < TimeAPI::$phases["sunset"]){ if($time < TimeAPI::$phases["sunset"]){
$time = "day"; $time = "day";
}elseif($time < TimeAPI::$phases["night"]){ } elseif($time < TimeAPI::$phases["night"]){
$time = "sunset"; $time = "sunset";
}elseif($time < TimeAPI::$phases["sunrise"]){ } elseif($time < TimeAPI::$phases["sunrise"]){
$time = "night"; $time = "night";
}else{ } else{
$time = "sunrise"; $time = "sunrise";
} }
return $time; return $time;
} }
@ -124,9 +133,10 @@ class TimeAPI{
} }
if(is_string($time) and isset(TimeAPI::$phases[$time])){ if(is_string($time) and isset(TimeAPI::$phases[$time])){
$level->setTime(TimeAPI::$phases[$time]); $level->setTime(TimeAPI::$phases[$time]);
}else{ } else{
$level->setTime((int) $time); $level->setTime((int) $time);
} }
return $level->getTime(); return $level->getTime();
} }

View File

@ -32,6 +32,7 @@ class BedBlock extends TransparentBlock{
$pk = new ChatPacket; $pk = new ChatPacket;
$pk->message = "You can only sleep at night"; $pk->message = "You can only sleep at night";
$player->dataPacket($pk); $player->dataPacket($pk);
return true; return true;
} }
@ -41,19 +42,20 @@ class BedBlock extends TransparentBlock{
$blockWest = $this->getSide(4); $blockWest = $this->getSide(4);
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
$b = $this; $b = $this;
}else{ //Bottom Part of Bed } else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){ if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$b = $blockNorth; $b = $blockNorth;
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){ } elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$b = $blockSouth; $b = $blockSouth;
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){ } elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$b = $blockEast; $b = $blockEast;
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){ } elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$b = $blockWest; $b = $blockWest;
}else{ } else{
$pk = new ChatPacket; $pk = new ChatPacket;
$pk->message = "This bed is incomplete"; $pk->message = "This bed is incomplete";
$player->dataPacket($pk); $player->dataPacket($pk);
return true; return true;
} }
} }
@ -63,6 +65,7 @@ class BedBlock extends TransparentBlock{
$pk->message = "This bed is occupied"; $pk->message = "This bed is occupied";
$player->dataPacket($pk); $player->dataPacket($pk);
} }
return true; return true;
} }
@ -82,9 +85,11 @@ class BedBlock extends TransparentBlock{
$meta = (($d + 3) % 4) & 0x03; $meta = (($d + 3) % 4) & 0x03;
$this->level->setBlock($block, BlockAPI::get($this->id, $meta), true, false, true); $this->level->setBlock($block, BlockAPI::get($this->id, $meta), true, false, true);
$this->level->setBlock($next, BlockAPI::get($this->id, $meta | 0x08), true, false, true); $this->level->setBlock($next, BlockAPI::get($this->id, $meta | 0x08), true, false, true);
return true; return true;
} }
} }
return false; return false;
} }
@ -97,25 +102,26 @@ class BedBlock extends TransparentBlock{
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true); $this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
}elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){ } elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true); $this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
}elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){ } elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){
$this->level->setBlock($blockEast, new AirBlock(), true, false, true); $this->level->setBlock($blockEast, new AirBlock(), true, false, true);
}elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){ } elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){
$this->level->setBlock($blockWest, new AirBlock(), true, false, true); $this->level->setBlock($blockWest, new AirBlock(), true, false, true);
} }
}else{ //Bottom Part of Bed } else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){ if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true); $this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){ } elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true); $this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){ } elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$this->level->setBlock($blockEast, new AirBlock(), true, false, true); $this->level->setBlock($blockEast, new AirBlock(), true, false, true);
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){ } elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$this->level->setBlock($blockWest, new AirBlock(), true, false, true); $this->level->setBlock($blockWest, new AirBlock(), true, false, true);
} }
} }
$this->level->setBlock($this, new AirBlock(), true, false, true); $this->level->setBlock($this, new AirBlock(), true, false, true);
return true; return true;
} }

View File

@ -30,6 +30,7 @@ class BedrockBlock extends SolidBlock{
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return true; return true;
} }
return false; return false;
} }

View File

@ -31,8 +31,10 @@ class BeetrootBlock extends FlowableBlock{
if($down->getID() === FARMLAND){ if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true; return true;
} }
return false; return false;
} }
@ -43,8 +45,10 @@ class BeetrootBlock extends FlowableBlock{
if(($player->gamemode & 0x01) === 0){ if(($player->gamemode & 0x01) === 0){
$item->count--; $item->count--;
} }
return true; return true;
} }
return false; return false;
} }
@ -53,19 +57,22 @@ class BeetrootBlock extends FlowableBlock{
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(BEETROOT_SEEDS, 0, 1)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(BEETROOT_SEEDS, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
}elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){ if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){ if($this->meta < 0x07){
++$this->meta; ++$this->meta;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
}else{ } else{
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
} }
return false; return false;
} }
@ -74,9 +81,10 @@ class BeetrootBlock extends FlowableBlock{
if($this->meta >= 0x07){ if($this->meta >= 0x07){
$drops[] = array(BEETROOT, 0, 1); $drops[] = array(BEETROOT, 0, 1);
$drops[] = array(BEETROOT_SEEDS, 0, mt_rand(0, 3)); $drops[] = array(BEETROOT_SEEDS, 0, mt_rand(0, 3));
}else{ } else{
$drops[] = array(BEETROOT_SEEDS, 0, 1); $drops[] = array(BEETROOT_SEEDS, 0, 1);
} }
return $drops; return $drops;
} }
} }

View File

@ -200,7 +200,7 @@ abstract class Block extends Position{
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
if(!isset(Block::$class[$this->id])){ //Unknown blocks if(!isset(Block::$class[$this->id])){ //Unknown blocks
return array(); return array();
}else{ } else{
return array( return array(
array($this->id, $this->meta, 1), array($this->id, $this->meta, 1),
); );
@ -211,6 +211,7 @@ abstract class Block extends Position{
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.15; return 0.15;
} }
return $this->breakTime; return $this->breakTime;
} }
@ -219,11 +220,12 @@ abstract class Block extends Position{
if($this->level instanceof Level){ if($this->level instanceof Level){
return $this->level->getBlock($v); return $this->level->getBlock($v);
} }
return $v; return $v;
} }
final public function __toString(){ final public function __toString(){
return "Block ". $this->name ." (".$this->id.":".$this->meta.")"; return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")";
} }
abstract function isBreakable(Item $item, Player $player); abstract function isBreakable(Item $item, Player $player);

View File

@ -50,7 +50,7 @@ class BricksBlock extends SolidBlock{
return array( return array(
array(BRICKS_BLOCK, 0, 1), array(BRICKS_BLOCK, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -30,9 +30,11 @@ class BrownMushroomBlock extends FlowableBlock{
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }
@ -40,8 +42,10 @@ class BrownMushroomBlock extends FlowableBlock{
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->isTransparent === false){ if($down->isTransparent === false){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
return false; return false;
} }
} }

View File

@ -40,15 +40,17 @@ class BurningFurnaceBlock extends SolidBlock{
"id" => new NBT\Tag\String("id", Tile::FURNACE), "id" => new NBT\Tag\String("id", Tile::FURNACE),
"x" => new NBT\Tag\Int("x", $this->x), "x" => new NBT\Tag\Int("x", $this->x),
"y" => new NBT\Tag\Int("y", $this->y), "y" => new NBT\Tag\Int("y", $this->y),
"z" =>new NBT\Tag\Int("z", $this->z) "z" => new NBT\Tag\Int("z", $this->z)
)); ));
$nbt->Items->setTagType(NBT\Tag_Compound); $nbt->Items->setTagType(NBT\Tag_Compound);
$furnace = new Furnace($this->level, $nbt); $furnace = new Furnace($this->level, $nbt);
return true; return true;
} }
public function onBreak(Item $item, Player $player){ public function onBreak(Item $item, Player $player){
$this->level->setBlock($this, new AirBlock(), true, true, true); $this->level->setBlock($this, new AirBlock(), true, true, true);
return true; return true;
} }
@ -58,13 +60,13 @@ class BurningFurnaceBlock extends SolidBlock{
$furnace = false; $furnace = false;
if($t instanceof Furnace){ if($t instanceof Furnace){
$furnace = $t; $furnace = $t;
}else{ } else{
$nbt = new NBT\Tag\Compound(false, array( $nbt = new NBT\Tag\Compound(false, array(
"Items" => new NBT\Tag\Enum("Items", array()), "Items" => new NBT\Tag\Enum("Items", array()),
"id" => new NBT\Tag\String("id", Tile::FURNACE), "id" => new NBT\Tag\String("id", Tile::FURNACE),
"x" => new NBT\Tag\Int("x", $this->x), "x" => new NBT\Tag\Int("x", $this->x),
"y" => new NBT\Tag\Int("y", $this->y), "y" => new NBT\Tag\Int("y", $this->y),
"z" =>new NBT\Tag\Int("z", $this->z) "z" => new NBT\Tag\Int("z", $this->z)
)); ));
$nbt->Items->setTagType(NBT\Tag_Compound); $nbt->Items->setTagType(NBT\Tag_Compound);
$furnace = new Furnace($this->level, $nbt); $furnace = new Furnace($this->level, $nbt);
@ -75,6 +77,7 @@ class BurningFurnaceBlock extends SolidBlock{
} }
$furnace->openInventory($player); $furnace->openInventory($player);
return true; return true;
} }
@ -112,6 +115,7 @@ class BurningFurnaceBlock extends SolidBlock{
} }
} }
} }
return $drops; return $drops;
} }
} }

View File

@ -32,9 +32,10 @@ class CactusBlock extends TransparentBlock{
if($down->getID() !== SAND and $down->getID() !== CACTUS){ //Replace with common break method if($down->getID() !== SAND and $down->getID() !== CACTUS){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false); $this->level->setBlock($this, new AirBlock(), false);
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
}elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== CACTUS){ if($this->getSide(0)->getID() !== CACTUS){
if($this->meta == 0x0F){ if($this->meta == 0x0F){
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
@ -46,13 +47,15 @@ class CactusBlock extends TransparentBlock{
} }
$this->meta = 0; $this->meta = 0;
$this->level->setBlock($this, $this, false); $this->level->setBlock($this, $this, false);
}else{ } else{
++$this->meta; ++$this->meta;
$this->level->setBlock($this, $this, false); $this->level->setBlock($this, $this, false);
} }
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
} }
return false; return false;
} }
@ -66,9 +69,11 @@ class CactusBlock extends TransparentBlock{
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){ if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true; return true;
} }
} }
return false; return false;
} }

View File

@ -32,8 +32,10 @@ class CakeBlock extends TransparentBlock{
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() !== AIR){ if($down->getID() !== AIR){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
return false; return false;
} }
@ -41,9 +43,11 @@ class CakeBlock extends TransparentBlock{
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method if($this->getSide(0)->getID() === AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), true, false, true); $this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }
@ -57,11 +61,13 @@ class CakeBlock extends TransparentBlock{
$player->entity->heal(3, "cake"); $player->entity->heal(3, "cake");
if($this->meta >= 0x06){ if($this->meta >= 0x06){
$this->level->setBlock($this, new AirBlock(), true, false, true); $this->level->setBlock($this, new AirBlock(), true, false, true);
}else{ } else{
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
} }
return true; return true;
} }
return false; return false;
} }

View File

@ -50,8 +50,10 @@ class CarpetBlock extends FlowableBlock{
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() !== AIR){ if($down->getID() !== AIR){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
return false; return false;
} }
@ -60,9 +62,11 @@ class CarpetBlock extends FlowableBlock{
if($this->getSide(0)->getID() === AIR){ //Replace with common break method if($this->getSide(0)->getID() === AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1));
$this->level->setBlock($this, new AirBlock(), true, false, true); $this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }

View File

@ -31,8 +31,10 @@ class CarrotBlock extends FlowableBlock{
if($down->getID() === FARMLAND){ if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true; return true;
} }
return false; return false;
} }
@ -43,8 +45,10 @@ class CarrotBlock extends FlowableBlock{
if(($player->gamemode & 0x01) === 0){ if(($player->gamemode & 0x01) === 0){
$item->count--; $item->count--;
} }
return true; return true;
} }
return false; return false;
} }
@ -53,19 +57,22 @@ class CarrotBlock extends FlowableBlock{
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(CARROT, 0, 1)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(CARROT, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
}elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){ if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){ if($this->meta < 0x07){
++$this->meta; ++$this->meta;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
}else{ } else{
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
} }
return false; return false;
} }
@ -73,9 +80,10 @@ class CarrotBlock extends FlowableBlock{
$drops = array(); $drops = array();
if($this->meta >= 0x07){ if($this->meta >= 0x07){
$drops[] = array(CARROT, 0, mt_rand(1, 4)); $drops[] = array(CARROT, 0, mt_rand(1, 4));
}else{ } else{
$drops[] = array(CARROT, 0, 1); $drops[] = array(CARROT, 0, 1);
} }
return $drops; return $drops;
} }
} }

View File

@ -25,6 +25,7 @@ class ChestBlock extends TransparentBlock{
$this->isActivable = true; $this->isActivable = true;
$this->hardness = 15; $this->hardness = 15;
} }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array( $faces = array(
0 => 4, 0 => 4,
@ -39,7 +40,7 @@ class ChestBlock extends TransparentBlock{
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
if(($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)){ if(($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)){
continue; continue;
}elseif(($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)){ } elseif(($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)){
continue; continue;
} }
$c = $this->getSide($side); $c = $this->getSide($side);
@ -57,7 +58,7 @@ class ChestBlock extends TransparentBlock{
"id" => new NBT\Tag\String("id", Tile::CHEST), "id" => new NBT\Tag\String("id", Tile::CHEST),
"x" => new NBT\Tag\Int("x", $this->x), "x" => new NBT\Tag\Int("x", $this->x),
"y" => new NBT\Tag\Int("y", $this->y), "y" => new NBT\Tag\Int("y", $this->y),
"z" =>new NBT\Tag\Int("z", $this->z) "z" => new NBT\Tag\Int("z", $this->z)
)); ));
$nbt->Items->setTagType(NBT\Tag_Compound); $nbt->Items->setTagType(NBT\Tag_Compound);
$tile = new Chest($this->level, $nbt); $tile = new Chest($this->level, $nbt);
@ -66,6 +67,7 @@ class ChestBlock extends TransparentBlock{
$chest->pairWith($tile); $chest->pairWith($tile);
$tile->pairWith($chest); $tile->pairWith($chest);
} }
return true; return true;
} }
@ -75,6 +77,7 @@ class ChestBlock extends TransparentBlock{
$t->unpair(); $t->unpair();
} }
$this->level->setBlock($this, new AirBlock(), true, true, true); $this->level->setBlock($this, new AirBlock(), true, true, true);
return true; return true;
} }
@ -88,25 +91,25 @@ class ChestBlock extends TransparentBlock{
$chest = false; $chest = false;
if($t instanceof Chest){ if($t instanceof Chest){
$chest = $t; $chest = $t;
}else{ } else{
$nbt = new NBT\Tag\Compound(false, array( $nbt = new NBT\Tag\Compound(false, array(
"Items" => new NBT\Tag\Enum("Items", array()), "Items" => new NBT\Tag\Enum("Items", array()),
"id" => new NBT\Tag\String("id", Tile::CHEST), "id" => new NBT\Tag\String("id", Tile::CHEST),
"x" => new NBT\Tag\Int("x", $this->x), "x" => new NBT\Tag\Int("x", $this->x),
"y" => new NBT\Tag\Int("y", $this->y), "y" => new NBT\Tag\Int("y", $this->y),
"z" =>new NBT\Tag\Int("z", $this->z) "z" => new NBT\Tag\Int("z", $this->z)
)); ));
$nbt->Items->setTagType(NBT\Tag_Compound); $nbt->Items->setTagType(NBT\Tag_Compound);
$chest = new Chest($this->level, $nbt); $chest = new Chest($this->level, $nbt);
} }
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return true; return true;
} }
$chest->openInventory($player); $chest->openInventory($player);
return true; return true;
} }
@ -123,6 +126,7 @@ class ChestBlock extends TransparentBlock{
} }
} }
} }
return $drops; return $drops;
} }
} }

View File

@ -50,7 +50,7 @@ class CoalBlock extends SolidBlock{
return array( return array(
array(COAL_BLOCK, 0, 1), array(COAL_BLOCK, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -50,7 +50,7 @@ class CoalOreBlock extends SolidBlock{
return array( return array(
array(COAL, 0, 1), array(COAL, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -50,7 +50,7 @@ class CobblestoneBlock extends SolidBlock{
return array( return array(
array(COBBLESTONE, 0, 1), array(COBBLESTONE, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -26,6 +26,7 @@ class CobwebBlock extends FlowableBlock{
$this->isFullBlock = false; $this->isFullBlock = false;
$this->hardness = 25; $this->hardness = 25;
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
return array(); return array();
} }

View File

@ -29,8 +29,10 @@ class CyanFlowerBlock extends FlowableBlock{
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){ if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
return false; return false;
} }
@ -39,9 +41,11 @@ class CyanFlowerBlock extends FlowableBlock{
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }
} }

View File

@ -29,8 +29,10 @@ class DandelionBlock extends FlowableBlock{
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){ if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
return false; return false;
} }
@ -39,9 +41,11 @@ class DandelionBlock extends FlowableBlock{
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }
} }

View File

@ -30,9 +30,11 @@ class DeadBushBlock extends FlowableBlock{
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }

View File

@ -44,7 +44,7 @@ class DiamondBlock extends SolidBlock{
return array( return array(
array(DIAMOND_BLOCK, 0, 1), array(DIAMOND_BLOCK, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -44,7 +44,7 @@ class DiamondOreBlock extends SolidBlock{
return array( return array(
array(DIAMOND, 0, 1), array(DIAMOND, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -32,8 +32,10 @@ class DirtBlock extends SolidBlock{
$item->useOn($this); $item->useOn($this);
} }
$this->level->setBlock($this, BlockAPI::get(FARMLAND, 0), true, false, true); $this->level->setBlock($this, BlockAPI::get(FARMLAND, 0), true, false, true);
return true; return true;
} }
return false; return false;
} }
} }

View File

@ -42,9 +42,11 @@ class DoorBlock extends TransparentBlock{
if($this->getSide(1) instanceof DoorBlock){ if($this->getSide(1) instanceof DoorBlock){
$this->level->setBlock($this->getSide(1), new AirBlock(), false); $this->level->setBlock($this->getSide(1), new AirBlock(), false);
} }
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }
@ -86,6 +88,7 @@ class DoorBlock extends TransparentBlock{
$this->level->setBlock($block, $this, true, false, true); //Bottom $this->level->setBlock($block, $this, true, false, true); //Bottom
return true; return true;
} }
return false; return false;
} }
@ -101,13 +104,14 @@ class DoorBlock extends TransparentBlock{
if($down->getID() === $this->id){ if($down->getID() === $this->id){
$this->level->setBlock($down, new AirBlock(), true, false, true); $this->level->setBlock($down, new AirBlock(), true, false, true);
} }
}else{ } else{
$up = $this->getSide(1); $up = $this->getSide(1);
if($up->getID() === $this->id){ if($up->getID() === $this->id){
$this->level->setBlock($up, new AirBlock(), true, false, true); $this->level->setBlock($up, new AirBlock(), true, false, true);
} }
} }
$this->level->setBlock($this, new AirBlock(), true, false, true); $this->level->setBlock($this, new AirBlock(), true, false, true);
return true; return true;
} }
@ -132,10 +136,12 @@ class DoorBlock extends TransparentBlock{
$pk->evid = 1003; $pk->evid = 1003;
$pk->data = 0; $pk->data = 0;
ServerAPI::request()->api->player->broadcastPacket($players, $pk); ServerAPI::request()->api->player->broadcastPacket($players, $pk);
return true; return true;
} }
return false; return false;
}else{ } else{
$this->meta ^= 0x04; $this->meta ^= 0x04;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
$players = ServerAPI::request()->api->player->getAll($this->level); $players = ServerAPI::request()->api->player->getAll($this->level);
@ -148,6 +154,7 @@ class DoorBlock extends TransparentBlock{
$pk->data = 0; $pk->data = 0;
ServerAPI::request()->api->player->broadcastPacket($players, $pk); ServerAPI::request()->api->player->broadcastPacket($players, $pk);
} }
return true; return true;
} }
} }

View File

@ -60,7 +60,7 @@ class DoubleSlabBlock extends SolidBlock{
return array( return array(
array(SLAB, $this->meta & 0x07, 2), array(SLAB, $this->meta & 0x07, 2),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -45,6 +45,7 @@ class FallableBlock extends SolidBlock{
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true); $ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL);
return $ret; return $ret;
} }
} }

View File

@ -24,6 +24,7 @@ class FarmlandBlock extends SolidBlock{
parent::__construct(FARMLAND, $meta, "Farmland"); parent::__construct(FARMLAND, $meta, "Farmland");
$this->hardness = 3; $this->hardness = 3;
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
return array( return array(
array(DIRT, 0, 1), array(DIRT, 0, 1),

View File

@ -25,11 +25,12 @@ class FenceGateBlock extends TransparentBlock{
$this->isActivable = true; $this->isActivable = true;
if(($this->meta & 0x04) === 0x04){ if(($this->meta & 0x04) === 0x04){
$this->isFullBlock = true; $this->isFullBlock = true;
}else{ } else{
$this->isFullBlock = false; $this->isFullBlock = false;
} }
$this->hardness = 15; $this->hardness = 15;
} }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array( $faces = array(
0 => 3, 0 => 3,
@ -39,13 +40,16 @@ class FenceGateBlock extends TransparentBlock{
); );
$this->meta = $faces[$player->entity->getDirection()] & 0x03; $this->meta = $faces[$player->entity->getDirection()] & 0x03;
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
return array( return array(
array($this->id, 0, 1), array($this->id, 0, 1),
); );
} }
public function onActivate(Item $item, Player $player){ public function onActivate(Item $item, Player $player){
$faces = array( $faces = array(
0 => 3, 0 => 3,
@ -56,10 +60,11 @@ class FenceGateBlock extends TransparentBlock{
$this->meta = ($faces[$player->entity->getDirection()] & 0x03) | ((~$this->meta) & 0x04); $this->meta = ($faces[$player->entity->getDirection()] & 0x03) | ((~$this->meta) & 0x04);
if(($this->meta & 0x04) === 0x04){ if(($this->meta & 0x04) === 0x04){
$this->isFullBlock = true; $this->isFullBlock = true;
}else{ } else{
$this->isFullBlock = false; $this->isFullBlock = false;
} }
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return true; return true;
} }
} }

View File

@ -41,13 +41,16 @@ class FireBlock extends FlowableBlock{
} }
} }
$this->level->setBlock($this, new AirBlock(), true, false, true); $this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
}elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== NETHERRACK){ if($this->getSide(0)->getID() !== NETHERRACK){
$this->level->setBlock($this, new AirBlock(), true, false, true); $this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }

View File

@ -88,8 +88,10 @@ class GenericBlock extends Block{
$e->spawnToAll(); $e->spawnToAll();
$server->api->block->blockUpdateAround(clone $this, BLOCK_UPDATE_NORMAL, 1); $server->api->block->blockUpdateAround(clone $this, BLOCK_UPDATE_NORMAL, 1);
} }
return false; return false;
} }
return false; return false;
} }

View File

@ -28,10 +28,12 @@ class GlowingRedstoneOreBlock extends SolidBlock{
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){ if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){
$this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false, false, true); $this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false, false, true);
return BLOCK_UPDATE_WEAK; return BLOCK_UPDATE_WEAK;
}else{ } else{
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
} }
return false; return false;
} }
@ -55,7 +57,7 @@ class GlowingRedstoneOreBlock extends SolidBlock{
return array( return array(
array(REDSTONE_DUST, 0, mt_rand(4, 5)), array(REDSTONE_DUST, 0, mt_rand(4, 5)),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -44,7 +44,7 @@ class GoldBlock extends SolidBlock{
return array( return array(
array(GOLD_BLOCK, 0, 1), array(GOLD_BLOCK, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -44,7 +44,7 @@ class GoldOreBlock extends SolidBlock{
return array( return array(
array(GOLD_ORE, 0, 1), array(GOLD_ORE, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -25,6 +25,7 @@ class GrassBlock extends SolidBlock{
$this->isActivable = true; $this->isActivable = true;
$this->hardness = 3; $this->hardness = 3;
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
return array( return array(
array(DIRT, 0, 1), array(DIRT, 0, 1),
@ -37,14 +38,17 @@ class GrassBlock extends SolidBlock{
$item->count--; $item->count--;
} }
TallGrassObject::growGrass($this->level, $this, new Random(), 8, 2); TallGrassObject::growGrass($this->level, $this, new Random(), 8, 2);
return true; return true;
}elseif($item->isHoe()){ } elseif($item->isHoe()){
if(($player->gamemode & 0x01) === 0){ if(($player->gamemode & 0x01) === 0){
$item->useOn($this); $item->useOn($this);
} }
$this->level->setBlock($this, new FarmlandBlock()); $this->level->setBlock($this, new FarmlandBlock());
return true; return true;
} }
return false; return false;
} }
} }

View File

@ -26,11 +26,12 @@ class GravelBlock extends FallableBlock{
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
if(mt_rand(1,10) === 1){ if(mt_rand(1, 10) === 1){
return array( return array(
array(FLINT, 0, 1), array(FLINT, 0, 1),
); );
} }
return array( return array(
array(GRAVEL, 0, 1), array(GRAVEL, 0, 1),
); );

View File

@ -37,6 +37,7 @@ class HayBaleBlock extends SolidBlock{
$this->meta = ($this->meta & 0x03) | $faces[$face]; $this->meta = ($this->meta & 0x03) | $faces[$face];
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }

View File

@ -28,9 +28,10 @@ class IceBlock extends TransparentBlock{
public function onBreak(Item $item, Player $player){ public function onBreak(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0){ if(($player->gamemode & 0x01) === 0){
$this->level->setBlock($this, new WaterBlock(), true, false, true); $this->level->setBlock($this, new WaterBlock(), true, false, true);
}else{ } else{
$this->level->setBlock($this, new AirBlock(), true, false, true); $this->level->setBlock($this, new AirBlock(), true, false, true);
} }
return true; return true;
} }

View File

@ -46,7 +46,7 @@ class IronBlock extends SolidBlock{
return array( return array(
array(IRON_BLOCK, 0, 1), array(IRON_BLOCK, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -51,7 +51,7 @@ class IronDoorBlock extends DoorBlock{
return array( return array(
array(IRON_DOOR, 0, 1), array(IRON_DOOR, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -46,7 +46,7 @@ class IronOreBlock extends SolidBlock{
return array( return array(
array(IRON_ORE, 0, 1), array(IRON_ORE, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -26,6 +26,7 @@ class LadderBlock extends TransparentBlock{
$this->isFullBlock = false; $this->isFullBlock = false;
$this->hardness = 2; $this->hardness = 2;
} }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($target->isTransparent === false){ if($target->isTransparent === false){
$faces = array( $faces = array(
@ -37,9 +38,11 @@ class LadderBlock extends TransparentBlock{
if(isset($faces[$face])){ if(isset($faces[$face])){
$this->meta = $faces[$face]; $this->meta = $faces[$face];
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
} }
return false; return false;
} }
@ -51,6 +54,7 @@ class LadderBlock extends TransparentBlock{
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
}*/ }*/
} }
return false; return false;
} }

View File

@ -46,7 +46,7 @@ class LapisBlock extends SolidBlock{
return array( return array(
array(LAPIS_BLOCK, 0, 1), array(LAPIS_BLOCK, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -46,7 +46,7 @@ class LapisOreBlock extends SolidBlock{
return array( return array(
array(DYE, 4, mt_rand(4, 8)), array(DYE, 4, mt_rand(4, 8)),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -28,13 +28,14 @@ class LavaBlock extends LiquidBlock{
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true); $ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 40, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 40, BLOCK_UPDATE_NORMAL);
return $ret; return $ret;
} }
public function getSourceCount(){ public function getSourceCount(){
$count = 0; $count = 0;
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
if($this->getSide($side) instanceof LavaBlock ){ if($this->getSide($side) instanceof LavaBlock){
$b = $this->getSide($side); $b = $this->getSide($side);
$level = $b->meta & 0x07; $level = $b->meta & 0x07;
if($level == 0x00){ if($level == 0x00){
@ -42,6 +43,7 @@ class LavaBlock extends LiquidBlock{
} }
} }
} }
return $count; return $count;
} }
@ -52,7 +54,7 @@ class LavaBlock extends LiquidBlock{
$level = $this->meta & 0x07; $level = $this->meta & 0x07;
if($level == 0x00){ if($level == 0x00){
$this->level->setBlock($this, new ObsidianBlock(), false, false, true); $this->level->setBlock($this, new ObsidianBlock(), false, false, true);
}else{ } else{
$this->level->setBlock($this, new CobblestoneBlock(), false, false, true); $this->level->setBlock($this, new CobblestoneBlock(), false, false, true);
} }
} }
@ -65,11 +67,12 @@ class LavaBlock extends LiquidBlock{
if($b instanceof LavaBlock){ if($b instanceof LavaBlock){
$tlevel = $b->meta & 0x07; $tlevel = $b->meta & 0x07;
$level = $this->meta & 0x07; $level = $this->meta & 0x07;
if( ($tlevel + 2) == $level || ($side == 0x01 && $level == 0x01 ) || ($tlevel == 6 && $level == 7 )){ if(($tlevel + 2) == $level || ($side == 0x01 && $level == 0x01) || ($tlevel == 6 && $level == 7)){
return $b; return $b;
} }
} }
} }
return null; return null;
} }
@ -94,26 +97,26 @@ class LavaBlock extends LiquidBlock{
if($down instanceof AirBlock || $down instanceof LavaBlock){ if($down instanceof AirBlock || $down instanceof LavaBlock){
$this->level->setBlock($down, new LavaBlock(0x01), false, false, true); $this->level->setBlock($down, new LavaBlock(0x01), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
}else{ } else{
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side); $b = $this->getSide($side);
if($b instanceof LavaBlock){ if($b instanceof LavaBlock){
}elseif($b->isFlowable === true){ } elseif($b->isFlowable === true){
$this->level->setBlock($b, new LavaBlock( min($level + 2,7) ), false, false, true); $this->level->setBlock($b, new LavaBlock(min($level + 2, 7)), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
} }
} }
} }
} }
}else{ } else{
//Extend Remove for Left Lavas //Extend Remove for Left Lavas
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$sb = $this->getSide($side); $sb = $this->getSide($side);
if($sb instanceof LavaBlock){ if($sb instanceof LavaBlock){
$tlevel = $sb->meta & 0x07; $tlevel = $sb->meta & 0x07;
if($tlevel != 0x00){ if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) { for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
} }
@ -124,7 +127,7 @@ class LavaBlock extends LiquidBlock{
if($b instanceof LavaBlock){ if($b instanceof LavaBlock){
$tlevel = $b->meta & 0x07; $tlevel = $b->meta & 0x07;
if($tlevel != 0x00){ if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) { for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
} }
@ -136,6 +139,7 @@ class LavaBlock extends LiquidBlock{
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
} }
return false; return false;
} }

View File

@ -23,6 +23,7 @@ class LeavesBlock extends TransparentBlock{
const OAK = 0; const OAK = 0;
const SPRUCE = 1; const SPRUCE = 1;
const BIRCH = 2; const BIRCH = 2;
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(LEAVES, $meta, "Leaves"); parent::__construct(LEAVES, $meta, "Leaves");
$names = array( $names = array(
@ -37,13 +38,13 @@ class LeavesBlock extends TransparentBlock{
private function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null){ private function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null){
++$check; ++$check;
$index = $pos->x.".".$pos->y.".".$pos->z; $index = $pos->x . "." . $pos->y . "." . $pos->z;
if(isset($visited[$index])){ if(isset($visited[$index])){
return false; return false;
} }
if($pos->getID() === WOOD){ if($pos->getID() === WOOD){
return true; return true;
}elseif($pos->getID() === LEAVES and $distance < 3){ } elseif($pos->getID() === LEAVES and $distance < 3){
$visited[$index] = true; $visited[$index] = true;
$down = $pos->getSide(0)->getID(); $down = $pos->getSide(0)->getID();
if($down === WOOD){ if($down === WOOD){
@ -55,41 +56,41 @@ class LeavesBlock extends TransparentBlock{
return true; return true;
} }
} }
}else{ //No more loops } else{ //No more loops
switch($fromSide){ switch($fromSide){
case 2: case 2:
if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){ if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){
return true; return true;
}elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){ } elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
return true; return true;
}elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){ } elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
return true; return true;
} }
break; break;
case 3: case 3:
if($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){ if($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
return true; return true;
}elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){ } elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
return true; return true;
}elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){ } elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
return true; return true;
} }
break; break;
case 4: case 4:
if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){ if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){
return true; return true;
}elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){ } elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
return true; return true;
}elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){ } elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
return true; return true;
} }
break; break;
case 5: case 5:
if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){ if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){
return true; return true;
}elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){ } elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
return true; return true;
}elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){ } elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
return true; return true;
} }
break; break;
@ -106,27 +107,29 @@ class LeavesBlock extends TransparentBlock{
$this->meta |= 0x08; $this->meta |= 0x08;
$this->level->setBlock($this, $this, false, false, true); $this->level->setBlock($this, $this, false, false, true);
} }
}elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === BLOCK_UPDATE_RANDOM){
if(($this->meta & 0b00001100) === 0x08){ if(($this->meta & 0b00001100) === 0x08){
$this->meta &= 0x03; $this->meta &= 0x03;
$visited = array(); $visited = array();
$check = 0; $check = 0;
if($this->findLog($this, $visited, 0, $check) === true){ if($this->findLog($this, $visited, 0, $check) === true){
$this->level->setBlock($this, $this, false, false, true); $this->level->setBlock($this, $this, false, false, true);
}else{ } else{
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
if(mt_rand(1,20) === 1){ //Saplings if(mt_rand(1, 20) === 1){ //Saplings
//TODO //TODO
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x03, 1)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x03, 1));
} }
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1, 200) === 1){ //Apples
//TODO //TODO
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1));
} }
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
} }
return false; return false;
} }
@ -139,14 +142,15 @@ class LeavesBlock extends TransparentBlock{
$drops = array(); $drops = array();
if($item->isShears()){ if($item->isShears()){
$drops[] = array(LEAVES, $this->meta & 0x03, 1); $drops[] = array(LEAVES, $this->meta & 0x03, 1);
}else{ } else{
if(mt_rand(1,20) === 1){ //Saplings if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = array(SAPLING, $this->meta & 0x03, 1); $drops[] = array(SAPLING, $this->meta & 0x03, 1);
} }
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1, 200) === 1){ //Apples
$drops[] = array(APPLE, 0, 1); $drops[] = array(APPLE, 0, 1);
} }
} }
return $drops; return $drops;
} }
} }

View File

@ -34,6 +34,7 @@ class LitPumpkinBlock extends SolidBlock{
); );
$this->meta = $faces[$player->entity->getDirection()]; $this->meta = $faces[$player->entity->getDirection()];
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
} }

View File

@ -24,6 +24,7 @@ class MelonBlock extends TransparentBlock{
parent::__construct(MELON_BLOCK, 0, "Melon Block"); parent::__construct(MELON_BLOCK, 0, "Melon Block");
$this->hardness = 5; $this->hardness = 5;
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
return array( return array(
array(MELON_SLICE, 0, mt_rand(3, 7)), array(MELON_SLICE, 0, mt_rand(3, 7)),

View File

@ -25,13 +25,16 @@ class MelonStemBlock extends FlowableBlock{
$this->isActivable = true; $this->isActivable = true;
$this->hardness = 0; $this->hardness = 0;
} }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() === FARMLAND){ if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true; return true;
} }
return false; return false;
} }
@ -40,30 +43,34 @@ class MelonStemBlock extends FlowableBlock{
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2))); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
}elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){ if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){ if($this->meta < 0x07){
++$this->meta; ++$this->meta;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
}else{ } else{
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side); $b = $this->getSide($side);
if($b->getID() === MELON_BLOCK){ if($b->getID() === MELON_BLOCK){
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
} }
$side = $this->getSide(mt_rand(2,5)); $side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(0); $d = $side->getSide(0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){ if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
$this->level->setBlock($side, new MelonBlock(), true, false, true); $this->level->setBlock($side, new MelonBlock(), true, false, true);
} }
} }
} }
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
return false; return false;
} }
@ -74,8 +81,10 @@ class MelonStemBlock extends FlowableBlock{
if(($player->gamemode & 0x01) === 0){ if(($player->gamemode & 0x01) === 0){
$item->count--; $item->count--;
} }
return true; return true;
} }
return false; return false;
} }

View File

@ -50,7 +50,7 @@ class MossStoneBlock extends SolidBlock{
return array( return array(
array(MOSS_STONE, 0, 1), array(MOSS_STONE, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -50,7 +50,7 @@ class NetherBricksBlock extends SolidBlock{
return array( return array(
array(NETHER_BRICKS, 0, 1), array(NETHER_BRICKS, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -50,7 +50,7 @@ class NetherrackBlock extends SolidBlock{
return array( return array(
array(NETHERRACK, 0, 1), array(NETHERRACK, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -31,7 +31,7 @@ class ObsidianBlock extends SolidBlock{
} }
if($item->isPickaxe() >= 5){ if($item->isPickaxe() >= 5){
return 9.4; return 9.4;
}else{ } else{
return 250; return 250;
} }
} }
@ -41,7 +41,7 @@ class ObsidianBlock extends SolidBlock{
return array( return array(
array(OBSIDIAN, 0, 1), array(OBSIDIAN, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -31,8 +31,10 @@ class PotatoBlock extends FlowableBlock{
if($down->getID() === FARMLAND){ if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true; return true;
} }
return false; return false;
} }
@ -43,8 +45,10 @@ class PotatoBlock extends FlowableBlock{
if(($player->gamemode & 0x01) === 0){ if(($player->gamemode & 0x01) === 0){
$item->count--; $item->count--;
} }
return true; return true;
} }
return false; return false;
} }
@ -53,19 +57,22 @@ class PotatoBlock extends FlowableBlock{
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(POTATO, 0, 1)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(POTATO, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
}elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){ if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){ if($this->meta < 0x07){
++$this->meta; ++$this->meta;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
}else{ } else{
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
} }
return false; return false;
} }
@ -73,9 +80,10 @@ class PotatoBlock extends FlowableBlock{
$drops = array(); $drops = array();
if($this->meta >= 0x07){ if($this->meta >= 0x07){
$drops[] = array(POTATO, 0, mt_rand(1, 4)); $drops[] = array(POTATO, 0, mt_rand(1, 4));
}else{ } else{
$drops[] = array(POTATO, 0, 1); $drops[] = array(POTATO, 0, 1);
} }
return $drops; return $drops;
} }
} }

View File

@ -25,13 +25,16 @@ class PumpkinStemBlock extends FlowableBlock{
$this->isActivable = true; $this->isActivable = true;
$this->hardness = 0; $this->hardness = 0;
} }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() === FARMLAND){ if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true; return true;
} }
return false; return false;
} }
@ -40,30 +43,34 @@ class PumpkinStemBlock extends FlowableBlock{
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2))); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
}elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){ if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){ if($this->meta < 0x07){
++$this->meta; ++$this->meta;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
}else{ } else{
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side); $b = $this->getSide($side);
if($b->getID() === PUMPKIN){ if($b->getID() === PUMPKIN){
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
} }
$side = $this->getSide(mt_rand(2,5)); $side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(0); $d = $side->getSide(0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){ if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
$this->level->setBlock($side, new PumpkinBlock(), true, false, true); $this->level->setBlock($side, new PumpkinBlock(), true, false, true);
} }
} }
} }
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
return false; return false;
} }
@ -74,8 +81,10 @@ class PumpkinStemBlock extends FlowableBlock{
if(($player->gamemode & 0x01) === 0){ if(($player->gamemode & 0x01) === 0){
$item->count--; $item->count--;
} }
return true; return true;
} }
return false; return false;
} }

View File

@ -56,7 +56,7 @@ class QuartzBlock extends SolidBlock{
return array( return array(
array(QUARTZ_BLOCK, $this->meta & 0x03, 1), array(QUARTZ_BLOCK, $this->meta & 0x03, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -31,9 +31,11 @@ class RedMushroomBlock extends FlowableBlock{
//TODO //TODO
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false); $this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }
@ -41,8 +43,10 @@ class RedMushroomBlock extends FlowableBlock{
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->isTransparent === false){ if($down->isTransparent === false){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
return false; return false;
} }
} }

View File

@ -29,8 +29,10 @@ class RedstoneOreBlock extends SolidBlock{
if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){ if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){
$this->level->setBlock($this, BlockAPI::get(GLOWING_REDSTONE_ORE, $this->meta), false, false, true); $this->level->setBlock($this, BlockAPI::get(GLOWING_REDSTONE_ORE, $this->meta), false, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return BLOCK_UPDATE_WEAK; return BLOCK_UPDATE_WEAK;
} }
return false; return false;
} }
@ -39,7 +41,7 @@ class RedstoneOreBlock extends SolidBlock{
return array( return array(
array(REDSTONE_DUST, 0, mt_rand(4, 5)), array(REDSTONE_DUST, 0, mt_rand(4, 5)),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -56,7 +56,7 @@ class SandstoneBlock extends SolidBlock{
return array( return array(
array(SANDSTONE, $this->meta & 0x03, 1), array(SANDSTONE, $this->meta & 0x03, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -44,8 +44,10 @@ class SaplingBlock extends FlowableBlock{
if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){ if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true; return true;
} }
return false; return false;
} }
@ -55,31 +57,37 @@ class SaplingBlock extends FlowableBlock{
if(($player->gamemode & 0x01) === 0){ if(($player->gamemode & 0x01) === 0){
$item->count--; $item->count--;
} }
return true; return true;
} }
return false; return false;
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO //TODO
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
}elseif($type === BLOCK_UPDATE_RANDOM){ //Growth } elseif($type === BLOCK_UPDATE_RANDOM){ //Growth
if(mt_rand(1,7) === 1){ if(mt_rand(1, 7) === 1){
if(($this->meta & 0x08) === 0x08){ if(($this->meta & 0x08) === 0x08){
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03); TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
}else{ } else{
$this->meta |= 0x08; $this->meta |= 0x08;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
}else{ } else{
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
} }
return false; return false;
} }

View File

@ -38,13 +38,16 @@ class SignPostBlock extends TransparentBlock{
if(!isset($faces[$face])){ if(!isset($faces[$face])){
$this->meta = floor((($player->entity->yaw + 180) * 16 / 360) + 0.5) & 0x0F; $this->meta = floor((($player->entity->yaw + 180) * 16 / 360) + 0.5) & 0x0F;
$this->level->setBlock($block, BlockAPI::get(SIGN_POST, $this->meta), true, false, true); $this->level->setBlock($block, BlockAPI::get(SIGN_POST, $this->meta), true, false, true);
return true; return true;
}else{ } else{
$this->meta = $faces[$face]; $this->meta = $faces[$face];
$this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta), true, false, true); $this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta), true, false, true);
return true; return true;
} }
} }
return false; return false;
} }
@ -53,14 +56,17 @@ class SignPostBlock extends TransparentBlock{
if($this->getSide(0)->getID() === AIR){ //Replace with common break method if($this->getSide(0)->getID() === AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SIGN, 0, 1)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SIGN, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, true, true); $this->level->setBlock($this, new AirBlock(), true, true, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }
public function onBreak(Item $item, Player $player){ public function onBreak(Item $item, Player $player){
$this->level->setBlock($this, new AirBlock(), true, true, true); $this->level->setBlock($this, new AirBlock(), true, true, true);
return true; return true;
} }

View File

@ -32,10 +32,10 @@ class SlabBlock extends TransparentBlock{
6 => "Quartz", 6 => "Quartz",
7 => "", 7 => "",
); );
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab"; $this->name = (($this->meta & 0x08) === 0x08 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab";
if(($this->meta & 0x08) === 0x08){ if(($this->meta & 0x08) === 0x08){
$this->isFullBlock = true; $this->isFullBlock = true;
}else{ } else{
$this->isFullBlock = false; $this->isFullBlock = false;
} }
$this->hardness = 30; $this->hardness = 30;
@ -46,40 +46,47 @@ class SlabBlock extends TransparentBlock{
if($face === 0){ if($face === 0){
if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); $this->level->setBlock($target, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true; return true;
}elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ } elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); $this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true; return true;
}else{ } else{
$this->meta |= 0x08; $this->meta |= 0x08;
} }
}elseif($face === 1){ } elseif($face === 1){
if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); $this->level->setBlock($target, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true; return true;
}elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ } elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); $this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true; return true;
} }
}elseif(!$player->entity->inBlock($block)){ } elseif(!$player->entity->inBlock($block)){
if($block->getID() === SLAB){ if($block->getID() === SLAB){
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); $this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true; return true;
} }
return false; return false;
}else{ } else{
if($fy > 0.5){ if($fy > 0.5){
$this->meta |= 0x08; $this->meta |= 0x08;
} }
} }
}else{ } else{
return false; return false;
} }
if($block->getID() === SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){ if($block->getID() === SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
return false; return false;
} }
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
@ -108,7 +115,7 @@ class SlabBlock extends TransparentBlock{
return array( return array(
array($this->id, $this->meta & 0x07, 1), array($this->id, $this->meta & 0x07, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -32,8 +32,10 @@ class SnowLayerBlock extends FlowableBlock{
$down = $this->getSide(0); $down = $this->getSide(0);
if($down instanceof SolidBlock){ if($down instanceof SolidBlock){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
return false; return false;
} }
@ -41,9 +43,11 @@ class SnowLayerBlock extends FlowableBlock{
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method if($this->getSide(0)->getID() === AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), true, false, true); $this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }
@ -53,6 +57,7 @@ class SnowLayerBlock extends FlowableBlock{
array(SNOWBALL, 0, 1), array(SNOWBALL, 0, 1),
); );
} }
return array(); return array();
} }
} }

View File

@ -29,7 +29,7 @@ class StairBlock extends TransparentBlock{
parent::__construct($id, $meta, $name); parent::__construct($id, $meta, $name);
if(($this->meta & 0x04) === 0x04){ if(($this->meta & 0x04) === 0x04){
$this->isFullBlock = true; $this->isFullBlock = true;
}else{ } else{
$this->isFullBlock = false; $this->isFullBlock = false;
} }
$this->hardness = 30; $this->hardness = 30;
@ -59,6 +59,7 @@ class StairBlock extends TransparentBlock{
$this->meta |= 0x04; //Upside-down stairs $this->meta |= 0x04; //Upside-down stairs
} }
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
@ -73,7 +74,7 @@ class StairBlock extends TransparentBlock{
return array( return array(
array($this->id, 0, 1), array($this->id, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -50,7 +50,7 @@ class StoneBlock extends SolidBlock{
return array( return array(
array(COBBLESTONE, 0, 1), array(COBBLESTONE, 0, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -57,7 +57,7 @@ class StoneBricksBlock extends SolidBlock{
return array( return array(
array(STONE_BRICKS, $this->meta & 0x03, 1), array(STONE_BRICKS, $this->meta & 0x03, 1),
); );
}else{ } else{
return array(); return array();
} }
} }

View File

@ -27,6 +27,7 @@ class StonecutterBlock extends SolidBlock{
public function onActivate(Item $item, Player $player){ public function onActivate(Item $item, Player $player){
$player->toCraft[-1] = 2; $player->toCraft[-1] = 2;
return true; return true;
} }

View File

@ -47,8 +47,10 @@ class SugarcaneBlock extends FlowableBlock{
if(($player->gamemode & 0x01) === 0){ if(($player->gamemode & 0x01) === 0){
$item->count--; $item->count--;
} }
return true; return true;
} }
return false; return false;
} }
@ -59,9 +61,10 @@ class SugarcaneBlock extends FlowableBlock{
//TODO //TODO
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE));
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
}elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== SUGARCANE_BLOCK){ if($this->getSide(0)->getID() !== SUGARCANE_BLOCK){
if($this->meta === 0x0F){ if($this->meta === 0x0F){
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
@ -73,13 +76,15 @@ class SugarcaneBlock extends FlowableBlock{
} }
$this->meta = 0; $this->meta = 0;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
}else{ } else{
++$this->meta; ++$this->meta;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
} }
return BLOCK_UPDATE_RANDOM; return BLOCK_UPDATE_RANDOM;
} }
} }
return false; return false;
} }
@ -87,8 +92,9 @@ class SugarcaneBlock extends FlowableBlock{
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() === SUGARCANE_BLOCK){ if($down->getID() === SUGARCANE_BLOCK){
$this->level->setBlock($block, new SugarcaneBlock(), true, false, true); $this->level->setBlock($block, new SugarcaneBlock(), true, false, true);
return true; return true;
}elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){ } elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){
$block0 = $down->getSide(2); $block0 = $down->getSide(2);
$block1 = $down->getSide(3); $block1 = $down->getSide(3);
$block2 = $down->getSide(4); $block2 = $down->getSide(4);
@ -96,9 +102,11 @@ class SugarcaneBlock extends FlowableBlock{
if(($block0 instanceof WaterBlock) or ($block1 instanceof WaterBlock) or ($block2 instanceof WaterBlock) or ($block3 instanceof WaterBlock)){ if(($block0 instanceof WaterBlock) or ($block1 instanceof WaterBlock) or ($block2 instanceof WaterBlock) or ($block3 instanceof WaterBlock)){
$this->level->setBlock($block, new SugarcaneBlock(), true, false, true); $this->level->setBlock($block, new SugarcaneBlock(), true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true; return true;
} }
} }
return false; return false;
} }
} }

View File

@ -42,8 +42,10 @@ class TNTBlock extends SolidBlock{
//TODO //TODO
$e = ServerAPI::request()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data); $e = ServerAPI::request()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
$e->spawnToAll(); $e->spawnToAll();
return true; return true;
} }
return false; return false;
} }
} }

View File

@ -36,9 +36,11 @@ class TallGrassBlock extends FlowableBlock{
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }
@ -63,6 +65,7 @@ class TallGrassBlock extends FlowableBlock{
if(($item = $possibleDrops[mt_rand(0, count($possibleDrops) - 1)]) !== 0){ if(($item = $possibleDrops[mt_rand(0, count($possibleDrops) - 1)]) !== 0){
$drops[] = $item; $drops[] = $item;
} }
return $drops; return $drops;
} }

View File

@ -41,9 +41,11 @@ class TorchBlock extends FlowableBlock{
if($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === FENCE)){ //Replace with common break method if($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === FENCE)){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, 0, 1)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, false, true); $this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
return false; return false;
} }
@ -58,14 +60,18 @@ class TorchBlock extends FlowableBlock{
); );
$this->meta = $faces[$face]; $this->meta = $faces[$face];
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
}elseif($this->getSide(0)->isTransparent === false or $this->getSide(0)->getID() === FENCE){ } elseif($this->getSide(0)->isTransparent === false or $this->getSide(0)->getID() === FENCE){
$this->meta = 0; $this->meta = 0;
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
return false; return false;
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
return array( return array(
array($this->id, 0, 1), array($this->id, 0, 1),

View File

@ -25,11 +25,12 @@ class TrapdoorBlock extends TransparentBlock{
$this->isActivable = true; $this->isActivable = true;
if(($this->meta & 0x04) === 0x04){ if(($this->meta & 0x04) === 0x04){
$this->isFullBlock = false; $this->isFullBlock = false;
}else{ } else{
$this->isFullBlock = true; $this->isFullBlock = true;
} }
$this->hardness = 15; $this->hardness = 15;
} }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if(($target->isTransparent === false or $target->getID() === SLAB) and $face !== 0 and $face !== 1){ if(($target->isTransparent === false or $target->getID() === SLAB) and $face !== 0 and $face !== 1){
$faces = array( $faces = array(
@ -43,18 +44,23 @@ class TrapdoorBlock extends TransparentBlock{
$this->meta |= 0x08; $this->meta |= 0x08;
} }
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
return false; return false;
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
return array( return array(
array($this->id, 0, 1), array($this->id, 0, 1),
); );
} }
public function onActivate(Item $item, Player $player){ public function onActivate(Item $item, Player $player){
$this->meta ^= 0x04; $this->meta ^= 0x04;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return true; return true;
} }
} }

View File

@ -28,13 +28,14 @@ class WaterBlock extends LiquidBlock{
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true); $ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, BLOCK_UPDATE_NORMAL);
return $ret; return $ret;
} }
public function getSourceCount(){ public function getSourceCount(){
$count = 0; $count = 0;
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
if( $this->getSide($side) instanceof WaterBlock ){ if($this->getSide($side) instanceof WaterBlock){
$b = $this->getSide($side); $b = $this->getSide($side);
$level = $b->meta & 0x07; $level = $b->meta & 0x07;
if($level == 0x00){ if($level == 0x00){
@ -42,6 +43,7 @@ class WaterBlock extends LiquidBlock{
} }
} }
} }
return $count; return $count;
} }
@ -55,12 +57,14 @@ class WaterBlock extends LiquidBlock{
$level = $b->meta & 0x07; $level = $b->meta & 0x07;
if($level == 0x00){ if($level == 0x00){
$this->level->setBlock($b, new ObsidianBlock(), false, false, true); $this->level->setBlock($b, new ObsidianBlock(), false, false, true);
}else{ } else{
$this->level->setBlock($b, new CobblestoneBlock(), false, false, true); $this->level->setBlock($b, new CobblestoneBlock(), false, false, true);
} }
return true; return true;
} }
} }
return false; return false;
} }
@ -70,11 +74,12 @@ class WaterBlock extends LiquidBlock{
if($b instanceof WaterBlock){ if($b instanceof WaterBlock){
$tlevel = $b->meta & 0x07; $tlevel = $b->meta & 0x07;
$level = $this->meta & 0x07; $level = $this->meta & 0x07;
if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){ if(($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01)){
return $b; return $b;
} }
} }
} }
return null; return null;
} }
@ -98,28 +103,28 @@ class WaterBlock extends LiquidBlock{
if($down instanceof AirBlock || $down instanceof WaterBlock){ if($down instanceof AirBlock || $down instanceof WaterBlock){
$this->level->setBlock($down, new WaterBlock(0x01), false, false, true); $this->level->setBlock($down, new WaterBlock(0x01), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
}else{ } else{
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side); $b = $this->getSide($side);
if($b instanceof WaterBlock){ if($b instanceof WaterBlock){
if( $this->getSourceCount() >= 2 && $level != 0x00){ if($this->getSourceCount() >= 2 && $level != 0x00){
$this->level->setBlock($this, new WaterBlock(0), false, false, true); $this->level->setBlock($this, new WaterBlock(0), false, false, true);
} }
}elseif($b->isFlowable === true){ } elseif($b->isFlowable === true){
$this->level->setBlock($b, new WaterBlock($level + 1), false, false, true); $this->level->setBlock($b, new WaterBlock($level + 1), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
} }
} }
} }
} }
}else{ } else{
//Extend Remove for Left Waters //Extend Remove for Left Waters
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$sb = $this->getSide($side); $sb = $this->getSide($side);
if($sb instanceof WaterBlock){ if($sb instanceof WaterBlock){
$tlevel = $sb->meta & 0x07; $tlevel = $sb->meta & 0x07;
if($tlevel != 0x00){ if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) { for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
} }
@ -130,7 +135,7 @@ class WaterBlock extends LiquidBlock{
if($b instanceof WaterBlock){ if($b instanceof WaterBlock){
$tlevel = $b->meta & 0x07; $tlevel = $b->meta & 0x07;
if($tlevel != 0x00){ if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) { for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
} }
@ -141,6 +146,7 @@ class WaterBlock extends LiquidBlock{
} }
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
} }
return false; return false;
} }
} }

View File

@ -31,8 +31,10 @@ class WheatBlock extends FlowableBlock{
if($down->getID() === FARMLAND){ if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true; return true;
} }
return false; return false;
} }
@ -43,8 +45,10 @@ class WheatBlock extends FlowableBlock{
if(($player->gamemode & 0x01) === 0){ if(($player->gamemode & 0x01) === 0){
$item->count--; $item->count--;
} }
return true; return true;
} }
return false; return false;
} }
@ -54,9 +58,10 @@ class WheatBlock extends FlowableBlock{
//TODO //TODO
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(WHEAT_SEEDS, 0, 1)); ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(WHEAT_SEEDS, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
}elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){ if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){ if($this->meta < 0x07){
++$this->meta; ++$this->meta;
@ -64,6 +69,7 @@ class WheatBlock extends FlowableBlock{
} }
} }
} }
return false; return false;
} }
@ -72,9 +78,10 @@ class WheatBlock extends FlowableBlock{
if($this->meta >= 0x07){ if($this->meta >= 0x07){
$drops[] = array(WHEAT, 0, 1); $drops[] = array(WHEAT, 0, 1);
$drops[] = array(WHEAT_SEEDS, 0, mt_rand(0, 3)); $drops[] = array(WHEAT_SEEDS, 0, mt_rand(0, 3));
}else{ } else{
$drops[] = array(WHEAT_SEEDS, 0, 1); $drops[] = array(WHEAT_SEEDS, 0, 1);
} }
return $drops; return $drops;
} }
} }

View File

@ -49,6 +49,7 @@ class WoodBlock extends SolidBlock{
$this->meta = ($this->meta & 0x03) | $faces[$face]; $this->meta = ($this->meta & 0x03) | $faces[$face];
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }

View File

@ -28,10 +28,10 @@ class WoodSlabBlock extends TransparentBlock{
2 => "Birch", 2 => "Birch",
3 => "Jungle", 3 => "Jungle",
); );
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Wooden Slab"; $this->name = (($this->meta & 0x08) === 0x08 ? "Upper " : "") . $names[$this->meta & 0x07] . " Wooden Slab";
if(($this->meta & 0x08) === 0x08){ if(($this->meta & 0x08) === 0x08){
$this->isFullBlock = true; $this->isFullBlock = true;
}else{ } else{
$this->isFullBlock = false; $this->isFullBlock = false;
} }
$this->hardness = 15; $this->hardness = 15;
@ -42,40 +42,47 @@ class WoodSlabBlock extends TransparentBlock{
if($face === 0){ if($face === 0){
if($target->getID() === WOOD_SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ if($target->getID() === WOOD_SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); $this->level->setBlock($target, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true; return true;
}elseif($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ } elseif($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); $this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true; return true;
}else{ } else{
$this->meta |= 0x08; $this->meta |= 0x08;
} }
}elseif($face === 1){ } elseif($face === 1){
if($target->getID() === WOOD_SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ if($target->getID() === WOOD_SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); $this->level->setBlock($target, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true; return true;
}elseif($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ } elseif($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); $this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true; return true;
} }
}elseif(!$player->entity->inBlock($block)){ } elseif(!$player->entity->inBlock($block)){
if($block->getID() === WOOD_SLAB){ if($block->getID() === WOOD_SLAB){
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); $this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true; return true;
} }
return false; return false;
}else{ } else{
if($fy > 0.5){ if($fy > 0.5){
$this->meta |= 0x08; $this->meta |= 0x08;
} }
} }
}else{ } else{
return false; return false;
} }
if($block->getID() === WOOD_SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){ if($block->getID() === WOOD_SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
return false; return false;
} }
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }

View File

@ -28,6 +28,7 @@ class WorkbenchBlock extends SolidBlock{
public function onActivate(Item $item, Player $player){ public function onActivate(Item $item, Player $player){
$player->toCraft[-1] = 1; $player->toCraft[-1] = 1;
return true; return true;
} }

View File

@ -48,23 +48,23 @@ const BLOCK_UPDATE_TOUCH = 5;
const ENTITY_PLAYER = 1; const ENTITY_PLAYER = 1;
const ENTITY_MOB = 2; const ENTITY_MOB = 2;
const MOB_CHICKEN = 10; const MOB_CHICKEN = 10;
const MOB_COW = 11; const MOB_COW = 11;
const MOB_PIG = 12; const MOB_PIG = 12;
const MOB_SHEEP = 13; const MOB_SHEEP = 13;
const MOB_ZOMBIE = 32; const MOB_ZOMBIE = 32;
const MOB_CREEPER = 33; const MOB_CREEPER = 33;
const MOB_SKELETON = 34; const MOB_SKELETON = 34;
const MOB_SPIDER = 35; const MOB_SPIDER = 35;
const MOB_PIGMAN = 36; const MOB_PIGMAN = 36;
const ENTITY_OBJECT = 3; const ENTITY_OBJECT = 3;
const OBJECT_PRIMEDTNT = 65; const OBJECT_PRIMEDTNT = 65;
const OBJECT_ARROW = 80; const OBJECT_ARROW = 80;
const OBJECT_PAINTING = 83; const OBJECT_PAINTING = 83;
const ENTITY_ITEM = 4; const ENTITY_ITEM = 4;
const ENTITY_FALLING = 5; const ENTITY_FALLING = 5;
const FALLING_SAND = 66; const FALLING_SAND = 66;

View File

@ -21,23 +21,23 @@
namespace PocketMine; namespace PocketMine;
const IRON_SHOVEL = 256;//Implemented const IRON_SHOVEL = 256; //Implemented
const IRON_PICKAXE = 257;//Implemented const IRON_PICKAXE = 257; //Implemented
const IRON_AXE = 258;//Implemented const IRON_AXE = 258; //Implemented
const FLINT_STEEL = 259; const FLINT_STEEL = 259;
const FLINT_AND_STEEL = 259; const FLINT_AND_STEEL = 259;
const APPLE = 260;//Implemented const APPLE = 260; //Implemented
const BOW = 261; const BOW = 261;
const ARROW = 262; const ARROW = 262;
const COAL = 263;//Implemented const COAL = 263; //Implemented
const DIAMOND = 264;//Implemented const DIAMOND = 264; //Implemented
const IRON_INGOT = 265;//Implemented const IRON_INGOT = 265; //Implemented
const GOLD_INGOT = 266;//Implemented const GOLD_INGOT = 266; //Implemented
const IRON_SWORD = 267; const IRON_SWORD = 267;
const WOODEN_SWORD = 268;//Implemented const WOODEN_SWORD = 268; //Implemented
const WOODEN_SHOVEL = 269;//Implemented const WOODEN_SHOVEL = 269; //Implemented
const WOODEN_PICKAXE = 270;//Implemented const WOODEN_PICKAXE = 270; //Implemented
const WOODEN_AXE = 271;//Implemented const WOODEN_AXE = 271; //Implemented
const STONE_SWORD = 272; const STONE_SWORD = 272;
const STONE_SHOVEL = 273; const STONE_SHOVEL = 273;
const STONE_PICKAXE = 274; const STONE_PICKAXE = 274;
@ -46,9 +46,9 @@ const DIAMOND_SWORD = 276;
const DIAMOND_SHOVEL = 277; const DIAMOND_SHOVEL = 277;
const DIAMOND_PICKAXE = 278; const DIAMOND_PICKAXE = 278;
const DIAMOND_AXE = 279; const DIAMOND_AXE = 279;
const STICK = 280;//Implemented const STICK = 280; //Implemented
const STICKS = 280; const STICKS = 280;
const BOWL = 281;//Implemented const BOWL = 281; //Implemented
const MUSHROOM_STEW = 282; const MUSHROOM_STEW = 282;
const GOLD_SWORD = 283; const GOLD_SWORD = 283;
const GOLD_SHOVEL = 284; const GOLD_SHOVEL = 284;
@ -59,11 +59,11 @@ const GOLDEN_SHOVEL = 284;
const GOLDEN_PICKAXE = 285; const GOLDEN_PICKAXE = 285;
const GOLDEN_AXE = 286; const GOLDEN_AXE = 286;
const STRING = 287; const STRING = 287;
const FEATHER = 288;//Implemented const FEATHER = 288; //Implemented
const GUNPOWDER = 289; const GUNPOWDER = 289;
const WOODEN_HOE = 290; const WOODEN_HOE = 290;
const STONE_HOE = 291; const STONE_HOE = 291;
const IRON_HOE = 292;//Implemented const IRON_HOE = 292; //Implemented
const DIAMOND_HOE = 293; const DIAMOND_HOE = 293;
const GOLD_HOE = 294; const GOLD_HOE = 294;
const GOLDEN_HOE = 294; const GOLDEN_HOE = 294;
@ -152,7 +152,7 @@ const SPAWN_EGG = 383;
const CARROT = 391; const CARROT = 391;
const CARROTS = 391; const CARROTS = 391;
const POTATO = 392; const POTATO = 392;
const POTATOES = 392;//@shoghicp Why the heck do we need plural redundant Item ID here???? const POTATOES = 392; //@shoghicp Why the heck do we need plural redundant Item ID here????
const BAKED_POTATO = 393; const BAKED_POTATO = 393;
const BAKED_POTATOES = 393; const BAKED_POTATOES = 393;

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine; use PocketMine;
interface Ageable{ interface Ageable{

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine; use PocketMine;
abstract class Animal extends Creature implements Ageable{ abstract class Animal extends Creature implements Ageable{

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine; use PocketMine;
class Arrow extends Projectile{ class Arrow extends Projectile{

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine; use PocketMine;
interface Attachable{ interface Attachable{

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine; use PocketMine;
class Chicken extends Animal{ class Chicken extends Animal{

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine; use PocketMine;
interface Colorable{ interface Colorable{

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine; use PocketMine;
class Cow extends Animal{ class Cow extends Animal{

View File

@ -20,6 +20,7 @@
*/ */
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine; use PocketMine;
abstract class Creature extends Living{ abstract class Creature extends Living{

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