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(
@ -108,8 +108,10 @@ abstract class Achievement{
$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,6 +20,7 @@
*/
namespace PocketMine;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Utils\Config as Config;
use PocketMine\Player as Player;
@ -83,6 +84,7 @@ class BanAPI{
} elseif($this->ops->exists($username)){
return true;
}
return false;
}
@ -108,6 +110,7 @@ class BanAPI{
return false;
}
}
return;
case "console.command": //Checks if a command is allowed with the current user permissions.
if(isset($this->cmdWhitelist[$data["cmd"]])){
@ -121,6 +124,7 @@ class BanAPI{
} elseif($data["issuer"] === "console" or $data["issuer"] === "rcon"){
return;
}
return false;
}
}
@ -148,7 +152,7 @@ class BanAPI{
break;
case "op":
$user = strtolower($params[0]);
if($user == NULL){
if($user == null){
$output .= "Usage: /op <player>\n";
break;
}
@ -310,6 +314,7 @@ class BanAPI{
}
break;
}
return $output;
}
@ -400,6 +405,7 @@ class BanAPI{
} 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;
@ -237,6 +238,7 @@ class BlockAPI{
foreach(explode(",", $str) as $b){
$blocks[] = BlockAPI::fromString($b, false);
}
return $blocks;
} else{
$b = explode(":", str_replace(" ", "_", trim($str)));
@ -254,6 +256,7 @@ class BlockAPI{
} else{
$item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta);
}
return $item;
}
}
@ -268,6 +271,7 @@ class BlockAPI{
if($v instanceof Position){
$b->position($v);
}
return $b;
}
@ -279,6 +283,7 @@ class BlockAPI{
} else{
$i = new Item($id, $meta, $count);
}
return $i;
}
@ -325,6 +330,7 @@ class BlockAPI{
break;
}
return $output;
}
@ -339,6 +345,7 @@ class BlockAPI{
if($send === true){
$player->sendInventorySlot($player->slot);
}
return 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;
}
@ -398,6 +406,7 @@ class BlockAPI{
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,6 +438,7 @@ class BlockAPI{
if($item->getCount() <= 0){
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0));
}
return false;
}
@ -437,6 +447,7 @@ class BlockAPI{
$hand->position($block);
} elseif($block->getID() === FIRE){
$player->level->setBlock($block, new Block\AirBlock(), true, false, true);
return false;
} else{
return $this->cancelAction($block, $player, false);
@ -519,6 +530,7 @@ class BlockAPI{
if($level === BLOCK_UPDATE_NORMAL){
$this->blockUpdateAround($block, $level);
}
return $level;
}
@ -533,8 +545,10 @@ class BlockAPI{
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 . ");");
return true;
}
return false;
}

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();
}
@ -100,6 +102,7 @@ class ChatAPI{
}
break;
}
return $output;
}

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();
@ -151,11 +153,13 @@ class ConsoleAPI{
$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;
}
@ -226,6 +230,7 @@ class ConsoleAPI{
$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":
@ -252,7 +257,8 @@ class ConsoleAPI{
}
if(($d1 = $this->server->api->dhandle("console.command." . $cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false
or ($d2 = $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false){
or ($d2 = $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false
){
$output = "You don't have permissions to use this command.\n";
} elseif($d1 !== true and (!isset($d2) or $d2 !== true)){
if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){
@ -265,6 +271,7 @@ class ConsoleAPI{
if($output != "" and ($issuer instanceof Player)){
$issuer->sendChat(trim($output));
}
return $output;
}
}
@ -296,6 +303,7 @@ class ConsoleLoop extends \Thread{
public $base;
public $ev;
public $fp;
public function __construct(){
$this->line = false;
$this->stop = false;
@ -315,6 +323,7 @@ class ConsoleLoop extends \Thread{
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)){
@ -60,6 +62,7 @@ class Container{
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{

View File

@ -20,6 +20,7 @@
*/
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;
}
@ -99,6 +102,7 @@ class LevelAPI{
$output .= "Seed: " . $this->server->api->level->getDefault()->getSeed() . "\n";
}
}
return $output;
}
@ -123,6 +127,7 @@ class LevelAPI{
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed);
$gen->generate();
$gen->close();
return true;
}
@ -137,6 +142,7 @@ class LevelAPI{
return false;
}
}
return true;
}
@ -153,6 +159,7 @@ class LevelAPI{
}
$level->close();
unset($this->levels[$name]);
return true;
}
@ -161,6 +168,7 @@ class LevelAPI{
return true;
} elseif($this->levelExists($name) === false){
console("[NOTICE] Level \"" . $name . "\" not found");
return false;
}
$path = \PocketMine\DATA . "worlds/" . $name . "/";
@ -168,6 +176,7 @@ class LevelAPI{
$level = new LevelFormat($path . "level.pmf");
if(!$level->isLoaded){
console("[ERROR] Could not load level \"" . $name . "\"");
return false;
}
//$entities = new Config($path."entities.yml", Config::YAML);
@ -272,6 +281,7 @@ class LevelAPI{
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"]);
}
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;
@ -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{
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;
}
@ -452,6 +457,7 @@ class Player extends RealHuman{
$this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk"));
++$this->chunkScheduled;
}
return;
} 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]);
@ -604,6 +612,7 @@ class Player extends RealHuman{
}*/
$this->setSpawn($pos);
$this->server->schedule(60, array($this, "checkSleep"));
return true;
}
@ -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,6 +658,7 @@ class Player extends RealHuman{
$pk->slot = (int) $s;
$pk->item = $slot;
$this->dataPacket($pk);
return true;
}
@ -952,6 +963,7 @@ class Player extends RealHuman{
}
}
}
return $res;
}
@ -994,6 +1006,7 @@ class Player extends RealHuman{
$this->inventory = $inv;
$this->sendSettings();
$this->sendInventory();
return true;
}
@ -1051,6 +1064,7 @@ class Player extends RealHuman{
$time = microtime(true);
if($time > $this->timeout){
$this->close("timeout");
return false;
}
@ -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){
@ -1245,22 +1260,27 @@ class Player extends RealHuman{
$this->directDataPacket($pk);
}
$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)){
$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;
}
@ -2019,7 +2041,8 @@ class Player extends RealHuman{
"slotdata" => $slot,
"itemdata" => $item,
"player" => $this,
)) === false){
)) === false
){
$pk = new Network\Protocol\ContainerSetSlotPacket;
$pk->windowid = $packet->windowid;
$pk->slot = $packet->slot;
@ -2071,7 +2094,8 @@ class Player extends RealHuman{
"slotdata" => $slot,
"itemdata" => $item,
"player" => $this,
)) === false){
)) === false
){
$pk = new Network\Protocol\ContainerSetSlotPacket;
$pk->windowid = $packet->windowid;
$pk->slot = $packet->slot;
@ -2213,6 +2237,7 @@ class Player extends RealHuman{
$this->recoveryQueue[$count] = $rk;
$this->send($rk);
}
return $cnts;
}
@ -2234,6 +2259,7 @@ class Player extends RealHuman{
}
$this->send($pk);
return array($pk->seqNumber);
}
@ -2267,6 +2293,7 @@ class Player extends RealHuman{
$packet->reliability = 2;
@$this->buffer->data[] = $packet;
$this->bufferLen += 6 + $len;
return array();
}

