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

View File

@ -20,33 +20,34 @@
*/
namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Utils\Config as Config;
use PocketMine\Player as Player;
class BanAPI{
private $server;
/*
* I would use PHPDoc Template here but PHPStorm does not recognise it. - @sekjun9878
*/
/** @var Config */
/*
* I would use PHPDoc Template here but PHPStorm does not recognise it. - @sekjun9878
*/
/** @var Config */
private $whitelist;
/** @var Config */
/** @var Config */
private $banned;
/** @var Config */
/** @var Config */
private $ops;
/** @var Config */
/** @var Config */
private $bannedIPs;
private $cmdWhitelist = array();//Command WhiteList
private $cmdWhitelist = array(); //Command WhiteList
function __construct(){
$this->server = ServerAPI::request();
}
public function init(){
$this->whitelist = new Config(\PocketMine\DATA."white-list.txt", Config::ENUM);//Open whitelist list file
$this->bannedIPs = new Config(\PocketMine\DATA."banned-ips.txt", Config::ENUM);//Open Banned IPs list file
$this->banned = new Config(\PocketMine\DATA."banned.txt", Config::ENUM);//Open Banned Usernames list file
$this->ops = new Config(\PocketMine\DATA."ops.txt", Config::ENUM);//Open list of OPs
$this->whitelist = new Config(\PocketMine\DATA . "white-list.txt", Config::ENUM); //Open whitelist list file
$this->bannedIPs = new Config(\PocketMine\DATA . "banned-ips.txt", Config::ENUM); //Open Banned IPs list file
$this->banned = new Config(\PocketMine\DATA . "banned.txt", Config::ENUM); //Open Banned Usernames list file
$this->ops = new Config(\PocketMine\DATA . "ops.txt", Config::ENUM); //Open list of OPs
$this->server->api->console->register("banip", "<add|remove|list|reload> [IP|player]", array($this, "commandHandler"));
$this->server->api->console->register("ban", "<add|remove|list|reload> [username]", array($this, "commandHandler"));
$this->server->api->console->register("kick", "<player> [reason ...]", array($this, "commandHandler"));
@ -58,58 +59,60 @@ class BanAPI{
$this->server->api->console->alias("banlist", "ban list");
$this->server->api->console->alias("pardon", "ban 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("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.flying", array($this, "permissionsCheck"), 1);//Flying Event
$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.place", array($this, "permissionsCheck"), 1); //Event handler for blocks
$this->server->addHandler("player.flying", array($this, "permissionsCheck"), 1); //Flying Event
}
/**
* @param string $cmd Command to Whitelist
*/
public function cmdWhitelist($cmd){//Whitelists a CMD so everyone can issue it - Even non OPs.
/**
* @param string $cmd Command to Whitelist
*/
public function cmdWhitelist($cmd){ //Whitelists a CMD so everyone can issue it - Even non OPs.
$this->cmdWhitelist[strtolower(trim($cmd))] = true;
}
/**
* @param string $username
*
* @return boolean
*/
public function isOp($username){//Is a player op?
/**
* @param string $username
*
* @return boolean
*/
public function isOp($username){ //Is a player op?
$username = strtolower($username);
if($this->server->api->dhandle("op.check", $username) === true){
return true;
}elseif($this->ops->exists($username)){
} elseif($this->ops->exists($username)){
return true;
}
return false;
}
/**
* @param mixed $data
* @param string $event
*
* @return boolean
*/
public function permissionsCheck($data, $event){
/**
* @param mixed $data
* @param string $event
*
* @return boolean
*/
public function permissionsCheck($data, $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())){
return true;
}
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())){
$t = new Vector2($data["target"]->x, $data["target"]->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;
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"]])){
return;
}
@ -118,22 +121,23 @@ class BanAPI{
if($this->server->api->handle("console.check", $data) === true or $this->isOp($data["issuer"]->getUsername())){
return;
}
}elseif($data["issuer"] === "console" or $data["issuer"] === "rcon"){
} elseif($data["issuer"] === "console" or $data["issuer"] === "rcon"){
return;
}
return false;
}
}
/**
* @param string $cmd
* @param array $params
* @param string $issuer
* @param string $alias
*
* @return string
*/
public function commandHandler($cmd, $params, $issuer, $alias){
/**
* @param string $cmd
* @param array $params
* @param string $issuer
* @param string $alias
*
* @return string
*/
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "sudo":
@ -144,24 +148,24 @@ class BanAPI{
break;
}
$this->server->api->console->run(implode(" ", $params), $player);
$output .= "Command ran as ".$player->getUsername().".\n";
$output .= "Command ran as " . $player->getUsername() . ".\n";
break;
case "op":
$user = strtolower($params[0]);
if($user == NULL){
$output .= "Usage: /op <player>\n";
break;
if($user == null){
$output .= "Usage: /op <player>\n";
break;
}
$player = Player::get($user);
if(!($player instanceof Player)){
$this->ops->set($user);
$this->ops->save();
$output .= $user." is now op\n";
$output .= $user . " is now op\n";
break;
}
$this->ops->set(strtolower($player->getUsername()));
$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());
break;
case "deop":
@ -170,32 +174,32 @@ class BanAPI{
if(!($player instanceof Player)){
$this->ops->remove($user);
$this->ops->save();
$output .= $user." is no longer op\n";
$output .= $user . " is no longer op\n";
break;
}
$this->ops->remove(strtolower($player->getUsername()));
$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());
break;
case "kick":
if(!isset($params[0])){
$output .= "Usage: /kick <player> [reason ...]\n";
}else{
} else{
$name = strtolower(array_shift($params));
$player = Player::get($name);
if($player === false){
$output .= "Player \"".$name."\" does not exist\n";
}else{
$output .= "Player \"" . $name . "\" does not exist\n";
} else{
$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;
if($issuer instanceof Player){
$this->server->api->chat->broadcast($player->getUsername()." has been kicked by ".$issuer->getUsername().": $reason\n");
}else{
$this->server->api->chat->broadcast($player->getUsername()." has been kicked: $reason\n");
$this->server->api->chat->broadcast($player->getUsername() . " has been kicked by " . $issuer->getUsername() . ": $reason\n");
} else{
$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";
break;
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;
case "list":
$output .= "White-list: ".implode(", ", $this->whitelist->getAll(true))."\n";
$output .= "White-list: " . implode(", ", $this->whitelist->getAll(true)) . "\n";
break;
case "on":
case "true":
@ -261,10 +265,10 @@ class BanAPI{
$output .= "IP \"$ip\" added to ban list\n";
break;
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;
case "list":
$output .= "IP ban list: ".implode(", ", $this->bannedIPs->getAll(true))."\n";
$output .= "IP ban list: " . implode(", ", $this->bannedIPs->getAll(true)) . "\n";
break;
default:
$output .= "Usage: /banip <add|remove|list|reload> [IP|player]\n";
@ -291,18 +295,18 @@ class BanAPI{
$player->close("You have been banned");
}
if($issuer instanceof Player){
$this->server->api->chat->broadcast($user." has been banned by ".$issuer->getUsername()."\n");
}else{
$this->server->api->chat->broadcast($user." has been banned\n");
$this->server->api->chat->broadcast($user . " has been banned by " . $issuer->getUsername() . "\n");
} else{
$this->server->api->chat->broadcast($user . " has been banned\n");
}
$this->kick($user, "Banned");
$output .= "Player \"$user\" added to ban list\n";
break;
case "reload":
$this->banned = new Config(\PocketMine\DATA."banned.txt", Config::ENUM);
$this->banned = new Config(\PocketMine\DATA . "banned.txt", Config::ENUM);
break;
case "list":
$output .= "Ban list: ".implode(", ", $this->banned->getAll(true))."\n";
$output .= "Ban list: " . implode(", ", $this->banned->getAll(true)) . "\n";
break;
default:
$output .= "Usage: /ban <add|remove|list|reload> [username]\n";
@ -310,42 +314,43 @@ class BanAPI{
}
break;
}
return $output;
}
/**
* @param string $username
*/
public function ban($username){
/**
* @param string $username
*/
public function ban($username){
$this->commandHandler("ban", array("add", $username), "console", "");
}
/**
* @param string $username
*/
/**
* @param string $username
*/
public function pardon($username){
$this->commandHandler("ban", array("pardon", $username), "console", "");
}
/**
* @param string $ip
*/
/**
* @param string $ip
*/
public function banIP($ip){
$this->commandHandler("banip", array("add", $ip), "console", "");
}
/**
* @param string $ip
*/
/**
* @param string $ip
*/
public function pardonIP($ip){
$this->commandHandler("banip", array("pardon", $ip), "console", "");
}
/**
* @param string $username
* @param string $reason
*/
public function kick($username, $reason = "No Reason"){
/**
* @param string $username
* @param string $reason
*/
public function kick($username, $reason = "No Reason"){
$this->commandHandler("kick", array($username, $reason), "console", "");
}
@ -355,51 +360,52 @@ class BanAPI{
$this->commandHandler("whitelist", array("reload"), "console", "");
}
/**
* @param string $ip
*
* @return boolean
*/
public function isIPBanned($ip){
/**
* @param string $ip
*
* @return boolean
*/
public function isIPBanned($ip){
if($this->server->api->dhandle("api.ban.ip.check", $ip) === false){
return true;
}elseif($this->bannedIPs->exists($ip, true)){
} elseif($this->bannedIPs->exists($ip, true)){
return true;
}else{
} else{
return false;
}
}
}
/**
* @param string $username
*
* @return boolean
*/
public function isBanned($username){
/**
* @param string $username
*
* @return boolean
*/
public function isBanned($username){
$username = strtolower($username);
if($this->server->api->dhandle("api.ban.check", $username) === false){
return true;
}elseif($this->banned->exists($username, true)){
} elseif($this->banned->exists($username, true)){
return true;
}else{
} else{
return false;
}
}
}
/**
* @param string $username
*
* @return boolean
*/
public function inWhitelist($username){
/**
* @param string $username
*
* @return boolean
*/
public function inWhitelist($username){
$username = strtolower($username);
if($this->isOp($username)){
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;
}elseif($this->whitelist->exists($username, true)){
} elseif($this->whitelist->exists($username, true)){
return true;
}
return false;
}
}

View File

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

View File

@ -20,11 +20,13 @@
*/
namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Player as Player;
class ChatAPI{
private $server;
function __construct(){
$this->server = ServerAPI::request();
}
@ -38,15 +40,15 @@ class ChatAPI{
$this->server->api->console->alias("msg", "tell");
}
/**
* @param string $cmd
* @param array $params
* @param string $issuer
* @param string $alias
*
* @return string
*/
public function commandHandler($cmd, $params, $issuer, $alias){
/**
* @param string $cmd
* @param array $params
* @param string $issuer
* @param string $alias
*
* @return string
*/
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "say":
@ -55,20 +57,20 @@ class ChatAPI{
$output .= "Usage: /say <message>\n";
break;
}
$sender = ($issuer instanceof Player) ? "Server":ucfirst($issuer);
$this->server->api->chat->broadcast("[$sender] ".$s);
$sender = ($issuer instanceof Player) ? "Server" : ucfirst($issuer);
$this->server->api->chat->broadcast("[$sender] " . $s);
break;
case "me":
if(!($issuer instanceof Player)){
if($issuer === "rcon"){
$sender = "Rcon";
}else{
} else{
$sender = ucfirst($issuer);
}
}else{
} else{
$sender = $issuer->getUsername();
}
$this->broadcast("* $sender ".implode(" ", $params));
$this->broadcast("* $sender " . implode(" ", $params));
break;
case "tell":
if(!isset($params[0]) or !isset($params[1])){
@ -77,55 +79,56 @@ class ChatAPI{
}
if(!($issuer instanceof Player)){
$sender = ucfirst($issuer);
}else{
} else{
$sender = $issuer->getUsername();
}
$n = array_shift($params);
$target = Player::get($n);
if($target instanceof Player){
$target = $target->getUsername();
}else{
} else{
$target = strtolower($n);
if($target === "server" or $target === "console" or $target === "rcon"){
$target = "Console";
}
}
$mes = implode(" ", $params);
$output .= "[me -> ".$target."] ".$mes."\n";
$output .= "[me -> " . $target . "] " . $mes . "\n";
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"){
console("[INFO] [".$sender." -> ".$target."] ".$mes);
console("[INFO] [" . $sender . " -> " . $target . "] " . $mes);
}
break;
}
return $output;
}
/**
* @param string $message
*/
public function broadcast($message){
/**
* @param string $message
*/
public function broadcast($message){
$this->send(false, $message);
}
/**
* @param string $owner
* @param string $text
* @param mixed $player Can be either Player object or string username. Boolean false for broadcast.
*/
public function sendTo($owner, $text, $player){
/**
* @param string $owner
* @param string $text
* @param mixed $player Can be either Player object or string username. Boolean false for broadcast.
*/
public function sendTo($owner, $text, $player){
$this->send($owner, $text, array($player));
}
/**
* @param mixed $owner Can be either Player object or string username. Boolean false for broadcast.
* @param string $text
* @param $whitelist
* @param $blacklist
*/
public function send($owner, $text, $whitelist = false, $blacklist = false){
/**
* @param mixed $owner Can be either Player object or string username. Boolean false for broadcast.
* @param string $text
* @param $whitelist
* @param $blacklist
*/
public function send($owner, $text, $whitelist = false, $blacklist = false){
$message = array(
"player" => $owner,
"message" => $text,
@ -133,14 +136,14 @@ class ChatAPI{
if($owner !== false){
if($owner instanceof Player){
if($whitelist === false){
console("[INFO] <".$owner->getUsername()."> ".$text);
console("[INFO] <" . $owner->getUsername() . "> " . $text);
}
}else{
} else{
if($whitelist === false){
console("[INFO] <".$owner."> ".$text);
console("[INFO] <" . $owner . "> " . $text);
}
}
}else{
} else{
if($whitelist === false){
console("[INFO] $text");
}

View File

@ -20,12 +20,14 @@
*/
namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Utils\TextFormat as TextFormat;
use PocketMine\Player as Player;
class ConsoleAPI{
private $loop, $server, $event, $help, $cmds, $alias;
function __construct(){
$this->help = array();
$this->cmds = array();
@ -59,103 +61,105 @@ class ConsoleAPI{
}
public function defaultCommands($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "defaultgamemode":
$gms = array(
"0" => SURVIVAL,
"survival" => SURVIVAL,
"s" => SURVIVAL,
"1" => CREATIVE,
"creative" => CREATIVE,
"c" => CREATIVE,
"2" => ADVENTURE,
"adventure" => ADVENTURE,
"a" => ADVENTURE,
"3" => VIEW,
"view" => VIEW,
"viewer" => VIEW,
"spectator" => VIEW,
"v" => VIEW,
);
if(!isset($gms[strtolower($params[0])])){
$output .= "Usage: /$cmd <mode>\n";
break;
}
$this->server->api->setProperty("gamemode", $gms[strtolower($params[0])]);
$output .= "Default Gamemode is now ".strtoupper($this->server->getGamemode()).".\n";
break;
case "status":
if(!($issuer instanceof Player) and $issuer === "console"){
$this->server->debugInfo(true);
}
$info = $this->server->debugInfo();
$output .= "TPS: ".$info["tps"].", Memory usage: ".$info["memory_usage"]." (Peak ".$info["memory_peak_usage"].")\n";
break;
case "update-done":
$this->server->api->setProperty("last-update", time());
break;
case "stop":
$this->loop->stop = true;
$output .= "Stopping the server\n";
$this->server->close();
break;
case "difficulty":
$s = trim(array_shift($params));
if($s === "" or (((int) $s) > 3 and ((int) $s) < 0)){
$output .= "Usage: /difficulty <0|1|2|3>\n";
break;
}
$this->server->api->setProperty("difficulty", (int) $s);
$output .= "Difficulty changed to ".$this->server->difficulty."\n";
break;
case "?":
if($issuer !== "console" and $issuer !== "rcon"){
break;
}
case "help":
if(isset($params[0]) and !is_numeric($params[0])){
$c = trim(strtolower($params[0]));
if(isset($this->help[$c]) or isset($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){
break;
}
$output .= "Usage: /$c ".$this->help[$c]."\n";
break;
}
}
$cmds = array();
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){
continue;
}
$cmds[$c] = $h;
}
$max = ceil(count($cmds) / 5);
$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";
$current = 1;
foreach($cmds as $c => $h){
$curpage = (int) ceil($current / 5);
if($curpage === $page){
$output .= "/$c ".$h."\n";
}elseif($curpage > $page){
break;
}
++$current;
}
break;
default:
$output .= "Command doesn't exist! Use /help\n";
break;
$output = "";
switch($cmd){
case "defaultgamemode":
$gms = array(
"0" => SURVIVAL,
"survival" => SURVIVAL,
"s" => SURVIVAL,
"1" => CREATIVE,
"creative" => CREATIVE,
"c" => CREATIVE,
"2" => ADVENTURE,
"adventure" => ADVENTURE,
"a" => ADVENTURE,
"3" => VIEW,
"view" => VIEW,
"viewer" => VIEW,
"spectator" => VIEW,
"v" => VIEW,
);
if(!isset($gms[strtolower($params[0])])){
$output .= "Usage: /$cmd <mode>\n";
break;
}
$this->server->api->setProperty("gamemode", $gms[strtolower($params[0])]);
$output .= "Default Gamemode is now " . strtoupper($this->server->getGamemode()) . ".\n";
break;
case "status":
if(!($issuer instanceof Player) and $issuer === "console"){
$this->server->debugInfo(true);
}
$info = $this->server->debugInfo();
$output .= "TPS: " . $info["tps"] . ", Memory usage: " . $info["memory_usage"] . " (Peak " . $info["memory_peak_usage"] . ")\n";
break;
case "update-done":
$this->server->api->setProperty("last-update", time());
break;
case "stop":
$this->loop->stop = true;
$output .= "Stopping the server\n";
$this->server->close();
break;
case "difficulty":
$s = trim(array_shift($params));
if($s === "" or (((int) $s) > 3 and ((int) $s) < 0)){
$output .= "Usage: /difficulty <0|1|2|3>\n";
break;
}
$this->server->api->setProperty("difficulty", (int) $s);
$output .= "Difficulty changed to " . $this->server->difficulty . "\n";
break;
case "?":
if($issuer !== "console" and $issuer !== "rcon"){
break;
}
case "help":
if(isset($params[0]) and !is_numeric($params[0])){
$c = trim(strtolower($params[0]));
if(isset($this->help[$c]) or isset($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){
break;
}
$output .= "Usage: /$c " . $this->help[$c] . "\n";
break;
}
}
$cmds = array();
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){
continue;
}
$cmds[$c] = $h;
}
$max = ceil(count($cmds) / 5);
$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";
$current = 1;
foreach($cmds as $c => $h){
$curpage = (int) ceil($current / 5);
if($curpage === $page){
$output .= "/$c " . $h . "\n";
} elseif($curpage > $page){
break;
}
++$current;
}
break;
default:
$output .= "Command doesn't exist! Use /help\n";
break;
}
return $output;
}
public function alias($alias, $cmd){
$this->alias[strtolower(trim($alias))] = trim($cmd);
return true;
}
@ -179,12 +183,12 @@ class ConsoleAPI{
$cmd = strtolower(substr($line, 0, $end));
$params = (string) substr($line, $end + 1);
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){
console("[DEBUG] ".TextFormat::AQUA.$issuer->getUsername().TextFormat::RESET." issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2);
}else{
console("[DEBUG] ".TextFormat::YELLOW."*".$issuer.TextFormat::RESET." issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2);
console("[DEBUG] " . TextFormat::AQUA . $issuer->getUsername() . TextFormat::RESET . " issued server command: " . ltrim("$alias ") . "/$cmd " . $params, true, true, 2);
} else{
console("[DEBUG] " . 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){
@ -199,13 +203,13 @@ class ConsoleAPI{
case "u":
case "player":
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);
$offsetshift -= strlen($selector[0]) - strlen($p) + 1;
break;
case "w":
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);
$offsetshift -= strlen($selector[0]) - strlen($p) + 1;
break;
@ -215,17 +219,18 @@ class ConsoleAPI{
if($this->server->api->ban->isOp($issuer->getUsername())){
$output = "";
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");
}
}else{
} else{
$output = "";
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;
case "r":
case "random":
@ -251,13 +256,14 @@ class ConsoleAPI{
$params = array();
}
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){
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
){
$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])){
$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);
}
}
@ -265,6 +271,7 @@ class ConsoleAPI{
if($output != "" and ($issuer instanceof Player)){
$issuer->sendChat(trim($output));
}
return $output;
}
}
@ -280,10 +287,10 @@ class ConsoleAPI{
if($output != ""){
$mes = explode("\n", trim($output));
foreach($mes as $m){
console("[CMD] ".$m);
console("[CMD] " . $m);
}
}
}else{
} else{
$this->loop->notify();
}
}
@ -296,6 +303,7 @@ class ConsoleLoop extends \Thread{
public $base;
public $ev;
public $fp;
public function __construct(){
$this->line = false;
$this->stop = false;
@ -309,12 +317,13 @@ class ConsoleLoop extends \Thread{
private function readLine(){
if($this->fp){
$line = trim(fgets($this->fp));
}else{
} else{
$line = trim(readline(""));
if($line != ""){
readline_add_history( $line );
readline_add_history($line);
}
}
return $line;
}

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -20,6 +20,7 @@
*/
namespace PocketMine;
use PocketMine\Entity\RealHuman as RealHuman;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\NBT\Tag\Compound as Compound;
@ -125,7 +126,7 @@ class Player extends RealHuman{
foreach(Player::$list as $player){
if($multiple === false and $player->iusername === $name){
return $player;
}elseif(strpos($player->iusername, $name) !== false){
} elseif(strpos($player->iusername, $name) !== false){
$players[$player->CID] = $player;
}
}
@ -133,10 +134,10 @@ class Player extends RealHuman{
if($multiple === false){
if(count($players) > 0){
return array_shift($players);
}else{
} else{
return false;
}
}else{
} else{
return $players;
}
}
@ -148,13 +149,13 @@ class Player extends RealHuman{
public static function getOffline($name){
$server = ServerAPI::request();
$iname = strtolower($name);
if(!file_exists(\PocketMine\DATA."players/".$iname.".dat")){
if(!file_exists(\PocketMine\DATA . "players/" . $iname . ".dat")){
$nbt = new Compound(false, array(
"Pos" => new Enum("Pos", array(
0 => new Double(0, $server->spawn->x),
1 => new Double(1, $server->spawn->y),
2 => new Double(2, $server->spawn->z)
)),
0 => new Double(0, $server->spawn->x),
1 => new Double(1, $server->spawn->y),
2 => new Double(2, $server->spawn->z)
)),
"Level" => new String("Level", $server->spawn->level->getName()),
"SpawnLevel" => new String("SpawnLevel", $server->spawn->level->getName()),
"SpawnX" => new Int("SpawnX", (int) $server->spawn->x),
@ -165,14 +166,14 @@ class Player extends RealHuman{
"Achievements" => new Compound("Achievements", array()),
"playerGameType" => new Int("playerGameType", $server->gamemode),
"Motion" => new Enum("Motion", array(
0 => new Double(0, 0.0),
1 => new Double(1, 0.0),
2 => new Double(2, 0.0)
)),
0 => new Double(0, 0.0),
1 => new Double(1, 0.0),
2 => new Double(2, 0.0)
)),
"Rotation" => new Enum("Rotation", array(
0 => new Float(0, 0.0),
1 => new Float(1, 0.0)
)),
0 => new Float(0, 0.0),
1 => new Float(1, 0.0)
)),
"FallDistance" => new Float("FallDistance", 0.0),
"Fire" => new Short("Fire", 0),
"Air" => new Short("Air", 0),
@ -185,8 +186,8 @@ class Player extends RealHuman{
$nbt->Inventory->setTagType(NBT\TAG_Compound);
$nbt->Motion->setTagType(NBT\TAG_Double);
$nbt->Rotation->setTagType(NBT\TAG_Float);
if(file_exists(\PocketMine\DATA."players/".$iname.".yml")){
$data = new Config(\PocketMine\DATA."players/".$iname.".yml", Config::YAML, array());
if(file_exists(\PocketMine\DATA . "players/" . $iname . ".yml")){
$data = new Config(\PocketMine\DATA . "players/" . $iname . ".yml", Config::YAML, array());
$nbt->playerGameType = (int) $data->get("gamemode");
$nbt->Level = $data->get("position")["level"];
$nbt->Pos[0] = $data->get("position")["x"];
@ -196,7 +197,7 @@ class Player extends RealHuman{
$nbt->SpawnX = (int) $data->get("spawn")["x"];
$nbt->SpawnY = (int) $data->get("spawn")["y"];
$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){
if(count($item) === 3){
$nbt->Inventory[$slot + 9] = new Compound(false, array(
@ -212,11 +213,11 @@ class Player extends RealHuman{
if(isset($nbt->Inventory[$itemSlot + 9])){
$item = $nbt->Inventory[$itemSlot + 9];
$nbt->Inventory[$slot] = new Compound(false, array(
"id" => new Short("id", $item->id),
"Damage" => new Short("Damage", $item->Damage),
"Count" => new Byte("Count", $item->Count),
"Slot" => new Byte("Slot", $slot),
"TrueSlot" => new Byte("TrueSlot", $item->TrueSlot)
"id" => new Short("id", $item->id),
"Damage" => new Short("Damage", $item->Damage),
"Count" => new Byte("Count", $item->Count),
"Slot" => new Byte("Slot", $slot),
"TrueSlot" => new Byte("TrueSlot", $item->TrueSlot)
));
}
}
@ -231,17 +232,17 @@ class Player extends RealHuman{
}
}
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");
}else{
console("[NOTICE] Player data not found for \"".$iname."\", creating new profile");
unlink(\PocketMine\DATA . "players/" . $iname . ".yml");
} else{
console("[NOTICE] Player data not found for \"" . $iname . "\", creating new profile");
Player::saveOffline($name, $nbt);
}
}else{
} else{
$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();
}
@ -254,7 +255,7 @@ class Player extends RealHuman{
ServerAPI::request()->handle("player.offline.save", $nbtTag);
$nbt = new NBT(NBT\BIG_ENDIAN);
$nbt->setData($nbtTag);
file_put_contents(\PocketMine\DATA."players/".strtolower($name).".dat", $nbt->write());
file_put_contents(\PocketMine\DATA . "players/" . strtolower($name) . ".dat", $nbt->write());
}
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){
$this->achievements[$achievementId] = true;
Achievement::broadcast($this, $achievementId);
return true;
}else{
} else{
return false;
}
}
return false;
}
public function hasAchievement($achievementId){
if(!isset(Achievement::$list[$achievementId]) or !isset($this->achievements)){
$this->achievements = array();
return false;
}
if(!isset($this->achievements[$achievementId]) or $this->achievements[$achievementId] == false){
return false;
}
return true;
}
@ -328,7 +333,7 @@ class Player extends RealHuman{
/**
* @param integer $clientID
* @param string $ip
* @param string $ip
* @param integer $port
* @param integer $MTU
*/
@ -349,13 +354,13 @@ class Player extends RealHuman{
$this->viewDistance = (int) $this->server->api->getProperty("view-distance");
$this->slot = 0;
$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->data = array();
$this->server->schedule(2, array($this, "handlePacketQueues"), array(), true);
$this->server->schedule(20 * 60, array($this, "clearQueue"), array(), true);
$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(){
@ -368,7 +373,7 @@ class Player extends RealHuman{
public function setSpawn(Vector3 $pos){
if(!($pos instanceof Position)){
$level = $this->level;
}else{
} else{
$level = $pos->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->chunkScheduled;
}
return;
}else{
} else{
unset($this->chunkCount[$count]);
}
}
@ -478,6 +484,7 @@ class Player extends RealHuman{
if($this->chunkScheduled === 0){
$this->server->schedule(40, array($this, "getNextChunk"));
}
return false;
}
$X = null;
@ -489,6 +496,7 @@ class Player extends RealHuman{
$this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk"));
++$this->chunkScheduled;
}
return false;
}
unset($this->chunksOrder[$index]);
@ -529,7 +537,7 @@ class Player extends RealHuman{
$this->namedtag->SpawnZ = (int) $this->spawnPosition->z;
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;
@ -538,8 +546,8 @@ class Player extends RealHuman{
}
/**
* @param string $reason Reason for closing connection
* @param boolean $msg Set to false to silently disconnect player. No broadcast.
* @param string $reason Reason for closing connection
* @param boolean $msg Set to false to silently disconnect player. No broadcast.
*/
public function close($reason = "", $msg = true){
if($this->connected === true){
@ -550,8 +558,8 @@ class Player extends RealHuman{
$this->server->api->handle("player.quit", $this);
$this->save();
}
$reason = $reason == "" ? "server stop":$reason;
$this->sendChat("You have been kicked. Reason: ".$reason."\n");
$reason = $reason == "" ? "server stop" : $reason;
$this->sendChat("You have been kicked. Reason: " . $reason . "\n");
$this->sendBuffer();
$this->directDataPacket(new Network\Protocol\DisconnectPacket);
unset(Player::$list[$this->CID]);
@ -568,10 +576,10 @@ class Player extends RealHuman{
Player::saveOffline($this->username, $this->namedtag);
}
if($msg === true and $this->username != "" and $this->spawned !== false){
$this->server->api->chat->broadcast($this->username." left the game");
$this->server->api->chat->broadcast($this->username . " left the game");
}
$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->armor = array();
$this->inventory = array();
@ -584,12 +592,12 @@ class Player extends RealHuman{
}
}
/**
* @param Vector3 $pos
*
* @return boolean
*/
public function sleepOn(Vector3 $pos){
/**
* @param Vector3 $pos
*
* @return boolean
*/
public function sleepOn(Vector3 $pos){
foreach($this->level->getPlayers() as $p){
if($p->sleeping instanceof Vector3){
if($pos->distance($p->sleeping) <= 0.1){
@ -604,13 +612,14 @@ class Player extends RealHuman{
}*/
$this->setSpawn($pos);
$this->server->schedule(60, array($this, "checkSleep"));
return true;
}
public function stopSleep(){
$this->sleeping = false;
//if($this->entity instanceof Entity){
//$this->entity->updateMetadata();
//$this->entity->updateMetadata();
//}
}
@ -632,7 +641,8 @@ class Player extends RealHuman{
public function sendInventorySlot($s){
$this->sendInventory();
return;
return; //TODO: Check if Mojang adds this
$s = (int) $s;
if(!isset($this->inventory[$s])){
$pk = new Network\Protocol\ContainerSetSlotPacket;
@ -648,14 +658,15 @@ class Player extends RealHuman{
$pk->slot = (int) $s;
$pk->item = $slot;
$this->dataPacket($pk);
return true;
}
/**
* @param mixed $data
* @param string $event
*/
public function eventHandler($data, $event){
/**
* @param mixed $data
* @param string $event
*/
public function eventHandler($data, $event){
switch($event){
case "tile.update":
if($data->level === $this->level){
@ -684,7 +695,7 @@ class Player extends RealHuman{
if($w === $data["tile"]){
$pk = new Network\Protocol\ContainerSetSlotPacket;
$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"];
$this->dataPacket($pk);
}
@ -709,7 +720,7 @@ class Player extends RealHuman{
$this->grantAchievement("diamond");
break;
}
}elseif($data["entity"]->level === $this->level){
} elseif($data["entity"]->level === $this->level){
$pk = new Network\Protocol\TakeItemEntityPacket;
$pk->eid = $data["eid"];
$pk->target = $data["entity"]->getID();
@ -728,7 +739,7 @@ class Player extends RealHuman{
case "entity.metadata":
if($data->getID() === $this->id){
$eid = 0;
}else{
} else{
$eid = $data->getID();
}
if($data->level === $this->level){
@ -741,7 +752,7 @@ class Player extends RealHuman{
case "entity.event":
if($data["entity"]->getID() === $this->id){
$eid = 0;
}else{
} else{
$eid = $data["entity"]->getID();
}
if($data["entity"]->level === $this->level){
@ -755,22 +766,22 @@ class Player extends RealHuman{
if(($data instanceof Container) === true){
if(!$data->check($this->username) and !$data->check($this->iusername)){
return;
}else{
} else{
$message = $data->get();
$this->sendChat($message["message"], $message["player"]);
}
}else{
} else{
$this->sendChat((string) $data);
}
break;
}
}
/**
* @param string $message
* @param string $author
*/
public function sendChat($message, $author = ""){
/**
* @param string $message
* @param string $author
*/
public function sendChat($message, $author = ""){
$mes = explode("\n", $message);
foreach($mes as $m){
if(preg_match_all('#@([@A-Za-z_]{1,})#', $m, $matches, PREG_OFFSET_CAPTURE) > 0){
@ -793,7 +804,7 @@ class Player extends RealHuman{
if($m !== ""){
$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 :(
$this->dataPacket($pk);
}
@ -850,14 +861,14 @@ class Player extends RealHuman{
$this->dataPacket($pk);
}
/**
* @param array $craft
* @param array $recipe
* @param $type
*
* @return array|bool
*/
public function craftItems(array $craft, array $recipe, $type){
/**
* @param array $craft
* @param array $recipe
* @param $type
*
* @return array|bool
*/
public function craftItems(array $craft, array $recipe, $type){
$craftItem = array(0, true, 0);
unset($craft[-1]);
foreach($craft as $slot => $item){
@ -865,7 +876,7 @@ class Player extends RealHuman{
$craftItem[0] = $item->getID();
if($item->getMetadata() !== $craftItem[1] and $craftItem[1] !== true){
$craftItem[1] = false;
}else{
} else{
$craftItem[1] = $item->getMetadata();
}
$craftItem[2] += $item->getCount();
@ -877,7 +888,7 @@ class Player extends RealHuman{
foreach($recipe as $slot => $item){
if(!isset($recipeItems[$item->getID()])){
$recipeItems[$item->getID()] = array($item->getID(), $item->getMetadata(), $item->getCount());
}else{
} else{
if($item->getMetadata() !== $recipeItems[$item->getID()][1]){
$recipeItems[$item->getID()][1] = false;
}
@ -910,7 +921,7 @@ class Player extends RealHuman{
$s = $this->getSlot($slot);
if($s->getCount() <= 0 or $s->getID() === AIR){
$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()));
}
@ -952,6 +963,7 @@ class Player extends RealHuman{
}
}
}
return $res;
}
@ -984,16 +996,17 @@ class Player extends RealHuman{
$inv =& $this->inventory;
if(($this->gamemode & 0x01) === ($gm & 0x01)){
$this->gamemode = $gm;
$this->sendChat("Your gamemode has been changed to ".$this->getGamemode().".\n");
}else{
$this->sendChat("Your gamemode has been changed to " . $this->getGamemode() . ".\n");
} else{
$this->blocked = true;
$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->inventory = $inv;
$this->sendSettings();
$this->sendInventory();
return true;
}
@ -1003,7 +1016,7 @@ class Player extends RealHuman{
}
if($this->packetStats[1] > 2){
$this->packetLoss = $this->packetStats[1] / max(1, $this->packetStats[0] + $this->packetStats[1]);
}else{
} else{
$this->packetLoss = 0;
}
$this->packetStats = array(0, 0);
@ -1051,6 +1064,7 @@ class Player extends RealHuman{
$time = microtime(true);
if($time > $this->timeout){
$this->close("timeout");
return false;
}
@ -1081,7 +1095,7 @@ class Player extends RealHuman{
if(isset($p->messageIndex) and $p->messageIndex !== false){
if($p->messageIndex > $this->receiveCount){
$this->receiveCount = $p->messageIndex;
}elseif($p->messageIndex !== 0){
} elseif($p->messageIndex !== 0){
if(isset($this->received[$p->messageIndex])){
continue;
}
@ -1232,6 +1246,7 @@ class Player extends RealHuman{
$this->loginData = array("clientId" => $packet->clientId, "loginData" => $packet->loginData);
if(count(Player::$list) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)){
$this->close("server is full!", false);
return;
}
if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){
@ -1239,28 +1254,33 @@ class Player extends RealHuman{
$pk = new Network\Protocol\LoginStatusPacket;
$pk->status = 1;
$this->directDataPacket($pk);
}else{
} else{
$pk = new Network\Protocol\LoginStatusPacket;
$pk->status = 2;
$this->directDataPacket($pk);
}
$this->close("Incorrect protocol #".$packet->protocol1, false);
$this->close("Incorrect protocol #" . $packet->protocol1, false);
return;
}
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);
return;
}
if($this->server->api->handle("player.connect", $this) === false){
$this->close("Unknown reason", false);
return;
}
if($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)){
$this->close("Server is white-listed", false);
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);
return;
}
$this->loggedIn = true;
@ -1287,11 +1307,13 @@ class Player extends RealHuman{
if($this->server->api->handle("player.join", $this) === false){
$this->close("join cancelled", false);
return;
}
if(!($nbt instanceof Compound)){
$this->close("no config created", false);
return;
}
@ -1312,7 +1334,7 @@ class Player extends RealHuman{
if(($this->gamemode & 0x01) === 0x01){
$this->slot = 0;
$this->hotbar[0] = 0;
}else{
} else{
$this->slot = $this->hotbar[0];
}
@ -1346,7 +1368,7 @@ class Player extends RealHuman{
$this->evid[] = $this->server->event("tile.update", array($this, "eventHandler"));
$this->lastMeasure = microtime(true);
$this->server->schedule(50, array($this, "measureLag"), array(), true);
console("[INFO] ".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;
case ProtocolInfo::READY_PACKET:
if($this->loggedIn === false){
@ -1360,7 +1382,7 @@ class Player extends RealHuman{
//$this->heal($this->data->get("health"), "spawn", true);
$this->spawned = true;
$this->spawnToAll();
$this->sendChat($this->server->motd."\n");
$this->sendChat($this->server->motd . "\n");
$this->sendInventory();
$this->sendSettings();
@ -1379,7 +1401,7 @@ class Player extends RealHuman{
$this->sendBuffer();
$this->server->handle("player.spawn", $this);
break;
case 2://Chunk loaded?
case 2: //Chunk loaded?
break;
}
break;
@ -1399,7 +1421,7 @@ class Player extends RealHuman{
if($this->forceMovement instanceof Vector3){
if($this->forceMovement->distance($newPos) <= 0.7){
$this->forceMovement = false;
}else{
} else{
$this->setPosition($this->forceMovement);
}
}
@ -1412,7 +1434,7 @@ class Player extends RealHuman{
console("[WARNING] ".$this->username." moved too quickly!");
}
}else{*/
$this->setPositionAndRotation($newPos, $packet->yaw, $packet->pitch);
$this->setPositionAndRotation($newPos, $packet->yaw, $packet->pitch);
//}
}
break;
@ -1423,7 +1445,7 @@ class Player extends RealHuman{
if($packet->slot === 0x28 or $packet->slot === 0){ //0 for 0.8.0 compatibility
$packet->slot = -1; //Air
}else{
} else{
$packet->slot -= 9;
}
@ -1436,13 +1458,13 @@ class Player extends RealHuman{
break;
}
}
}else{
} else{
$item = $this->getSlot($packet->slot);
}
if($packet->slot === false or EventHandler::callEvent(new PlayerEquipmentChangeEvent($this, $item, $packet->slot, 0)) === Event::DENY){
$this->sendInventorySlot($packet->slot);
}else{
} else{
$this->setEquipmentSlot(0, $packet->slot);
$this->setCurrentEquipmentSlot(0);
if(($this->gamemode & 0x01) === SURVIVAL){
@ -1510,12 +1532,12 @@ class Player extends RealHuman{
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);
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);
}else{
} else{
$this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->fx, $packet->fy, $packet->fz);
break;
}
@ -1538,7 +1560,7 @@ class Player extends RealHuman{
$pk->meta = $block->getMetadata();
$this->dataPacket($pk);
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->startAction = microtime(true);
//$this->updateMetadata();
@ -1649,7 +1671,7 @@ class Player extends RealHuman{
$s = $packet->slots[$i];
if($s === 0 or $s === 255){
$s = BlockAPI::getItem(AIR, 0, 0);
}else{
} else{
$s = BlockAPI::getItem($s + 256, 0, 1);
}
$slot = $this->getArmorSlot($i);
@ -1657,25 +1679,25 @@ class Player extends RealHuman{
if($this->setArmorSlot($i, BlockAPI::getItem(AIR, 0, 0)) === false){
$this->sendArmor();
$this->sendInventory();
}else{
} else{
$this->addItem($slot);
$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){
$this->sendArmor();
$this->sendInventory();
}else{
} else{
$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){
$this->sendArmor();
$this->sendInventory();
}else{
} else{
$this->setSlot($sl, $slot);
}
}else{
} else{
$packet->slots[$i] = 255;
}
@ -1890,12 +1912,12 @@ class Player extends RealHuman{
$message = $packet->message;
if($message{0} === "/"){ //Command
$this->server->api->console->run(substr($message, 1), $this);
}else{
} else{
$data = array("player" => $this, "message" => $message);
if($this->server->api->handle("player.chat", $data) !== false){
if(isset($data["message"])){
$this->server->api->chat->send($this, $data["message"]);
}else{
} else{
$this->server->api->chat->send($this, $message);
}
}
@ -1919,7 +1941,7 @@ class Player extends RealHuman{
$pk->case2 = 0;
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->x = $this->windows[$packet->windowid]->x;
$pk->y = $this->windows[$packet->windowid]->y;
@ -1943,7 +1965,7 @@ class Player extends RealHuman{
if($this->lastCraft <= (microtime(true) - 1)){
if(isset($this->toCraft[-1])){
$this->toCraft = array(-1 => $this->toCraft[-1]);
}else{
} else{
$this->toCraft = array();
}
$this->craftingItems = array();
@ -1956,14 +1978,14 @@ class Player extends RealHuman{
$use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->getCount() - $packet->item->getCount());
$this->craftingItems[$packet->slot] = $use;
$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());
if(count($this->toCraft) === 0){
$this->toCraft[-1] = 0;
}
$this->toCraft[$packet->slot] = $craftItem;
$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());
if(count($this->toCraft) === 0){
$this->toCraft[-1] = 0;
@ -1982,12 +2004,12 @@ class Player extends RealHuman{
if($recipe === false){
$this->sendInventory();
$this->toCraft = array();
}else{
} else{
$this->toCraft = array(-1 => $this->toCraft[-1]);
}
$this->craftingItems = array();
}
}else{
} else{
$this->toCraft = array();
$this->craftingItems = array();
}
@ -2001,11 +2023,11 @@ class Player extends RealHuman{
$tile = $tiles[0];
$slotn = $packet->slot;
$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];
$slotn = $packet->slot - Chest::SLOTS;
$offset = Chest::SLOTS;
}else{
} else{
break;
}
@ -2013,13 +2035,14 @@ class Player extends RealHuman{
$slot = $tile->getSlot($slotn);
if($this->server->api->dhandle("player.container.slot", array(
"tile" => $tile,
"slot" => $packet->slot,
"offset" => $offset,
"slotdata" => $slot,
"itemdata" => $item,
"player" => $this,
)) === false){
"tile" => $tile,
"slot" => $packet->slot,
"offset" => $offset,
"slotdata" => $slot,
"itemdata" => $item,
"player" => $this,
)) === false
){
$pk = new Network\Protocol\ContainerSetSlotPacket;
$pk->windowid = $packet->windowid;
$pk->slot = $packet->slot;
@ -2035,12 +2058,12 @@ class Player extends RealHuman{
$this->sendInventory();
break;
}
}elseif($slot->getCount() > $item->getCount()){
} elseif($slot->getCount() > $item->getCount()){
$it = clone $item;
$it->setCount($slot->getCount() - $item->getCount());
$this->addItem($it);
}
}else{
} else{
if($this->removeItem($item) === false){
$this->sendInventory();
break;
@ -2048,7 +2071,7 @@ class Player extends RealHuman{
$this->addItem($slot);
}
$tile->setSlot($slotn, $item, true, $offset);
}else{
} else{
$tile = $this->windows[$packet->windowid];
if(
!($tile instanceof Chest or $tile instanceof Furnace)
@ -2066,12 +2089,13 @@ class Player extends RealHuman{
$slot = $tile->getSlot($packet->slot);
if($this->server->api->dhandle("player.container.slot", array(
"tile" => $tile,
"slot" => $packet->slot,
"slotdata" => $slot,
"itemdata" => $item,
"player" => $this,
)) === false){
"tile" => $tile,
"slot" => $packet->slot,
"slotdata" => $slot,
"itemdata" => $item,
"player" => $this,
)) === false
){
$pk = new Network\Protocol\ContainerSetSlotPacket;
$pk->windowid = $packet->windowid;
$pk->slot = $packet->slot;
@ -2096,12 +2120,12 @@ class Player extends RealHuman{
$this->sendInventory();
break;
}
}elseif($slot->getCount() > $item->getCount()){
} elseif($slot->getCount() > $item->getCount()){
$it = clone $item;
$it->setCount($slot->count - $item->count);
$this->addItem($it);
}
}else{
} else{
if($this->removeItem($item) === false){
$this->sendInventory();
break;
@ -2126,19 +2150,19 @@ class Player extends RealHuman{
if($t instanceof Sign){
if($t->namedtag->creator !== $this->username){
$t->spawnTo($this);
}else{
} else{
$nbt = new NBT(NBT\LITTLE_ENDIAN);
$nbt->read($packet->namedtag);
if($nbt->id !== Tile::SIGN){
$t->spawnTo($this);
}else{
} else{
$t->setText($nbt->Text1, $nbt->Text2, $nbt->Text3, $nbt->Text4);
}
}
}
break;
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;
}
}
@ -2213,6 +2237,7 @@ class Player extends RealHuman{
$this->recoveryQueue[$count] = $rk;
$this->send($rk);
}
return $cnts;
}
@ -2234,16 +2259,17 @@ class Player extends RealHuman{
}
$this->send($pk);
return array($pk->seqNumber);
}
/**
* @param integer $id
* @param array $data
*
* @return array|bool
*/
public function dataPacket(DataPacket $packet){
/**
* @param integer $id
* @param array $data
*
* @return array|bool
*/
public function dataPacket(DataPacket $packet){
if($this->connected === false){
return false;
}
@ -2267,6 +2293,7 @@ class Player extends RealHuman{
$packet->reliability = 2;
@$this->buffer->data[] = $packet;
$this->bufferLen += 6 + $len;
return array();
}

View File

@ -14,12 +14,13 @@
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
* @link http://www.pocketmine.net/
*
*
*/
namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Entity\Entity as Entity;
use PocketMine\Player as Player;
@ -29,6 +30,7 @@ use PocketMine\Level\Position as Position;
class PlayerAPI{
private $server;
function __construct(){
$this->server = ServerAPI::request();
}
@ -75,14 +77,14 @@ class PlayerAPI{
if($e instanceof Entity){
switch($e->class){
case ENTITY_PLAYER:
$message = " was killed by ".$e->name;
$message = " was killed by " . $e->name;
break;
default:
$message = " was killed";
break;
}
}
}else{
} else{
switch($data["cause"]){
case "cactus":
$message = " was pricked to death";
@ -117,8 +119,10 @@ class PlayerAPI{
}
}
$this->server->api->chat->broadcast($data["player"]->getUsername() . $message);
return true;
}
return;
}
public function commandHandler($cmd, $params, $issuer, $alias){
@ -138,10 +142,10 @@ class PlayerAPI{
$tg = array_shift($params);
if(count($params) === 3 and substr($tg, 0, 2) === "w:"){
$target = $this->server->api->level->get(substr($tg, 2));
}else{
} else{
$target = Player::get($tg);
}
}else{
} else{
$target = $issuer;
}
@ -153,19 +157,19 @@ class PlayerAPI{
if(count($params) === 3){
if($target instanceof Level){
$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);
}
}else{
} else{
$spawn = new Position($issuer->entity->x, $issuer->entity->y, $issuer->entity->z, $issuer->entity->level);
}
$target->setSpawn($spawn);
if($target instanceof Level){
$output .= "Spawnpoint of world ".$target->getName()." set correctly!\n";
}elseif($target !== $issuer){
$output .= "Spawnpoint of ".$target->getUsername()." set correctly!\n";
}else{
$output .= "Spawnpoint of world " . $target->getName() . " set correctly!\n";
} elseif($target !== $issuer){
$output .= "Spawnpoint of " . $target->getUsername() . " set correctly!\n";
} else{
$output .= "Spawnpoint set correctly!\n";
}
break;
@ -181,7 +185,7 @@ class PlayerAPI{
$output .= "Please run this command in-game.\n";
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;
case "gamemode":
$player = false;
@ -206,14 +210,14 @@ class PlayerAPI{
if(Player::get($params[1]) instanceof Player){
$player = Player::get($params[1]);
$setgm = $params[0];
}elseif(Player::get($params[0]) instanceof Player){
} elseif(Player::get($params[0]) instanceof Player){
$player = Player::get($params[0]);
$setgm = $params[1];
}else{
} else{
$output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n";
break;
}
}elseif(isset($params[0])){
} elseif(isset($params[0])){
if(!(Player::get($params[0]) instanceof Player)){
if($issuer instanceof Player){
$setgm = $params[0];
@ -227,7 +231,7 @@ class PlayerAPI{
break;
}
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;
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)){
$name = $issuer->getUsername();
$target = implode(" ", $params);
}elseif(isset($params[1]) and isset($params[0])){
} elseif(isset($params[1]) and isset($params[0])){
$name = array_shift($params);
$target = implode(" ", $params);
}else{
} else{
$output .= "Usage: /$cmd [target player] <destination player | w:world>\n";
break;
}
if($this->teleport($name, $target) !== false){
$output .= "\"$name\" teleported to \"$target\"\n";
}else{
} else{
$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)){
$name = $issuer->getUsername();
$x = $params[0];
$y = $params[1];
$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];
$x = $params[1];
$y = $params[2];
$z = $params[3];
}else{
} else{
$output .= "Usage: /$cmd [player] <x> <y> <z>\n";
break;
}
if($this->tppos($name, $x, $y, $z)){
$output .= "\"$name\" teleported to ($x, $y, $z)\n";
}else{
} else{
$output .= "Couldn't teleport.\n";
}
}
@ -273,27 +277,28 @@ class PlayerAPI{
case "suicide":
if(!isset($params[0]) and ($issuer instanceof Player)){
$player = $issuer;
}else{
} else{
$player = Player::get($params[0]);
}
if($player instanceof Player){
$player->entity->harm(1000, "console", true);
$player->sendChat("Ouch. That looks like it hurt.\n");
}else{
} else{
$output .= "Usage: /$cmd [player]\n";
}
break;
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){
break;
}
foreach(Player::$list as $c){
$output .= $c->getUsername().", ";
$output .= $c->getUsername() . ", ";
}
$output = substr($output, 0, -2)."\n";
$output = substr($output, 0, -2) . "\n";
break;
}
return $output;
}
@ -304,9 +309,10 @@ class PlayerAPI{
$origin = Player::get($name);
if($origin instanceof Player){
$name = $origin->getUsername();
return $origin->teleport($lv->getSafeSpawn());
}
}else{
} else{
return false;
}
}
@ -316,9 +322,11 @@ class PlayerAPI{
$origin = Player::get($name);
if($origin instanceof Player){
$name = $origin->getUsername();
return $origin->teleport($player->entity);
}
}
return false;
}
@ -326,12 +334,14 @@ class PlayerAPI{
$player = Player::get($name);
if($player instanceof Player and $player->spawned === true){
$name = $player->getUsername();
$x = $x{0} === "~" ? $player->entity->x + floatval(substr($x, 1)):floatval($x);
$y = $y{0} === "~" ? $player->entity->y + floatval(substr($y, 1)):floatval($y);
$z = $z{0} === "~" ? $player->entity->z + floatval(substr($z, 1)):floatval($z);
$x = $x{0} === "~" ? $player->entity->x + floatval(substr($x, 1)) : floatval($x);
$y = $y{0} === "~" ? $player->entity->y + floatval(substr($y, 1)) : floatval($y);
$z = $z{0} === "~" ? $player->entity->z + floatval(substr($z, 1)) : floatval($z);
$player->teleport(new Vector3($x, $y, $z));
return true;
}
return false;
}
}

View File

@ -20,6 +20,7 @@
*/
namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Utils\Utils as Utils;
use PocketMine\Network\Protocol\Info as Info;
@ -31,6 +32,7 @@ class PluginAPI extends \stdClass{
private $server;
private $plugins = array();
private $randomNonce;
public function __construct(){
$this->server = ServerAPI::request();
$this->randomNonce = Utils::getRandomBytes(16, false);
@ -39,24 +41,25 @@ class PluginAPI extends \stdClass{
$this->server->api->ban->cmdWhitelist("version");
}
public function commandHandler($cmd, $params, $issuer, $alias){
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "plugins":
$output = "Plugins: ";
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;
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)){
$output .= " (git ".GIT_COMMIT.")";
$output .= " (git " . GIT_COMMIT . ")";
}
$output .= "\n";
break;
}
return $output;
}
@ -72,6 +75,7 @@ class PluginAPI extends \stdClass{
foreach($this->plugins as $p){
$list[] = $p[1];
}
return $list;
}
@ -81,18 +85,20 @@ class PluginAPI extends \stdClass{
public function load($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;
}
if(strtolower(substr($file, -3)) === "pmf"){
$pmf = new PMFPlugin($file);
$info = $pmf->getPluginInfo();
}else{
} else{
$content = file_get_contents($file);
$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
console("[ERROR] Failed parsing of ".basename($file));
console("[ERROR] Failed parsing of " . basename($file));
return false;
}
$info = array();
@ -116,23 +122,26 @@ class PluginAPI extends \stdClass{
$info["class"] = trim(strtolower($info["class"]));
}
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;
}
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"])){
console("[ERROR] Failed loading plugin: class already exists");
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"])){
console("[ERROR] Failed loading {$info['name']}: evaluation error");
return false;
}
$className = $info["class"];
$apiversion = array_map("intval", explode(",", (string) $info["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"]);
@ -140,18 +149,19 @@ class PluginAPI extends \stdClass{
if($info["class"] !== "none"){
$object = new $className($this->server->api, false);
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")){
$object->__destruct();
}
$object = null;
unset($object);
}else{
} else{
$this->plugins[$identifier] = array($object, $info);
}
}else{
} else{
$this->plugins[$identifier] = array(new DummyPlugin($this->server->api, false), $info);
}
return true;
}
@ -166,17 +176,20 @@ class PluginAPI extends \stdClass{
return $p;
}
}
return false;
}
if(isset($this->plugins[$identifier])){
return $this->plugins[$identifier];
}
return false;
}
public function pluginsPath(){
$path = join(DIRECTORY_SEPARATOR, array(\PocketMine\DATA."plugins", ""));
$path = join(DIRECTORY_SEPARATOR, array(\PocketMine\DATA . "plugins", ""));
@mkdir($path);
return $path;
}
@ -190,6 +203,7 @@ class PluginAPI extends \stdClass{
$path = $this->pluginsPath() . $p[1]["name"] . DIRECTORY_SEPARATOR;
$this->plugins[$identifier][1]["path"] = $path;
@mkdir($path);
return $path;
}
@ -199,8 +213,9 @@ class PluginAPI extends \stdClass{
return false;
}
$path = $this->configPath($plugin);
$cnf = new Config($path."config.yml", Config::YAML, $default);
$cnf = new Config($path . "config.yml", Config::YAML, $default);
$cnf->save();
return $path;
}
@ -240,7 +255,9 @@ class PluginAPI extends \stdClass{
interface Plugin{
public function __construct(ServerAPI $api, $server = false);
public function init();
public function __destruct();
}

View File

@ -20,6 +20,7 @@
*/
namespace PocketMine;
use PocketMine\Utils\VersionString as VersionString;
use PocketMine\Utils\Utils as Utils;
use PocketMine\Network\Handler as Handler;
@ -44,12 +45,12 @@ class Server{
private function load(){
$this->version = new VersionString();
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));
$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->serverID = $this->serverID === false ? Utils::readLong(substr(Utils::getUniqueID(true, $this->serverip . $this->port), 8)) : $this->serverID;
$this->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : $this->seed;
$this->startDatabase();
$this->api = false;
$this->tCnt = 1;
@ -85,26 +86,27 @@ class Server{
$this->doTick = true;
$this->gamemode = (int) $gamemode;
$this->name = $name;
$this->motd = "Welcome to ".$name;
$this->motd = "Welcome to " . $name;
$this->serverID = false;
$this->seed = $seed;
$this->serverip = $serverip;
$this->load();
}
/**
* @return float
*/
public function getTPS(){
/**
* @return float
*/
public function getTPS(){
$v = array_values($this->tickMeasure);
$tps = 40 / ($v[39] - $v[0]);
return round($tps, 4);
}
public function titleTick(){
$time = microtime(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);
}
@ -127,7 +129,7 @@ class Server{
public function checkMemory(){
$info = $this->debugInfo();
$data = $info["memory_usage"].",".$info["players"].",".$info["entities"];
$data = $info["memory_usage"] . "," . $info["players"] . "," . $info["entities"];
$i = count($this->memoryStats) - 1;
if($i < 0 or $this->memoryStats[$i] !== $data){
$this->memoryStats[] = $data;
@ -152,18 +154,19 @@ class Server{
}
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)){
$result = $result->fetchArray(SQLITE3_ASSOC);
}
return $result;
}
public function debugInfo($console = false){
$info = array();
$info["tps"] = $this->getTPS();
$info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2)."MB";
$info["memory_peak_usage"] = round((memory_get_peak_usage() / 1024) / 1024, 2)."MB";
$info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2) . "MB";
$info["memory_peak_usage"] = round((memory_get_peak_usage() / 1024) / 1024, 2) . "MB";
$info["entities"] = count(Entity::$list);
$info["players"] = count(Player::$list);
$info["events"] = count($this->eventsID);
@ -174,15 +177,16 @@ class Server{
$info["garbage"] = gc_collect_cycles();
$this->handle("server.debug", $info);
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;
}
/**
* @param string $reason
*/
public function close($reason = "server stop"){
/**
* @param string $reason
*/
public function close($reason = "server stop"){
if($this->stop !== true){
if(is_int($reason)){
$reason = "signal stop";
@ -223,25 +227,26 @@ class Server{
$type = (int) $type;
switch($type){
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;
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"]));
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;
case ASYNC_FUNCTION:
$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;
default:
return false;
}
$ID = $this->asyncID++;
$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;
}
@ -276,7 +281,7 @@ class Server{
if(is_array($this->async[$ID])){
$method = $this->async[$ID][1];
$result = $this->async[$ID][0]->$method($data, $type, $ID);
}else{
} else{
$result = $this->async[$ID]($data, $type, $ID);
}
}
@ -284,28 +289,29 @@ class Server{
}
}
/**
* @param string $event
* @param callable $callable
* @param integer $priority
*
* @return boolean
*/
public function addHandler($event,callable $callable, $priority = 5){
/**
* @param string $event
* @param callable $callable
* @param integer $priority
*
* @return boolean
*/
public function addHandler($event, callable $callable, $priority = 5){
if(!is_callable($callable)){
return false;
}elseif(isset(Deprecation::$events[$event])){
} elseif(isset(Deprecation::$events[$event])){
$sub = "";
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;
$hnid = $this->handCnt++;
$this->handlers[$hnid] = $callable;
$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);
$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);
return $hnid;
}
@ -331,17 +337,17 @@ class Server{
if(is_array($handler)){
$method = $handler[1];
$result = $handler[0]->$method($data, $event);
}else{
} else{
$result = $handler($data, $event);
}
}else{
} else{
break;
}
}
}elseif(isset(Deprecation::$events[$event])){
} elseif(isset(Deprecation::$events[$event])){
$sub = "";
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]");
}
@ -349,6 +355,7 @@ class Server{
if($result !== false){
$this->trigger($event, $data);
}
return $result;
}
@ -358,10 +365,10 @@ class Server{
}
}
/**
* @return string
*/
public function getGamemode(){
/**
* @return string
*/
public function getGamemode(){
switch($this->gamemode){
case SURVIVAL:
return "survival";
@ -375,10 +382,9 @@ class Server{
}
public function init(){
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();
register_shutdown_function(array($this, "dumpError"));
@ -388,9 +394,9 @@ class Server{
pcntl_signal(SIGINT, 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));
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();
}
@ -400,7 +406,7 @@ class Server{
}
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");
$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();
$errorConversion = array(
E_ERROR => "E_ERROR",
@ -419,8 +425,8 @@ class Server{
E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED",
);
$er["type"] = isset($errorConversion[$er["type"]]) ? $errorConversion[$er["type"]]:$er["type"];
$dump .= "Error: ".var_export($er, true)."\r\n\r\n";
$er["type"] = isset($errorConversion[$er["type"]]) ? $errorConversion[$er["type"]] : $er["type"];
$dump .= "Error: " . var_export($er, true) . "\r\n\r\n";
if(stripos($er["file"], "plugin") !== false){
$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";
$file = @file($er["file"], FILE_IGNORE_NEW_LINES);
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 .= "Backtrace: \r\n";
@ -437,25 +443,25 @@ class Server{
}
$dump .= "\r\n\r\n";
$version = new VersionString();
$dump .= "PocketMine-MP version: ".$version." #".$version->getNumber()." [Protocol ".Info::CURRENT_PROTOCOL."; API ".API_VERSION."]\r\n";
$dump .= "Git commit: ".GIT_COMMIT."\r\n";
$dump .= "uname -a: ".php_uname("a")."\r\n";
$dump .= "PHP Version: " .phpversion()."\r\n";
$dump .= "Zend version: ".zend_version()."\r\n";
$dump .= "OS : " .PHP_OS.", ".Utils::getOS()."\r\n";
$dump .= "Debug Info: ".var_export($this->debugInfo(false), true)."\r\n\r\n\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 .= "uname -a: " . php_uname("a") . "\r\n";
$dump .= "PHP Version: " . phpversion() . "\r\n";
$dump .= "Zend version: " . zend_version() . "\r\n";
$dump .= "OS : " . PHP_OS . ", " . Utils::getOS() . "\r\n";
$dump .= "Debug Info: " . var_export($this->debugInfo(false), true) . "\r\n\r\n\r\n";
global $arguments;
$dump .= "Parameters: ".var_export($arguments, true)."\r\n\r\n\r\n";
$dump .= "Parameters: " . var_export($arguments, true) . "\r\n\r\n\r\n";
$p = $this->api->getProperties();
if($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){
$plist = $this->api->plugin->getList();
$dump .= "Loaded plugins:\r\n";
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";
}
@ -465,15 +471,15 @@ class Server{
$extensions[$ext] = phpversion($ext);
}
$dump .= "Loaded Modules: ".var_export($extensions, true)."\r\n";
$dump .= "Loaded Modules: " . var_export($extensions, true) . "\r\n";
$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();
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();
$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);
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;
unset($this->tickMeasure[key($this->tickMeasure)]);
++$this->ticks;
return $this->tickerFunction($time);
}
return 0;
}
@ -499,7 +507,7 @@ class Server{
$CID = Server::clientID($packet->ip, $packet->port);
if(isset(Player::$list[$CID])){
Player::$list[$CID]->handlePacket($packet);
}else{
} else{
switch($packet->pid()){
case RakNetInfo::UNCONNECTED_PING:
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
@ -513,33 +521,33 @@ class Server{
$this->send($pk);
break;
}
if(!isset($this->custom["times_".$CID])){
$this->custom["times_".$CID] = 0;
if(!isset($this->custom["times_" . $CID])){
$this->custom["times_" . $CID] = 0;
}
$ln = 15;
if($this->description == "" or substr($this->description, -1) != " "){
$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));
$pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
$pk->pingID = $packet->pingID;
$pk->serverID = $this->serverID;
$pk->serverType = $this->serverType . $this->name . " [".count(Player::$list)."/".$this->maxClients."] ".$txt;
$pk->serverType = $this->serverType . $this->name . " [" . count(Player::$list) . "/" . $this->maxClients . "] " . $txt;
$pk->ip = $packet->ip;
$pk->port = $packet->port;
$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;
case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
if($packet->structure !== RakNetInfo::STRUCTURE){
console("[DEBUG] Incorrect structure #".$packet->structure." from ".$packet->ip.":".$packet->port, true, true, 2);
console("[DEBUG] Incorrect structure #" . $packet->structure . " from " . $packet->ip . ":" . $packet->port, true, true, 2);
$pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION);
$pk->serverID = $this->serverID;
$pk->ip = $packet->ip;
$pk->port = $packet->port;
$this->send($pk);
}else{
} else{
$pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1);
$pk->serverID = $this->serverID;
$pk->mtuSize = strlen($packet->buffer);
@ -580,15 +588,15 @@ class Server{
}
if($this->tick() > 0){
$lastLoop = 0;
}else{
} else{
++$lastLoop;
if($lastLoop < 64){
}elseif($lastLoop < 256){
} elseif($lastLoop < 256){
usleep(100);
}elseif($lastLoop < 512){
} elseif($lastLoop < 512){
usleep(512);
}else{
} else{
usleep(5000);
}
}
@ -605,14 +613,14 @@ class Server{
if(is_array($ev)){
$method = $ev[1];
$ev[0]->$method($data, $event);
}else{
} else{
$ev($data, $event);
}
}
}elseif(isset(Deprecation::$events[$event])){
} elseif(isset(Deprecation::$events[$event])){
$sub = "";
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]");
}
@ -624,7 +632,8 @@ class Server{
}
$chcnt = $this->scheduleCnt++;
$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;
}
@ -644,31 +653,32 @@ class Server{
$this->preparedSQL->updateAction->execute();
if(!@is_callable($this->schedule[$cid][0])){
$return = false;
}else{
} else{
++$actionCount;
$return = call_user_func($this->schedule[$cid][0], $this->schedule[$cid][1], $this->schedule[$cid][2]);
}
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;
unset($this->schedule[$cid]);
}
}
$actions->finalize();
}
return $actionCount;
}
public function event($event,callable $func){
public function event($event, callable $func){
if(!is_callable($func)){
return false;
}elseif(isset(Deprecation::$events[$event])){
} elseif(isset(Deprecation::$events[$event])){
$sub = "";
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++;
if(!isset($this->events[$event])){
@ -676,7 +686,8 @@ class Server{
}
$this->events[$event][$evid] = $func;
$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;
}

View File

@ -20,6 +20,7 @@
*/
namespace PocketMine;
use PocketMine\Utils\VersionString as VersionString;
use PocketMine\Utils\TextFormat as TextFormat;
use PocketMine\Utils\Config as Config;
@ -46,7 +47,7 @@ class ServerAPI{
public $query;
//TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs.
//TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs.
/**
* @var ConsoleAPI
@ -101,13 +102,14 @@ class ServerAPI{
public function run(){
$this->load();
return $this->init();
}
public function load(){
@mkdir(\PocketMine\DATA."players/", 0755);
@mkdir(\PocketMine\DATA."worlds/", 0755);
@mkdir(\PocketMine\DATA."plugins/", 0755);
@mkdir(\PocketMine\DATA . "players/", 0755);
@mkdir(\PocketMine\DATA . "worlds/", 0755);
@mkdir(\PocketMine\DATA . "plugins/", 0755);
//Init all the events
foreach(get_declared_classes() as $class){
@ -117,7 +119,7 @@ class ServerAPI{
}
$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...");
$this->config = new Config(\PocketMine\DATA . "server.properties", Config::PROPERTIES, array(
@ -165,49 +167,49 @@ class ServerAPI{
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;
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);
if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){
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()){
$info = json_decode(Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/commits"), true);
if($info === false or !isset($info[0])){
console("[ERROR] Github API error");
}else{
} else{
$last = new \DateTime($info[0]["commit"]["committer"]["date"]);
$last = $last->getTimestamp();
if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false and GIT_COMMIT != $info[0]["sha"]){
console("[NOTICE] ".TextFormat::YELLOW."A new DEVELOPMENT version of PocketMine-MP has been released!");
console("[NOTICE] ".TextFormat::YELLOW."Commit \"".$info[0]["commit"]["message"]."\" [".substr($info[0]["sha"], 0, 10)."] by ".$info[0]["commit"]["committer"]["name"]);
console("[NOTICE] ".TextFormat::YELLOW."Get it at PocketMine.net or at https://github.com/PocketMine/PocketMine-MP/archive/".$info[0]["sha"].".zip");
console("[NOTICE] " . TextFormat::YELLOW . "A new DEVELOPMENT version of PocketMine-MP has been released!");
console("[NOTICE] " . TextFormat::YELLOW . "Commit \"" . $info[0]["commit"]["message"] . "\" [" . substr($info[0]["sha"], 0, 10) . "] by " . $info[0]["commit"]["committer"]["name"]);
console("[NOTICE] " . TextFormat::YELLOW . "Get it at PocketMine.net or at https://github.com/PocketMine/PocketMine-MP/archive/" . $info[0]["sha"] . ".zip");
console("[NOTICE] This message will dissapear after issuing the command \"/update-done\"");
}else{
} else{
$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);
if($info === false or !isset($info[0])){
console("[ERROR] Github API error");
}else{
} else{
$newest = new VersionString(VERSION);
$newestN = $newest->getNumber();
$update = new VersionString($info[0]["name"]);
$updateN = $update->getNumber();
if($updateN > $newestN){
console("[NOTICE] ".TextFormat::GREEN."A new STABLE version of PocketMine-MP has been released!");
console("[NOTICE] ".TextFormat::GREEN."Version \"".$info[0]["name"]."\" #".$updateN);
console("[NOTICE] Get it at PocketMine.net or at ".$info[0]["zipball_url"]);
console("[NOTICE] " . TextFormat::GREEN . "A new STABLE version of PocketMine-MP has been released!");
console("[NOTICE] " . TextFormat::GREEN . "Version \"" . $info[0]["name"] . "\" #" . $updateN);
console("[NOTICE] Get it at PocketMine.net or at " . $info[0]["zipball_url"]);
console("[NOTICE] This message will dissapear as soon as you update");
}else{
} else{
$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){
$cnt = $this->asyncCnt++;
$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){
@ -266,8 +269,10 @@ class ServerAPI{
}
$ob = $this->asyncCalls[$id];
unset($this->asyncCalls[$id]);
return $ob;
}
public function autoSave(){
console("[DEBUG] Saving....", true, true, 2);
$this->server->api->level->saveAll();
@ -277,7 +282,7 @@ class ServerAPI{
console("[DEBUG] Sending usage data...", true, true, 2);
$plist = "";
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(
@ -296,7 +301,7 @@ class ServerAPI{
"max" => $this->server->maxClients,
"plugins" => $plist,
),
), NULL);
), null);
}
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);
}
@ini_set("memory_limit", $memory);
}else{
} else{
$this->setProperty("memory-limit", "128M");
}
@ -342,7 +347,7 @@ class ServerAPI{
case "last-update":
if($v === false){
$v = time();
}else{
} else{
$v = (int) $v;
}
break;
@ -355,7 +360,7 @@ class ServerAPI{
break;
case "server-id":
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;
}
@ -379,7 +384,7 @@ class ServerAPI{
$this->server->schedule(18000, array($this, "autoSave"), array(), 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){
@ -394,10 +399,11 @@ class ServerAPI{
$this->rcon->stop();
}
$this->__destruct();
if($this->getProperty("upnp-forwarding") === true ){
if($this->getProperty("upnp-forwarding") === true){
console("[INFO] [UPnP] Removing port forward...");
RemovePortForward($this->getProperty("server-port"));
}
return $this->restart;
}
@ -460,7 +466,7 @@ class ServerAPI{
case "last-update":
if($v === false){
$v = time();
}else{
} else{
$v = (int) $v;
}
break;
@ -472,9 +478,11 @@ class ServerAPI{
$v = (int) $v;
break;
}
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){

View File

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

View File

@ -32,91 +32,97 @@ class BedBlock extends TransparentBlock{
$pk = new ChatPacket;
$pk->message = "You can only sleep at night";
$player->dataPacket($pk);
return true;
}
$blockNorth = $this->getSide(2); //Gets the blocks around them
$blockSouth = $this->getSide(3);
$blockEast = $this->getSide(5);
$blockWest = $this->getSide(4);
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
$b = $this;
}else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$b = $blockNorth;
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$b = $blockSouth;
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$b = $blockEast;
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$b = $blockWest;
}else{
$pk = new ChatPacket;
$pk->message = "This bed is incomplete";
$player->dataPacket($pk);
return true;
}
$blockNorth = $this->getSide(2); //Gets the blocks around them
$blockSouth = $this->getSide(3);
$blockEast = $this->getSide(5);
$blockWest = $this->getSide(4);
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
$b = $this;
} else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$b = $blockNorth;
} elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$b = $blockSouth;
} elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$b = $blockEast;
} elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$b = $blockWest;
} else{
$pk = new ChatPacket;
$pk->message = "This bed is incomplete";
$player->dataPacket($pk);
return true;
}
}
if($player->sleepOn($b) === false){
$pk = new ChatPacket;
$pk->message = "This bed is occupied";
$player->dataPacket($pk);
}
return true;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->isTransparent === false){
$faces = array(
0 => 3,
1 => 4,
2 => 2,
3 => 5,
);
$d = $player->entity->getDirection();
$next = $this->getSide($faces[(($d + 3) % 4)]);
$downNext = $this->getSide(0);
if($next->isReplaceable === true and $downNext->isTransparent === false){
$meta = (($d + 3) % 4) & 0x03;
$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);
return true;
}
$down = $this->getSide(0);
if($down->isTransparent === false){
$faces = array(
0 => 3,
1 => 4,
2 => 2,
3 => 5,
);
$d = $player->entity->getDirection();
$next = $this->getSide($faces[(($d + 3) % 4)]);
$downNext = $this->getSide(0);
if($next->isReplaceable === true and $downNext->isTransparent === false){
$meta = (($d + 3) % 4) & 0x03;
$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);
return true;
}
}
return false;
}
public function onBreak(Item $item, Player $player){
$blockNorth = $this->getSide(2); //Gets the blocks around them
$blockSouth = $this->getSide(3);
$blockEast = $this->getSide(5);
$blockWest = $this->getSide(4);
$blockNorth = $this->getSide(2); //Gets the blocks around them
$blockSouth = $this->getSide(3);
$blockEast = $this->getSide(5);
$blockWest = $this->getSide(4);
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
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
}elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
}elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){
$this->level->setBlock($blockEast, new AirBlock(), true, false, true);
}elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){
$this->level->setBlock($blockWest, new AirBlock(), true, false, true);
}
}else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$this->level->setBlock($blockEast, new AirBlock(), true, false, true);
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$this->level->setBlock($blockWest, new AirBlock(), true, false, true);
}
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
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
} elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
} elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){
$this->level->setBlock($blockEast, new AirBlock(), true, false, true);
} elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){
$this->level->setBlock($blockWest, new AirBlock(), true, false, true);
}
$this->level->setBlock($this, new AirBlock(), true, false, true);
return true;
} else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
} elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
} elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$this->level->setBlock($blockEast, new AirBlock(), true, false, true);
} elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$this->level->setBlock($blockWest, new AirBlock(), true, false, true);
}
}
$this->level->setBlock($this, new AirBlock(), true, false, true);
return true;
}
public function getDrops(Item $item, Player $player){

View File

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

View File

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

View File

@ -21,130 +21,130 @@
abstract class Block extends Position{
public static $class = array(
AIR => "AirBlock",
STONE => "StoneBlock",
GRASS => "GrassBlock",
DIRT => "DirtBlock",
COBBLESTONE => "CobblestoneBlock",
PLANKS => "PlanksBlock",
SAPLING => "SaplingBlock",
BEDROCK => "BedrockBlock",
WATER => "WaterBlock",
STILL_WATER => "StillWaterBlock",
LAVA => "LavaBlock",
STILL_LAVA => "StillLavaBlock",
SAND => "SandBlock",
GRAVEL => "GravelBlock",
GOLD_ORE => "GoldOreBlock",
IRON_ORE => "IronOreBlock",
COAL_ORE => "CoalOreBlock",
WOOD => "WoodBlock",
LEAVES => "LeavesBlock",
SPONGE => "SpongeBlock",
GLASS => "GlassBlock",
LAPIS_ORE => "LapisOreBlock",
LAPIS_BLOCK => "LapisBlock",
SANDSTONE => "SandstoneBlock",
BED_BLOCK => "BedBlock",
COBWEB => "CobwebBlock",
TALL_GRASS => "TallGrassBlock",
DEAD_BUSH => "DeadBushBlock",
WOOL => "WoolBlock",
DANDELION => "DandelionBlock",
CYAN_FLOWER => "CyanFlowerBlock",
BROWN_MUSHROOM => "BrownMushroomBlock",
RED_MUSHROOM => "RedMushRoomBlock",
GOLD_BLOCK => "GoldBlock",
IRON_BLOCK => "IronBlock",
DOUBLE_SLAB => "DoubleSlabBlock",
SLAB => "SlabBlock",
BRICKS_BLOCK => "BricksBlock",
TNT => "TNTBlock",
BOOKSHELF => "BookshelfBlock",
MOSS_STONE => "MossStoneBlock",
OBSIDIAN => "ObsidianBlock",
TORCH => "TorchBlock",
FIRE => "FireBlock",
AIR => "AirBlock",
STONE => "StoneBlock",
GRASS => "GrassBlock",
DIRT => "DirtBlock",
COBBLESTONE => "CobblestoneBlock",
PLANKS => "PlanksBlock",
SAPLING => "SaplingBlock",
BEDROCK => "BedrockBlock",
WATER => "WaterBlock",
STILL_WATER => "StillWaterBlock",
LAVA => "LavaBlock",
STILL_LAVA => "StillLavaBlock",
SAND => "SandBlock",
GRAVEL => "GravelBlock",
GOLD_ORE => "GoldOreBlock",
IRON_ORE => "IronOreBlock",
COAL_ORE => "CoalOreBlock",
WOOD => "WoodBlock",
LEAVES => "LeavesBlock",
SPONGE => "SpongeBlock",
GLASS => "GlassBlock",
LAPIS_ORE => "LapisOreBlock",
LAPIS_BLOCK => "LapisBlock",
SANDSTONE => "SandstoneBlock",
BED_BLOCK => "BedBlock",
COBWEB => "CobwebBlock",
TALL_GRASS => "TallGrassBlock",
DEAD_BUSH => "DeadBushBlock",
WOOL => "WoolBlock",
DANDELION => "DandelionBlock",
CYAN_FLOWER => "CyanFlowerBlock",
BROWN_MUSHROOM => "BrownMushroomBlock",
RED_MUSHROOM => "RedMushRoomBlock",
GOLD_BLOCK => "GoldBlock",
IRON_BLOCK => "IronBlock",
DOUBLE_SLAB => "DoubleSlabBlock",
SLAB => "SlabBlock",
BRICKS_BLOCK => "BricksBlock",
TNT => "TNTBlock",
BOOKSHELF => "BookshelfBlock",
MOSS_STONE => "MossStoneBlock",
OBSIDIAN => "ObsidianBlock",
TORCH => "TorchBlock",
FIRE => "FireBlock",
WOOD_STAIRS => "WoodStairsBlock",
CHEST => "ChestBlock",
WOOD_STAIRS => "WoodStairsBlock",
CHEST => "ChestBlock",
DIAMOND_ORE => "DiamondOreBlock",
DIAMOND_BLOCK => "DiamondBlock",
WORKBENCH => "WorkbenchBlock",
WHEAT_BLOCK => "WheatBlock",
FARMLAND => "FarmlandBlock",
FURNACE => "FurnaceBlock",
BURNING_FURNACE => "BurningFurnaceBlock",
SIGN_POST => "SignPostBlock",
WOOD_DOOR_BLOCK => "WoodDoorBlock",
LADDER => "LadderBlock",
DIAMOND_ORE => "DiamondOreBlock",
DIAMOND_BLOCK => "DiamondBlock",
WORKBENCH => "WorkbenchBlock",
WHEAT_BLOCK => "WheatBlock",
FARMLAND => "FarmlandBlock",
FURNACE => "FurnaceBlock",
BURNING_FURNACE => "BurningFurnaceBlock",
SIGN_POST => "SignPostBlock",
WOOD_DOOR_BLOCK => "WoodDoorBlock",
LADDER => "LadderBlock",
COBBLESTONE_STAIRS => "CobblestoneStairsBlock",
WALL_SIGN => "WallSignBlock",
COBBLESTONE_STAIRS => "CobblestoneStairsBlock",
WALL_SIGN => "WallSignBlock",
IRON_DOOR_BLOCK => "IronDoorBlock",
REDSTONE_ORE => "RedstoneOreBlock",
GLOWING_REDSTONE_ORE => "GlowingRedstoneOreBlock",
IRON_DOOR_BLOCK => "IronDoorBlock",
REDSTONE_ORE => "RedstoneOreBlock",
GLOWING_REDSTONE_ORE => "GlowingRedstoneOreBlock",
SNOW_LAYER => "SnowLayerBlock",
ICE => "IceBlock",
SNOW_BLOCK => "SnowBlock",
CACTUS => "CactusBlock",
CLAY_BLOCK => "ClayBlock",
SUGARCANE_BLOCK => "SugarcaneBlock",
SNOW_LAYER => "SnowLayerBlock",
ICE => "IceBlock",
SNOW_BLOCK => "SnowBlock",
CACTUS => "CactusBlock",
CLAY_BLOCK => "ClayBlock",
SUGARCANE_BLOCK => "SugarcaneBlock",
FENCE => "FenceBlock",
PUMPKIN => "PumpkinBlock",
NETHERRACK => "NetherrackBlock",
SOUL_SAND => "SoulSandBlock",
GLOWSTONE_BLOCK => "GlowstoneBlock",
FENCE => "FenceBlock",
PUMPKIN => "PumpkinBlock",
NETHERRACK => "NetherrackBlock",
SOUL_SAND => "SoulSandBlock",
GLOWSTONE_BLOCK => "GlowstoneBlock",
LIT_PUMPKIN => "LitPumpkinBlock",
CAKE_BLOCK => "CakeBlock",
LIT_PUMPKIN => "LitPumpkinBlock",
CAKE_BLOCK => "CakeBlock",
TRAPDOOR => "TrapdoorBlock",
TRAPDOOR => "TrapdoorBlock",
STONE_BRICKS => "StoneBricksBlock",
STONE_BRICKS => "StoneBricksBlock",
IRON_BARS => "IronBarsBlock",
GLASS_PANE => "GlassPaneBlock",
MELON_BLOCK => "MelonBlock",
PUMPKIN_STEM => "PumpkinStemBlock",
MELON_STEM => "MelonStemBlock",
IRON_BARS => "IronBarsBlock",
GLASS_PANE => "GlassPaneBlock",
MELON_BLOCK => "MelonBlock",
PUMPKIN_STEM => "PumpkinStemBlock",
MELON_STEM => "MelonStemBlock",
FENCE_GATE => "FenceGateBlock",
BRICK_STAIRS => "BrickStairsBlock",
STONE_BRICK_STAIRS => "StoneBrickStairsBlock",
FENCE_GATE => "FenceGateBlock",
BRICK_STAIRS => "BrickStairsBlock",
STONE_BRICK_STAIRS => "StoneBrickStairsBlock",
NETHER_BRICKS => "NetherBricksBlock",
NETHER_BRICKS => "NetherBricksBlock",
NETHER_BRICKS_STAIRS => "NetherBricksStairsBlock",
NETHER_BRICKS_STAIRS => "NetherBricksStairsBlock",
SANDSTONE_STAIRS => "SandstoneStairsBlock",
SANDSTONE_STAIRS => "SandstoneStairsBlock",
SPRUCE_WOOD_STAIRS => "SpruceWoodStairsBlock",
BIRCH_WOOD_STAIRS => "BirchWoodStairsBlock",
JUNGLE_WOOD_STAIRS => "JungleWoodStairsBlock",
STONE_WALL => "StoneWallBlock",
SPRUCE_WOOD_STAIRS => "SpruceWoodStairsBlock",
BIRCH_WOOD_STAIRS => "BirchWoodStairsBlock",
JUNGLE_WOOD_STAIRS => "JungleWoodStairsBlock",
STONE_WALL => "StoneWallBlock",
CARROT_BLOCK => "CarrotBlock",
POTATO_BLOCK => "PotatoBlock",
CARROT_BLOCK => "CarrotBlock",
POTATO_BLOCK => "PotatoBlock",
QUARTZ_BLOCK => "QuartzBlock",
QUARTZ_STAIRS => "QuartzStairsBlock",
DOUBLE_WOOD_SLAB => "DoubleWoodSlabBlock",
WOOD_SLAB => "WoodSlabBlock",
QUARTZ_BLOCK => "QuartzBlock",
QUARTZ_STAIRS => "QuartzStairsBlock",
DOUBLE_WOOD_SLAB => "DoubleWoodSlabBlock",
WOOD_SLAB => "WoodSlabBlock",
HAY_BALE => "HayBaleBlock",
CARPET => "CarpetBlock",
HAY_BALE => "HayBaleBlock",
CARPET => "CarpetBlock",
COAL_BLOCK => "CoalBlock",
COAL_BLOCK => "CoalBlock",
BEETROOT_BLOCK => "BeetrootBlock",
STONECUTTER => "StonecutterBlock",
GLOWING_OBSIDIAN => "GlowingObsidianBlock",
NETHER_REACTOR => "NetherReactorBlock",
BEETROOT_BLOCK => "BeetrootBlock",
STONECUTTER => "StonecutterBlock",
GLOWING_OBSIDIAN => "GlowingObsidianBlock",
NETHER_REACTOR => "NetherReactorBlock",
);
protected $id;
protected $meta;
@ -200,7 +200,7 @@ abstract class Block extends Position{
public function getDrops(Item $item, Player $player){
if(!isset(Block::$class[$this->id])){ //Unknown blocks
return array();
}else{
} else{
return array(
array($this->id, $this->meta, 1),
);
@ -211,6 +211,7 @@ abstract class Block extends Position{
if(($player->gamemode & 0x01) === 0x01){
return 0.15;
}
return $this->breakTime;
}
@ -219,11 +220,12 @@ abstract class Block extends Position{
if($this->level instanceof Level){
return $this->level->getBlock($v);
}
return $v;
}
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);

View File

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

View File

@ -30,18 +30,22 @@ class BrownMushroomBlock extends FlowableBlock{
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->isTransparent === false){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
$down = $this->getSide(0);
if($down->isTransparent === false){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
}

View File

@ -40,15 +40,17 @@ class BurningFurnaceBlock extends SolidBlock{
"id" => new NBT\Tag\String("id", Tile::FURNACE),
"x" => new NBT\Tag\Int("x", $this->x),
"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);
$furnace = new Furnace($this->level, $nbt);
return true;
}
public function onBreak(Item $item, Player $player){
$this->level->setBlock($this, new AirBlock(), true, true, true);
return true;
}
@ -58,13 +60,13 @@ class BurningFurnaceBlock extends SolidBlock{
$furnace = false;
if($t instanceof Furnace){
$furnace = $t;
}else{
} else{
$nbt = new NBT\Tag\Compound(false, array(
"Items" => new NBT\Tag\Enum("Items", array()),
"id" => new NBT\Tag\String("id", Tile::FURNACE),
"x" => new NBT\Tag\Int("x", $this->x),
"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);
$furnace = new Furnace($this->level, $nbt);
@ -75,6 +77,7 @@ class BurningFurnaceBlock extends SolidBlock{
}
$furnace->openInventory($player);
return true;
}
@ -112,6 +115,7 @@ class BurningFurnaceBlock extends SolidBlock{
}
}
}
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
$this->level->setBlock($this, new AirBlock(), false);
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
} elseif($type === BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== CACTUS){
if($this->meta == 0x0F){
for($y = 1; $y < 3; ++$y){
@ -46,13 +47,15 @@ class CactusBlock extends TransparentBlock{
}
$this->meta = 0;
$this->level->setBlock($this, $this, false);
}else{
} else{
++$this->meta;
$this->level->setBlock($this, $this, false);
}
return BLOCK_UPDATE_RANDOM;
}
}
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){
$this->level->setBlock($this, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
}
return false;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,11 +26,13 @@ class CyanFlowerBlock extends FlowableBlock{
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
$down = $this->getSide(0);
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
@ -39,9 +41,11 @@ class CyanFlowerBlock extends FlowableBlock{
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}
return false;
}
}

View File

@ -26,11 +26,13 @@ class DandelionBlock extends FlowableBlock{
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
$down = $this->getSide(0);
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
@ -39,9 +41,11 @@ class DandelionBlock extends FlowableBlock{
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}
return false;
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -20,47 +20,49 @@
*/
class DoorBlock extends TransparentBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isSolid = false;
}
/**
* @param int $type
*
* @return bool|int
*/
public function onUpdate($type){
/**
* @param int $type
*
* @return bool|int
*/
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false);
if($this->getSide(1) instanceof DoorBlock){
$this->level->setBlock($this->getSide(1), new AirBlock(), false);
}
return BLOCK_UPDATE_NORMAL;
}
}
return false;
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param integer $face
* @param integer $fx
* @param integer $fy
* @param integer $fz
*
* @return boolean
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param integer $face
* @param integer $fx
* @param integer $fy
* @param integer $fz
*
* @return boolean
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($face === 1){
$blockUp = $this->getSide(1);
$blockDown = $this->getSide(0);
@ -86,38 +88,40 @@ class DoorBlock extends TransparentBlock{
$this->level->setBlock($block, $this, true, false, true); //Bottom
return true;
}
return false;
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function onBreak(Item $item, Player $player){
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function onBreak(Item $item, Player $player){
if(($this->meta & 0x08) === 0x08){
$down = $this->getSide(0);
if($down->getID() === $this->id){
$this->level->setBlock($down, new AirBlock(), true, false, true);
}
}else{
} else{
$up = $this->getSide(1);
if($up->getID() === $this->id){
$this->level->setBlock($up, new AirBlock(), true, false, true);
}
}
$this->level->setBlock($this, new AirBlock(), true, false, true);
return true;
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function onActivate(Item $item, Player $player){
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function onActivate(Item $item, Player $player){
if(($this->meta & 0x08) === 0x08){ //Top
$down = $this->getSide(0);
if($down->getID() === $this->id){
@ -132,10 +136,12 @@ class DoorBlock extends TransparentBlock{
$pk->evid = 1003;
$pk->data = 0;
ServerAPI::request()->api->player->broadcastPacket($players, $pk);
return true;
}
return false;
}else{
} else{
$this->meta ^= 0x04;
$this->level->setBlock($this, $this, true, false, true);
$players = ServerAPI::request()->api->player->getAll($this->level);
@ -148,6 +154,7 @@ class DoorBlock extends TransparentBlock{
$pk->data = 0;
ServerAPI::request()->api->player->broadcastPacket($players, $pk);
}
return true;
}
}

View File

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

View File

@ -20,31 +20,32 @@
*/
class FallableBlock extends SolidBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->hasPhysics = true;
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param int $face
* @param int $fx
* @param int $fy
* @param int $fz
*
* @return mixed
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param int $face
* @param int $fx
* @param int $fy
* @param int $fz
*
* @return mixed
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL);
return $ret;
}
}

View File

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

View File

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

View File

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

View File

@ -20,12 +20,12 @@
*/
class FlowableBlock extends TransparentBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isFlowable = true;
$this->isFullBlock = false;

View File

@ -21,57 +21,57 @@
class GenericBlock extends Block{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param integer $face
* @param integer $fx
* @param integer $fy
* @param integer $fz
*
* @return mixed
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param integer $face
* @param integer $fx
* @param integer $fy
* @param integer $fz
*
* @return mixed
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
return $this->level->setBlock($this, $this, true, false, true);
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function isBreakable(Item $item, Player $player){
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function isBreakable(Item $item, Player $player){
return ($this->breakable);
}
/**
* @param Item $item
* @param Player $player
*
* @return mixed
*/
public function onBreak(Item $item, Player $player){
/**
* @param Item $item
* @param Player $player
*
* @return mixed
*/
public function onBreak(Item $item, Player $player){
return $this->level->setBlock($this, new AirBlock(), true, false, true);
}
/**
* @param integer $type
*
* @return boolean
*/
public function onUpdate($type){
/**
* @param integer $type
*
* @return boolean
*/
public function onUpdate($type){
if($this->hasPhysics === true and $type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->getID() === AIR or ($down instanceof LiquidBlock)){
@ -88,18 +88,20 @@ class GenericBlock extends Block{
$e->spawnToAll();
$server->api->block->blockUpdateAround(clone $this, BLOCK_UPDATE_NORMAL, 1);
}
return false;
}
return false;
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function onActivate(Item $item, Player $player){
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function onActivate(Item $item, Player $player){
return $this->isActivable;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -20,12 +20,12 @@
*/
class LiquidBlock extends TransparentBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isLiquid = true;
$this->breakable = false;

View File

@ -25,15 +25,16 @@ class LitPumpkinBlock extends SolidBlock{
$this->hardness = 5;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array(
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
$this->meta = $faces[$player->entity->getDirection()];
$this->level->setBlock($block, $this, true, false, true);
return true;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array(
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
$this->meta = $faces[$player->entity->getDirection()];
$this->level->setBlock($block, $this, true, false, true);
return true;
}
}

View File

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

View File

@ -25,13 +25,16 @@ class MelonStemBlock extends FlowableBlock{
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
}
@ -40,30 +43,34 @@ class MelonStemBlock extends FlowableBlock{
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)));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
} elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}else{
} else{
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b->getID() === MELON_BLOCK){
return BLOCK_UPDATE_RANDOM;
}
}
$side = $this->getSide(mt_rand(2,5));
$side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(0);
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);
}
}
}
return BLOCK_UPDATE_RANDOM;
}
return false;
}
@ -74,8 +81,10 @@ class MelonStemBlock extends FlowableBlock{
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
return true;
}
return false;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -25,13 +25,16 @@ class PumpkinStemBlock extends FlowableBlock{
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
}
@ -40,30 +43,34 @@ class PumpkinStemBlock extends FlowableBlock{
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)));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
} elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}else{
} else{
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b->getID() === PUMPKIN){
return BLOCK_UPDATE_RANDOM;
}
}
$side = $this->getSide(mt_rand(2,5));
$side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(0);
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);
}
}
}
return BLOCK_UPDATE_RANDOM;
}
return false;
}
@ -74,8 +81,10 @@ class PumpkinStemBlock extends FlowableBlock{
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
return true;
}
return false;
}

View File

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

View File

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

View File

@ -29,8 +29,10 @@ class RedstoneOreBlock extends SolidBlock{
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->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return BLOCK_UPDATE_WEAK;
}
return false;
}
@ -39,7 +41,7 @@ class RedstoneOreBlock extends SolidBlock{
return array(
array(REDSTONE_DUST, 0, mt_rand(4, 5)),
);
}else{
} else{
return array();
}
}

View File

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

View File

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

View File

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

View File

@ -32,55 +32,62 @@ class SlabBlock extends TransparentBlock{
6 => "Quartz",
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){
$this->isFullBlock = true;
}else{
} else{
$this->isFullBlock = false;
}
$this->hardness = 30;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$this->meta &= 0x07;
if($face === 0){
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);
return true;
}elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->meta &= 0x07;
if($face === 0){
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);
return true;
} elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
} else{
$this->meta |= 0x08;
}
} elseif($face === 1){
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);
return true;
} elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}
} elseif(!$player->entity->inBlock($block)){
if($block->getID() === SLAB){
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}else{
}
return false;
} else{
if($fy > 0.5){
$this->meta |= 0x08;
}
}elseif($face === 1){
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);
return true;
}elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}
}elseif(!$player->entity->inBlock($block)){
if($block->getID() === SLAB){
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}
return false;
}else{
if($fy > 0.5){
$this->meta |= 0x08;
}
}
}else{
return false;
}
if($block->getID() === SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
return false;
}
$this->level->setBlock($block, $this, true, false, true);
return true;
} else{
return false;
}
if($block->getID() === SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
return false;
}
$this->level->setBlock($block, $this, true, false, true);
return true;
}
public function getBreakTime(Item $item, Player $player){
@ -108,7 +115,7 @@ class SlabBlock extends TransparentBlock{
return array(
array($this->id, $this->meta & 0x07, 1),
);
}else{
} else{
return array();
}
}

View File

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

View File

@ -20,12 +20,12 @@
*/
class SolidBlock extends GenericBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isSolid = true;
$this->isFullBlock = true;

View File

@ -20,34 +20,34 @@
*/
class StairBlock extends TransparentBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
if(($this->meta & 0x04) === 0x04){
$this->isFullBlock = true;
}else{
} else{
$this->isFullBlock = false;
}
$this->hardness = 30;
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param int $face
* @param int $fx
* @param int $fy
* @param int $fz
*
* @return bool|mixed
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param int $face
* @param int $fx
* @param int $fy
* @param int $fz
*
* @return bool|mixed
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array(
0 => 0,
1 => 2,
@ -59,21 +59,22 @@ class StairBlock extends TransparentBlock{
$this->meta |= 0x04; //Upside-down stairs
}
$this->level->setBlock($block, $this, true, false, true);
return true;
}
/**
* @param Item $item
* @param Player $player
*
* @return array
*/
public function getDrops(Item $item, Player $player){
/**
* @param Item $item
* @param Player $player
*
* @return array
*/
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array($this->id, 0, 1),
);
}else{
} else{
return array();
}
}

View File

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

View File

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

View File

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

View File

@ -47,8 +47,10 @@ class SugarcaneBlock extends FlowableBlock{
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
return true;
}
return false;
}
@ -59,9 +61,10 @@ class SugarcaneBlock extends FlowableBlock{
//TODO
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
} elseif($type === BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== SUGARCANE_BLOCK){
if($this->meta === 0x0F){
for($y = 1; $y < 3; ++$y){
@ -73,32 +76,37 @@ class SugarcaneBlock extends FlowableBlock{
}
$this->meta = 0;
$this->level->setBlock($this, $this, true, false, true);
}else{
} else{
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
}
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === SUGARCANE_BLOCK){
$down = $this->getSide(0);
if($down->getID() === SUGARCANE_BLOCK){
$this->level->setBlock($block, new SugarcaneBlock(), true, false, true);
return true;
} elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){
$block0 = $down->getSide(2);
$block1 = $down->getSide(3);
$block2 = $down->getSide(4);
$block3 = $down->getSide(5);
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->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){
$block0 = $down->getSide(2);
$block1 = $down->getSide(3);
$block2 = $down->getSide(4);
$block3 = $down->getSide(5);
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->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
}
}
return false;
}
}

View File

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

View File

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

View File

@ -29,21 +29,23 @@ class TorchBlock extends FlowableBlock{
if($type === BLOCK_UPDATE_NORMAL){
$side = $this->getMetadata();
$faces = array(
1 => 4,
2 => 5,
3 => 2,
4 => 3,
5 => 0,
6 => 0,
0 => 0,
1 => 4,
2 => 5,
3 => 2,
4 => 3,
5 => 0,
6 => 0,
0 => 0,
);
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));
$this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL;
}
}
return false;
}
@ -58,14 +60,18 @@ class TorchBlock extends FlowableBlock{
);
$this->meta = $faces[$face];
$this->level->setBlock($block, $this, true, false, 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->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function getDrops(Item $item, Player $player){
return array(
array($this->id, 0, 1),

View File

@ -20,12 +20,12 @@
*/
class TransparentBlock extends GenericBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isActivable = false;
$this->breakable = true;

View File

@ -25,11 +25,12 @@ class TrapdoorBlock extends TransparentBlock{
$this->isActivable = true;
if(($this->meta & 0x04) === 0x04){
$this->isFullBlock = false;
}else{
} else{
$this->isFullBlock = true;
}
$this->hardness = 15;
}
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){
$faces = array(
@ -43,18 +44,23 @@ class TrapdoorBlock extends TransparentBlock{
$this->meta |= 0x08;
}
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function getDrops(Item $item, Player $player){
return array(
array($this->id, 0, 1),
);
}
public function onActivate(Item $item, Player $player){
$this->meta ^= 0x04;
$this->level->setBlock($this, $this, true, false, 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){
$ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, BLOCK_UPDATE_NORMAL);
return $ret;
}
public function getSourceCount(){
$count = 0;
for($side = 2; $side <= 5; ++$side){
if( $this->getSide($side) instanceof WaterBlock ){
if($this->getSide($side) instanceof WaterBlock){
$b = $this->getSide($side);
$level = $b->meta & 0x07;
if($level == 0x00){
@ -42,6 +43,7 @@ class WaterBlock extends LiquidBlock{
}
}
}
return $count;
}
@ -55,12 +57,14 @@ class WaterBlock extends LiquidBlock{
$level = $b->meta & 0x07;
if($level == 0x00){
$this->level->setBlock($b, new ObsidianBlock(), false, false, true);
}else{
} else{
$this->level->setBlock($b, new CobblestoneBlock(), false, false, true);
}
return true;
}
}
return false;
}
@ -70,11 +74,12 @@ class WaterBlock extends LiquidBlock{
if($b instanceof WaterBlock){
$tlevel = $b->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 null;
}
@ -98,31 +103,31 @@ class WaterBlock extends LiquidBlock{
if($down instanceof AirBlock || $down instanceof WaterBlock){
$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);
}else{
} else{
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
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);
}
}elseif($b->isFlowable === true){
} elseif($b->isFlowable === 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);
}
}
}
}
}else{
} else{
//Extend Remove for Left Waters
for($side = 2; $side <= 5; ++$side){
$sb = $this->getSide($side);
if($sb instanceof WaterBlock){
$tlevel = $sb->meta & 0x07;
if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) {
$ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
}
for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($sb, new AirBlock(), false, false, true);
}
}
@ -130,10 +135,10 @@ class WaterBlock extends LiquidBlock{
if($b instanceof WaterBlock){
$tlevel = $b->meta & 0x07;
if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) {
$ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
}
for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($b, new AirBlock(), false, false, true);
}
}
@ -141,6 +146,7 @@ class WaterBlock extends LiquidBlock{
}
$this->level->setBlock($this, new AirBlock(), false, false, true);
}
return false;
}
}

