Lots of typos fixed, undefined variables, unused code

This commit is contained in:
Shoghi Cervantes 2014-02-19 01:55:42 +01:00
parent 3d3111fef6
commit f1b5f83fd4
35 changed files with 63 additions and 251 deletions

View File

@ -32,7 +32,7 @@ class BanAPI{
private $ops; private $ops;
/** @var Config */ /** @var Config */
private $bannedIPs; private $bannedIPs;
private $cmdWL = array();//Command WhiteList private $cmdWhitelist = array();//Command WhiteList
function __construct(){ function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
@ -104,7 +104,6 @@ class BanAPI{
} }
} }
return; return;
break;
case "console.command"://Checks if a command is allowed with the current user permissions. case "console.command"://Checks if a command is allowed with the current user permissions.
if(isset($this->cmdWhitelist[$data["cmd"]])){ if(isset($this->cmdWhitelist[$data["cmd"]])){
return; return;
@ -118,7 +117,6 @@ class BanAPI{
return; return;
} }
return false; return false;
break;
} }
} }
@ -152,7 +150,7 @@ class BanAPI{
$player = $this->server->api->player->get($user); $player = $this->server->api->player->get($user);
if(!($player instanceof Player)){ if(!($player instanceof Player)){
$this->ops->set($user); $this->ops->set($user);
$this->ops->save($user); $this->ops->save();
$output .= $user." is now op\n"; $output .= $user." is now op\n";
break; break;
} }

View File

@ -516,13 +516,9 @@ class BlockAPI{
public function nextRandomUpdate(Position $pos){ public function nextRandomUpdate(Position $pos){
if(!isset($this->scheduledUpdates[$pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".BLOCK_UPDATE_RANDOM])){ if(!isset($this->scheduledUpdates[$pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".BLOCK_UPDATE_RANDOM])){
$X = (($pos->x >> 4) << 4);
$Y = (($pos->y >> 4) << 4);
$Z = (($pos->z >> 4) << 4);
$time = microtime(true); $time = microtime(true);
$i = 0;
$offset = 0; $offset = 0;
while(true){ do{
$t = $offset + Utils::getRandomUpdateTicks() * 0.05; $t = $offset + Utils::getRandomUpdateTicks() * 0.05;
$update = $this->server->query("SELECT COUNT(*) FROM blockUpdates WHERE level = '".$pos->level->getName()."' AND type = ".BLOCK_UPDATE_RANDOM." AND delay >= ".($time + $t - 1)." AND delay <= ".($time + $t + 1).";"); $update = $this->server->query("SELECT COUNT(*) FROM blockUpdates WHERE level = '".$pos->level->getName()."' AND type = ".BLOCK_UPDATE_RANDOM." AND delay >= ".($time + $t - 1)." AND delay <= ".($time + $t + 1).";");
if($update instanceof SQLite3Result){ if($update instanceof SQLite3Result){
@ -534,7 +530,7 @@ class BlockAPI{
break; break;
} }
$offset += mt_rand(25, 75); $offset += mt_rand(25, 75);
} }while(true);
$this->scheduleBlockUpdate($pos, $t / 0.05, BLOCK_UPDATE_RANDOM); $this->scheduleBlockUpdate($pos, $t / 0.05, BLOCK_UPDATE_RANDOM);
} }
} }

View File

@ -26,7 +26,6 @@ class ConsoleAPI{
$this->cmds = array(); $this->cmds = array();
$this->alias = array(); $this->alias = array();
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->last = microtime(true);
} }
public function init(){ public function init(){
@ -250,7 +249,7 @@ class ConsoleAPI{
if(($d1 = $this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false if(($d1 = $this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false
or ($d2 = $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false){ or ($d2 = $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false){
$output = "You don't have permissions to use this command.\n"; $output = "You don't have permissions to use this command.\n";
}elseif($d1 !== true and $d2 !== true){ }elseif($d1 !== true and (isset($d2) and $d2 !== true)){
if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){ if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){
$output = @call_user_func($this->cmds[$cmd], $cmd, $params, $issuer, $alias); $output = @call_user_func($this->cmds[$cmd], $cmd, $params, $issuer, $alias);
}elseif($this->server->api->dhandle("console.command.unknown", array("cmd" => $cmd, "params" => $params, "issuer" => $issuer, "alias" => $alias)) !== false){ }elseif($this->server->api->dhandle("console.command.unknown", array("cmd" => $cmd, "params" => $params, "issuer" => $issuer, "alias" => $alias)) !== false){
@ -326,7 +325,7 @@ class ConsoleLoop extends Thread{
} }
if(!extension_loaded("readline")){ if(!extension_loaded("readline")){
@fclose($fp); @fclose($this->fp);
} }
exit(0); exit(0);
} }

View File

@ -198,7 +198,6 @@ class LevelAPI{
$t = $this->server->api->tile->add($this->levels[$name], $tile["id"], $tile["x"], $tile["y"], $tile["z"], $tile); $t = $this->server->api->tile->add($this->levels[$name], $tile["id"], $tile["x"], $tile["y"], $tile["z"], $tile);
} }
$timeu = microtime(true);
foreach($blockUpdates->getAll() as $bupdate){ foreach($blockUpdates->getAll() as $bupdate){
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]); $this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
} }

View File

@ -111,7 +111,6 @@ class PlayerAPI{
} }
$this->server->api->chat->broadcast($data["player"]->username . $message); $this->server->api->chat->broadcast($data["player"]->username . $message);
return true; return true;
break;
} }
} }