View File

@ -20,6 +20,7 @@
*/
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();
}
@ -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){
@ -294,6 +298,7 @@ class PlayerAPI{
$output = substr($output, 0, -2) . "\n";
break;
}
return $output;
}
@ -304,6 +309,7 @@ class PlayerAPI{
$origin = Player::get($name);
if($origin instanceof Player){
$name = $origin->getUsername();
return $origin->teleport($lv->getSafeSpawn());
}
} else{
@ -316,9 +322,11 @@ class PlayerAPI{
$origin = Player::get($name);
if($origin instanceof Player){
$name = $origin->getUsername();
return $origin->teleport($player->entity);
}
}
return false;
}
@ -330,8 +338,10 @@ class PlayerAPI{
$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);
@ -57,6 +59,7 @@ class PluginAPI extends \stdClass{
$output .= "\n";
break;
}
return $output;
}
@ -72,6 +75,7 @@ class PluginAPI extends \stdClass{
foreach($this->plugins as $p){
$list[] = $p[1];
}
return $list;
}
@ -82,6 +86,7 @@ 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");
return false;
}
if(strtolower(substr($file, -3)) === "pmf"){
@ -93,6 +98,7 @@ class PluginAPI extends \stdClass{
$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));
return false;
}
$info = array();
@ -117,15 +123,18 @@ class PluginAPI extends \stdClass{
}
if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"]) or !isset($info["author"])){
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);
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;
}
@ -152,6 +161,7 @@ class PluginAPI extends \stdClass{
} 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", ""));
@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;
}
@ -201,6 +215,7 @@ class PluginAPI extends \stdClass{
$path = $this->configPath($plugin);
$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;
@ -98,6 +99,7 @@ class Server{
public function getTPS(){
$v = array_values($this->tickMeasure);
$tps = 40 / ($v[39] - $v[0]);
return round($tps, 4);
}
@ -156,6 +158,7 @@ class Server{
if($fetch === true and ($result instanceof \SQLite3Result)){
$result = $result->fetchArray(SQLITE3_ASSOC);
}
return $result;
}
@ -176,6 +179,7 @@ class Server{
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);
}
return $info;
}
@ -242,6 +246,7 @@ class Server{
$ID = $this->asyncID++;
$this->async[$ID] = $callable;
$this->asyncThread->input .= Utils::writeInt($ID) . Utils::writeShort($type) . $d;
return $ID;
}
@ -306,6 +311,7 @@ class Server{
$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);
return $hnid;
}
@ -349,6 +355,7 @@ class Server{
if($result !== false){
$this->trigger($event, $data);
}
return $result;
}
@ -375,7 +382,6 @@ class Server{
}
public function init(){
register_tick_function(array($this, "tick"));
declare(ticks = 5000); //Minimum TPS for main thread locks
@ -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;
}
@ -625,6 +633,7 @@ 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) . ");");
return $chcnt;
}
@ -657,6 +666,7 @@ class Server{
}
$actions->finalize();
}
return $actionCount;
}
@ -677,6 +687,7 @@ 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);
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;
@ -101,6 +102,7 @@ class ServerAPI{
public function run(){
$this->load();
return $this->init();
}
@ -257,6 +259,7 @@ 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;
}
@ -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();
@ -296,7 +301,7 @@ class ServerAPI{
"max" => $this->server->maxClients,
"plugins" => $plist,
),
), NULL);
), null);
}
public function __destruct(){
@ -398,6 +403,7 @@ class ServerAPI{
console("[INFO] [UPnP] Removing port forward...");
RemovePortForward($this->getProperty("server-port"));
}
return $this->restart;
}
@ -472,8 +478,10 @@ class ServerAPI{
$v = (int) $v;
break;
}
return $v;
}
return ($this->config->exists($name) ? $this->config->get($name) : $default);
}

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();
}
@ -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,6 +95,7 @@ class TimeAPI{
if(!($level instanceof Level)){
$level = $this->server->api->level->getDefault();
}
return $raw === true ? $level->getTime() : abs($level->getTime()) % 19200;
}
@ -101,6 +108,7 @@ 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);
}
@ -115,6 +123,7 @@ class TimeAPI{
} else{
$time = "sunrise";
}
return $time;
}
@ -127,6 +136,7 @@ class TimeAPI{
} else{
$level->setTime((int) $time);
}
return $level->getTime();
}