View File

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

View File

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

View File

@ -28,55 +28,62 @@ class WoodSlabBlock extends TransparentBlock{
2 => "Birch",
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){
$this->isFullBlock = true;
}else{
} else{
$this->isFullBlock = false;
}
$this->hardness = 15;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$this->meta &= 0x07;
if($face === 0){
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);
return true;
}elseif($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->meta &= 0x07;
if($face === 0){
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);
return true;
} 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);
return true;
} else{
$this->meta |= 0x08;
}
} elseif($face === 1){
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);
return true;
} 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);
return true;
}
} elseif(!$player->entity->inBlock($block)){
if($block->getID() === WOOD_SLAB){
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true;
}else{
}
return false;
} else{
if($fy > 0.5){
$this->meta |= 0x08;
}
}elseif($face === 1){
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);
return true;
}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);
return true;
}
}elseif(!$player->entity->inBlock($block)){
if($block->getID() === WOOD_SLAB){
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true;
}
return false;
}else{
if($fy > 0.5){
$this->meta |= 0x08;
}
}
}else{
return false;
}
if($block->getID() === WOOD_SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
return false;
}
$this->level->setBlock($block, $this, true, false, true);
return true;
} else{
return false;
}
if($block->getID() === WOOD_SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
return false;
}
$this->level->setBlock($block, $this, true, false, true);
return true;
}
public function getBreakTime(Item $item, Player $player){
@ -101,7 +108,7 @@ class WoodSlabBlock extends TransparentBlock{
public function getDrops(Item $item, Player $player){
return array(
array($this->id, $this->meta & 0x07, 1),
array($this->id, $this->meta & 0x07, 1),
);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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