View File

@ -196,19 +196,6 @@ class PluginAPI extends stdClass{
return $path; return $path;
} }
private function fillDefaults($default, &$yaml){
foreach($default as $k => $v){
if(is_array($v)){
if(!isset($yaml[$k]) or !is_array($yaml[$k])){
$yaml[$k] = array();
}
$this->fillDefaults($v, $yaml[$k]);
}elseif(!isset($yaml[$k])){
$yaml[$k] = $v;
}
}
}
public function readYAML($file){ public function readYAML($file){
return yaml_parse(preg_replace("#^([ ]*)([a-zA-Z_]{1}[^\:]*)\:#m", "$1\"$2\":", file_get_contents($file))); return yaml_parse(preg_replace("#^([ ]*)([a-zA-Z_]{1}[^\:]*)\:#m", "$1\"$2\":", file_get_contents($file)));
} }

View File

@ -222,7 +222,6 @@ class Player{
$Y = $id[1]; $Y = $id[1];
$x = $X << 4; $x = $X << 4;
$z = $Z << 4; $z = $Z << 4;
$y = $Y << 4;
$this->level->useChunk($X, $Z, $this); $this->level->useChunk($X, $Z, $this);
$Yndex = 1 << $Y; $Yndex = 1 << $Y;
for($iY = 0; $iY < 8; ++$iY){ for($iY = 0; $iY < 8; ++$iY){
@ -328,7 +327,7 @@ class Player{
$this->chunksLoaded = array(); $this->chunksLoaded = array();
$this->chunksOrder = array(); $this->chunksOrder = array();
$this->chunkCount = array(); $this->chunkCount = array();
$this->cratingItems = array(); $this->craftingItems = array();
$this->received = array(); $this->received = array();
} }
} }
@ -698,11 +697,10 @@ class Player{
return; return;
}else{ }else{
$message = $data->get(); $message = $data->get();
$this->sendChat(preg_replace('/\x1b\[[0-9;]*m/', "", $message["message"]), $message["player"]); //Remove ANSI codes from chat $this->sendChat($message["message"], $message["player"]);
} }
}else{ }else{
$message = (string) $data; $this->sendChat((string) $data);
$this->sendChat(preg_replace('/\x1b\[[0-9;]*m/', "", (string) $data)); //Remove ANSI codes from chat
} }
break; break;
} }
@ -1377,8 +1375,8 @@ class Player{
$inv[] = array($item[0], $item[1], 1); $inv[] = array($item[0], $item[1], 1);
} }
} }
$this->data->set("inventory", $inv);
} }
$this->data->set("inventory", $inv);
} }
$this->achievements = $this->data->get("achievements"); $this->achievements = $this->data->get("achievements");
$this->data->set("caseusername", $this->username); $this->data->set("caseusername", $this->username);
@ -2007,6 +2005,7 @@ class Player{
$packet->item = $this->getSlot($this->slot); $packet->item = $this->getSlot($this->slot);
$this->craftingItems = array(); $this->craftingItems = array();
$this->toCraft = array(); $this->toCraft = array();
$data = array();
$data["eid"] = $packet->eid; $data["eid"] = $packet->eid;
$data["unknown"] = $packet->unknown; $data["unknown"] = $packet->unknown;
$data["item"] = $packet->item; $data["item"] = $packet->item;
@ -2374,7 +2373,7 @@ class Player{
return $cnts; return $cnts;
} }
public function directDataPacket(RakNetDataPacket $packet, $reliability = 0, $recover = true){ public function directDataPacket(RakNetDataPacket $packet, $recover = true){
if($this->connected === false){ if($this->connected === false){
return false; return false;
} }
@ -2382,7 +2381,6 @@ class Player{
if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){ if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){
return array(); return array();
} }
$packet->encode(); $packet->encode();
$pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0);
$pk->data[] = $packet; $pk->data[] = $packet;