View File

@ -32,6 +32,7 @@ class BedBlock extends TransparentBlock{
$pk = new ChatPacket;
$pk->message = "You can only sleep at night";
$player->dataPacket($pk);
return true;
}
@ -54,6 +55,7 @@ class BedBlock extends TransparentBlock{
$pk = new ChatPacket;
$pk->message = "This bed is incomplete";
$player->dataPacket($pk);
return true;
}
}
@ -63,6 +65,7 @@ class BedBlock extends TransparentBlock{
$pk->message = "This bed is occupied";
$player->dataPacket($pk);
}
return true;
}
@ -82,9 +85,11 @@ class BedBlock extends TransparentBlock{
$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;
}
@ -116,6 +121,7 @@ class BedBlock extends TransparentBlock{
}
}
$this->level->setBlock($this, new AirBlock(), true, false, true);
return true;
}

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,6 +57,7 @@ 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){
@ -60,12 +65,14 @@ class BeetrootBlock extends FlowableBlock{
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
} else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}
@ -77,6 +84,7 @@ class BeetrootBlock extends FlowableBlock{
} else{
$drops[] = array(BEETROOT_SEEDS, 0, 1);
}
return $drops;
}
}

View File

@ -211,6 +211,7 @@ abstract class Block extends Position{
if(($player->gamemode & 0x01) === 0x01){
return 0.15;
}
return $this->breakTime;
}
@ -219,6 +220,7 @@ abstract class Block extends Position{
if($this->level instanceof Level){
return $this->level->getBlock($v);
}
return $v;
}

