mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-19 15:36:08 +00:00
Fixed TABS
This commit is contained in:
@@ -37,14 +37,14 @@ class BlockAPI{
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
$this->server->addHandler("world.block.update", array($this, "updateBlockRemote"), 1);
|
||||
$this->server->addHandler("player.block.break", array($this, "blockBreak"), 1);
|
||||
$this->server->addHandler("player.block.action", array($this, "blockAction"), 1);
|
||||
$this->server->api->console->register("give", "Give items to a player", array($this, "commandHandler"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function commandHandler($cmd, $params){
|
||||
switch($cmd){
|
||||
case "give":
|
||||
@@ -74,11 +74,11 @@ class BlockAPI{
|
||||
}else{
|
||||
console("[INFO] Unknown player");
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function cancelAction($block){
|
||||
$this->server->api->dhandle("world.block.change", array(
|
||||
"x" => $block[2][0],
|
||||
@@ -90,7 +90,7 @@ class BlockAPI{
|
||||
));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function blockBreak($data, $event){
|
||||
if($event !== "player.block.break"){
|
||||
return;
|
||||
@@ -189,7 +189,7 @@ class BlockAPI{
|
||||
$this->server->trigger("player.block.break", $data);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function drop($x, $y, $z, $block, $meta, $stack = 1){
|
||||
if($block === 0 or $stack <= 0 or $this->server->gamemode === 1){
|
||||
return;
|
||||
@@ -213,7 +213,7 @@ class BlockAPI{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function blockAction($data, $event){
|
||||
if($event !== "player.block.action"){
|
||||
return;
|
||||
@@ -225,9 +225,9 @@ class BlockAPI{
|
||||
if($target[0] === 0){ //If no block exists
|
||||
$this->cancelAction($target);
|
||||
$block = $this->server->api->level->getBlockFace($target, $data["face"]);
|
||||
return $this->cancelAction($block);
|
||||
return $this->cancelAction($block);
|
||||
}
|
||||
|
||||
|
||||
$cancelPlace = false;
|
||||
if(isset(Material::$activable[$target[0]])){
|
||||
switch($target[0]){
|
||||
@@ -252,7 +252,7 @@ class BlockAPI{
|
||||
"type" => WINDOW_FURNACE,
|
||||
"slots" => 3,
|
||||
"title" => "Furnace",
|
||||
));
|
||||
));
|
||||
break;
|
||||
case 6:
|
||||
if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal
|
||||
@@ -273,9 +273,9 @@ class BlockAPI{
|
||||
if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal
|
||||
$data["block"] = $target[0];
|
||||
$data["meta"] = 0x07;
|
||||
$this->server->handle("player.block.place", $data);
|
||||
$this->server->handle("player.block.place", $data);
|
||||
$cancelPlace = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 64: //Door
|
||||
if(($target[1] & 0x08) === 0x08){
|
||||
@@ -320,13 +320,13 @@ class BlockAPI{
|
||||
default:
|
||||
$cancelPlace = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($cancelPlace === true){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$replace = false;
|
||||
switch($target[0]){
|
||||
case 44: //Slabs
|
||||
@@ -340,29 +340,29 @@ class BlockAPI{
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if($replace === false){
|
||||
BlockFace::setPosition($data, $data["face"]);
|
||||
}
|
||||
|
||||
|
||||
if($data["y"] >= 127){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$block = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
|
||||
|
||||
|
||||
if($replace === false and !isset(Material::$replaceable[$block[0]])){
|
||||
return $this->cancelAction($block);
|
||||
}
|
||||
|
||||
|
||||
if(isset(Material::$placeable[$data["block"]])){
|
||||
$data["block"] = Material::$placeable[$data["block"]] === true ? $data["block"]:Material::$placeable[$data["block"]];
|
||||
}else{
|
||||
return $this->cancelAction($block);
|
||||
}
|
||||
|
||||
$direction = $this->server->api->entity->get($data["eid"])->getDirection();
|
||||
|
||||
|
||||
$direction = $this->server->api->entity->get($data["eid"])->getDirection();
|
||||
|
||||
switch($data["block"]){
|
||||
case 6:
|
||||
if($target[0] === 60){
|
||||
@@ -391,7 +391,7 @@ class BlockAPI{
|
||||
$block2 = $this->server->api->level->getBlock($data["x"] + 1, $data["y"], $data["z"]);
|
||||
$block3 = $this->server->api->level->getBlock($data["x"] - 1, $data["y"], $data["z"]);
|
||||
if($block0[0] === 9 or $block0[0] === 8 or $block1[0] === 9 or $block1[0] === 8 or $block2[0] === 9 or $block2[0] === 8 or $block3[0] === 9 or $block3[0] === 8){
|
||||
|
||||
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
@@ -527,11 +527,11 @@ class BlockAPI{
|
||||
$this->server->handle("player.block.place", $data);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function blockScheduler($data){
|
||||
$this->updateBlock($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_SCHEDULED);
|
||||
}
|
||||
|
||||
|
||||
public function updateBlockRemote($data, $event){
|
||||
if($event !== "world.block.update"){
|
||||
return;
|
||||
@@ -570,14 +570,14 @@ class BlockAPI{
|
||||
"type" => BLOCK_UPDATE_NORMAL,
|
||||
));
|
||||
$this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], 10, $level | $down, false);
|
||||
return true;
|
||||
return true;
|
||||
}elseif(($source[1] & 0x08) === 0x08){
|
||||
$this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], $source[0], $source[1] & 0x07, false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function flowWaterOn($source, $face){
|
||||
$down = 0;
|
||||
if($face === BlockFace::BOTTOM){
|
||||
@@ -609,14 +609,14 @@ class BlockAPI{
|
||||
"type" => BLOCK_UPDATE_NORMAL,
|
||||
));
|
||||
$this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], 8, $level | $down, false);
|
||||
return true;
|
||||
return true;
|
||||
}elseif(($source[1] & 0x08) === 0x08){
|
||||
$this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], $source[0], $source[1] & 0x07, false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function updateBlock($x, $y, $z, $type = BLOCK_UPDATE_NORMAL){
|
||||
$block = $this->server->api->level->getBlock($x, $y, $z);
|
||||
$changed = false;
|
||||
@@ -690,7 +690,7 @@ class BlockAPI{
|
||||
"z" => $block[2][2],
|
||||
"type" => BLOCK_UPDATE_NORMAL,
|
||||
));
|
||||
$this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], 0, 0, false);
|
||||
$this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], 0, 0, false);
|
||||
}else{
|
||||
$block[1] = ($block[1] & 0x08) | $level;
|
||||
$this->server->schedule(10, array($this, "blockScheduler"), array(
|
||||
@@ -732,7 +732,7 @@ class BlockAPI{
|
||||
$this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], $block[0], $block[1], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
case 11:
|
||||
@@ -802,7 +802,7 @@ class BlockAPI{
|
||||
"z" => $block[2][2],
|
||||
"type" => BLOCK_UPDATE_NORMAL,
|
||||
));
|
||||
$this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], 0, 0, false);
|
||||
$this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], 0, 0, false);
|
||||
}else{
|
||||
$block[1] = ($block[1] & 0x08) | $level;
|
||||
$this->server->schedule(20, array($this, "blockScheduler"), array(
|
||||
@@ -845,7 +845,7 @@ class BlockAPI{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case 74:
|
||||
if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){
|
||||
@@ -874,7 +874,7 @@ class BlockAPI{
|
||||
$this->updateBlocksAround($x, $y, $z, $type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function updateBlocksAround($x, $y, $z, $type){
|
||||
$this->updateBlock($x + 1, $y, $z, $type);
|
||||
$this->updateBlock($x, $y + 1, $z, $type);
|
||||
|
@@ -33,20 +33,20 @@ class ConsoleAPI{
|
||||
$this->server = $server;
|
||||
$this->last = microtime(true);
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
$this->event = $this->server->event("server.tick", array($this, "handle"));
|
||||
$this->loop = new ConsoleLoop;
|
||||
$this->loop->start();
|
||||
}
|
||||
|
||||
|
||||
function __destruct(){
|
||||
$this->server->deleteEvent($this->event);
|
||||
$this->loop->stop = true;
|
||||
$this->loop->notify();
|
||||
$this->loop->join();
|
||||
}
|
||||
|
||||
|
||||
public function defaultCommands($cmd, $params){
|
||||
switch($cmd){
|
||||
case "invisible":
|
||||
@@ -79,7 +79,7 @@ class ConsoleAPI{
|
||||
break;
|
||||
case "stop":
|
||||
$this->loop->stop = true;
|
||||
console("[INFO] Stopping the server...");
|
||||
console("[INFO] Stopping the server...");
|
||||
$this->server->close();
|
||||
break;
|
||||
/*case "restart":
|
||||
@@ -93,7 +93,7 @@ class ConsoleAPI{
|
||||
case "pardon":
|
||||
case "remove":
|
||||
$ip = trim(implode($params));
|
||||
$new = array();
|
||||
$new = array();
|
||||
foreach(explode("\n", str_replace(array("\r","\t"), "", file_get_contents(FILE_PATH."banned-ips.txt"))) as $i){
|
||||
if($i == $ip){
|
||||
console("[INFO] IP \"$ip\" removed from ban list");
|
||||
@@ -154,7 +154,7 @@ class ConsoleAPI{
|
||||
switch($p){
|
||||
case "remove":
|
||||
$user = trim(implode(" ", $params));
|
||||
$new = array();
|
||||
$new = array();
|
||||
foreach(explode("\n", str_replace(array("\r","\t"), "", file_get_contents(FILE_PATH."white-list.txt"))) as $u){
|
||||
if($u == $user){
|
||||
console("[INFO] Player \"$user\" removed from white-list");
|
||||
@@ -225,11 +225,11 @@ class ConsoleAPI{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function alias($alias, $cmd){
|
||||
$this->cmds[strtolower(trim($alias))] = &$this->cmds[$cmd];
|
||||
}
|
||||
|
||||
|
||||
public function register($cmd, $help, $callback){
|
||||
if(!is_callable($callback)){
|
||||
return false;
|
||||
@@ -238,7 +238,7 @@ class ConsoleAPI{
|
||||
$this->cmds[$cmd] = $callback;
|
||||
$this->help[$cmd] = $help;
|
||||
}
|
||||
|
||||
|
||||
public function handle($time){
|
||||
if($this->loop->line !== false){
|
||||
$line = trim($this->loop->line);
|
||||
|
@@ -30,11 +30,11 @@ class EntityAPI{
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
$this->server->addHandler("player.death", array($this, "handle"), 1);
|
||||
}
|
||||
|
||||
|
||||
public function handle($data, $event){
|
||||
switch($event){
|
||||
case "player.death":
|
||||
@@ -58,7 +58,7 @@ class EntityAPI{
|
||||
}
|
||||
$this->server->chat(false, $message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get($eid){
|
||||
@@ -67,15 +67,15 @@ class EntityAPI{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getAll(){
|
||||
return $this->server->entities;
|
||||
}
|
||||
|
||||
|
||||
public function heal($eid, $heal = 1, $cause){
|
||||
$this->harm($eid, -$heal, $cause);
|
||||
}
|
||||
|
||||
|
||||
public function harm($eid, $attack = 1, $cause){
|
||||
$e = $this->get($eid);
|
||||
if($e === false or $e->dead === true){
|
||||
@@ -83,13 +83,13 @@ class EntityAPI{
|
||||
}
|
||||
$e->setHealth($e->getHealth()-$attack, $cause);
|
||||
}
|
||||
|
||||
|
||||
public function add($class, $type = 0, $data = array()){
|
||||
$eid = $this->server->eidCnt++;
|
||||
$this->server->entities[$eid] = new Entity($this->server, $eid, $class, $type, $data);
|
||||
return $this->server->entities[$eid];
|
||||
}
|
||||
|
||||
|
||||
public function spawnTo($eid, $player){
|
||||
$e = $this->get($eid);
|
||||
if($e === false){
|
||||
@@ -97,7 +97,7 @@ class EntityAPI{
|
||||
}
|
||||
$e->spawn($player);
|
||||
}
|
||||
|
||||
|
||||
public function spawnToAll($eid){
|
||||
$e = $this->get($eid);
|
||||
if($e === false){
|
||||
@@ -109,17 +109,17 @@ class EntityAPI{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function spawnAll($player){
|
||||
foreach($this->getAll() as $e){
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function remove($eid){
|
||||
if(isset($this->server->entities[$eid])){
|
||||
$this->server->entities[$eid]->close();
|
||||
unset($this->server->entities[$eid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -32,13 +32,13 @@ class LevelAPI{
|
||||
$this->map = $this->server->map;
|
||||
$this->heightMap = array_fill(0, 256, array());
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
$this->server->event("player.block.break", array($this, "handle"));
|
||||
$this->server->event("player.block.place", array($this, "handle"));
|
||||
$this->server->event("player.block.update", array($this, "handle"));
|
||||
}
|
||||
|
||||
|
||||
public function handle($data, $event){
|
||||
switch($event){
|
||||
case "player.block.place":
|
||||
@@ -49,7 +49,7 @@ class LevelAPI{
|
||||
case "player.block.break":
|
||||
$block = $this->getBlock($data["x"], $data["y"], $data["z"]);
|
||||
console("[DEBUG] EID ".$data["eid"]." broke ".$block[0].":".$block[1]." at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2);
|
||||
|
||||
|
||||
if($block[0] === 0){
|
||||
break;
|
||||
}
|
||||
@@ -57,34 +57,34 @@ class LevelAPI{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getSpawn(){
|
||||
return $this->server->spawn;
|
||||
}
|
||||
|
||||
public function getChunk($X, $Z){
|
||||
return $this->map->map[$X][$Z];
|
||||
return $this->map->map[$X][$Z];
|
||||
}
|
||||
|
||||
|
||||
public function getBlockFace($block, $face){
|
||||
$data = array("x" => $block[2][0], "y" => $block[2][1], "z" => $block[2][2]);
|
||||
BlockFace::setPosition($data, $face);
|
||||
return $this->getBlock($data["x"], $data["y"], $data["z"]);
|
||||
}
|
||||
|
||||
|
||||
public function getBlock($x, $y, $z){
|
||||
$b = $this->map->getBlock($x, $y, $z);
|
||||
$b[2] = array($x, $y, $z);
|
||||
return $b;
|
||||
}
|
||||
|
||||
|
||||
public function getFloor($x, $z){
|
||||
if(!isset($this->heightMap[$z][$x])){
|
||||
$this->heightMap[$z][$x] = $this->map->getFloor($x, $z);
|
||||
}
|
||||
return $this->heightMap[$z][$x];
|
||||
}
|
||||
|
||||
|
||||
public function setBlock($x, $y, $z, $block, $meta = 0, $update = true){
|
||||
$this->map->setBlock($x, $y, $z, $block, $meta);
|
||||
$this->heightMap[$z][$x] = $this->map->getFloor($x, $z);
|
||||
@@ -101,7 +101,7 @@ class LevelAPI{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getOrderedChunk($X, $Z, $columnsPerPacket = 2){
|
||||
$columnsPerPacket = max(1, (int) $columnsPerPacket);
|
||||
$c = $this->getChunk($X, $Z);
|
||||
|
@@ -30,7 +30,7 @@ class PlayerAPI{
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
$this->server->event("server.regeneration", array($this, "handle"));
|
||||
$this->server->api->console->register("list", "Shows connected player list", array($this, "commandHandler"));
|
||||
@@ -38,7 +38,7 @@ class PlayerAPI{
|
||||
$this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler"));
|
||||
}
|
||||
|
||||
|
||||
public function handle($data, $event){
|
||||
switch($event){
|
||||
case "server.regeneration":
|
||||
@@ -53,7 +53,7 @@ class PlayerAPI{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function commandHandler($cmd, $params){
|
||||
switch($cmd){
|
||||
case "tp":
|
||||
@@ -100,7 +100,7 @@ class PlayerAPI{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function teleport($name, $target){
|
||||
$target = $this->get($target);
|
||||
if($target !== false){
|
||||
@@ -108,7 +108,7 @@ class PlayerAPI{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function tppos($name, $x, $y, $z){
|
||||
$player = $this->get($name);
|
||||
if($player !== false){
|
||||
@@ -124,7 +124,7 @@ class PlayerAPI{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function get($name){
|
||||
$CID = $this->server->query("SELECT ip,port FROM players WHERE name = '".str_replace("'", "", $name)."';", true);
|
||||
$CID = $this->server->clientID($CID["ip"], $CID["port"]);
|
||||
@@ -133,11 +133,11 @@ class PlayerAPI{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getAll(){
|
||||
return $this->server->clients;
|
||||
}
|
||||
|
||||
|
||||
public function getByEID($eid){
|
||||
$eid = (int) $eid;
|
||||
$CID = $this->server->query("SELECT ip,port FROM players WHERE EID = '".$eid."';", true);
|
||||
@@ -147,7 +147,7 @@ class PlayerAPI{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getByClientID($clientID){
|
||||
$clientID = (int) $clientID;
|
||||
$CID = $this->server->query("SELECT ip,port FROM players WHERE clientID = '".$clientID."';", true);
|
||||
@@ -155,9 +155,9 @@ class PlayerAPI{
|
||||
if(isset($this->server->clients[$CID])){
|
||||
return $this->server->clients[$CID];
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function online(){
|
||||
$o = array();
|
||||
foreach($this->server->clients as $p){
|
||||
@@ -167,7 +167,7 @@ class PlayerAPI{
|
||||
}
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
public function add($CID){
|
||||
if(isset($this->server->clients[$CID])){
|
||||
$player = $this->server->clients[$CID];
|
||||
@@ -176,7 +176,7 @@ class PlayerAPI{
|
||||
$this->server->query("INSERT OR REPLACE INTO players (clientID, ip, port, name) VALUES (".$player->clientID.", '".$player->ip."', ".$player->port.", '".$player->username."');");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function remove($CID){
|
||||
if(isset($this->server->clients[$CID])){
|
||||
$player = $this->server->clients[$CID];
|
||||
@@ -189,7 +189,7 @@ class PlayerAPI{
|
||||
unset($this->server->clients[$player->CID]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getOffline($name){
|
||||
if(!file_exists(FILE_PATH."players/".$name.".dat")){
|
||||
console("[NOTICE] Player data not found for \"".$name."\", creating new profile");
|
||||
@@ -210,9 +210,9 @@ class PlayerAPI{
|
||||
$this->server->handle("api.player.offline.get", $data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function saveOffline($name, $data){
|
||||
$this->server->handle("api.player.offline.save", $data);
|
||||
file_put_contents(FILE_PATH."players/".str_replace("/", "", $name).".dat", serialize($data));
|
||||
}
|
||||
}
|
||||
}
|
@@ -32,7 +32,7 @@ class PluginAPI extends stdClass{
|
||||
$this->plugins = array();
|
||||
require_once("classes/Spyc.class.php"); //YAML parser
|
||||
}
|
||||
|
||||
|
||||
public function getList(){
|
||||
$list = array();
|
||||
foreach($this->plugins as $p){
|
||||
@@ -40,7 +40,7 @@ class PluginAPI extends stdClass{
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
public function getInfo($className){
|
||||
if(!isset($this->plugins[$className])){
|
||||
return false;
|
||||
@@ -48,7 +48,7 @@ class PluginAPI extends stdClass{
|
||||
$plugin = $this->plugins[$className];
|
||||
return array($plugin[1], get_class_methods($plugin[0]));
|
||||
}
|
||||
|
||||
|
||||
public function load($file){
|
||||
$content = file_get_contents($file);
|
||||
$info = strstr($content, "*/", true);
|
||||
@@ -95,12 +95,12 @@ class PluginAPI extends stdClass{
|
||||
$object->__destruct();
|
||||
}
|
||||
$object = null;
|
||||
unset($object);
|
||||
unset($object);
|
||||
}else{
|
||||
$this->plugins[$className] = array($object, $info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get(Plugin $plugin){
|
||||
foreach($this->plugins as &$p){
|
||||
if($p[0] === $plugin){
|
||||
@@ -109,7 +109,7 @@ class PluginAPI extends stdClass{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function createConfig(Plugin $plugin, $default = array()){
|
||||
$p = $this->get($plugin);
|
||||
if($p === false){
|
||||
@@ -127,7 +127,7 @@ class PluginAPI extends stdClass{
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
||||
private function fillDefaults($default, &$yaml){
|
||||
foreach($default as $k => $v){
|
||||
if(is_array($v)){
|
||||
@@ -140,19 +140,19 @@ class PluginAPI extends stdClass{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function readYAML($file){
|
||||
return Spyc::YAMLLoad(file_get_contents($file));
|
||||
}
|
||||
|
||||
|
||||
public function writeYAML($file, $data){
|
||||
return file_put_contents($file, Spyc::YAMLDump($data));
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
$this->server->event("server.start", array($this, "loadAll"));
|
||||
}
|
||||
|
||||
|
||||
public function loadAll(){
|
||||
console("[INFO] Loading Plugins...");
|
||||
$dir = dir(FILE_PATH."plugins/");
|
||||
|
@@ -69,7 +69,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!file_exists(FILE_PATH."white-list.txt")){
|
||||
console("[NOTICE] No white-list.txt found, creating blank file");
|
||||
file_put_contents(FILE_PATH."white-list.txt", "");
|
||||
@@ -84,7 +84,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
console("[NOTICE] No server.properties found, using default settings");
|
||||
copy(FILE_PATH."src/common/default.properties", FILE_PATH."server.properties");
|
||||
}
|
||||
|
||||
|
||||
console("[DEBUG] Loading server.properties...", true, true, 2);
|
||||
$this->parseProperties();
|
||||
define("DEBUG", $this->config["debug"]);
|
||||
@@ -98,7 +98,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
$channel = "dev";
|
||||
}
|
||||
$this->setProperty("update-channel", $channel);
|
||||
|
||||
|
||||
if($channel === "dev"){
|
||||
$info = json_decode(Utils::curl_get("https://api.github.com/repos/shoghicp/PocketMine-MP"), true);
|
||||
if($info === false or !isset($info["updated_at"])){
|
||||
@@ -131,7 +131,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
$newest = array($i, $update);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($newest[0] !== -1){
|
||||
$target = $info[$newest[0]];
|
||||
console("[NOTICE] A new STABLE version of PocketMine-MP has been released");
|
||||
@@ -144,7 +144,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
console("[INFO] This is the latest STABLE version");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if(file_exists(FILE_PATH."worlds/level.dat")){
|
||||
@@ -174,7 +174,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
}
|
||||
$this->loadProperties();
|
||||
$this->server->loadMap();
|
||||
|
||||
|
||||
//Autoload all default APIs
|
||||
console("[INFO] Loading default APIs");
|
||||
$dir = dir(FILE_PATH."src/API/");
|
||||
@@ -192,10 +192,10 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
$ob->init();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->server->loadEntities();
|
||||
}
|
||||
|
||||
|
||||
public function __destruct(){
|
||||
foreach($this->apiList as $ob){
|
||||
if(is_callable($ob, "__destruct")){
|
||||
@@ -204,8 +204,8 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private function loadProperties(){
|
||||
if(isset($this->config["memory-limit"])){
|
||||
@ini_set("memory_limit", $this->config["memory-limit"]);
|
||||
@@ -228,7 +228,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
$this->server->reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function writeProperties(){
|
||||
if(is_object($this->server)){
|
||||
$this->config["server-id"] = $this->server->serverID;
|
||||
@@ -242,7 +242,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
}
|
||||
file_put_contents(FILE_PATH."server.properties", $prop);
|
||||
}
|
||||
|
||||
|
||||
private function parseProperties(){
|
||||
$prop = file_get_contents(FILE_PATH."server.properties");
|
||||
$prop = explode("\n", str_replace("\r", "", $prop));
|
||||
@@ -291,7 +291,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
$this->config[$n] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function start(){
|
||||
$this->server->init();
|
||||
unregister_tick_function(array($this->server, "tick"));
|
||||
@@ -299,7 +299,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
unset($this->server);
|
||||
return $this->restart;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
public function addHandler($e, $c, $p = 5){
|
||||
@@ -309,31 +309,31 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
public function dhandle($e, $d){
|
||||
return $this->server->handle($e, $d);
|
||||
}
|
||||
|
||||
|
||||
public function handle($e, &$d){
|
||||
return $this->server->handle($e, $d);
|
||||
}
|
||||
|
||||
|
||||
public function action($t, $c, $r = true){
|
||||
return $this->server->action($t, $c, $r);
|
||||
}
|
||||
|
||||
|
||||
public function schedule($t, $c, $d, $r = false, $e = "server.schedule"){
|
||||
return $this->server->schedule($t, $c, $d, $r, $e);
|
||||
}
|
||||
|
||||
|
||||
public function event($e, $d){
|
||||
return $this->server->event($e, $d);
|
||||
}
|
||||
|
||||
|
||||
public function trigger($e, $d){
|
||||
return $this->server->trigger($e, $d);
|
||||
}
|
||||
|
||||
|
||||
public function deleteEvent($id){
|
||||
return $this->server->deleteEvent($id);
|
||||
}
|
||||
|
||||
|
||||
public function importMap($dir, $remove = false){
|
||||
if(file_exists($dir."level.dat")){
|
||||
$nbt = new NBT();
|
||||
@@ -341,7 +341,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
console("[DEBUG] Importing map \"".$level["LevelName"]."\" gamemode ".$level["GameType"]." with seed ".$level["RandomSeed"], true, true, 2);
|
||||
unset($level["Player"]);
|
||||
$lvName = $level["LevelName"]."/";
|
||||
@mkdir(FILE_PATH."worlds/".$lvName, 0777);
|
||||
@mkdir(FILE_PATH."worlds/".$lvName, 0777);
|
||||
file_put_contents(FILE_PATH."worlds/".$lvName."level.dat", serialize($level));
|
||||
$entities = parseNBTData($nbt->loadFile($dir."entities.dat"));
|
||||
file_put_contents(FILE_PATH."worlds/".$lvName."entities.dat", serialize($entities["Entities"]));
|
||||
@@ -350,7 +350,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
}
|
||||
file_put_contents(FILE_PATH."worlds/".$lvName."tileEntities.dat", serialize($entities["TileEntities"]));
|
||||
console("[DEBUG] Imported ".count($entities["Entities"])." Entities and ".count($entities["TileEntities"])." TileEntities", true, true, 2);
|
||||
|
||||
|
||||
if($remove === true){
|
||||
rename($dir."chunks.dat", FILE_PATH."worlds/".$lvName."chunks.dat");
|
||||
unlink($dir."level.dat");
|
||||
@@ -369,29 +369,29 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
$this->writeProperties();
|
||||
}
|
||||
console("[INFO] Map \"".$level["LevelName"]."\" importing done!");
|
||||
unset($level, $entities, $nbt);
|
||||
unset($level, $entities, $nbt);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getProperty($name){
|
||||
if(isset($this->config[$name])){
|
||||
return $this->config[$name];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function setProperty($name, $value){
|
||||
$this->config[$name] = $value;
|
||||
$this->writeProperties();
|
||||
$this->loadProperties();
|
||||
}
|
||||
|
||||
|
||||
public function getList(){
|
||||
return $this->apiList;
|
||||
}
|
||||
|
||||
|
||||
public function loadAPI($name, $class, $dir = false){
|
||||
if($dir === false){
|
||||
$dir = FILE_PATH."src/API/";
|
||||
|
@@ -36,11 +36,11 @@ class TimeAPI{
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
$this->server->api->console->register("time", "Manages server time", array($this, "commandHandler"));
|
||||
}
|
||||
|
||||
|
||||
public function commandHandler($cmd, $params){
|
||||
switch($cmd){
|
||||
case "time":
|
||||
@@ -74,7 +74,7 @@ class TimeAPI{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function night(){
|
||||
$this->set("night");
|
||||
}
|
||||
@@ -87,20 +87,20 @@ class TimeAPI{
|
||||
public function sunset(){
|
||||
$this->set("sunset");
|
||||
}
|
||||
|
||||
|
||||
public function get($raw = false){
|
||||
return $raw === true ? $this->server->time:abs($this->server->time) % 19200;
|
||||
}
|
||||
|
||||
|
||||
public function add($time){
|
||||
$this->server->time += (int) $time;
|
||||
}
|
||||
|
||||
|
||||
public function getDate($time = false){
|
||||
$time = $time === false ? $this->get():$time;
|
||||
return str_pad(strval((floor($time /800) + 6) % 24), 2, "0", STR_PAD_LEFT).":".str_pad(strval(floor(($time % 800) / 13.33)), 2, "0", STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
|
||||
public function getPhase($time = false){
|
||||
$time = $time === false ? $this->get():$time;
|
||||
if($time < $this->phase["sunset"]){
|
||||
@@ -114,7 +114,7 @@ class TimeAPI{
|
||||
}
|
||||
return $time;
|
||||
}
|
||||
|
||||
|
||||
public function set($time){
|
||||
if(is_string($time) and isset($this->phases[$time])){
|
||||
$this->server->time = $this->phases[$time];
|
||||
@@ -122,6 +122,6 @@ class TimeAPI{
|
||||
$this->server->time = (int) $time;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user