View File

@ -21,8 +21,8 @@
class PocketMinecraftServer{ class PocketMinecraftServer{
public $tCnt; public $tCnt;
public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $spawn, $seed, $stop, $gamemode, $difficulty$name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $ticks, $memoryStats, $async = array(), $asyncID = 0; private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $doTick, $ticks, $memoryStats, $schedule, $asyncThread, $async = array(), $asyncID = 0;
/** /**
* @var ServerAPI * @var ServerAPI
@ -45,10 +45,7 @@ class PocketMinecraftServer{
$this->eventsID = array(); $this->eventsID = array();
$this->handlers = array(); $this->handlers = array();
$this->invisible = false; $this->invisible = false;
$this->levelData = false;
$this->difficulty = 1; $this->difficulty = 1;
$this->tiles = array();
$this->entities = array();
$this->custom = array(); $this->custom = array();
$this->evCnt = 1; $this->evCnt = 1;
$this->handCnt = 1; $this->handCnt = 1;
@ -57,7 +54,6 @@ class PocketMinecraftServer{
$this->schedule = array(); $this->schedule = array();
$this->scheduleCnt = 1; $this->scheduleCnt = 1;
$this->description = ""; $this->description = "";
$this->whitelist = false;
$this->memoryStats = array(); $this->memoryStats = array();
$this->clients = array(); $this->clients = array();
$this->spawn = false; $this->spawn = false;
@ -129,7 +125,7 @@ class PocketMinecraftServer{
public function startDatabase(){ public function startDatabase(){
$this->preparedSQL = new stdClass(); $this->preparedSQL = new stdClass();
$this->preparedSQL->entity = new stdClass(); $this->preparedSQL->entity = new stdClass();
$this->database = new SQLite3(":memory:"); $this->database = new SQLite3(":memory:", SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
$this->query("PRAGMA journal_mode = OFF;"); $this->query("PRAGMA journal_mode = OFF;");
$this->query("PRAGMA encoding = \"UTF-8\";"); $this->query("PRAGMA encoding = \"UTF-8\";");
$this->query("PRAGMA secure_delete = OFF;"); $this->query("PRAGMA secure_delete = OFF;");
@ -316,7 +312,6 @@ class PocketMinecraftServer{
$handlers->finalize(); $handlers->finalize();
foreach($call as $hnid => $boolean){ foreach($call as $hnid => $boolean){
if($result !== false and $result !== true){ if($result !== false and $result !== true){
$called[$hnid] = true;
$handler = $this->handlers[$hnid]; $handler = $this->handlers[$hnid];
if(is_array($handler)){ if(is_array($handler)){
$method = $handler[1]; $method = $handler[1];

View File

@ -51,7 +51,7 @@ elif [ "$1" == "mac" ]; then
[ -z "$march" ] && march=prescott; [ -z "$march" ] && march=prescott;
[ -z "$mtune" ] && mtune=generic; [ -z "$mtune" ] && mtune=generic;
[ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -fomit-frame-pointer"; [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -fomit-frame-pointer";
[ -z "$LDFLAGS" ] && LDFLAGS="-undefined dynamic_lookup -Wl,-rpath,@loader_path/../lib"; [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib";
export DYLD_LIBRARY_PATH="@loader_path/../lib" export DYLD_LIBRARY_PATH="@loader_path/../lib"
OPENSSL_TARGET="darwin-i386-cc" OPENSSL_TARGET="darwin-i386-cc"
echo "[INFO] Compiling for Intel MacOS x86" echo "[INFO] Compiling for Intel MacOS x86"
@ -59,7 +59,7 @@ elif [ "$1" == "mac64" ]; then
[ -z "$march" ] && march=core2; [ -z "$march" ] && march=core2;
[ -z "$mtune" ] && mtune=generic; [ -z "$mtune" ] && mtune=generic;
[ -z "$CFLAGS" ] && CFLAGS="-m64 -arch x86_64 -fomit-frame-pointer"; [ -z "$CFLAGS" ] && CFLAGS="-m64 -arch x86_64 -fomit-frame-pointer";
[ -z "$LDFLAGS" ] && LDFLAGS="-undefined dynamic_lookup -Wl,-rpath,@loader_path/../lib"; [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib";
export DYLD_LIBRARY_PATH="@loader_path/../lib" export DYLD_LIBRARY_PATH="@loader_path/../lib"
OPENSSL_TARGET="darwin64-x86_64-cc" OPENSSL_TARGET="darwin64-x86_64-cc"
echo "[INFO] Compiling for Intel MacOS x86_64" echo "[INFO] Compiling for Intel MacOS x86_64"

View File

@ -22,7 +22,6 @@
abstract class EventHandler{ abstract class EventHandler{
public static function callEvent(BaseEvent $event){ public static function callEvent(BaseEvent $event){
$status = BaseEvent::NORMAL;
foreach($event::$handlerPriority as $priority => $handlerList){ foreach($event::$handlerPriority as $priority => $handlerList){
if(count($handlerList) > 0){ if(count($handlerList) > 0){
$event->setPrioritySlot($priority); $event->setPrioritySlot($priority);

View File

@ -140,7 +140,7 @@ function arguments ( $args ){
$args = array(); $args = array();
} }
array_shift( $args ); array_shift( $args );
$args = join( $args, ' ' ); $args = implode( $args, ' ' );
preg_match_all('/ (--[\w\-]+ (?:[= ] [^-\s]+ )? ) | (-\w+) | (\w+) /x', $args, $match ); preg_match_all('/ (--[\w\-]+ (?:[= ] [^-\s]+ )? ) | (-\w+) | (\w+) /x', $args, $match );
$args = array_shift( $match ); $args = array_shift( $match );
@ -158,7 +158,7 @@ function arguments ( $args ){
$value = preg_split( '/[= ]/', $arg, 2 ); $value = preg_split( '/[= ]/', $arg, 2 );
$com = substr( array_shift($value), 2 ); $com = substr( array_shift($value), 2 );
$value = join($value); $value = implode($value);
$ret['commands'][$com] = !empty($value) ? $value : true; $ret['commands'][$com] = !empty($value) ? $value : true;
continue; continue;

View File

@ -41,7 +41,7 @@ class SignPostBlock extends TransparentBlock{
return true; return true;
}else{ }else{
$this->meta = $faces[$face]; $this->meta = $faces[$face];
$this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta, true, false, true)); $this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta), true, false, true);
return true; return true;
} }
} }

View File

@ -43,7 +43,6 @@ class SpawnEggItem extends Item{
--$this->count; --$this->count;
} }
return true; return true;
break;
} }
return false; return false;
} }

View File

@ -30,7 +30,6 @@ class MinecraftInterface{
exit(1); exit(1);
} }
$this->bandwidth = array(0, 0, microtime(true)); $this->bandwidth = array(0, 0, microtime(true));
$this->start = microtime(true);
$this->packets = array(); $this->packets = array();
} }
@ -90,7 +89,7 @@ class MinecraftInterface{
if(EventHandler::callEvent(new PacketSendEvent($packet)) === BaseEvent::DENY){ if(EventHandler::callEvent(new PacketSendEvent($packet)) === BaseEvent::DENY){
return 0; return 0;
}elseif($packet instanceof RakNetPacket){ }elseif($packet instanceof RakNetPacket){
$codec = new RakNetCodec($packet); new RakNetCodec($packet);
} }
$write = $this->socket->write($packet->buffer, $packet->ip, $packet->port); $write = $this->socket->write($packet->buffer, $packet->ip, $packet->port);
$this->bandwidth[1] += $write; $this->bandwidth[1] += $write;

View File

@ -22,7 +22,7 @@
class UDPSocket{ class UDPSocket{
public $connected, $sock, $server; public $connected, $sock, $server, $port;
function __construct($server, $port, $listen = false, $serverip = "0.0.0.0"){ function __construct($server, $port, $listen = false, $serverip = "0.0.0.0"){
$this->server = $server; $this->server = $server;
$this->port = $port; $this->port = $port;

View File

@ -21,6 +21,7 @@
class RakNetCodec{ class RakNetCodec{
public $packet; public $packet;
private $buffer;
public function __construct(RakNetPacket $packet){ public function __construct(RakNetPacket $packet){
$this->packet = $packet; $this->packet = $packet;
$this->buffer =& $this->packet->buffer; $this->buffer =& $this->packet->buffer;

View File

@ -76,8 +76,8 @@ abstract class RakNetDataPacket extends stdClass{
$this->buffer .= Utils::writeLong($v); $this->buffer .= Utils::writeLong($v);
} }
protected function getInt($unsigned = false){ protected function getInt(){
return Utils::readInt($this->get(4), $unsigned); return Utils::readInt($this->get(4));
} }
protected function putInt($v){ protected function putInt($v){

View File

@ -50,8 +50,8 @@ class RakNetParser{
return Utils::readLong($this->get(8), $unsigned); return Utils::readLong($this->get(8), $unsigned);
} }
private function getInt($unsigned = false){ private function getInt(){
return Utils::readInt($this->get(4), $unsigned); return Utils::readInt($this->get(4));
} }
private function getShort($unsigned = false){ private function getShort($unsigned = false){

View File

@ -95,7 +95,7 @@ class PMFLevel extends PMF{
} }
private function createBlank(){ private function createBlank(){
$this->saveData(false); $this->saveData();
@mkdir(dirname($this->file)."/chunks/", 0755); @mkdir(dirname($this->file)."/chunks/", 0755);
if(!file_exists(dirname($this->file)."/entities.yml")){ if(!file_exists(dirname($this->file)."/entities.yml")){
$entities = new Config(dirname($this->file)."/entities.yml", CONFIG_YAML); $entities = new Config(dirname($this->file)."/entities.yml", CONFIG_YAML);

View File

@ -76,7 +76,6 @@ class Config{
*/ */
public function __construct($file, $type = CONFIG_DETECT, $default = array(), &$correct = null){ public function __construct($file, $type = CONFIG_DETECT, $default = array(), &$correct = null){
$this->load($file, $type, $default); $this->load($file, $type, $default);
$correct = $this->check();
} }
public function reload(){ public function reload(){
@ -84,7 +83,6 @@ class Config{
unset($this->correct); unset($this->correct);
unset($this->type); unset($this->type);
$this->load($this->file); $this->load($this->file);
$correct = $this->check();
} }
public function fixYAMLIndexes($str){ public function fixYAMLIndexes($str){
@ -141,7 +139,6 @@ class Config{
default: default:
$this->correct = false; $this->correct = false;
return false; return false;
break;
} }
if(!is_array($this->config)){ if(!is_array($this->config)){
$this->config = $default; $this->config = $default;

View File

@ -107,7 +107,7 @@ class NBT{
} }
public function writeTAG_FLOAT($v){ public function writeTAG_FLOAT($v){
$this->binary .= Utils::writeLFloar($v); $this->binary .= Utils::writeLFloat($v);
} }
public function writeTAG_DOUBLE($v){ public function writeTAG_DOUBLE($v){

View File

@ -620,7 +620,7 @@ class Utils{
} }
public static function writeLLong($value){ public static function writeLLong($value){
return strrev(Utils::writeLong($str)); return strrev(Utils::writeLong($value));
} }

View File

@ -33,6 +33,7 @@ class VersionString{
private $release; private $release;
private $minor; private $minor;
private $development = false; private $development = false;
private $generation;
public function __construct($version = MAJOR_VERSION){ public function __construct($version = MAJOR_VERSION){
if(is_int($version)){ if(is_int($version)){
$this->minor = $version & 0x1F; $this->minor = $version & 0x1F;

View File

@ -87,7 +87,7 @@ class AsyncMultipleQueue extends Thread{
$d = array(); $d = array();
for($c = 0; $c < $cnt; ++$c){ for($c = 0; $c < $cnt; ++$c){
$key = $this->get(Utils::readShort($this->get(2), false)); $key = $this->get(Utils::readShort($this->get(2), false));
$d[$key] = $this->get(Utils::readInt($this->get(4), false)); $d[$key] = $this->get(Utils::readInt($this->get(4)));
} }
$res = (string) Utils::curl_post($url, $d, $timeout); $res = (string) Utils::curl_post($url, $d, $timeout);
$this->lock(); $this->lock();

View File

@ -43,8 +43,16 @@ class Entity extends Position{
public $attach; public $attach;
public $closed; public $closed;
public $player; public $player;
public $status;
public $fallY; public $fallY;
public $health;
public $fire;
public $crouched;
public $invincible;
public $fallStart; public $fallStart;
public $stack;
public $meta;
private $position;
private $tickCounter; private $tickCounter;
private $speedMeasure = array(0, 0, 0, 0, 0, 0, 0); private $speedMeasure = array(0, 0, 0, 0, 0, 0, 0);
private $server; private $server;
@ -526,8 +534,8 @@ class Entity extends Position{
} }
}elseif($this->fallY !== false){ //Fall damage! }elseif($this->fallY !== false){ //Fall damage!
if($y < $this->fallY){ if($y < $this->fallY){
$d = $this->level->getBlock(new Vector3($x, $y + 1, $z)); $d = $this->level->getBlock(new Vector3($this->x, $y + 1, $this->z));
$d2 = $this->level->getBlock(new Vector3($x, $y + 2, $z)); $d2 = $this->level->getBlock(new Vector3($this->x, $y + 2, $this->z));
$dmg = ($this->fallY - $y) - 3; $dmg = ($this->fallY - $y) - 3;
if($dmg > 0 and !($d instanceof LiquidBlock) and $d->getID() !== LADDER and $d->getID() !== COBWEB and !($d2 instanceof LiquidBlock) and $d2->getID() !== LADDER and $d2->getID() !== COBWEB){ if($dmg > 0 and !($d instanceof LiquidBlock) and $d->getID() !== LADDER and $d->getID() !== COBWEB and !($d2 instanceof LiquidBlock) and $d2->getID() !== LADDER and $d2->getID() !== COBWEB){
$this->harm($dmg, "fall"); $this->harm($dmg, "fall");
@ -562,10 +570,10 @@ class Entity extends Position{
if($this->isStatic === false and ($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z or $this->last[3] != $this->yaw or $this->last[4] != $this->pitch)){ if($this->isStatic === false and ($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z or $this->last[3] != $this->yaw or $this->last[4] != $this->pitch)){
if($this->class === ENTITY_PLAYER or ($this->last[5] + 8) < $now){ if($this->class === ENTITY_PLAYER or ($this->last[5] + 8) < $now){
if($this->server->api->handle("entity.move", $this) === false){ if($this->server->api->handle("entity.move", $this) === false){
if($this->class === ENTITY_PLAYER){ if($this->class === ENTITY_PLAYER and $this->player instanceof Player){
$this->player->teleport(new Vector3($this->last[0], $this->last[1], $this->last[2]), $this->last[3], $this->last[4]); $this->player->teleport(new Vector3($this->last[0], $this->last[1], $this->last[2]), $this->last[3], $this->last[4]);
}else{ }else{
$this->setPosition($this->last[0], $this->last[1], $this->last[2], $this->last[3], $this->last[4]); $this->setPosition(new Vector3($this->last[0], $this->last[1], $this->last[2]), $this->last[3], $this->last[4]);
} }
}else{ }else{
$this->updateLast(); $this->updateLast();
@ -593,7 +601,7 @@ class Entity extends Position{
} }
} }
}else{ }else{
$this->updatePosition($this->x, $this->y, $this->z, $this->yaw, $this->pitch); $this->updatePosition();
} }
} }
$this->lastUpdate = $now; $this->lastUpdate = $now;
@ -658,7 +666,7 @@ class Entity extends Position{
} }
switch($this->class){ switch($this->class){
case ENTITY_PLAYER: case ENTITY_PLAYER:
if($this->player->connected !== true or $this->player->spawned === false){ if(!($this->player instanceof Player) or $this->player->connected !== true or $this->player->spawned === false){
return false; return false;
} }

View File

@ -19,14 +19,19 @@
* *
*/ */
/**
* WARNING: This code is old, and only supports the file format partially (reverse engineering)
* It can break, lock, or hit you in the face in any moment.
*
*/
class PocketChunkParser{ class PocketChunkParser{
private $location, $raw = b"", $file; private $location, $raw = b"", $file;
var $sectorLength = 4096; //16 * 16 * 16 public $sectorLength = 4096; //16 * 16 * 16
var $chunkLength = 86016; //21 * $sectorLength public $chunkLength = 86016; //21 * $sectorLength
var $map; public $map = array();
function __construct(){ public function __construct(){
$map = array();
} }
private function loadLocationTable(){ private function loadLocationTable(){

View File

@ -31,6 +31,8 @@ class Tile extends Position{
public $attach; public $attach;
public $metadata; public $metadata;
public $closed; public $closed;
private $lastUpdate;
private $scheduledUpdate;
private $server; private $server;
function __construct(Level $level, $id, $class, $x, $y, $z, $data = array()){ function __construct(Level $level, $id, $class, $x, $y, $z, $data = array()){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();

View File

@ -80,6 +80,7 @@ class NormalGenerator implements LevelGenerator{
public function generateChunk($chunkX, $chunkZ){ public function generateChunk($chunkX, $chunkZ){
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
$hills = array(); $hills = array();
$patches = array();
$patchesSmall = array(); $patchesSmall = array();
$base = array(); $base = array();
for($z = 0; $z < 16; ++$z){ for($z = 0; $z < 16; ++$z){

View File

@ -24,7 +24,7 @@ require_once("LevelGenerator.php");
/***REM_END***/ /***REM_END***/
class SuperflatGenerator implements LevelGenerator{ class SuperflatGenerator implements LevelGenerator{
private $level, $random, $structure, $chunks, $options, $floorLevel, $populators = array(); private $level, $random, $structure, $chunks, $options, $floorLevel, $preset, $populators = array();
public function getSettings(){ public function getSettings(){
return $this->options; return $this->options;

View File

@ -20,7 +20,7 @@
*/ */
class WorldGenerator{ class WorldGenerator{
private $seed, $level, $path, $random, $generator, $width; private $seed, $level, $path, $random, $generator, $height;
public function __construct(LevelGenerator $generator, $name, $seed = false, $height = 8){ public function __construct(LevelGenerator $generator, $name, $seed = false, $height = 8){
$this->seed = $seed !== false ? (int) $seed:Utils::readInt(Utils::getRandomBytes(4, false)); $this->seed = $seed !== false ? (int) $seed:Utils::readInt(Utils::getRandomBytes(4, false));
$this->random = new Random($this->seed); $this->random = new Random($this->seed);

View File

@ -1,108 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
abstract class OctaveGenerator{
protected $octaves;
protected $xScale = 1;
protected $yScale = 1;
protected $zScale = 1;
public function __construct(array $octaves){
$this->octaves = $octaves;
}
public function setScale($scale){
$this->setXScale($scale);
$this->setYScale($scale);
$this->setZScale($scale);
}
public function getXScale(){
return $this->xScale;
}
public function setXScale($scale){
$this->xScale = $scale;
}
public function getYScale(){
return $this->yScale;
}
public function setYScale($scale){
$this->yScale = $scale;
}
public function getZScale(){
return $this->zScale;
}
public function setZScale($scale){
$this->zScale = $scale;
}
public function getOctaves(){
$array = array();
foreach($this->octaves as $index => $value){
$array[$index] = clone $value;
}
return $array;
}
//1D-noise
public function noise1D($x, $frequency, $amplitude, $normalized = false){
return $this->noise3D($x, 0, 0, $frequency, $amplitude, $normalized);
}
//2D-noise
public function noise2D($x, $y, $frequency, $amplitude, $normalized = false){
return $this->noise3D($x, $y, 0, $frequency, $amplitude, $normalized);
}
//3D-noise
public function noise3D($x, $y, $z, $frequency, $amplitude, $normalized = false){
$result = 0;
$amp = 1;
$freq = 1;
$max = 0;
$x *= $this->xScale;
$y *= $this->yScale;
$z *= $this->zScale;
foreach($this->octaves as $noiseGenerator){
$result += $octave->noise($x * $freq, $y * $freq, $z * $freq) * $amp;
$max += $amp;
$freq *= $frequency;
$amp *= $amplitude;
}
if($normalized === true){
$result /= $max;
}
return $result;
}
/*public function generateNoiseOctaves($x, $y, $z, $frequency, $amplitude){
}*/
}

View File

@ -1,63 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/***REM_START***/
require_once("OctaveGenerator.php");
/***REM_END***/
class PerlinOctaveGenerator extends OctaveGenerator{
public function __construct(Random $random, $octaves){
$this->octaves = array();
for($o = 0; $o < $octaves; ++$o){
$this->octaves[$o] = new NoiseGeneratorPerlin($random);
}
}
/*public function generateNoiseOctaves($x, $y, $z, $sizeX, $sizeY, $sizeZ, $fX, $fY, $fZ){
$adouble = array_fill(0, $sizeX * $sizeY * $sizeZ, 0.0);
$d3 = 1.0;
foreach($this->octaves as $octave){
$dX = $x * $d3 * $fX;
$dY = $y * $d3 * $fY;
$dZ = $x * $d3 * $fZ;
$x1 = NoiseGenerator::floor($dX);
$z1 = NoiseGenerator::floor($dZ);
$dX -= $x1;
$dZ -= $z1;
$x1 %= 16777216;
$z1 %= 16777216;
//$x1 &= 0xFFFFFF;
//$z1 &= 0xFFFFFF;
$dX += $x1;
$dZ += $z1;
$octave->populateNoiseArray($adouble, $dX, $dY, $dZ, $sizeX, $sizeY, $sizeZ, $fX * $d3, $fY * $d3, $fZ * $d3, $d3);
$d3 *= 0.5;
}
return $adouble;
}*/
}

View File

@ -55,7 +55,7 @@ class SpruceTreeObject extends TreeObject{
public function placeObject(Level $level, Vector3 $pos, Random $random){ public function placeObject(Level $level, Vector3 $pos, Random $random){
if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) { if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) {
$this->findRandomLeavesSize(); $this->findRandomLeavesSize($random);
} }
$level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new DirtBlock()); $level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new DirtBlock());
$leavesRadius = 0; $leavesRadius = 0;

View File

@ -47,8 +47,8 @@ class TreeObject{
$tree = new SmallTreeObject(); $tree = new SmallTreeObject();
$tree->type = SaplingBlock::JUNGLE; $tree->type = SaplingBlock::JUNGLE;
break; break;
default:
case SaplingBlock::OAK: case SaplingBlock::OAK:
default:
/*if($random->nextRange(0, 9) === 0){ /*if($random->nextRange(0, 9) === 0){
$tree = new BigTreeObject(); $tree = new BigTreeObject();
}else{*/ }else{*/