View File

@ -30,9 +30,11 @@ 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;
}
@ -40,8 +42,10 @@ class BrownMushroomBlock extends FlowableBlock{
$down = $this->getSide(0);
if($down->isTransparent === false){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
}

View File

@ -44,11 +44,13 @@ class BurningFurnaceBlock extends SolidBlock{
));
$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;
}
@ -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,6 +32,7 @@ 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){
@ -50,9 +51,11 @@ class CactusBlock extends TransparentBlock{
++$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;
}
@ -60,8 +64,10 @@ class CakeBlock extends TransparentBlock{
} 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,6 +57,7 @@ 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){
@ -60,12 +65,14 @@ class CarrotBlock extends FlowableBlock{
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
} else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}
@ -76,6 +83,7 @@ class CarrotBlock extends FlowableBlock{
} 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,
@ -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;
}
@ -101,12 +104,12 @@ class ChestBlock extends TransparentBlock{
}
if(($player->gamemode & 0x01) === 0x01){
return true;
}
$chest->openInventory($player);
return true;
}
@ -123,6 +126,7 @@ class ChestBlock extends TransparentBlock{
}
}
}
return $drops;
}
}

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

@ -29,8 +29,10 @@ class CyanFlowerBlock extends FlowableBlock{
$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

@ -29,8 +29,10 @@ class DandelionBlock extends FlowableBlock{
$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

@ -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

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

View File

@ -45,6 +45,7 @@ class FallableBlock extends SolidBlock{
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$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

@ -30,6 +30,7 @@ class FenceGateBlock extends TransparentBlock{
}
$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,
@ -60,6 +64,7 @@ class FenceGateBlock extends TransparentBlock{
$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){
if($this->getSide(0)->getID() !== NETHERRACK){
$this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL;
}
}
return false;
}

View File

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

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{
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
}
return false;
}

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()){
if(($player->gamemode & 0x01) === 0){
$item->useOn($this);
}
$this->level->setBlock($this, new FarmlandBlock());
return true;
}
return false;
}
}

View File

@ -31,6 +31,7 @@ class GravelBlock extends FallableBlock{
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

@ -31,6 +31,7 @@ class IceBlock extends TransparentBlock{
} else{
$this->level->setBlock($this, new AirBlock(), true, false, true);
}
return true;
}

View File

@ -26,6 +26,7 @@ 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(
@ -37,9 +38,11 @@ class LadderBlock extends TransparentBlock{
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

@ -28,6 +28,7 @@ class LavaBlock 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, 40, BLOCK_UPDATE_NORMAL);
return $ret;
}
@ -42,6 +43,7 @@ class LavaBlock extends LiquidBlock{
}
}
}
return $count;
}
@ -70,6 +72,7 @@ class LavaBlock extends LiquidBlock{
}
}
}
return null;
}
@ -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(
@ -123,10 +124,12 @@ class LeavesBlock extends TransparentBlock{
//TODO
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1));
}
return BLOCK_UPDATE_NORMAL;
}
}
}
return false;
}
@ -147,6 +150,7 @@ class LeavesBlock extends TransparentBlock{
$drops[] = array(APPLE, 0, 1);
}
}
return $drops;
}
}

View File

@ -34,6 +34,7 @@ class LitPumpkinBlock extends SolidBlock{
);
$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;
}
return false;
}
@ -40,6 +43,7 @@ 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){
@ -47,6 +51,7 @@ class MelonStemBlock extends FlowableBlock{
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
} else{
for($side = 2; $side <= 5; ++$side){
@ -62,8 +67,10 @@ class MelonStemBlock extends FlowableBlock{
}
}
}
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

@ -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,6 +57,7 @@ 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){
@ -60,12 +65,14 @@ class PotatoBlock extends FlowableBlock{
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
} else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}
@ -76,6 +83,7 @@ class PotatoBlock extends FlowableBlock{
} 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;
}
return false;
}
@ -40,6 +43,7 @@ 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){
@ -47,6 +51,7 @@ class PumpkinStemBlock extends FlowableBlock{
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
} else{
for($side = 2; $side <= 5; ++$side){
@ -62,8 +67,10 @@ class PumpkinStemBlock extends FlowableBlock{
}
}
}
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

@ -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;
}

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,16 +57,20 @@ 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
@ -74,12 +80,14 @@ class SaplingBlock extends FlowableBlock{
} else{
$this->meta |= 0x08;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
} 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{
$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

@ -46,9 +46,11 @@ class SlabBlock extends TransparentBlock{
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;
@ -56,17 +58,21 @@ class SlabBlock extends TransparentBlock{
} 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){
@ -80,6 +86,7 @@ class SlabBlock extends TransparentBlock{
return false;
}
$this->level->setBlock($block, $this, true, false, true);
return true;
}

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

@ -59,6 +59,7 @@ class StairBlock extends TransparentBlock{
$this->meta |= 0x04; //Upside-down stairs
}
$this->level->setBlock($block, $this, true, false, true);
return true;
}

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,6 +61,7 @@ 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){
@ -77,9 +80,11 @@ class SugarcaneBlock extends FlowableBlock{
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
}
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}
@ -87,6 +92,7 @@ class SugarcaneBlock extends FlowableBlock{
$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);
@ -96,9 +102,11 @@ class SugarcaneBlock extends FlowableBlock{
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

@ -41,9 +41,11 @@ class TorchBlock extends FlowableBlock{
if($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === FENCE)){ //Replace with common break method
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){
$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

@ -30,6 +30,7 @@ class TrapdoorBlock extends TransparentBlock{
}
$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,6 +28,7 @@ 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;
}
@ -42,6 +43,7 @@ class WaterBlock extends LiquidBlock{
}
}
}
return $count;
}
@ -58,9 +60,11 @@ class WaterBlock extends LiquidBlock{
} else{
$this->level->setBlock($b, new CobblestoneBlock(), false, false, true);
}
return true;
}
}
return false;
}
@ -75,6 +79,7 @@ class WaterBlock extends LiquidBlock{
}
}
}
return null;
}
@ -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,6 +58,7 @@ 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){
@ -64,6 +69,7 @@ class WheatBlock extends FlowableBlock{
}
}
}
return false;
}
@ -75,6 +81,7 @@ class WheatBlock extends FlowableBlock{
} 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

@ -42,9 +42,11 @@ class WoodSlabBlock extends TransparentBlock{
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;
@ -52,17 +54,21 @@ class WoodSlabBlock extends TransparentBlock{
} 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){
@ -76,6 +82,7 @@ class WoodSlabBlock extends TransparentBlock{
return false;
}
$this->level->setBlock($block, $this, true, false, true);
return true;
}

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

@ -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{

View File

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

View File

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

View File

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

View File

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

View File

@ -20,6 +20,7 @@
*/
namespace PocketMine\Entity;
use PocketMine;
class Creeper extends Monster implements Explosive{

View File

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

View File

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

View File

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

View File

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

View File

@ -20,6 +20,7 @@
*/
namespace PocketMine\Entity;
use PocketMine;
class Enderman extends Monster implements InventorySource{

View File

@ -20,6 +20,7 @@
*/
namespace PocketMine\Entity;
use PocketMine;
use PocketMine\Level\Position as Position;
use PocketMine\Level\Level as Level;
@ -244,6 +245,7 @@ abstract class Entity extends Position{
}
$this->lastUpdate = $timeNow;
return false;
}
@ -364,8 +366,10 @@ abstract class Entity extends Position{
public function setPositionAndRotation(Vector3 $pos, $yaw, $pitch){
if($this->setPosition($pos) === true){
$this->setRotation($yaw, $pitch);
return true;
}
return false;
}
@ -413,6 +417,7 @@ abstract class Entity extends Position{
$this->boundingBox->setBounds($pos->x - $radius, $pos->y, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height, $pos->z + $radius);
$this->scheduleUpdate();
return true;
}
@ -462,8 +467,10 @@ abstract class Entity extends Position{
$pk->yaw = $this->yaw;
$this->dataPacket($pk);
}
return true;
}
return false;
}

View File

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

View File

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

View File

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

View File

@ -20,6 +20,7 @@
*/
namespace PocketMine\Entity;
use PocketMine;
use PocketMine\Item\Item as Item;
use PocketMine\BlockAPI as BlockAPI;
@ -196,6 +197,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
if($this instanceof Player){
$this->sendArmor();
}
return true;
}
@ -204,6 +206,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
if(!isset($this->armor[$slot])){
$this->armor[$slot] = BlockAPI::getItem(AIR, 0, 0);
}
return $this->armor[$slot];
}
@ -241,6 +244,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
16 => array("type" => 0, "value" => 0),
17 => array("type" => 6, "value" => array(0, 0, 0)),
);
/*if($this->class === ENTITY_MOB and $this->type === MOB_SHEEP){
if(!isset($this->data["Sheared"])){
$this->data["Sheared"] = 0;
@ -255,6 +259,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
$d[17]["value"] = array($this->player->sleeping->x, $this->player->sleeping->y, $this->player->sleeping->z);
}
}*/
return $d;
}
@ -272,6 +277,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
return $i;
}
}
return false;
}
@ -300,6 +306,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
}
$item->setCount($item->getCount() - $add);
}
return true;
}
@ -329,6 +336,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
}
$item->setCount($item->getCount() - $add);
}
return true;
}
@ -356,6 +364,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
}
$item->setCount($item->getCount() - $remove);
}
return true;
}
@ -364,6 +373,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
return false;
}
$this->inventory[(int) $slot] = $ev->getNewItem();
return true;
}
@ -372,6 +382,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
if(!isset($this->inventory[$slot])){
$this->inventory[$slot] = BlockAPI::getItem(AIR, 0, 0);
}
return $this->inventory[$slot];
}

View File

@ -20,6 +20,7 @@
*/
namespace PocketMine\Entity;
use PocketMine;
use PocketMine\Item\Item as Item;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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