support php8019 and some cleanup (by @D-aHTuCT)

This commit is contained in:
kotyara 2022-07-26 16:06:34 +05:00
parent cf0f9df267
commit b60f0877e1
376 changed files with 6528 additions and 13472 deletions

View file

@ -1,146 +1,101 @@
<?php <?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/
*
*
*/
class AchievementAPI{ class AchievementAPI{
public static $achievements = array(
public static $achievements = [
/*"openInventory" => array( /*"openInventory" => array(
"name" => "Taking Inventory", "name" => "Taking Inventory",
"requires" => array(), "requires" => array(),
),*/ ),*/
"mineWood" => array( "mineWood" => [
"name" => "Getting Wood", "name" => "Getting Wood",
"requires" => array( "requires" => [
//"openInventory", //"openInventory",
), ],
), ],
"buildWorkBench" => array( "buildWorkBench" => [
"name" => "Benchmarking", "name" => "Benchmarking",
"requires" => array( "requires" => [
"mineWood", "mineWood",
), ],
), ],
"buildPickaxe" => array( "buildPickaxe" => [
"name" => "Time to Mine!", "name" => "Time to Mine!",
"requires" => array( "requires" => [
"buildWorkBench", "buildWorkBench",
), ],
), ],
"buildFurnace" => array( "buildFurnace" => [
"name" => "Hot Topic", "name" => "Hot Topic",
"requires" => array( "requires" => [
"buildPickaxe", "buildPickaxe",
), ],
), ],
"acquireIron" => array( "acquireIron" => [
"name" => "Acquire hardware", "name" => "Acquire hardware",
"requires" => array( "requires" => [
"buildFurnace", "buildFurnace",
), ],
), ],
"buildHoe" => array( "buildHoe" => [
"name" => "Time to Farm!", "name" => "Time to Farm!",
"requires" => array( "requires" => [
"buildWorkBench", "buildWorkBench",
), ],
), ],
"makeBread" => array( "makeBread" => [
"name" => "Bake Bread", "name" => "Bake Bread",
"requires" => array( "requires" => [
"buildHoe", "buildHoe",
), ],
), ],
"bakeCake" => array( "bakeCake" => [
"name" => "The Lie", "name" => "The Lie",
"requires" => array( "requires" => [
"buildHoe", "buildHoe",
), ],
), ],
"buildBetterPickaxe" => array( "buildBetterPickaxe" => [
"name" => "Getting an Upgrade", "name" => "Getting an Upgrade",
"requires" => array( "requires" => [
"buildPickaxe", "buildPickaxe",
), ],
), ],
"buildSword" => array( "buildSword" => [
"name" => "Time to Strike!", "name" => "Time to Strike!",
"requires" => array( "requires" => [
"buildWorkBench", "buildWorkBench",
), ],
), ],
"diamonds" => array( "diamonds" => [
"name" => "DIAMONDS!", "name" => "DIAMONDS!",
"requires" => array( "requires" => [
"acquireIron", "acquireIron",
), ],
), ],
"leather" => array( "leather" => [
"name" => "Cow Tipper", "name" => "Cow Tipper",
"requires" => array( "requires" => [
"buildSword", "buildSword",
), ],
), ],
); ];
function __construct(){ function __construct(){
} }
public static function broadcastAchievement(Player $player, $achievementId){ public static function addAchievement($achievementId, $achievementName, array $requires = []){
if(isset(self::$achievements[$achievementId])){
$result = ServerAPI::request()->api->dhandle("achievement.broadcast", array("player" => $player, "achievementId" => $achievementId));
if($result !== false and $result !== true){
if(ServerAPI::request()->api->getProperty("announce-player-achievements") == true){
ServerAPI::request()->api->chat->broadcast($player->username." has just earned the achievement [".self::$achievements[$achievementId]["name"]."]");
}else{
$player->sendChat("You have just earned the achievement [".self::$achievements[$achievementId]["name"]."]");
}
}
return true;
}
return false;
}
public static function addAchievement($achievementId, $achievementName, array $requires = array()){
if(!isset(self::$achievements[$achievementId])){ if(!isset(self::$achievements[$achievementId])){
self::$achievements[$achievementId] = array( self::$achievements[$achievementId] = [
"name" => $achievementName, "name" => $achievementName,
"requires" => $requires, "requires" => $requires,
); ];
return true; return true;
} }
return false; return false;
} }
public static function hasAchievement(Player $player, $achievementId){
if(!isset(self::$achievements[$achievementId]) or !isset($player->achievements)){
$player->achievements = array();
return false;
}
if(!isset($player->achievements[$achievementId]) or $player->achievements[$achievementId] == false){
return false;
}
return true;
}
public static function grantAchievement(Player $player, $achievementId){ public static function grantAchievement(Player $player, $achievementId){
if(isset(self::$achievements[$achievementId]) and !self::hasAchievement($player, $achievementId)){ if(isset(self::$achievements[$achievementId]) and !self::hasAchievement($player, $achievementId)){
foreach(self::$achievements[$achievementId]["requires"] as $requerimentId){ foreach(self::$achievements[$achievementId]["requires"] as $requerimentId){
@ -148,7 +103,7 @@ class AchievementAPI{
return false; return false;
} }
} }
if(ServerAPI::request()->api->dhandle("achievement.grant", array("player" => $player, "achievementId" => $achievementId)) !== false){ if(ServerAPI::request()->api->dhandle("achievement.grant", ["player" => $player, "achievementId" => $achievementId]) !== false){
$player->achievements[$achievementId] = true; $player->achievements[$achievementId] = true;
self::broadcastAchievement($player, $achievementId); self::broadcastAchievement($player, $achievementId);
return true; return true;
@ -159,6 +114,33 @@ class AchievementAPI{
return false; return false;
} }
public static function hasAchievement(Player $player, $achievementId){
if(!isset(self::$achievements[$achievementId]) or !isset($player->achievements)){
$player->achievements = [];
return false;
}
if(!isset($player->achievements[$achievementId]) or $player->achievements[$achievementId] == false){
return false;
}
return true;
}
public static function broadcastAchievement(Player $player, $achievementId){
if(isset(self::$achievements[$achievementId])){
$result = ServerAPI::request()->api->dhandle("achievement.broadcast", ["player" => $player, "achievementId" => $achievementId]);
if($result !== false and $result !== true){
if(ServerAPI::request()->api->getProperty("announce-player-achievements") == true){
ServerAPI::request()->api->chat->broadcast($player->username . " has just earned the achievement [" . self::$achievements[$achievementId]["name"] . "]");
}else{
$player->sendChat("You have just earned the achievement [" . self::$achievements[$achievementId]["name"] . "]");
}
}
return true;
}
return false;
}
public static function removeAchievement(Player $player, $achievementId){ public static function removeAchievement(Player $player, $achievementId){
if(self::hasAchievement($player, $achievementId)){ if(self::hasAchievement($player, $achievementId)){
$player->achievements[$achievementId] = false; $player->achievements[$achievementId] = false;

View file

@ -1,25 +1,7 @@
<?php <?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/
*
*
*/
class BanAPI{ class BanAPI{
private $server; private $server;
/* /*
* I would use PHPDoc Template here but PHPStorm does not recognise it. - @sekjun9878 * I would use PHPDoc Template here but PHPStorm does not recognise it. - @sekjun9878
@ -32,31 +14,32 @@ class BanAPI{
private $ops; private $ops;
/** @var Config */ /** @var Config */
private $bannedIPs; private $bannedIPs;
private $cmdWL = array();//Command WhiteList private $cmdWL = [];//Command WhiteList
function __construct(){ function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
public function init(){ public function init(){
$this->whitelist = new Config(DATA_PATH."white-list.txt", CONFIG_LIST);//Open whitelist list file $this->whitelist = new Config(DATA_PATH . "white-list.txt", CONFIG_LIST);//Open whitelist list file
$this->bannedIPs = new Config(DATA_PATH."banned-ips.txt", CONFIG_LIST);//Open Banned IPs list file $this->bannedIPs = new Config(DATA_PATH . "banned-ips.txt", CONFIG_LIST);//Open Banned IPs list file
$this->banned = new Config(DATA_PATH."banned.txt", CONFIG_LIST);//Open Banned Usernames list file $this->banned = new Config(DATA_PATH . "banned.txt", CONFIG_LIST);//Open Banned Usernames list file
$this->ops = new Config(DATA_PATH."ops.txt", CONFIG_LIST);//Open list of OPs $this->ops = new Config(DATA_PATH . "ops.txt", CONFIG_LIST);//Open list of OPs
$this->server->api->console->register("banip", "<add|remove|list|reload> [IP|player]", array($this, "commandHandler")); $this->server->api->console->register("banip", "<add|remove|list|reload> [IP|player]", [$this, "commandHandler"]);
$this->server->api->console->register("ban", "<add|remove|list|reload> [username]", array($this, "commandHandler")); $this->server->api->console->register("ban", "<add|remove|list|reload> [username]", [$this, "commandHandler"]);
$this->server->api->console->register("kick", "<player> [reason ...]", array($this, "commandHandler")); $this->server->api->console->register("kick", "<player> [reason ...]", [$this, "commandHandler"]);
$this->server->api->console->register("whitelist", "<on|off|list|add|remove|reload> [username]", array($this, "commandHandler")); $this->server->api->console->register("whitelist", "<on|off|list|add|remove|reload> [username]", [$this, "commandHandler"]);
$this->server->api->console->register("op", "<player>", array($this, "commandHandler")); $this->server->api->console->register("op", "<player>", [$this, "commandHandler"]);
$this->server->api->console->register("deop", "<player>", array($this, "commandHandler")); $this->server->api->console->register("deop", "<player>", [$this, "commandHandler"]);
$this->server->api->console->register("sudo", "<player>", array($this, "commandHandler")); $this->server->api->console->register("sudo", "<player>", [$this, "commandHandler"]);
$this->server->api->console->alias("ban-ip", "banip add"); $this->server->api->console->alias("ban-ip", "banip add");
$this->server->api->console->alias("banlist", "ban list"); $this->server->api->console->alias("banlist", "ban list");
$this->server->api->console->alias("pardon", "ban remove"); $this->server->api->console->alias("pardon", "ban remove");
$this->server->api->console->alias("pardon-ip", "banip remove"); $this->server->api->console->alias("pardon-ip", "banip remove");
$this->server->addHandler("console.command", array($this, "permissionsCheck"), 1);//Event handler when commands are issued. Used to check permissions of commands that go through the server. $this->server->addHandler("console.command", [$this, "permissionsCheck"], 1);//Event handler when commands are issued. Used to check permissions of commands that go through the server.
$this->server->addHandler("player.block.break", array($this, "permissionsCheck"), 1);//Event handler for blocks $this->server->addHandler("player.block.break", [$this, "permissionsCheck"], 1);//Event handler for blocks
$this->server->addHandler("player.block.place", array($this, "permissionsCheck"), 1);//Event handler for blocks $this->server->addHandler("player.block.place", [$this, "permissionsCheck"], 1);//Event handler for blocks
$this->server->addHandler("player.flying", array($this, "permissionsCheck"), 1);//Flying Event $this->server->addHandler("player.flying", [$this, "permissionsCheck"], 1);//Flying Event
} }
/** /**
@ -66,21 +49,6 @@ class BanAPI{
$this->cmdWhitelist[strtolower(trim($cmd))] = true; $this->cmdWhitelist[strtolower(trim($cmd))] = true;
} }
/**
* @param string $username
*
* @return boolean
*/
public function isOp($username){//Is a player op?
$username = strtolower($username);
if($this->server->api->dhandle("op.check", $username) === true){
return true;
}elseif($this->ops->exists($username)){
return true;
}
return false;
}
/** /**
* @param mixed $data * @param mixed $data
* @param string $event * @param string $event
@ -99,7 +67,7 @@ class BanAPI{
if(!$this->isOp($data["player"]->iusername)){ if(!$this->isOp($data["player"]->iusername)){
$t = new Vector2($data["target"]->x, $data["target"]->z); $t = new Vector2($data["target"]->x, $data["target"]->z);
$s = new Vector2($this->server->spawn->x, $this->server->spawn->z); $s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event.".spawn", $data) !== true){ if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){
return false; return false;
} }
} }
@ -122,6 +90,28 @@ class BanAPI{
} }
} }
/**
* @param string $username
*
* @return boolean
*/
public function isOp($username){//Is a player op?
$username = strtolower($username);
if($this->server->api->dhandle("op.check", $username) === true){
return true;
}elseif($this->ops->exists($username)){
return true;
}
return false;
}
/**
* @param string $username
*/
public function ban($username){
$this->commandHandler("ban", ["add", $username], "console", "");
}
/** /**
* @param string $cmd * @param string $cmd
* @param array $params * @param array $params
@ -141,11 +131,11 @@ class BanAPI{
break; break;
} }
$this->server->api->console->run(implode(" ", $params), $player); $this->server->api->console->run(implode(" ", $params), $player);
$output .= "Command ran as ".$player->username.".\n"; $output .= "Command ran as " . $player->username . ".\n";
break; break;
case "op": case "op":
$user = strtolower($params[0]); $user = strtolower($params[0]);
if($user == NULL){ if($user == null){
$output .= "Usage: /op <player>\n"; $output .= "Usage: /op <player>\n";
break; break;
} }
@ -153,12 +143,12 @@ class BanAPI{
if(!($player instanceof Player)){ if(!($player instanceof Player)){
$this->ops->set($user); $this->ops->set($user);
$this->ops->save($user); $this->ops->save($user);
$output .= $user." is now op\n"; $output .= $user . " is now op\n";
break; break;
} }
$this->ops->set($player->iusername); $this->ops->set($player->iusername);
$this->ops->save(); $this->ops->save();
$output .= $player->iusername." is now op\n"; $output .= $player->iusername . " is now op\n";
$this->server->api->chat->sendTo(false, "You are now op.", $player->iusername); $this->server->api->chat->sendTo(false, "You are now op.", $player->iusername);
break; break;
case "deop": case "deop":
@ -167,12 +157,12 @@ class BanAPI{
if(!($player instanceof Player)){ if(!($player instanceof Player)){
$this->ops->remove($user); $this->ops->remove($user);
$this->ops->save(); $this->ops->save();
$output .= $user." is no longer op\n"; $output .= $user . " is no longer op\n";
break; break;
} }
$this->ops->remove($player->iusername); $this->ops->remove($player->iusername);
$this->ops->save(); $this->ops->save();
$output .= $player->iusername." is no longer op\n"; $output .= $player->iusername . " is no longer op\n";
$this->server->api->chat->sendTo(false, "You are no longer op.", $player->iusername); $this->server->api->chat->sendTo(false, "You are no longer op.", $player->iusername);
break; break;
case "kick": case "kick":
@ -182,17 +172,17 @@ class BanAPI{
$name = strtolower(array_shift($params)); $name = strtolower(array_shift($params));
$player = $this->server->api->player->get($name); $player = $this->server->api->player->get($name);
if($player === false){ if($player === false){
$output .= "Player \"".$name."\" does not exist\n"; $output .= "Player \"" . $name . "\" does not exist\n";
}else{ }else{
$reason = implode(" ", $params); $reason = implode(" ", $params);
$reason = $reason == "" ? "No reason":$reason; $reason = $reason == "" ? "No reason" : $reason;
$this->server->schedule(60, array($player, "close"), "You have been kicked: ".$reason); //Forces a kick $this->server->schedule(60, [$player, "close"], "You have been kicked: " . $reason); //Forces a kick
$player->blocked = true; $player->blocked = true;
if($issuer instanceof Player){ if($issuer instanceof Player){
$this->server->api->chat->broadcast($player->username." has been kicked by ".$issuer->username.": $reason\n"); $this->server->api->chat->broadcast($player->username . " has been kicked by " . $issuer->username . ": $reason\n");
}else{ }else{
$this->server->api->chat->broadcast($player->username." has been kicked: $reason\n"); $this->server->api->chat->broadcast($player->username . " has been kicked: $reason\n");
} }
} }
} }
@ -213,10 +203,10 @@ class BanAPI{
$output .= "Player \"$user\" added to white-list\n"; $output .= "Player \"$user\" added to white-list\n";
break; break;
case "reload": case "reload":
$this->whitelist = new Config(DATA_PATH."white-list.txt", CONFIG_LIST); $this->whitelist = new Config(DATA_PATH . "white-list.txt", CONFIG_LIST);
break; break;
case "list": case "list":
$output .= "White-list: ".implode(", ", $this->whitelist->getAll(true))."\n"; $output .= "White-list: " . implode(", ", $this->whitelist->getAll(true)) . "\n";
break; break;
case "on": case "on":
case "true": case "true":
@ -258,10 +248,10 @@ class BanAPI{
$output .= "IP \"$ip\" added to ban list\n"; $output .= "IP \"$ip\" added to ban list\n";
break; break;
case "reload": case "reload":
$this->bannedIPs = new Config(DATA_PATH."banned-ips.txt", CONFIG_LIST); $this->bannedIPs = new Config(DATA_PATH . "banned-ips.txt", CONFIG_LIST);
break; break;
case "list": case "list":
$output .= "IP ban list: ".implode(", ", $this->bannedIPs->getAll(true))."\n"; $output .= "IP ban list: " . implode(", ", $this->bannedIPs->getAll(true)) . "\n";
break; break;
default: default:
$output .= "Usage: /banip <add|remove|list|reload> [IP|player]\n"; $output .= "Usage: /banip <add|remove|list|reload> [IP|player]\n";
@ -288,18 +278,18 @@ class BanAPI{
$player->close("You have been banned"); $player->close("You have been banned");
} }
if($issuer instanceof Player){ if($issuer instanceof Player){
$this->server->api->chat->broadcast($user." has been banned by ".$issuer->username."\n"); $this->server->api->chat->broadcast($user . " has been banned by " . $issuer->username . "\n");
}else{ }else{
$this->server->api->chat->broadcast($user." has been banned\n"); $this->server->api->chat->broadcast($user . " has been banned\n");
} }
$this->kick($user, "Banned"); $this->kick($user, "Banned");
$output .= "Player \"$user\" added to ban list\n"; $output .= "Player \"$user\" added to ban list\n";
break; break;
case "reload": case "reload":
$this->banned = new Config(DATA_PATH."banned.txt", CONFIG_LIST); $this->banned = new Config(DATA_PATH . "banned.txt", CONFIG_LIST);
break; break;
case "list": case "list":
$output .= "Ban list: ".implode(", ", $this->banned->getAll(true))."\n"; $output .= "Ban list: " . implode(", ", $this->banned->getAll(true)) . "\n";
break; break;
default: default:
$output .= "Usage: /ban <add|remove|list|reload> [username]\n"; $output .= "Usage: /ban <add|remove|list|reload> [username]\n";
@ -312,44 +302,37 @@ class BanAPI{
/** /**
* @param string $username * @param string $username
* @param string $reason
*/ */
public function ban($username){ public function kick($username, $reason = "No Reason"){
$this->commandHandler("ban", array("add", $username), "console", ""); $this->commandHandler("kick", [$username, $reason], "console", "");
} }
/** /**
* @param string $username * @param string $username
*/ */
public function pardon($username){ public function pardon($username){
$this->commandHandler("ban", array("pardon", $username), "console", ""); $this->commandHandler("ban", ["pardon", $username], "console", "");
} }
/** /**
* @param string $ip * @param string $ip
*/ */
public function banIP($ip){ public function banIP($ip){
$this->commandHandler("banip", array("add", $ip), "console", ""); $this->commandHandler("banip", ["add", $ip], "console", "");
} }
/** /**
* @param string $ip * @param string $ip
*/ */
public function pardonIP($ip){ public function pardonIP($ip){
$this->commandHandler("banip", array("pardon", $ip), "console", ""); $this->commandHandler("banip", ["pardon", $ip], "console", "");
}
/**
* @param string $username
* @param string $reason
*/
public function kick($username, $reason = "No Reason"){
$this->commandHandler("kick", array($username, $reason), "console", "");
} }
public function reload(){ public function reload(){
$this->commandHandler("ban", array("reload"), "console", ""); $this->commandHandler("ban", ["reload"], "console", "");
$this->commandHandler("banip", array("reload"), "console", ""); $this->commandHandler("banip", ["reload"], "console", "");
$this->commandHandler("whitelist", array("reload"), "console", ""); $this->commandHandler("whitelist", ["reload"], "console", "");
} }
/** /**

View file

@ -1,233 +1,341 @@
<?php <?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/
*
*
*/
class BlockAPI{ class BlockAPI{
private $server;
private $scheduledUpdates = array(); public static $creative = [
private $randomUpdates = array();
public static $creative = array(
//Building //Building
array(STONE, 0), [STONE, 0],
array(COBBLESTONE, 0), [COBBLESTONE, 0],
array(STONE_BRICKS, 0), [STONE_BRICKS, 0],
array(STONE_BRICKS, 1), [STONE_BRICKS, 1],
array(STONE_BRICKS, 2), [STONE_BRICKS, 2],
array(MOSS_STONE, 0), [MOSS_STONE, 0],
array(WOODEN_PLANKS, 0), [WOODEN_PLANKS, 0],
array(WOODEN_PLANKS, 1), [WOODEN_PLANKS, 1],
array(WOODEN_PLANKS, 2), [WOODEN_PLANKS, 2],
array(WOODEN_PLANKS, 3), [WOODEN_PLANKS, 3],
array(BRICKS, 0), [BRICKS, 0],
array(DIRT, 0), [DIRT, 0],
array(GRASS, 0), [GRASS, 0],
array(CLAY_BLOCK, 0), [CLAY_BLOCK, 0],
array(SANDSTONE, 0), [SANDSTONE, 0],
array(SANDSTONE, 1), [SANDSTONE, 1],
array(SANDSTONE, 2), [SANDSTONE, 2],
array(SAND, 0), [SAND, 0],
array(GRAVEL, 0), [GRAVEL, 0],
array(TRUNK, 0), [TRUNK, 0],
array(TRUNK, 1), [TRUNK, 1],
array(TRUNK, 2), [TRUNK, 2],
array(TRUNK, 3), [TRUNK, 3],
array(NETHER_BRICKS, 0), [NETHER_BRICKS, 0],
array(NETHERRACK, 0), [NETHERRACK, 0],
array(BEDROCK, 0), [BEDROCK, 0],
array(COBBLESTONE_STAIRS, 0), [COBBLESTONE_STAIRS, 0],
array(OAK_WOODEN_STAIRS, 0), [OAK_WOODEN_STAIRS, 0],
array(SPRUCE_WOODEN_STAIRS, 0), [SPRUCE_WOODEN_STAIRS, 0],
array(BIRCH_WOODEN_STAIRS, 0), [BIRCH_WOODEN_STAIRS, 0],
array(JUNGLE_WOODEN_STAIRS, 0), [JUNGLE_WOODEN_STAIRS, 0],
array(BRICK_STAIRS, 0), [BRICK_STAIRS, 0],
array(SANDSTONE_STAIRS, 0), [SANDSTONE_STAIRS, 0],
array(STONE_BRICK_STAIRS, 0), [STONE_BRICK_STAIRS, 0],
array(NETHER_BRICKS_STAIRS, 0), [NETHER_BRICKS_STAIRS, 0],
array(QUARTZ_STAIRS, 0), [QUARTZ_STAIRS, 0],
array(SLAB, 0), [SLAB, 0],
array(SLAB, 1), [SLAB, 1],
array(WOODEN_SLAB, 0), [WOODEN_SLAB, 0],
array(WOODEN_SLAB, 1), [WOODEN_SLAB, 1],
array(WOODEN_SLAB, 2), [WOODEN_SLAB, 2],
array(WOODEN_SLAB, 3), [WOODEN_SLAB, 3],
array(SLAB, 3), [SLAB, 3],
array(SLAB, 4), [SLAB, 4],
array(SLAB, 5), [SLAB, 5],
array(SLAB, 6), [SLAB, 6],
array(QUARTZ_BLOCK, 0), [QUARTZ_BLOCK, 0],
array(QUARTZ_BLOCK, 1), [QUARTZ_BLOCK, 1],
array(QUARTZ_BLOCK, 2), [QUARTZ_BLOCK, 2],
array(COAL_ORE, 0), [COAL_ORE, 0],
array(IRON_ORE, 0), [IRON_ORE, 0],
array(GOLD_ORE, 0), [GOLD_ORE, 0],
array(DIAMOND_ORE, 0), [DIAMOND_ORE, 0],
array(LAPIS_ORE, 0), [LAPIS_ORE, 0],
array(REDSTONE_ORE, 0), [REDSTONE_ORE, 0],
array(OBSIDIAN, 0), [OBSIDIAN, 0],
array(ICE, 0), [ICE, 0],
array(SNOW_BLOCK, 0), [SNOW_BLOCK, 0],
//Decoration //Decoration
array(COBBLESTONE_WALL, 0), [COBBLESTONE_WALL, 0],
array(COBBLESTONE_WALL, 1), [COBBLESTONE_WALL, 1],
array(GOLD_BLOCK, 0), [GOLD_BLOCK, 0],
array(IRON_BLOCK, 0), [IRON_BLOCK, 0],
array(DIAMOND_BLOCK, 0), [DIAMOND_BLOCK, 0],
array(LAPIS_BLOCK, 0), [LAPIS_BLOCK, 0],
array(COAL_BLOCK, 0), [COAL_BLOCK, 0],
array(SNOW_LAYER, 0), [SNOW_LAYER, 0],
array(GLASS, 0), [GLASS, 0],
array(GLOWSTONE_BLOCK, 0), [GLOWSTONE_BLOCK, 0],
array(NETHER_REACTOR, 0), [NETHER_REACTOR, 0],
array(WOOL, 0), [WOOL, 0],
array(WOOL, 7), [WOOL, 7],
array(WOOL, 6), [WOOL, 6],
array(WOOL, 5), [WOOL, 5],
array(WOOL, 4), [WOOL, 4],
array(WOOL, 3), [WOOL, 3],
array(WOOL, 2), [WOOL, 2],
array(WOOL, 1), [WOOL, 1],
array(WOOL, 15), [WOOL, 15],
array(WOOL, 14), [WOOL, 14],
array(WOOL, 13), [WOOL, 13],
array(WOOL, 12), [WOOL, 12],
array(WOOL, 11), [WOOL, 11],
array(WOOL, 10), [WOOL, 10],
array(WOOL, 9), [WOOL, 9],
array(WOOL, 8), [WOOL, 8],
array(LADDER, 0), [LADDER, 0],
array(SPONGE, 0), [SPONGE, 0],
array(GLASS_PANE, 0), [GLASS_PANE, 0],
array(WOODEN_DOOR, 0), [WOODEN_DOOR, 0],
array(TRAPDOOR, 0), [TRAPDOOR, 0],
array(FENCE, 0), [FENCE, 0],
array(FENCE_GATE, 0), [FENCE_GATE, 0],
array(IRON_BARS, 0), [IRON_BARS, 0],
array(BED, 0), [BED, 0],
array(BOOKSHELF, 0), [BOOKSHELF, 0],
array(PAINTING, 0), [PAINTING, 0],
array(WORKBENCH, 0), [WORKBENCH, 0],
array(STONECUTTER, 0), [STONECUTTER, 0],
array(CHEST, 0), [CHEST, 0],
array(FURNACE, 0), [FURNACE, 0],
array(DANDELION, 0), [DANDELION, 0],
array(CYAN_FLOWER, 0), [CYAN_FLOWER, 0],
array(BROWN_MUSHROOM, 0), [BROWN_MUSHROOM, 0],
array(RED_MUSHROOM, 0), [RED_MUSHROOM, 0],
array(CACTUS, 0), [CACTUS, 0],
array(MELON_BLOCK, 0), [MELON_BLOCK, 0],
array(PUMPKIN, 0), [PUMPKIN, 0],
array(LIT_PUMPKIN, 0), [LIT_PUMPKIN, 0],
array(COBWEB, 0), [COBWEB, 0],
array(HAY_BALE, 0), [HAY_BALE, 0],
array(TALL_GRASS, 1), [TALL_GRASS, 1],
array(TALL_GRASS, 2), [TALL_GRASS, 2],
array(DEAD_BUSH, 0), [DEAD_BUSH, 0],
array(SAPLING, 0), [SAPLING, 0],
array(SAPLING, 1), [SAPLING, 1],
array(SAPLING, 2), [SAPLING, 2],
array(SAPLING, 3), [SAPLING, 3],
array(LEAVES, 0), [LEAVES, 0],
array(LEAVES, 1), [LEAVES, 1],
array(LEAVES, 2), [LEAVES, 2],
array(LEAVES, 3), [LEAVES, 3],
array(CAKE, 0), [CAKE, 0],
array(SIGN, 0), [SIGN, 0],
array(CARPET, 0), [CARPET, 0],
array(CARPET, 7), [CARPET, 7],
array(CARPET, 6), [CARPET, 6],
array(CARPET, 5), [CARPET, 5],
array(CARPET, 4), [CARPET, 4],
array(CARPET, 3), [CARPET, 3],
array(CARPET, 2), [CARPET, 2],
array(CARPET, 1), [CARPET, 1],
array(CARPET, 15), [CARPET, 15],
array(CARPET, 14), [CARPET, 14],
array(CARPET, 13), [CARPET, 13],
array(CARPET, 12), [CARPET, 12],
array(CARPET, 11), [CARPET, 11],
array(CARPET, 10), [CARPET, 10],
array(CARPET, 9), [CARPET, 9],
array(CARPET, 8), [CARPET, 8],
//Tools //Tools
array(RAIL, 0), [RAIL, 0],
array(POWERED_RAIL, 0), [POWERED_RAIL, 0],
array(TORCH, 0), [TORCH, 0],
array(BUCKET, 0), [BUCKET, 0],
array(BUCKET, 8), [BUCKET, 8],
array(BUCKET, 10), [BUCKET, 10],
array(TNT, 0), [TNT, 0],
array(IRON_HOE, 0), [IRON_HOE, 0],
array(IRON_SWORD, 0), [IRON_SWORD, 0],
array(BOW, 0), [BOW, 0],
array(SHEARS, 0), [SHEARS, 0],
array(FLINT_AND_STEEL, 0), [FLINT_AND_STEEL, 0],
array(CLOCK, 0), [CLOCK, 0],
array(COMPASS, 0), [COMPASS, 0],
array(MINECART, 0), [MINECART, 0],
array(SPAWN_EGG, MOB_CHICKEN), [SPAWN_EGG, MOB_CHICKEN],
array(SPAWN_EGG, MOB_COW), [SPAWN_EGG, MOB_COW],
array(SPAWN_EGG, MOB_PIG), [SPAWN_EGG, MOB_PIG],
array(SPAWN_EGG, MOB_SHEEP), [SPAWN_EGG, MOB_SHEEP],
array(SPAWN_EGG, MOB_ZOMBIE), [SPAWN_EGG, MOB_ZOMBIE],
array(SPAWN_EGG, MOB_CREEPER), [SPAWN_EGG, MOB_CREEPER],
array(SPAWN_EGG, MOB_SKELETON), [SPAWN_EGG, MOB_SKELETON],
array(SPAWN_EGG, MOB_SPIDER), [SPAWN_EGG, MOB_SPIDER],
array(SPAWN_EGG, MOB_PIGMAN), [SPAWN_EGG, MOB_PIGMAN],
//Seeds //Seeds
array(SUGARCANE, 0), [SUGARCANE, 0],
array(WHEAT, 0), [WHEAT, 0],
array(SEEDS, 0), [SEEDS, 0],
array(MELON_SEEDS, 0), [MELON_SEEDS, 0],
array(PUMPKIN_SEEDS, 0), [PUMPKIN_SEEDS, 0],
array(CARROT, 0), [CARROT, 0],
array(POTATO, 0), [POTATO, 0],
array(BEETROOT_SEEDS, 0), [BEETROOT_SEEDS, 0],
array(EGG, 0), [EGG, 0],
array(DYE, 0), [DYE, 0],
array(DYE, 7), [DYE, 7],
array(DYE, 6), [DYE, 6],
array(DYE, 5), [DYE, 5],
array(DYE, 4), [DYE, 4],
array(DYE, 3), [DYE, 3],
array(DYE, 2), [DYE, 2],
array(DYE, 1), [DYE, 1],
array(DYE, 15), [DYE, 15],
array(DYE, 14), [DYE, 14],
array(DYE, 13), [DYE, 13],
array(DYE, 12), [DYE, 12],
array(DYE, 11), [DYE, 11],
array(DYE, 10), [DYE, 10],
array(DYE, 9), [DYE, 9],
array(DYE, 8), [DYE, 8],
); ];
private $server;
private $scheduledUpdates = [];
private $randomUpdates = [];
function __construct(){
$this->server = ServerAPI::request();
}
public static function get($id, $meta = 0, $v = false){
if(isset(Block::$class[$id])){
$classname = Block::$class[$id];
$b = new $classname($meta);
}else{
$b = new GenericBlock((int) $id, $meta);
}
if($v instanceof Position){
$b->position($v);
}
return $b;
}
public function init(){
$this->server->schedule(1, [$this, "blockUpdateTick"], [], true);
$this->server->api->console->register("setblock", "<x> <y> <z> <block[:damage]>", [$this, "commandHandler"]);
$this->server->api->console->register("give", "<player> <item[:damage]> [amount]", [$this, "commandHandler"]);
}
public function commandHandler($cmd, $args, $issuer, $alias){
$output = "";
switch($cmd){
case "setblock":
if(!($issuer instanceof Player)){
$output .= "Please run this command in-game.\n";
break;
}
if(count($args) < 4){
$output .= "Usage: /setblock <x> <y> <z> <block[:damage]>\n";
break;
}
if($args[0] == '~')
$x = round($issuer->entity->x, 0);
elseif((int) $args[0] < 255)
$x = $args[0];
else{
$output .= "Usage: /setblock <x> <y> <z> <block[:damage]>\n";
break;
}
if($args[1] == '~')
$y = round($issuer->entity->y, 0);
elseif((int) $args[1] < 255)
$y = $args[1];
else{
$output .= "Usage: /setblock <x> <y> <z> <block[:damage]>\n";
break;
}
if($args[2] == '~')
$z = round($issuer->entity->z, 0);
elseif((int) $args[2] < 255)
$z = $args[2];
else{
$output .= "Usage: /setblock <x> <y> <z> <block[:damage]>\n";
break;
}
$pos = new Position($x, $y, $z, $issuer->entity->level);
$block = BlockAPI::fromString($args[3])->getBlock();
if(!($block instanceof Block)){
$output .= "Usage: /setblock <x> <y> <z> <block[:damage]>\n";
break;
}else{
$issuer->level->setBlock($pos, $block, true, false, true);
$output .= "Placed " . $block . " in " . $x . ", " . $y . ", " . $z;
}
break;
case "give":
if(count($args) == 1 and $issuer instanceof Player){
$item = BlockAPI::fromString($args[0]);
if(($issuer->gamemode & 0x01) === 0x01){
$output .= "You are in creative mode.\n";
break;
}
if($item->getID() == 0){
$output .= "You cannot give an air block to a player.\n";
break;
}
if(!isset($args[1])){
$item->count = $item->getMaxStackSize();
}else{
$item->count = (int) $args[1];
}
$issuer->addItem($item->getID(), $item->getMetadata(), $item->count);
$output .= "Giving " . $item->count . " of " . $item->getName() . " (" . $item->getID() . ":" . $item->getMetadata() . ") to " . $issuer->username . "\n";
break;
}
$player = $this->server->api->player->get($args[0]);
$item = BlockAPI::fromString($args[1]);
if(!isset($args[2])){
$item->count = $item->getMaxStackSize();
}else{
$item->count = (int) $args[2];
}
if($player instanceof Player){
if(($player->gamemode & 0x01) === 0x01){
$output .= "Player is in creative mode.\n";
break;
}
if($item->getID() == 0){
$output .= "You cannot give an air block to a player.\n";
break;
}
$player->addItem($item->getID(), $item->getMetadata(), $item->count);
$output .= "Giving " . $item->count . " of " . $item->getName() . " (" . $item->getID() . ":" . $item->getMetadata() . ") to " . $player->username . "\n";
}else{
$output .= "Unknown player.\n";
}
break;
}
return $output;
}
public static function fromString($str, $multiple = false){ public static function fromString($str, $multiple = false){
if($multiple === true){ if($multiple === true){
$blocks = array(); $blocks = [];
foreach(explode(",",$str) as $b){ foreach(explode(",", $str) as $b){
$blocks[] = BlockAPI::fromString($b, false); $blocks[] = BlockAPI::fromString($b, false);
} }
return $blocks; return $blocks;
@ -255,19 +363,6 @@ class BlockAPI{
} }
} }
public static function get($id, $meta = 0, $v = false){
if(isset(Block::$class[$id])){
$classname = Block::$class[$id];
$b = new $classname($meta);
}else{
$b = new GenericBlock((int) $id, $meta);
}
if($v instanceof Position){
$b->position($v);
}
return $b;
}
public static function getItem($id, $meta = 0, $count = 1){ public static function getItem($id, $meta = 0, $count = 1){
$id = (int) $id; $id = (int) $id;
if(isset(Item::$class[$id])){ if(isset(Item::$class[$id])){
@ -279,148 +374,25 @@ class BlockAPI{
return $i; return $i;
} }
function __construct(){
$this->server = ServerAPI::request();
}
public function init(){
$this->server->schedule(1, array($this, "blockUpdateTick"), array(), true);
$this->server->api->console->register("setblock", "<x> <y> <z> <block[:damage]>", array($this, "commandHandler"));
$this->server->api->console->register("give", "<player> <item[:damage]> [amount]", array($this, "commandHandler"));
}
public function commandHandler($cmd, $args, $issuer, $alias){
$output = "";
switch($cmd){
case "setblock":
if(!($issuer instanceof Player)){
$output .= "Please run this command in-game.\n";
break;
}
if(count($args) < 4){
$output .= "Usage: /setblock <x> <y> <z> <block[:damage]>\n";
break;
}
if($args[0] == '~') $x = round($issuer->entity->x, 0);
elseif((int)$args[0] < 255) $x = $args[0];
else{
$output .= "Usage: /setblock <x> <y> <z> <block[:damage]>\n";
break;
}
if($args[1] == '~') $y = round($issuer->entity->y, 0);
elseif((int)$args[1] < 255) $y = $args[1];
else{
$output .= "Usage: /setblock <x> <y> <z> <block[:damage]>\n";
break;
}
if($args[2] == '~') $z = round($issuer->entity->z, 0);
elseif((int)$args[2] < 255) $z = $args[2];
else{
$output .= "Usage: /setblock <x> <y> <z> <block[:damage]>\n";
break;
}
$pos = new Position($x, $y, $z, $issuer->entity->level);
$block = BlockAPI::fromString($args[3])->getBlock();
if(!($block instanceof Block)){
$output .= "Usage: /setblock <x> <y> <z> <block[:damage]>\n";
break;
}
else{
$issuer->level->setBlock($pos, $block, true, false, true);
$output .= "Placed ".$block." in ".$x.", ".$y.", ".$z;
}
break;
case "give":
if(count($args) == 1 and $issuer instanceof Player){
$item = BlockAPI::fromString($args[0]);
if(($issuer->gamemode & 0x01) === 0x01){
$output .= "You are in creative mode.\n";
break;
}
if($item->getID() == 0){
$output .= "You cannot give an air block to a player.\n";
break;
}
if(!isset($args[1])){
$item->count = $item->getMaxStackSize();
}
else{
$item->count = (int)$args[1];
}
$issuer->addItem($item->getID(), $item->getMetadata(), $item->count);
$output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$issuer->username."\n";
break;
}
$player = $this->server->api->player->get($args[0]);
$item = BlockAPI::fromString($args[1]);
if(!isset($args[2])){
$item->count = $item->getMaxStackSize();
}else{
$item->count = (int) $args[2];
}
if($player instanceof Player){
if(($player->gamemode & 0x01) === 0x01){
$output .= "Player is in creative mode.\n";
break;
}
if($item->getID() == 0) {
$output .= "You cannot give an air block to a player.\n";
break;
}
$player->addItem($item->getID(), $item->getMetadata(), $item->count);
$output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username."\n";
}else{
$output .= "Unknown player.\n";
}
break;
}
return $output;
}
private function cancelAction(Block $block, Player $player, $send = true){
$pk = new UpdateBlockPacket;
$pk->x = $block->x;
$pk->y = $block->y;
$pk->z = $block->z;
$pk->block = $block->getID();
$pk->meta = $block->getMetadata();
$player->dataPacket($pk);
if($send === true){
$player->sendInventorySlot($player->slot);
}
return false;
}
public function playerBlockBreak(Player $player, Vector3 $vector){ public function playerBlockBreak(Player $player, Vector3 $vector){
$target = $player->level->getBlock($vector); $target = $player->level->getBlock($vector);
$item = $player->getSlot($player->slot); $item = $player->getSlot($player->slot);
if($this->server->api->dhandle("player.block.touch", array("type" => "break", "player" => $player, "target" => $target, "item" => $item)) === false){ if($this->server->api->dhandle("player.block.touch", ["type" => "break", "player" => $player, "target" => $target, "item" => $item]) === false){
if($this->server->api->dhandle("player.block.break.bypass", array("player" => $player, "target" => $target, "item" => $item)) !== true){ if($this->server->api->dhandle("player.block.break.bypass", ["player" => $player, "target" => $target, "item" => $item]) !== true){
return $this->cancelAction($target, $player, false); return $this->cancelAction($target, $player, false);
} }
} }
if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or ($player->gamemode & 0x02) === 0x02 or (($player->lastBreak - $player->getLag() / 1000) + $target->getBreakTime($item, $player) - 0.2) >= microtime(true)){ if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", ["player" => $player, "target" => $target, "item" => $item]) !== true) or ($player->gamemode & 0x02) === 0x02 or (($player->lastBreak - $player->getLag() / 1000) + $target->getBreakTime($item, $player) - 0.2) >= microtime(true)){
if($this->server->api->dhandle("player.block.break.bypass", array("player" => $player, "target" => $target, "item" => $item)) !== true){ if($this->server->api->dhandle("player.block.break.bypass", ["player" => $player, "target" => $target, "item" => $item]) !== true){
return $this->cancelAction($target, $player, false); return $this->cancelAction($target, $player, false);
} }
} }
$player->lastBreak = microtime(true); $player->lastBreak = microtime(true);
if($this->server->api->dhandle("player.block.break", array("player" => $player, "target" => $target, "item" => $item)) !== false){ if($this->server->api->dhandle("player.block.break", ["player" => $player, "target" => $target, "item" => $item]) !== false){
$drops = $target->getDrops($item, $player); $drops = $target->getDrops($item, $player);
if($target->onBreak($item, $player) === false){ if($target->onBreak($item, $player) === false){
return $this->cancelAction($target, $player, false); return $this->cancelAction($target, $player, false);
@ -441,6 +413,20 @@ class BlockAPI{
return false; return false;
} }
private function cancelAction(Block $block, Player $player, $send = true){
$pk = new UpdateBlockPacket;
$pk->x = $block->x;
$pk->y = $block->y;
$pk->z = $block->z;
$pk->block = $block->getID();
$pk->meta = $block->getMetadata();
$player->dataPacket($pk);
if($send === true){
$player->sendInventorySlot($player->slot);
}
return false;
}
public function playerBlockAction(Player $player, Vector3 $vector, $face, $fx, $fy, $fz){ public function playerBlockAction(Player $player, Vector3 $vector, $face, $fx, $fy, $fz){
if($face < 0 or $face > 5){ if($face < 0 or $face > 5){
return false; return false;
@ -450,28 +436,28 @@ class BlockAPI{
$block = $target->getSide($face); $block = $target->getSide($face);
$item = $player->getSlot($player->slot); $item = $player->getSlot($player->slot);
if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ //If no block exists or not allowed in CREATIVE if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){ //If no block exists or not allowed in CREATIVE
if($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){
$this->cancelAction($target, $player); $this->cancelAction($target, $player);
return $this->cancelAction($block, $player); return $this->cancelAction($block, $player);
} }
} }
if($this->server->api->dhandle("player.block.touch", array("type" => "place", "player" => $player, "block" => $block, "target" => $target, "item" => $item)) === false){ if($this->server->api->dhandle("player.block.touch", ["type" => "place", "player" => $player, "block" => $block, "target" => $target, "item" => $item]) === false){
if($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){
return $this->cancelAction($block, $player); return $this->cancelAction($block, $player);
} }
} }
$this->blockUpdate($target, BLOCK_UPDATE_TOUCH); $this->blockUpdate($target, BLOCK_UPDATE_TOUCH);
if($target->isActivable === true){ if($target->isActivable === true){
if($this->server->api->dhandle("player.block.activate", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== false and $target->onActivate($item, $player) === true){ if($this->server->api->dhandle("player.block.activate", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== false and $target->onActivate($item, $player) === true){
return false; return false;
} }
} }
if(($player->gamemode & 0x02) === 0x02){ //Adventure mode!! if(($player->gamemode & 0x02) === 0x02){ //Adventure mode!!
if($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){
return $this->cancelAction($block, $player, false); return $this->cancelAction($block, $player, false);
} }
} }
@ -511,7 +497,7 @@ class BlockAPI{
return $this->cancelAction($block, $player, false); //Entity in block return $this->cancelAction($block, $player, false); //Entity in block
} }
if($this->server->api->dhandle("player.block.place", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) === false){ if($this->server->api->dhandle("player.block.place", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) === false){
return $this->cancelAction($block, $player); return $this->cancelAction($block, $player);
}elseif($hand->place($item, $player, $block, $target, $face, $fx, $fy, $fz) === false){ }elseif($hand->place($item, $player, $block, $target, $face, $fx, $fy, $fz) === false){
return $this->cancelAction($block, $player, false); return $this->cancelAction($block, $player, false);
@ -531,24 +517,6 @@ class BlockAPI{
return false; return false;
} }
public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){
if($delay !== false){
$this->scheduleBlockUpdate($pos->getSide(0), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(1), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(2), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(3), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(4), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(5), $delay, $type);
}else{
$this->blockUpdate($pos->getSide(0), $type);
$this->blockUpdate($pos->getSide(1), $type);
$this->blockUpdate($pos->getSide(2), $type);
$this->blockUpdate($pos->getSide(3), $type);
$this->blockUpdate($pos->getSide(4), $type);
$this->blockUpdate($pos->getSide(5), $type);
}
}
public function blockUpdate(Position $pos, $type = BLOCK_UPDATE_NORMAL){ public function blockUpdate(Position $pos, $type = BLOCK_UPDATE_NORMAL){
if(!($pos instanceof Block)){ if(!($pos instanceof Block)){
$block = $pos->level->getBlock($pos); $block = $pos->level->getBlock($pos);
@ -570,24 +538,42 @@ class BlockAPI{
return $level; return $level;
} }
public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){
if($delay !== false){
$this->scheduleBlockUpdate($pos->getSide(0), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(1), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(2), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(3), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(4), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(5), $delay, $type);
}else{
$this->blockUpdate($pos->getSide(0), $type);
$this->blockUpdate($pos->getSide(1), $type);
$this->blockUpdate($pos->getSide(2), $type);
$this->blockUpdate($pos->getSide(3), $type);
$this->blockUpdate($pos->getSide(4), $type);
$this->blockUpdate($pos->getSide(5), $type);
}
}
public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){ public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){
$type = (int) $type; $type = (int) $type;
if($delay < 0){ if($delay < 0){
return false; return false;
} }
$index = $pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".$type; $index = $pos->x . "." . $pos->y . "." . $pos->z . "." . $pos->level->getName() . "." . $type;
$delay = microtime(true) + $delay * 0.05; $delay = microtime(true) + $delay * 0.05;
if(!isset($this->scheduledUpdates[$index])){ if(!isset($this->scheduledUpdates[$index])){
$this->scheduledUpdates[$index] = $pos; $this->scheduledUpdates[$index] = $pos;
$this->server->query("INSERT INTO blockUpdates (x, y, z, level, type, delay) VALUES (".$pos->x.", ".$pos->y.", ".$pos->z.", '".$pos->level->getName()."', ".$type.", ".$delay.");"); $this->server->query("INSERT INTO blockUpdates (x, y, z, level, type, delay) VALUES (" . $pos->x . ", " . $pos->y . ", " . $pos->z . ", '" . $pos->level->getName() . "', " . $type . ", " . $delay . ");");
return true; return true;
} }
return false; return false;
} }
public function 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); $X = (($pos->x >> 4) << 4);
$Y = (($pos->y >> 4) << 4); $Y = (($pos->y >> 4) << 4);
$Z = (($pos->z >> 4) << 4); $Z = (($pos->z >> 4) << 4);
@ -596,7 +582,7 @@ class BlockAPI{
$offset = 0; $offset = 0;
while(true){ while(true){
$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){
$update = $update->fetchArray(SQLITE3_NUM); $update = $update->fetchArray(SQLITE3_NUM);
if($update[0] < 3){ if($update[0] < 3){
@ -614,17 +600,17 @@ class BlockAPI{
public function blockUpdateTick(){ public function blockUpdateTick(){
$time = microtime(true); $time = microtime(true);
if(count($this->scheduledUpdates) > 0){ if(count($this->scheduledUpdates) > 0){
$update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE delay <= ".$time.";"); $update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE delay <= " . $time . ";");
if($update instanceof SQLite3Result){ if($update instanceof SQLite3Result){
$upp = array(); $upp = [];
while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){ while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){
$index = $up["x"].".".$up["y"].".".$up["z"].".".$up["level"].".".$up["type"]; $index = $up["x"] . "." . $up["y"] . "." . $up["z"] . "." . $up["level"] . "." . $up["type"];
if(isset($this->scheduledUpdates[$index])){ if(isset($this->scheduledUpdates[$index])){
$upp[] = array((int) $up["type"], $this->scheduledUpdates[$index]); $upp[] = [(int) $up["type"], $this->scheduledUpdates[$index]];
unset($this->scheduledUpdates[$index]); unset($this->scheduledUpdates[$index]);
} }
} }
$this->server->query("DELETE FROM blockUpdates WHERE delay <= ".$time.";"); $this->server->query("DELETE FROM blockUpdates WHERE delay <= " . $time . ";");
foreach($upp as $b){ foreach($upp as $b){
$this->blockUpdate($b[1], $b[0]); $this->blockUpdate($b[1], $b[0]);
} }

View file

@ -1,34 +1,17 @@
<?php <?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/
*
*
*/
class ChatAPI{ class ChatAPI{
private $server; private $server;
function __construct(){ function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
public function init(){ public function init(){
$this->server->api->console->register("tell", "<player> <private message ...>", array($this, "commandHandler")); $this->server->api->console->register("tell", "<player> <private message ...>", [$this, "commandHandler"]);
$this->server->api->console->register("me", "<action ...>", array($this, "commandHandler")); $this->server->api->console->register("me", "<action ...>", [$this, "commandHandler"]);
$this->server->api->console->register("say", "<message ...>", array($this, "commandHandler")); $this->server->api->console->register("say", "<message ...>", [$this, "commandHandler"]);
$this->server->api->ban->cmdWhitelist("tell"); $this->server->api->ban->cmdWhitelist("tell");
$this->server->api->ban->cmdWhitelist("me"); $this->server->api->ban->cmdWhitelist("me");
$this->server->api->console->alias("msg", "tell"); $this->server->api->console->alias("msg", "tell");
@ -51,8 +34,8 @@ class ChatAPI{
$output .= "Usage: /say <message>\n"; $output .= "Usage: /say <message>\n";
break; break;
} }
$sender = ($issuer instanceof Player) ? "Server":ucfirst($issuer); $sender = ($issuer instanceof Player) ? "Server" : ucfirst($issuer);
$this->server->api->chat->broadcast("[$sender] ".$s); $this->server->api->chat->broadcast("[$sender] " . $s);
break; break;
case "me": case "me":
$s = implode(" ", $params); $s = implode(" ", $params);
@ -69,7 +52,7 @@ class ChatAPI{
}else{ }else{
$sender = $issuer->username; $sender = $issuer->username;
} }
$this->broadcast("* $sender ".implode(" ", $params)); $this->broadcast("* $sender " . implode(" ", $params));
break; break;
case "tell": case "tell":
if(!isset($params[0]) or !isset($params[1])){ if(!isset($params[0]) or !isset($params[1])){
@ -92,12 +75,12 @@ class ChatAPI{
} }
} }
$mes = implode(" ", $params); $mes = implode(" ", $params);
$output .= "You're whispering to ".$target.": ".$mes."\n"; $output .= "You're whispering to " . $target . ": " . $mes . "\n";
if($target !== "Console" and $target !== "Rcon"){ if($target !== "Console" and $target !== "Rcon"){
$this->sendTo(false, $sender." whispers to you: ".$mes, $target); $this->sendTo(false, $sender . " whispers to you: " . $mes, $target);
} }
if($target === "Console" or $sender === "Console"){ if($target === "Console" or $sender === "Console"){
console("[INFO] ".$sender." whispers to ".$target.": ".$mes); console("[INFO] " . $sender . " whispers to " . $target . ": " . $mes);
} }
break; break;
} }
@ -112,15 +95,6 @@ class ChatAPI{
$this->server->send2Discord($message); $this->server->send2Discord($message);
} }
/**
* @param string $owner
* @param string $text
* @param mixed $player Can be either Player object or string username. Boolean false for broadcast.
*/
public function sendTo($owner, $text, $player){
$this->send($owner, $text, array($player));
}
/** /**
* @param mixed $owner Can be either Player object or string username. Boolean false for broadcast. * @param mixed $owner Can be either Player object or string username. Boolean false for broadcast.
* @param string $text * @param string $text
@ -128,18 +102,18 @@ class ChatAPI{
* @param $blacklist * @param $blacklist
*/ */
public function send($owner, $text, $whitelist = false, $blacklist = false){ public function send($owner, $text, $whitelist = false, $blacklist = false){
$message = array( $message = [
"player" => $owner, "player" => $owner,
"message" => $text, "message" => $text,
); ];
if($owner !== false){ if($owner !== false){
if($owner instanceof Player){ if($owner instanceof Player){
if($whitelist === false){ if($whitelist === false){
console("[INFO] <".$owner->username."> ".$text); console("[INFO] <" . $owner->username . "> " . $text);
} }
}else{ }else{
if($whitelist === false){ if($whitelist === false){
console("[INFO] <".$owner."> ".$text); console("[INFO] <" . $owner . "> " . $text);
} }
} }
}else{ }else{
@ -151,4 +125,13 @@ class ChatAPI{
$container = new Container($message, $whitelist, $blacklist); $container = new Container($message, $whitelist, $blacklist);
$this->server->handle("server.chat", $container); $this->server->handle("server.chat", $container);
} }
/**
* @param string $owner
* @param string $text
* @param mixed $player Can be either Player object or string username. Boolean false for broadcast.
*/
public function sendTo($owner, $text, $player){
$this->send($owner, $text, [$player]);
}
} }

View file

@ -1,48 +1,41 @@
<?php <?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/
*
*
*/
class ConsoleAPI{ class ConsoleAPI{
private $loop, $server, $event, $help, $cmds, $alias; private $loop, $server, $event, $help, $cmds, $alias;
function __construct(){ function __construct(){
$this->help = array(); $this->help = [];
$this->cmds = array(); $this->cmds = [];
$this->alias = array(); $this->alias = [];
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->last = microtime(true); $this->last = microtime(true);
} }
public function init(){ public function init(){
$this->server->schedule(2, array($this, "handle"), array(), true); $this->server->schedule(2, [$this, "handle"], [], true);
if(!defined("NO_THREADS")){ if(!defined("NO_THREADS")){
$this->loop = new ConsoleLoop(); $this->loop = new ConsoleLoop();
} }
$this->register("help", "[page|command name]", array($this, "defaultCommands")); $this->register("help", "[page|command name]", [$this, "defaultCommands"]);
$this->register("status", "", array($this, "defaultCommands")); $this->register("status", "", [$this, "defaultCommands"]);
$this->register("difficulty", "<0|1|2|3>", array($this, "defaultCommands")); $this->register("difficulty", "<0|1|2|3>", [$this, "defaultCommands"]);
$this->register("stop", "", array($this, "defaultCommands")); $this->register("stop", "", [$this, "defaultCommands"]);
$this->register("defaultgamemode", "<mode>", array($this, "defaultCommands")); $this->register("defaultgamemode", "<mode>", [$this, "defaultCommands"]);
$this->server->api->ban->cmdWhitelist("help"); $this->server->api->ban->cmdWhitelist("help");
$this->server->api->ban->cmdWhitelist("status"); $this->server->api->ban->cmdWhitelist("status");
} }
public function register($cmd, $help, $callback){
if(!is_callable($callback)){
return false;
}
$cmd = strtolower(trim($cmd));
$this->cmds[$cmd] = $callback;
$this->help[$cmd] = $help;
ksort($this->help, SORT_NATURAL | SORT_FLAG_CASE);
}
function __destruct(){ function __destruct(){
$this->server->deleteEvent($this->event); $this->server->deleteEvent($this->event);
if(!defined("NO_THREADS")){ if(!defined("NO_THREADS")){
@ -55,115 +48,28 @@ class ConsoleAPI{
} }
} }
public function defaultCommands($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "defaultgamemode":
$gms = array(
"0" => SURVIVAL,
"survival" => SURVIVAL,
"s" => SURVIVAL,
"1" => CREATIVE,
"creative" => CREATIVE,
"c" => CREATIVE,
"2" => ADVENTURE,
"adventure" => ADVENTURE,
"a" => ADVENTURE,
"3" => VIEW,
"view" => VIEW,
"viewer" => VIEW,
"spectator" => VIEW,
"v" => VIEW,
);
if(!isset($gms[strtolower($params[0])])){
$output .= "Usage: /$cmd <mode>\n";
break;
}
$this->server->api->setProperty("gamemode", $gms[strtolower($params[0])]);
$output .= "Default Gamemode is now ".strtoupper($this->server->getGamemode()).".\n";
break;
case "status":
if(!($issuer instanceof Player) and $issuer === "console"){
$this->server->debugInfo(true);
}
$info = $this->server->debugInfo();
$output .= "TPS: ".$info["tps"].", Memory usage: ".$info["memory_usage"]." (Peak ".$info["memory_peak_usage"].")\n";
break;
case "update-done":
$this->server->api->setProperty("last-update", time());
break;
case "stop":
$this->loop->stop = true;
$output .= "Stopping the server\n";
$this->server->close();
break;
case "difficulty":
$s = trim(array_shift($params));
if($s === "" or (((int) $s) > 3 and ((int) $s) < 0)){
$output .= "Usage: /difficulty <0|1|2|3>\n";
break;
}
$this->server->api->setProperty("difficulty", (int) $s);
$output .= "Difficulty changed to ".$this->server->difficulty."\n";
break;
case "?":
if($issuer !== "console" and $issuer !== "rcon"){
break;
}
case "help":
if(isset($params[0]) and !is_numeric($params[0])){
$c = trim(strtolower($params[0]));
if(isset($this->help[$c]) or isset($this->alias[$c])){
$c = isset($this->help[$c]) ? $c : $this->alias[$c];
if($this->server->api->dhandle("console.command.".$c, array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false or $this->server->api->dhandle("console.command", array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false){
break;
}
$output .= "Usage: /$c ".$this->help[$c]."\n";
break;
}
}
$cmds = array();
foreach($this->help as $c => $h){
if($this->server->api->dhandle("console.command.".$c, array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false or $this->server->api->dhandle("console.command", array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false){
continue;
}
$cmds[$c] = $h;
}
$max = ceil(count($cmds) / 5);
$page = (int) (isset($params[0]) ? min($max, max(1, intval($params[0]))):1);
$output .= FORMAT_RED."-".FORMAT_RESET." Showing help page $page of $max (/help <page>) ".FORMAT_RED."-".FORMAT_RESET."\n";
$current = 1;
foreach($cmds as $c => $h){
$curpage = (int) ceil($current / 5);
if($curpage === $page){
$output .= "/$c ".$h."\n";
}elseif($curpage > $page){
break;
}
++$current;
}
break;
default:
$output .= "Command doesn't exist! Use /help\n";
break;
}
return $output;
}
public function alias($alias, $cmd){ public function alias($alias, $cmd){
$this->alias[strtolower(trim($alias))] = trim($cmd); $this->alias[strtolower(trim($alias))] = trim($cmd);
return true; return true;
} }
public function register($cmd, $help, $callback){ public function handle($time){
if(!is_callable($callback)){ if(defined("NO_THREADS")){
return false; return;
}
if($this->loop->line !== false){
$line = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", trim($this->loop->line));
$this->loop->line = false;
$output = $this->run($line, "console");
if($output != ""){
$mes = explode("\n", trim($output));
foreach($mes as $m){
console("[CMD] " . $m);
}
}
}else{
$this->loop->notify();
} }
$cmd = strtolower(trim($cmd));
$this->cmds[$cmd] = $callback;
$this->help[$cmd] = $help;
ksort($this->help, SORT_NATURAL | SORT_FLAG_CASE);
} }
public function run($line = "", $issuer = "console", $alias = false){ public function run($line = "", $issuer = "console", $alias = false){
@ -176,7 +82,7 @@ class ConsoleAPI{
$cmd = strtolower(substr($line, 0, $end)); $cmd = strtolower(substr($line, 0, $end));
$params = (string) substr($line, $end + 1); $params = (string) substr($line, $end + 1);
if(isset($this->alias[$cmd])){ if(isset($this->alias[$cmd])){
return $this->run($this->alias[$cmd] . ($params !== "" ? " " .$params:""), $issuer, $cmd); return $this->run($this->alias[$cmd] . ($params !== "" ? " " . $params : ""), $issuer, $cmd);
} }
if(preg_match_all('#@([@a-z]{1,})#', $params, $matches, PREG_OFFSET_CAPTURE) > 0){ if(preg_match_all('#@([@a-z]{1,})#', $params, $matches, PREG_OFFSET_CAPTURE) > 0){
@ -191,13 +97,13 @@ class ConsoleAPI{
case "u": case "u":
case "player": case "player":
case "username": case "username":
$p = ($issuer instanceof Player) ? $issuer->username:$issuer; $p = ($issuer instanceof Player) ? $issuer->username : $issuer;
$params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1); $params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1);
$offsetshift -= strlen($selector[0]) - strlen($p) + 1; $offsetshift -= strlen($selector[0]) - strlen($p) + 1;
break; break;
case "w": case "w":
case "world": case "world":
$p = ($issuer instanceof Player) ? $issuer->level->getName():$this->server->api->level->getDefault()->getName(); $p = ($issuer instanceof Player) ? $issuer->level->getName() : $this->server->api->level->getDefault()->getName();
$params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1); $params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1);
$offsetshift -= strlen($selector[0]) - strlen($p) + 1; $offsetshift -= strlen($selector[0]) - strlen($p) + 1;
break; break;
@ -207,7 +113,7 @@ class ConsoleAPI{
if($this->server->api->ban->isOp($issuer->username)){ if($this->server->api->ban->isOp($issuer->username)){
$output = ""; $output = "";
foreach($this->server->api->player->getAll() as $p){ foreach($this->server->api->player->getAll() as $p){
$output .= $this->run($cmd . " ". substr_replace($params, $p->username, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias); $output .= $this->run($cmd . " " . substr_replace($params, $p->username, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias);
} }
}else{ }else{
$issuer->sendChat("You don't have permissions to use this command.\n"); $issuer->sendChat("You don't have permissions to use this command.\n");
@ -215,13 +121,13 @@ class ConsoleAPI{
}else{ }else{
$output = ""; $output = "";
foreach($this->server->api->player->getAll() as $p){ foreach($this->server->api->player->getAll() as $p){
$output .= $this->run($cmd . " ". substr_replace($params, $p->username, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias); $output .= $this->run($cmd . " " . substr_replace($params, $p->username, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias);
} }
} }
return $output; return $output;
case "r": case "r":
case "random": case "random":
$l = array(); $l = [];
foreach($this->server->api->player->getAll() as $p){ foreach($this->server->api->player->getAll() as $p){
if($p !== $issuer){ if($p !== $issuer){
$l[] = $p; $l[] = $p;
@ -240,11 +146,11 @@ class ConsoleAPI{
} }
$params = explode(" ", $params); $params = explode(" ", $params);
if(count($params) === 1 and $params[0] === ""){ if(count($params) === 1 and $params[0] === ""){
$params = array(); $params = [];
} }
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, ["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", ["cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias])) === false){
if(in_array(strtolower($cmd), array_keys($this->cmds))){ if(in_array(strtolower($cmd), array_keys($this->cmds))){
$output = "You don't have permissions to use this command.\n"; $output = "You don't have permissions to use this command.\n";
}else{ }else{
@ -253,7 +159,7 @@ class ConsoleAPI{
}elseif($d1 !== true and (!isset($d2) or $d2 !== true)){ }elseif($d1 !== true and (!isset($d2) or $d2 !== true)){
if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){ if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){
$output = @call_user_func($this->cmds[$cmd], $cmd, $params, $issuer, $alias); $output = @call_user_func($this->cmds[$cmd], $cmd, $params, $issuer, $alias);
}elseif($this->server->api->dhandle("console.command.unknown", array("cmd" => $cmd, "params" => $params, "issuer" => $issuer, "alias" => $alias)) !== false){ }elseif($this->server->api->dhandle("console.command.unknown", ["cmd" => $cmd, "params" => $params, "issuer" => $issuer, "alias" => $alias]) !== false){
$output = $this->defaultCommands($cmd, $params, $issuer, $alias); $output = $this->defaultCommands($cmd, $params, $issuer, $alias);
} }
} }
@ -265,33 +171,112 @@ class ConsoleAPI{
} }
} }
public function handle($time){ public function defaultCommands($cmd, $params, $issuer, $alias){
if(defined("NO_THREADS")){ $output = "";
return; switch($cmd){
case "defaultgamemode":
$gms = [
"0" => SURVIVAL,
"survival" => SURVIVAL,
"s" => SURVIVAL,
"1" => CREATIVE,
"creative" => CREATIVE,
"c" => CREATIVE,
"2" => ADVENTURE,
"adventure" => ADVENTURE,
"a" => ADVENTURE,
"3" => VIEW,
"view" => VIEW,
"viewer" => VIEW,
"spectator" => VIEW,
"v" => VIEW,
];
if(!isset($gms[strtolower($params[0])])){
$output .= "Usage: /$cmd <mode>\n";
break;
} }
if($this->loop->line !== false){ $this->server->api->setProperty("gamemode", $gms[strtolower($params[0])]);
$line = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", trim($this->loop->line)); $output .= "Default Gamemode is now " . strtoupper($this->server->getGamemode()) . ".\n";
$this->loop->line = false; break;
$output = $this->run($line, "console"); case "status":
if($output != ""){ if(!($issuer instanceof Player) and $issuer === "console"){
$mes = explode("\n", trim($output)); $this->server->debugInfo(true);
foreach($mes as $m){ }
console("[CMD] ".$m); $info = $this->server->debugInfo();
$output .= "TPS: " . $info["tps"] . ", Memory usage: " . $info["memory_usage"] . " (Peak " . $info["memory_peak_usage"] . ")\n";
break;
case "update-done":
$this->server->api->setProperty("last-update", time());
break;
case "stop":
$this->loop->stop = true;
$output .= "Stopping the server\n";
$this->server->close();
break;
case "difficulty":
$s = trim(array_shift($params));
if($s === "" or (((int) $s) > 3 and ((int) $s) < 0)){
$output .= "Usage: /difficulty <0|1|2|3>\n";
break;
}
$this->server->api->setProperty("difficulty", (int) $s);
$output .= "Difficulty changed to " . $this->server->difficulty . "\n";
break;
case "?":
if($issuer !== "console" and $issuer !== "rcon"){
break;
}
case "help":
if(isset($params[0]) and !is_numeric($params[0])){
$c = trim(strtolower($params[0]));
if(isset($this->help[$c]) or isset($this->alias[$c])){
$c = isset($this->help[$c]) ? $c : $this->alias[$c];
if($this->server->api->dhandle("console.command." . $c, ["cmd" => $c, "parameters" => [], "issuer" => $issuer, "alias" => false]) === false or $this->server->api->dhandle("console.command", ["cmd" => $c, "parameters" => [], "issuer" => $issuer, "alias" => false]) === false){
break;
}
$output .= "Usage: /$c " . $this->help[$c] . "\n";
break;
} }
} }
}else{ $cmds = [];
$this->loop->notify(); foreach($this->help as $c => $h){
if($this->server->api->dhandle("console.command." . $c, ["cmd" => $c, "parameters" => [], "issuer" => $issuer, "alias" => false]) === false or $this->server->api->dhandle("console.command", ["cmd" => $c, "parameters" => [], "issuer" => $issuer, "alias" => false]) === false){
continue;
} }
$cmds[$c] = $h;
}
$max = ceil(count($cmds) / 5);
$page = (int) (isset($params[0]) ? min($max, max(1, intval($params[0]))) : 1);
$output .= FORMAT_RED . "-" . FORMAT_RESET . " Showing help page $page of $max (/help <page>) " . FORMAT_RED . "-" . FORMAT_RESET . "\n";
$current = 1;
foreach($cmds as $c => $h){
$curpage = (int) ceil($current / 5);
if($curpage === $page){
$output .= "/$c " . $h . "\n";
}elseif($curpage > $page){
break;
}
++$current;
}
break;
default:
$output .= "Command doesn't exist! Use /help\n";
break;
}
return $output;
} }
} }
class ConsoleLoop extends Thread{ class ConsoleLoop extends Thread{
public $line; public $line;
public $stop; public $stop;
public $base; public $base;
public $ev; public $ev;
public $fp; public $fp;
public function __construct(){ public function __construct(){
$this->line = false; $this->line = false;
$this->stop = false; $this->stop = false;
@ -302,32 +287,33 @@ class ConsoleLoop extends Thread{
$this->stop = true; $this->stop = true;
} }
private function readLine(){
if($this->fp){
$line = trim(fgets($this->fp));
}else{
$line = trim(readline(""));
if($line != ""){
readline_add_history( $line );
}
}
return $line;
}
public function run(){ public function run(){
if(!extension_loaded("readline")){ if(!extension_loaded("readline")){
$this->fp = fopen("php://stdin", "r"); $this->fp = fopen("php://stdin", "r");
} }
while($this->stop === false){ while(!$this->stop){
$this->line = $this->readLine(); $this->line = $this->readLine();
$this->wait(); $this->wait();
$this->line = false; $this->line = false;
} }
if(!extension_loaded("readline")){ if(!extension_loaded("readline")){
@fclose($fp); @fclose($this->fp);
} }
exit(0); exit(0);
} }
private function readLine(){
if($this->fp){
$line = trim(fgets($this->fp));
}else{
$line = trim(readline(""));
if($line != ""){
readline_add_history($line);
}
}
return $line;
}
} }

View file

@ -1,34 +1,16 @@
<?php <?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/
*
*
*/
class EntityAPI{ class EntityAPI{
private $server;
public $entities; public $entities;
private $server;
private $eCnt = 1; private $eCnt = 1;
function __construct(){ function __construct(){
$this->entities = array(); $this->entities = [];
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->hp = array( $this->hp = [
10 => 4, 10 => 4,
11 => 10, 11 => 10,
12 => 10, 12 => 10,
@ -39,9 +21,9 @@ class EntityAPI{
34 => 20, 34 => 20,
35 => 16, 35 => 16,
36 => 20, 36 => 20,
); ];
$this->mob = array( $this->mob = [
"chicken" => 10, "chicken" => 10,
"cow" => 11, "cow" => 11,
"pig" => 12, "pig" => 12,
@ -52,9 +34,9 @@ class EntityAPI{
"skeleton" => 34, "skeleton" => 34,
"spider" => 35, "spider" => 35,
"pigman" => 36, "pigman" => 36,
); ];
$this->mobName = array( $this->mobName = [
10 => "Chicken", 10 => "Chicken",
11 => "Cow", 11 => "Cow",
12 => "Pig", 12 => "Pig",
@ -65,29 +47,22 @@ class EntityAPI{
34 => "Skeleton", 34 => "Skeleton",
35 => "Spider", 35 => "Spider",
36 => "Pigman", 36 => "Pigman",
); ];
$this->serverSpawnAnimals = $this->server->api->getProperty("spawn-animals"); $this->serverSpawnAnimals = $this->server->api->getProperty("spawn-animals");
$this->serverSpawnMobs = $this->server->api->getProperty("spawn-mobs"); $this->serverSpawnMobs = $this->server->api->getProperty("spawn-mobs");
} }
public function get($eid){
if(isset($this->entities[$eid])){
return $this->entities[$eid];
}
return false;
}
public function init(){ public function init(){
$this->server->schedule(25, array($this, "updateEntities"), array(), true); $this->server->schedule(25, [$this, "updateEntities"], [], true);
$this->server->api->console->register("summon", "<mob>", array($this, "commandHandler")); $this->server->api->console->register("summon", "<mob>", [$this, "commandHandler"]);
$this->server->api->console->register("spawnmob", "<mob>", array($this, "commandHandler")); $this->server->api->console->register("spawnmob", "<mob>", [$this, "commandHandler"]);
$this->server->api->console->register("despawn", "", array($this, "CommandHandler")); $this->server->api->console->register("despawn", "", [$this, "CommandHandler"]);
} }
public function commandHandler($cmd, $args, $issuer, $alias){ public function commandHandler($cmd, $args, $issuer, $alias){
$output = ""; $output = "";
switch ($cmd){ switch($cmd){
case 'summon': case 'summon':
case 'spawnmob': case 'spawnmob':
if(!($issuer instanceof Player)){ if(!($issuer instanceof Player)){
@ -112,18 +87,17 @@ class EntityAPI{
$spawnZ = round($issuer->entity->z, 1, PHP_ROUND_HALF_UP); $spawnZ = round($issuer->entity->z, 1, PHP_ROUND_HALF_UP);
$spawnLevel = $issuer->entity->level; $spawnLevel = $issuer->entity->level;
$entityit = $this->add($spawnLevel, ENTITY_MOB, $type, array( $entityit = $this->add($spawnLevel, ENTITY_MOB, $type, [
"x" => $spawnX, "x" => $spawnX,
"y" => $spawnY, "y" => $spawnY,
"z" => $spawnZ, "z" => $spawnZ,
"Health" => $this->hp[$type], "Health" => $this->hp[$type],
)); ]);
$this->spawnToAll($entityit, $level); $this->spawnToAll($entityit, $level);
$output .= $this->mobName[$type]." spawned in ".$spawnX.", ".$spawnY.", ".$spawnZ."."; $output .= $this->mobName[$type] . " spawned in " . $spawnX . ", " . $spawnY . ", " . $spawnZ . ".";
break; break;
} }elseif(is_numeric($args[1])){//summon <mob> [amount]
elseif(is_numeric($args[1])){//summon <mob> [amount] $amount = (int) $args[1];
$amount = (int)$args[1];
if($amount > 25){ if($amount > 25){
$output .= "Cannot spawn > 25 mobs"; $output .= "Cannot spawn > 25 mobs";
break; break;
@ -144,129 +118,68 @@ class EntityAPI{
$spawnLevel = $issuer->entity->level; $spawnLevel = $issuer->entity->level;
for($cnt = $amount; $cnt > 0; --$cnt){ for($cnt = $amount; $cnt > 0; --$cnt){
$entityit = $this->add($spawnLevel, ENTITY_MOB, $type, array( $entityit = $this->add($spawnLevel, ENTITY_MOB, $type, [
"x" => $spawnX, "x" => $spawnX,
"y" => $spawnY, "y" => $spawnY,
"z" => $spawnZ, "z" => $spawnZ,
"Health" => $this->hp[$type], "Health" => $this->hp[$type],
"IsBaby" => $isBaby, "IsBaby" => $isBaby,
)); ]);
$this->spawnToAll($entityit, $level); $this->spawnToAll($entityit, $level);
} }
if($type == 13 or $amount == 1) $plural = ''; if($type == 13 or $amount == 1)
$plural = '';
else $plural = 's'; else $plural = 's';
if($isBaby == 1) $baby = "Baby "; if($isBaby == 1)
$baby = "Baby ";
else $baby = ''; else $baby = '';
$output .= $amount." ".$baby.$this->mobName[$type].$plural." spawned in ".$spawnX.", ".$spawnY.", ".$spawnZ."."; $output .= $amount . " " . $baby . $this->mobName[$type] . $plural . " spawned in " . $spawnX . ", " . $spawnY . ", " . $spawnZ . ".";
break; break;
} }elseif(strtolower($args[1]) == 'baby'){//summon <mob> [baby]
elseif(strtolower($args[1]) == 'baby'){//summon <mob> [baby]
if($type > 13){ if($type > 13){
$output .= "This mob cant be baby!"; $output .= "This mob cant be baby!";
break; break;
} }else{
else{
$spawnX = round($issuer->entity->x, 1, PHP_ROUND_HALF_UP); $spawnX = round($issuer->entity->x, 1, PHP_ROUND_HALF_UP);
$spawnY = round($issuer->entity->y, 1, PHP_ROUND_HALF_UP); $spawnY = round($issuer->entity->y, 1, PHP_ROUND_HALF_UP);
$spawnZ = round($issuer->entity->z, 1, PHP_ROUND_HALF_UP); $spawnZ = round($issuer->entity->z, 1, PHP_ROUND_HALF_UP);
$spawnLevel = $issuer->entity->level; $spawnLevel = $issuer->entity->level;
$entityit = $this->add($spawnLevel, ENTITY_MOB, $type, array( $entityit = $this->add($spawnLevel, ENTITY_MOB, $type, [
"x" => $spawnX, "x" => $spawnX,
"y" => $spawnY, "y" => $spawnY,
"z" => $spawnZ, "z" => $spawnZ,
"Health" => $this->hp[$type], "Health" => $this->hp[$type],
"isBaby" => 1, "isBaby" => 1,
)); ]);
$this->spawnToAll($entityit, $level); $this->spawnToAll($entityit, $level);
$output .= "Baby ".$this->mobName[$type]." spawned in ".$spawnX.", ".$spawnY.", ".$spawnZ."."; $output .= "Baby " . $this->mobName[$type] . " spawned in " . $spawnX . ", " . $spawnY . ", " . $spawnZ . ".";
break; break;
} }
break; break;
} }
case 'despawn': case 'despawn':
$cnt = 0; $cnt = 0;
$l = $this->server->query("SELECT EID FROM entities WHERE class = ".ENTITY_MOB.";"); $l = $this->server->query("SELECT EID FROM entities WHERE class = " . ENTITY_MOB . ";");
if ($l !== false and $l !== true){ if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]); $e = $this->get($e["EID"]);
if ($e instanceof Entity){ if($e instanceof Entity){
$this->remove($e->eid); $this->remove($e->eid);
$cnt++; $cnt++;
} }
} }
} }
$output .= $cnt." mobs have been despawned!"; $output .= $cnt . " mobs have been despawned!";
break; break;
} }
return $output; return $output;
} }
public function updateEntities(){ public function add(Level $level, $class, $type = 0, $data = []){
$l = $this->server->query("SELECT EID FROM entities WHERE hasUpdate = 1;");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$e->update();
$this->server->query("UPDATE entities SET hasUpdate = 0 WHERE EID = ".$e->eid.";");
}
}
}
}
public function updateRadius(Position $center, $radius = 15, $class = false){
$this->server->query("UPDATE entities SET hasUpdate = 1 WHERE level = '".$center->level->getName()."' ".($class !== false ? "AND class = $class ":"")."AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
}
public function getRadius(Position $center, $radius = 15, $class = false){
$entities = array();
$l = $this->server->query("SELECT EID FROM entities WHERE level = '".$center->level->getName()."' ".($class !== false ? "AND class = $class ":"")."AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$entities[$e->eid] = $e;
}
}
}
return $entities;
}
public function getAll($level = null){
if($level instanceof Level){
$entities = array();
$l = $this->server->query("SELECT EID FROM entities WHERE level = '".$level->getName()."';");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$entities[$e->eid] = $e;
}
}
}
return $entities;
}
return $this->entities;
}
public function heal($eid, $heal = 1, $cause){
$this->harm($eid, -$heal, $cause);
}
public function harm($eid, $attack = 1, $cause, $force = false){
$e = $this->get($eid);
if($e === false or $e->dead === true){
return false;
}
$e->setHealth($e->getHealth() - $attack, $cause, $force);
}
public function add(Level $level, $class, $type = 0, $data = array()){
$eid = $this->eCnt++; $eid = $this->eCnt++;
$efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class); $efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class);
if($efl instanceof PropertyEntity){ if($efl instanceof PropertyEntity){
@ -287,23 +200,98 @@ class EntityAPI{
} }
} }
public function get($eid){
if(isset($this->entities[$eid])){
return $this->entities[$eid];
}
return false;
}
public function remove($eid){
if(isset($this->entities[$eid])){
$entity = $this->entities[$eid];
$this->entities[$eid] = null;
unset($this->entities[$eid]);
$entity->closed = true;
$this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";");
if($entity->class === ENTITY_PLAYER){
$pk = new RemovePlayerPacket;
$pk->eid = $entity->eid;
$pk->clientID = 0;
$this->server->api->player->broadcastPacket($this->server->api->player->getAll(), $pk);
}else{
$pk = new RemoveEntityPacket;
$pk->eid = $entity->eid;
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($entity->level), $pk);
}
$this->server->api->dhandle("entity.remove", $entity);
$entity = null;
unset($entity);
}
}
public function updateEntities(){
$l = $this->server->query("SELECT EID FROM entities WHERE hasUpdate = 1;");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$e->update();
$this->server->query("UPDATE entities SET hasUpdate = 0 WHERE EID = " . $e->eid . ";");
}
}
}
}
public function updateRadius(Position $center, $radius = 15, $class = false){
$this->server->query("UPDATE entities SET hasUpdate = 1 WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
}
public function getRadius(Position $center, $radius = 15, $class = false){
$entities = [];
$l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$entities[$e->eid] = $e;
}
}
}
return $entities;
}
public function heal($eid, $heal = 1, $cause){
$this->harm($eid, -$heal, $cause);
}
public function harm($eid, $attack = 1, $cause, $force = false){
$e = $this->get($eid);
if($e === false or $e->dead === true){
return false;
}
$e->setHealth($e->getHealth() - $attack, $cause, $force);
}
public function drop(Position $pos, Item $item){ public function drop(Position $pos, Item $item){
if($item->getID() === AIR or $item->count <= 0){ if($item->getID() === AIR or $item->count <= 0){
return; return;
} }
$i = 0; $i = 0;
do { // drop the block to the first supporting block do{ // drop the block to the first supporting block
$i++; $i++;
$v = new Vector3($pos->x, $pos->y - $i, $pos->z); $v = new Vector3($pos->x, $pos->y - $i, $pos->z);
$b = $pos->level->getBlock($v); $b = $pos->level->getBlock($v);
if($b->isSolid === true) break; if($b->isSolid === true)
break;
if(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL) if(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL)
break; break;
} }while($i < 200);
while ($i<200); if($i == 200)
if ($i==200) $i=0; $i = 0;
$data = array( $data = [
"x" => $pos->x + mt_rand(-10, 10) / 50, "x" => $pos->x + mt_rand(-10, 10) / 50,
"y" => $pos->y + 0.19 - $i + 1, "y" => $pos->y + 0.19 - $i + 1,
"z" => $pos->z + mt_rand(-10, 10) / 50, "z" => $pos->z + mt_rand(-10, 10) / 50,
@ -312,9 +300,9 @@ class EntityAPI{
"speedY" => mt_rand(5, 8) / 2, "speedY" => mt_rand(5, 8) / 2,
//"speedZ" => mt_rand(-3, 3) / 8, //"speedZ" => mt_rand(-3, 3) / 8,
"item" => $item, "item" => $item,
); ];
if($this->server->api->handle("item.drop", $data) !== false){ if($this->server->api->handle("item.drop", $data) !== false){
for($count = $item->count; $count > 0; ){ for($count = $item->count; $count > 0;){
$item->count = min($item->getMaxStackSize(), $count); $item->count = min($item->getMaxStackSize(), $count);
$count -= $item->count; $count -= $item->count;
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data); $e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
@ -332,26 +320,20 @@ class EntityAPI{
} }
} }
public function remove($eid){ public function getAll($level = null){
if(isset($this->entities[$eid])){ if($level instanceof Level){
$entity = $this->entities[$eid]; $entities = [];
$this->entities[$eid] = null; $l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $level->getName() . "';");
unset($this->entities[$eid]); if($l !== false and $l !== true){
$entity->closed = true; while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$this->server->query("DELETE FROM entities WHERE EID = ".$eid.";"); $e = $this->get($e["EID"]);
if($entity->class === ENTITY_PLAYER){ if($e instanceof Entity){
$pk = new RemovePlayerPacket; $entities[$e->eid] = $e;
$pk->eid = $entity->eid;
$pk->clientID = 0;
$this->server->api->player->broadcastPacket($this->server->api->player->getAll(), $pk);
}else{
$pk = new RemoveEntityPacket;
$pk->eid = $entity->eid;
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($entity->level), $pk);
} }
$this->server->api->dhandle("entity.remove", $entity);
$entity = null;
unset($entity);
} }
} }
return $entities;
}
return $this->entities;
}
} }

View file

@ -1,48 +1,20 @@
<?php <?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/
*
*
*/
class LevelAPI{ class LevelAPI{
private $server, $levels, $default; private $server, $levels, $default;
public function __construct(){ public function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->levels = array(); $this->levels = [];
}
public function get($name){
if(isset($this->levels[$name])){
return $this->levels[$name];
}
return false;
}
public function getDefault(){
return $this->levels[$this->default];
} }
public function init(){ public function init(){
$this->server->api->console->register("seed", "[world]", array($this, "commandHandler")); $this->server->api->console->register("seed", "[world]", [$this, "commandHandler"]);
$this->server->api->console->register("save-all", "", array($this, "commandHandler")); $this->server->api->console->register("save-all", "", [$this, "commandHandler"]);
$this->server->api->console->register("save-on", "", array($this, "commandHandler")); $this->server->api->console->register("save-on", "", [$this, "commandHandler"]);
$this->server->api->console->register("save-off", "", array($this, "commandHandler")); $this->server->api->console->register("save-off", "", [$this, "commandHandler"]);
$this->server->api->console->register("setwspawn", "Set the spawn position for your current world. ", array($this, "commandHandler")); $this->server->api->console->register("setwspawn", "Set the spawn position for your current world. ", [$this, "commandHandler"]);
$this->default = $this->server->api->getProperty("level-name"); $this->default = $this->server->api->getProperty("level-name");
if($this->loadLevel($this->default) === false){ if($this->loadLevel($this->default) === false){
$this->generateLevel($this->default, $this->server->seed); $this->generateLevel($this->default, $this->server->seed);
@ -51,131 +23,33 @@ class LevelAPI{
$this->server->spawn = $this->getDefault()->getSafeSpawn(); $this->server->spawn = $this->getDefault()->getSafeSpawn();
} }
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "setwspawn":
if(!($issuer instanceof Player)){return("Please run this command in-game. ");}
$issuer->entity->level->setSpawn(new Vector3($issuer->entity->x, $issuer->entity->y, $issuer->entity->z));
return("Spawn set!");
break;
case "save-all":
$save = $this->server->saveEnabled;
$this->server->saveEnabled = true;
$this->saveAll();
$this->server->saveEnabled = $save;
$this->server->api->chat->broadcast("[NostalgiaCore] All files are saved.");
break;
case "save-on":
$this->server->saveEnabled = true;
break;
case "save-off":
$this->server->saveEnabled = false;
break;
case "seed":
if(!isset($params[0]) and ($issuer instanceof Player)){
$output .= "Seed: ".$issuer->level->getSeed()."\n";
}elseif(isset($params[0])){
if(($lv = $this->server->api->level->get(trim(implode(" ", $params)))) !== false){
$output .= "Seed: ".$lv->getSeed()."\n";
}
}else{
$output .= "Seed: ".$this->server->api->level->getDefault()->getSeed()."\n";
}
}
return $output;
}
public function generateLevel($name, $seed = false, $generator = false){
if($this->levelExists($name)){
return false;
}
$options = array();
if($this->server->api->getProperty("generator-settings") !== false and trim($this->server->api->getProperty("generator-settings")) != ""){
$options["preset"] = $this->server->api->getProperty("generator-settings");
}
if($generator !== false and class_exists($generator)){
$generator = new $generator($options);
}else{
if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){
$generator = new SuperflatGenerator($options);
}else{
$generator = new TemporalGenerator($options);
}
}
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):(int) $seed);
$gen->generate();
$gen->close();
return true;
}
public function levelExists($name){
if($name === ""){
return false;
}
$path = DATA_PATH."worlds/".$name."/";
if($this->get($name) === false and !file_exists($path."level.pmf")){
$level = new LevelImport($path);
if($level->import() === false){
return false;
}
}
return true;
}
public function unloadLevel(Level $level, $force = false){
$name = $level->getName();
if($name === $this->default and $force !== true){
return false;
}
console("[INFO] Unloading level \"".$name."\"");
$level->nextSave = PHP_INT_MAX;
$level->save();
foreach($this->server->api->player->getAll($level) as $player){
$player->teleport($this->server->spawn);
}
foreach($this->server->api->entity->getAll($level) as $entity){
if($entity->class !== ENTITY_PLAYER){
$entity->close();
}
}
foreach($this->server->api->tile->getAll($level) as $tile){
$tile->close();
}
$level->close();
unset($this->levels[$name]);
return true;
}
public function loadLevel($name){ public function loadLevel($name){
if($this->get($name) !== false){ if($this->get($name) !== false){
return true; return true;
}elseif($this->levelExists($name) === false){ }elseif($this->levelExists($name) === false){
console("[NOTICE] Level \"".$name."\" not found"); console("[NOTICE] Level \"" . $name . "\" not found");
return false; return false;
} }
$path = DATA_PATH."worlds/".$name."/"; $path = DATA_PATH . "worlds/" . $name . "/";
console("[INFO] Preparing level \"".$name."\""); console("[INFO] Preparing level \"" . $name . "\"");
$level = new PMFLevel($path."level.pmf"); $level = new PMFLevel($path . "level.pmf");
if(!$level->isLoaded){ if(!$level->isLoaded){
console("[ERROR] Could not load level \"".$name."\""); console("[ERROR] Could not load level \"" . $name . "\"");
return false; return false;
} }
$entities = new Config($path."entities.yml", CONFIG_YAML); $entities = new Config($path . "entities.yml", CONFIG_YAML);
if(file_exists($path."tileEntities.yml")){ if(file_exists($path . "tileEntities.yml")){
@rename($path."tileEntities.yml", $path."tiles.yml"); @rename($path . "tileEntities.yml", $path . "tiles.yml");
} }
$tiles = new Config($path."tiles.yml", CONFIG_YAML); $tiles = new Config($path . "tiles.yml", CONFIG_YAML);
$blockUpdates = new Config($path."bupdates.yml", CONFIG_YAML); $blockUpdates = new Config($path . "bupdates.yml", CONFIG_YAML);
$this->levels[$name] = new Level($level, $entities, $tiles, $blockUpdates, $name); $this->levels[$name] = new Level($level, $entities, $tiles, $blockUpdates, $name);
foreach($entities->getAll() as $entity){ foreach($entities->getAll() as $entity){
if(!isset($entity["id"])){ if(!isset($entity["id"])){
break; break;
} }
if($entity["id"] === 64){ //Item Drop if($entity["id"] === 64){ //Item Drop
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_ITEM, $entity["Item"]["id"], array( $e = $this->server->api->entity->add($this->levels[$name], ENTITY_ITEM, $entity["Item"]["id"], [
"meta" => $entity["Item"]["Damage"], "meta" => $entity["Item"]["Damage"],
"stack" => $entity["Item"]["Count"], "stack" => $entity["Item"]["Count"],
"x" => $entity["Pos"][0], "x" => $entity["Pos"][0],
@ -183,7 +57,7 @@ class LevelAPI{
"z" => $entity["Pos"][2], "z" => $entity["Pos"][2],
"yaw" => $entity["Rotation"][0], "yaw" => $entity["Rotation"][0],
"pitch" => $entity["Rotation"][1], "pitch" => $entity["Rotation"][1],
)); ]);
}elseif($entity["id"] === FALLING_SAND){ }elseif($entity["id"] === FALLING_SAND){
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_FALLING, $entity["id"], $entity); $e = $this->server->api->entity->add($this->levels[$name], ENTITY_FALLING, $entity["id"], $entity);
$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); $e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
@ -208,14 +82,95 @@ class LevelAPI{
$timeu = microtime(true); $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"]);
} }
return true; return true;
} }
public function handle($data, $event){ public function get($name){
switch($event){ if(isset($this->levels[$name])){
return $this->levels[$name];
} }
return false;
}
public function levelExists($name){
if($name === ""){
return false;
}
$path = DATA_PATH . "worlds/" . $name . "/";
if($this->get($name) === false and !file_exists($path . "level.pmf")){
$level = new LevelImport($path);
if($level->import() === false){
return false;
}
}
return true;
}
public function generateLevel($name, $seed = false, $generator = false){
if($this->levelExists($name)){
return false;
}
$options = [];
if($this->server->api->getProperty("generator-settings") !== false and trim($this->server->api->getProperty("generator-settings")) != ""){
$options["preset"] = $this->server->api->getProperty("generator-settings");
}
if($generator !== false and class_exists($generator)){
$generator = new $generator($options);
}else{
if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){
$generator = new SuperflatGenerator($options);
}else{
$generator = new TemporalGenerator($options);
}
}
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed);
$gen->generate();
$gen->close();
return true;
}
public function getDefault(){
return $this->levels[$this->default];
}
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "setwspawn":
if(!($issuer instanceof Player)){
return ("Please run this command in-game. ");
}
$issuer->entity->level->setSpawn(new Vector3($issuer->entity->x, $issuer->entity->y, $issuer->entity->z));
return ("Spawn set!");
break;
case "save-all":
$save = $this->server->saveEnabled;
$this->server->saveEnabled = true;
$this->saveAll();
$this->server->saveEnabled = $save;
$this->server->api->chat->broadcast("[NostalgiaCore] All files are saved.");
break;
case "save-on":
$this->server->saveEnabled = true;
break;
case "save-off":
$this->server->saveEnabled = false;
break;
case "seed":
if(!isset($params[0]) and ($issuer instanceof Player)){
$output .= "Seed: " . $issuer->level->getSeed() . "\n";
}elseif(isset($params[0])){
if(($lv = $this->server->api->level->get(trim(implode(" ", $params)))) !== false){
$output .= "Seed: " . $lv->getSeed() . "\n";
}
}else{
$output .= "Seed: " . $this->server->api->level->getDefault()->getSeed() . "\n";
}
}
return $output;
} }
public function saveAll(){ public function saveAll(){
@ -224,6 +179,11 @@ class LevelAPI{
} }
} }
public function handle($data, $event){
switch($event){
}
}
public function __destruct(){ public function __destruct(){
$this->saveAll(); $this->saveAll();
foreach($this->levels as $level){ foreach($this->levels as $level){
@ -231,18 +191,42 @@ class LevelAPI{
} }
} }
public function unloadLevel(Level $level, $force = false){
$name = $level->getName();
if($name === $this->default and $force !== true){
return false;
}
console("[INFO] Unloading level \"" . $name . "\"");
$level->nextSave = PHP_INT_MAX;
$level->save();
foreach($this->server->api->player->getAll($level) as $player){
$player->teleport($this->server->spawn);
}
foreach($this->server->api->entity->getAll($level) as $entity){
if($entity->class !== ENTITY_PLAYER){
$entity->close();
}
}
foreach($this->server->api->tile->getAll($level) as $tile){
$tile->close();
}
$level->close();
unset($this->levels[$name]);
return true;
}
public function getSpawn(){ public function getSpawn(){
return $this->server->spawn; return $this->server->spawn;
} }
public function loadMap(){ public function loadMap(){
if($this->mapName !== false and trim($this->mapName) !== ""){ if($this->mapName !== false and trim($this->mapName) !== ""){
if(!file_exists($this->mapDir."level.pmf")){ if(!file_exists($this->mapDir . "level.pmf")){
$level = new LevelImport($this->mapDir); $level = new LevelImport($this->mapDir);
$level->import(); $level->import();
} }
$this->level = new PMFLevel($this->mapDir."level.pmf"); $this->level = new PMFLevel($this->mapDir . "level.pmf");
console("[INFO] Preparing level \"".$this->level->getData("name")."\""); console("[INFO] Preparing level \"" . $this->level->getData("name") . "\"");
$this->time = (int) $this->level->getData("time"); $this->time = (int) $this->level->getData("time");
$this->seed = (int) $this->level->getData("seed"); $this->seed = (int) $this->level->getData("seed");
$this->spawn = $this->level->getSpawn(); $this->spawn = $this->level->getSpawn();

View file

@ -1,36 +1,19 @@
<?php <?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/
*
*
*/
class PlayerAPI{ class PlayerAPI{
private $server; private $server;
function __construct(){ function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
public function init(){ public function init(){
$this->server->schedule(20 * 15, array($this, "handle"), 1, true, "server.regeneration"); $this->server->schedule(20 * 15, [$this, "handle"], 1, true, "server.regeneration");
$this->server->addHandler("player.death", array($this, "handle"), 1); $this->server->addHandler("player.death", [$this, "handle"], 1);
$this->registerCmd("list"); $this->registerCmd("list");
$this->registerCmd("kill", "<player>"); $this->registerCmd("kill", "<player>");
$this->registerCmd("gamemode", "<mode> [player]", array($this, "commandHandler")); $this->registerCmd("gamemode", "<mode> [player]", [$this, "commandHandler"]);
$this->registerCmd("tp", "[target player] <destination player|w:world> OR /tp [target player] <x> <y> <z>"); $this->registerCmd("tp", "[target player] <destination player|w:world> OR /tp [target player] <x> <y> <z>");
$this->registerCmd("spawnpoint", "[player] [x] [y] [z]"); $this->registerCmd("spawnpoint", "[player] [x] [y] [z]");
$this->registerCmd("spawn"); $this->registerCmd("spawn");
@ -41,11 +24,11 @@ class PlayerAPI{
$this->server->api->ban->cmdWhitelist("list"); $this->server->api->ban->cmdWhitelist("list");
$this->server->api->ban->cmdWhitelist("ping"); $this->server->api->ban->cmdWhitelist("ping");
$this->server->api->ban->cmdWhitelist("spawn"); $this->server->api->ban->cmdWhitelist("spawn");
$this->server->preparedSQL->selectPlayersToHeal = $this->server->database->prepare("SELECT EID FROM entities WHERE class = ".ENTITY_PLAYER." AND health < 20;"); $this->server->preparedSQL->selectPlayersToHeal = $this->server->database->prepare("SELECT EID FROM entities WHERE class = " . ENTITY_PLAYER . " AND health < 20;");
} }
public function registerCmd($cmd, $help = ""){ public function registerCmd($cmd, $help = ""){
$this->server->api->console->register($cmd, $help, array($this, "commandHandler")); $this->server->api->console->register($cmd, $help, [$this, "commandHandler"]);
} }
public function handle($data, $event){ public function handle($data, $event){
@ -72,7 +55,7 @@ class PlayerAPI{
if($e instanceof Entity){ if($e instanceof Entity){
switch($e->class){ switch($e->class){
case ENTITY_PLAYER: case ENTITY_PLAYER:
$message = " was killed by ".$e->name; $message = " was killed by " . $e->name;
break; break;
default: default:
$message = " was killed"; $message = " was killed";
@ -160,12 +143,12 @@ class PlayerAPI{
$output .= "Please run this command in-game.\n"; $output .= "Please run this command in-game.\n";
break; break;
} }
$output .= "ping ".round($issuer->getLag(), 2)."ms, packet loss ".round($issuer->getPacketLoss() * 100, 2)."%, ".round($issuer->getBandwidth() / 1024, 2)." KB/s\n"; $output .= "ping " . round($issuer->getLag(), 2) . "ms, packet loss " . round($issuer->getPacketLoss() * 100, 2) . "%, " . round($issuer->getBandwidth() / 1024, 2) . " KB/s\n";
break; break;
case "gamemode": case "gamemode":
$player = false; $player = false;
$setgm = false; $setgm = false;
$gms = array( $gms = [
"0" => SURVIVAL, "0" => SURVIVAL,
"survival" => SURVIVAL, "survival" => SURVIVAL,
"s" => SURVIVAL, "s" => SURVIVAL,
@ -180,14 +163,13 @@ class PlayerAPI{
"viewer" => VIEW, "viewer" => VIEW,
"spectator" => VIEW, "spectator" => VIEW,
"v" => VIEW, "v" => VIEW,
); ];
if($issuer instanceof Player){ if($issuer instanceof Player){
$player = $issuer; $player = $issuer;
} }
if(count($args) == 1){ if(count($args) == 1){
$setgm = $args[0]; $setgm = $args[0];
} }elseif(isset($args[1])){
elseif(isset($args[1])){
if($this->server->api->player->get($args[1]) instanceof Player){ if($this->server->api->player->get($args[1]) instanceof Player){
$player = $this->server->api->player->get($args[1]); $player = $this->server->api->player->get($args[1]);
$setgm = $args[0]; $setgm = $args[0];
@ -204,7 +186,7 @@ class PlayerAPI{
break; break;
} }
if($player->setGamemode($gms[strtolower($setgm)])){ if($player->setGamemode($gms[strtolower($setgm)])){
$output .= "Gamemode of ".$player->username." changed to ".$player->getGamemode()."\n"; $output .= "Gamemode of " . $player->username . " changed to " . $player->getGamemode() . "\n";
} }
break; break;
case "tp": case "tp":
@ -261,19 +243,49 @@ class PlayerAPI{
} }
break; break;
case "list": case "list":
$output .= "There are ".count($this->server->clients)."/".$this->server->maxClients." players online:\n"; $output .= "There are " . count($this->server->clients) . "/" . $this->server->maxClients . " players online:\n";
if(count($this->server->clients) == 0){ if(count($this->server->clients) == 0){
break; break;
} }
foreach($this->server->clients as $c){ foreach($this->server->clients as $c){
$output .= $c->username.", "; $output .= $c->username . ", ";
} }
$output = substr($output, 0, -2)."\n"; $output = substr($output, 0, -2) . "\n";
break; break;
} }
return $output; return $output;
} }
public function get($name, $alike = true, $multiple = false){
$name = trim(strtolower($name));
if($name === ""){
return false;
}
$query = $this->server->query("SELECT ip,port,name FROM players WHERE name " . ($alike === true ? "LIKE '%" . $name . "%'" : "= '" . $name . "'") . ";");
$players = [];
if($query !== false and $query !== true){
while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){
$CID = PocketMinecraftServer::clientID($d["ip"], $d["port"]);
if(isset($this->server->clients[$CID])){
$players[$CID] = $this->server->clients[$CID];
if($multiple === false and $d["name"] === $name){
return $players[$CID];
}
}
}
}
if($multiple === false){
if(count($players) > 0){
return array_shift($players);
}else{
return false;
}
}else{
return $players;
}
}
public function teleport(&$name, &$target){ public function teleport(&$name, &$target){
if(substr($target, 0, 2) === "w:"){ if(substr($target, 0, 2) === "w:"){
$lv = $this->server->api->level->get(substr($target, 2)); $lv = $this->server->api->level->get(substr($target, 2));
@ -303,80 +315,23 @@ class PlayerAPI{
$player = $this->get($name); $player = $this->get($name);
if(($player instanceof Player) and ($player->entity instanceof Entity)){ if(($player instanceof Player) and ($player->entity instanceof Entity)){
$name = $player->username; $name = $player->username;
$x = $x[0] === "~" ? $player->entity->x + floatval(substr($x, 1)):floatval($x); $x = $x[0] === "~" ? $player->entity->x + floatval(substr($x, 1)) : floatval($x);
$y = $y[0] === "~" ? $player->entity->y + floatval(substr($y, 1)):floatval($y); $y = $y[0] === "~" ? $player->entity->y + floatval(substr($y, 1)) : floatval($y);
$z = $z[0] === "~" ? $player->entity->z + floatval(substr($z, 1)):floatval($z); $z = $z[0] === "~" ? $player->entity->z + floatval(substr($z, 1)) : floatval($z);
$player->teleport(new Vector3($x, $y, $z)); $player->teleport(new Vector3($x, $y, $z));
return true; return true;
} }
return false; return false;
} }
public function get($name, $alike = true, $multiple = false){
$name = trim(strtolower($name));
if($name === ""){
return false;
}
$query = $this->server->query("SELECT ip,port,name FROM players WHERE name ".($alike === true ? "LIKE '%".$name."%'":"= '".$name."'").";");
$players = array();
if($query !== false and $query !== true){
while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){
$CID = PocketMinecraftServer::clientID($d["ip"], $d["port"]);
if(isset($this->server->clients[$CID])){
$players[$CID] = $this->server->clients[$CID];
if($multiple === false and $d["name"] === $name){
return $players[$CID];
}
}
}
}
if($multiple === false){
if(count($players) > 0){
return array_shift($players);
}else{
return false;
}
}else{
return $players;
}
}
public function getAll($level = null){
if($level instanceof Level){
$clients = array();
$l = $this->server->query("SELECT EID FROM entities WHERE level = '".$level->getName()."' AND class = '".ENTITY_PLAYER."';");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->getByEID($e["EID"]);
if($e instanceof Player){
$clients[$e->CID] = $e;
}
}
}
return $clients;
}
return $this->server->clients;
}
public function broadcastPacket(array $players, RakNetDataPacket $packet){ public function broadcastPacket(array $players, RakNetDataPacket $packet){
foreach($players as $p){ foreach($players as $p){
$p->dataPacket(clone $packet); $p->dataPacket(clone $packet);
} }
} }
public function getByEID($eid){
$eid = (int) $eid;
$CID = $this->server->query("SELECT ip,port FROM players WHERE EID = '".$eid."';", true);
$CID = PocketMinecraftServer::clientID($CID["ip"], $CID["port"]);
if(isset($this->server->clients[$CID])){
return $this->server->clients[$CID];
}
return false;
}
public function online(){ public function online(){
$o = array(); $o = [];
foreach($this->server->clients as $p){ foreach($this->server->clients as $p){
if($p->auth === true){ if($p->auth === true){
$o[] = $p->username; $o[] = $p->username;
@ -392,17 +347,60 @@ class PlayerAPI{
$player->gamemode = $player->data->get("gamemode"); $player->gamemode = $player->data->get("gamemode");
if(($player->level = $this->server->api->level->get($player->data->get("position")["level"])) === false){ if(($player->level = $this->server->api->level->get($player->data->get("position")["level"])) === false){
$player->level = $this->server->api->level->getDefault(); $player->level = $this->server->api->level->getDefault();
$player->data->set("position", array( $player->data->set("position", [
"level" => $player->level->getName(), "level" => $player->level->getName(),
"x" => $player->level->getSpawn()->x, "x" => $player->level->getSpawn()->x,
"y" => $player->level->getSpawn()->y, "y" => $player->level->getSpawn()->y,
"z" => $player->level->getSpawn()->z, "z" => $player->level->getSpawn()->z,
)); ]);
} }
$this->server->query("INSERT OR REPLACE INTO players (CID, ip, port, name) VALUES (".$player->CID.", '".$player->ip."', ".$player->port.", '".strtolower($player->username)."');"); $this->server->query("INSERT OR REPLACE INTO players (CID, ip, port, name) VALUES (" . $player->CID . ", '" . $player->ip . "', " . $player->port . ", '" . strtolower($player->username) . "');");
} }
} }
public function getOffline($name){
$iname = strtolower($name);
$default = [
"caseusername" => $name,
"position" => [
"level" => $this->server->spawn->level->getName(),
"x" => $this->server->spawn->x,
"y" => $this->server->spawn->y,
"z" => $this->server->spawn->z,
],
"spawn" => [
"level" => $this->server->spawn->level->getName(),
"x" => $this->server->spawn->x,
"y" => $this->server->spawn->y,
"z" => $this->server->spawn->z,
],
"inventory" => array_fill(0, PLAYER_SURVIVAL_SLOTS, [AIR, 0, 0]),
"hotbar" => [0, -1, -1, -1, -1, -1, -1, -1, -1],
"armor" => array_fill(0, 4, [AIR, 0]),
"gamemode" => $this->server->gamemode,
"health" => 20,
"lastIP" => "",
"lastID" => 0,
"achievements" => [],
];
if(!file_exists(DATA_PATH . "players/" . $iname . ".yml")){
if($this->server->extraprops->get("save-player-data")){
console("[NOTICE] Player data not found for \"" . $iname . "\", creating new profile");
$data = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default);
$data->save();
}
}
$data = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default);
if(($data->get("gamemode") & 0x01) === 1){
$data->set("health", 20);
}
$this->server->handle("player.offline.get", $data);
return $data;
}
public function spawnAllPlayers(Player $player){ public function spawnAllPlayers(Player $player){
foreach($this->getAll() as $p){ foreach($this->getAll() as $p){
if($p !== $player and ($p->entity instanceof Entity)){ if($p !== $player and ($p->entity instanceof Entity)){
@ -421,6 +419,33 @@ class PlayerAPI{
} }
} }
public function getAll($level = null){
if($level instanceof Level){
$clients = [];
$l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $level->getName() . "' AND class = '" . ENTITY_PLAYER . "';");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->getByEID($e["EID"]);
if($e instanceof Player){
$clients[$e->CID] = $e;
}
}
}
return $clients;
}
return $this->server->clients;
}
public function getByEID($eid){
$eid = (int) $eid;
$CID = $this->server->query("SELECT ip,port FROM players WHERE EID = '" . $eid . "';", true);
$CID = PocketMinecraftServer::clientID($CID["ip"], $CID["port"]);
if(isset($this->server->clients[$CID])){
return $this->server->clients[$CID];
}
return false;
}
public function spawnToAllPlayers(Player $player){ public function spawnToAllPlayers(Player $player){
foreach($this->getAll() as $p){ foreach($this->getAll() as $p){
if($p !== $player and ($p->entity instanceof Entity) and ($player->entity instanceof Entity)){ if($p !== $player and ($p->entity instanceof Entity) and ($player->entity instanceof Entity)){
@ -447,7 +472,7 @@ class PlayerAPI{
if($player->username != "" and ($player->data instanceof Config)){ if($player->username != "" and ($player->data instanceof Config)){
$this->saveOffline($player->data); $this->saveOffline($player->data);
} }
$this->server->query("DELETE FROM players WHERE name = '".$player->username."';"); $this->server->query("DELETE FROM players WHERE name = '" . $player->username . "';");
if($player->entity instanceof Entity){ if($player->entity instanceof Entity){
unset($player->entity->player); unset($player->entity->player);
//unset($player->entity); //unset($player->entity);
@ -458,51 +483,8 @@ class PlayerAPI{
} }
} }
public function getOffline($name){
$iname = strtolower($name);
$default = array(
"caseusername" => $name,
"position" => array(
"level" => $this->server->spawn->level->getName(),
"x" => $this->server->spawn->x,
"y" => $this->server->spawn->y,
"z" => $this->server->spawn->z,
),
"spawn" => array(
"level" => $this->server->spawn->level->getName(),
"x" => $this->server->spawn->x,
"y" => $this->server->spawn->y,
"z" => $this->server->spawn->z,
),
"inventory" => array_fill(0, PLAYER_SURVIVAL_SLOTS, array(AIR, 0, 0)),
"hotbar" => array(0, -1, -1, -1, -1, -1, -1, -1, -1),
"armor" => array_fill(0, 4, array(AIR, 0)),
"gamemode" => $this->server->gamemode,
"health" => 20,
"lastIP" => "",
"lastID" => 0,
"achievements" => array(),
);
if(!file_exists(DATA_PATH."players/".$iname.".yml")){
if($this->server->extraprops->get("save-player-data")) {
console("[NOTICE] Player data not found for \"".$iname."\", creating new profile");
$data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default);
$data->save();
}
}
$data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default);
if(($data->get("gamemode") & 0x01) === 1){
$data->set("health", 20);
}
$this->server->handle("player.offline.get", $data);
return $data;
}
public function saveOffline(Config $data){ public function saveOffline(Config $data){
if($this->server->extraprops->get("save-player-data")) { if($this->server->extraprops->get("save-player-data")){
$this->server->handle("player.offline.save", $data); $this->server->handle("player.offline.save", $data);
$data->save(); $data->save();
} }

View file

@ -1,33 +1,30 @@
<?php <?php
/** interface OtherPluginRequirement{
*
* ____ _ _ __ __ _ __ __ ____ public function getRequiredPlugins();
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ }
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ interface Plugin{
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
* public function __construct(ServerAPI $api, $server = false);
* 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 public function init();
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. public function __destruct();
* }
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class PluginAPI extends stdClass{ class PluginAPI extends stdClass{
private $server; private $server;
private $plugins = array(); private $plugins = [];
private $randomNonce; private $randomNonce;
public function __construct(){ public function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->randomNonce = Utils::getRandomBytes(16, false); $this->randomNonce = Utils::getRandomBytes(16, false);
$this->server->api->console->register("plugins", "", array($this, "commandHandler")); $this->server->api->console->register("plugins", "", [$this, "commandHandler"]);
$this->server->api->console->register("version", "", array($this, "commandHandler")); $this->server->api->console->register("version", "", [$this, "commandHandler"]);
$this->server->api->ban->cmdWhitelist("version"); $this->server->api->ban->cmdWhitelist("version");
$this->server->api->console->alias("pl", "plugins"); $this->server->api->console->alias("pl", "plugins");
$this->server->api->console->alias("ver", "version"); $this->server->api->console->alias("ver", "version");
@ -40,14 +37,14 @@ class PluginAPI extends stdClass{
case "plugins": case "plugins":
$output = "Plugins (" . count($this->plugins) . "): "; $output = "Plugins (" . count($this->plugins) . "): ";
foreach($this->getList() as $plugin){ foreach($this->getList() as $plugin){
$output .= $plugin["name"] . " v".$plugin["version"] .", "; $output .= $plugin["name"] . " v" . $plugin["version"] . ", ";
} }
$output = $output === "Plugins (0): " ? "No plugins installed.\n" : substr($output, 0, -2)."\n"; $output = $output === "Plugins (0): " ? "No plugins installed.\n" : substr($output, 0, -2) . "\n";
break; break;
case "version": case "version":
$output = "This server is running NostalgiaCore version " . MAJOR_VERSION . "\nCODENAME: 「 " . CODENAME . " 」\n(Implementing API version #" . CURRENT_API_VERSION . " for Minecraft: PE " . CURRENT_MINECRAFT_VERSION . ")"; $output = "This server is running NostalgiaCore version " . MAJOR_VERSION . "\nCODENAME: 「 " . CODENAME . " 」\n(Implementing API version #" . CURRENT_API_VERSION . " for Minecraft: PE " . CURRENT_MINECRAFT_VERSION . ")";
if(GIT_COMMIT !== str_repeat("00", 20)){ if(GIT_COMMIT !== str_repeat("00", 20)){
$output .= " (git ".GIT_COMMIT.")"; $output .= " (git " . GIT_COMMIT . ")";
} }
$output .= "\n"; $output .= "\n";
break; break;
@ -55,6 +52,14 @@ class PluginAPI extends stdClass{
return $output; return $output;
} }
public function getList(){
$list = [];
foreach($this->plugins as $p){
$list[] = $p[1];
}
return $list;
}
public function __destruct(){ public function __destruct(){
foreach($this->plugins as $p){ foreach($this->plugins as $p){
$p[0]->__destruct(); $p[0]->__destruct();
@ -62,21 +67,87 @@ class PluginAPI extends stdClass{
unset($plugins); unset($plugins);
} }
public function getList(){
$list = array();
foreach($this->plugins as $p){
$list[] = $p[1];
}
return $list;
}
public function getAll(){ public function getAll(){
return $this->plugins; return $this->plugins;
} }
public function createConfig(Plugin $plugin, $default = []){
$p = $this->get($plugin);
if($p === false){
return false;
}
$path = $this->configPath($plugin);
$cnf = new Config($path . "config.yml", CONFIG_YAML, $default);
$cnf->save();
return $path;
}
public function get($identifier){
if($identifier instanceof Plugin){
foreach($this->plugins as $p){
if($p[0] === $identifier){
return $p;
}
}
return false;
}
if(isset($this->plugins[$identifier])){
return $this->plugins[$identifier];
}
return false;
}
public function configPath(Plugin $plugin){
$p = $this->get($plugin);
$identifier = $this->getIdentifier($p[1]["name"], $p[1]["author"]);
if($p === false){
return false;
}
$path = $this->pluginsPath() . $p[1]["name"] . DIRECTORY_SEPARATOR;
$this->plugins[$identifier][1]["path"] = $path;
if(!file_exists($path)){
mkdir($path, 0777);
}
return $path;
}
public function pluginsPath(){
$path = join(DIRECTORY_SEPARATOR, [DATA_PATH . "plugins", ""]);
if(!file_exists($path)){
mkdir($path, 0777);
}
return $path;
}
public function readYAML($file){
return yaml_parse(preg_replace("#^([ ]*)([a-zA-Z_]{1}[^\:]*)\:#m", "$1\"$2\":", file_get_contents($file)));
}
public function writeYAML($file, $data){
return file_put_contents($file, yaml_emit($data, YAML_UTF8_ENCODING));
}
public function init(){
$this->server->event("server.start", [$this, "initAll"]);
$this->loadAll();
}
private function loadAll(){
$dir = dir($this->pluginsPath());
while(false !== ($file = $dir->read())){
if($file[0] !== "."){
$ext = strtolower(substr($file, -3));
if($ext === "php" or $ext === "pmf"){
$this->load($dir->path . $file);
}
}
}
}
public function load($file){ public function load($file){
if(is_link($file) or is_dir($file) or !file_exists($file)){ if(is_link($file) or is_dir($file) or !file_exists($file)){
console("[ERROR] ".basename($file)." is not a file"); console("[ERROR] " . basename($file) . " is not a file");
return false; return false;
} }
if(strtolower(substr($file, -3)) === "pmf"){ if(strtolower(substr($file, -3)) === "pmf"){
@ -85,12 +156,12 @@ class PluginAPI extends stdClass{
}else{ }else{
$content = file_get_contents($file); $content = file_get_contents($file);
$info = strstr($content, "*/", true); $info = strstr($content, "*/", true);
$content = str_repeat(PHP_EOL, substr_count($info, "\n")).substr(strstr($content, "*/"),2); $content = str_repeat(PHP_EOL, substr_count($info, "\n")) . substr(strstr($content, "*/"), 2);
if(preg_match_all('#([a-zA-Z0-9\-_]*)=([^\r\n]*)#u', $info, $matches) == 0){ //false or 0 matches if(preg_match_all('#([a-zA-Z0-9\-_]*)=([^\r\n]*)#u', $info, $matches) == 0){ //false or 0 matches
console("[ERROR] Failed parsing of ".basename($file)); console("[ERROR] Failed parsing of " . basename($file));
return false; return false;
} }
$info = array(); $info = [];
foreach($matches[1] as $k => $i){ foreach($matches[1] as $k => $i){
$v = $matches[2][$k]; $v = $matches[2][$k];
switch(strtolower($v)){ switch(strtolower($v)){
@ -111,10 +182,10 @@ class PluginAPI extends stdClass{
$info["class"] = trim(strtolower($info["class"])); $info["class"] = trim(strtolower($info["class"]));
} }
if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"]) or !isset($info["author"])){ if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"]) or !isset($info["author"])){
console("[ERROR] Failed parsing of ".basename($file)); console("[ERROR] Failed parsing of " . basename($file));
return false; return false;
} }
console("[INFO] Loading plugin \"".FORMAT_GREEN.$info["name"].FORMAT_RESET."\" ".FORMAT_AQUA.$info["version"].FORMAT_RESET." by ".FORMAT_AQUA.$info["author"].FORMAT_RESET); console("[INFO] Loading plugin \"" . FORMAT_GREEN . $info["name"] . FORMAT_RESET . "\" " . FORMAT_AQUA . $info["version"] . FORMAT_RESET . " by " . FORMAT_AQUA . $info["author"] . FORMAT_RESET);
if($info["class"] !== "none" and class_exists($info["class"])){ if($info["class"] !== "none" and class_exists($info["class"])){
console("[ERROR] Failed loading plugin: class already exists"); console("[ERROR] Failed loading plugin: class already exists");
return false; return false;
@ -127,7 +198,7 @@ class PluginAPI extends stdClass{
$className = $info["class"]; $className = $info["class"];
$apiversion = array_map("floatval", explode(",", (string) $info["apiversion"])); $apiversion = array_map("floatval", explode(",", (string) $info["apiversion"]));
if(!in_array((string) CURRENT_API_VERSION, $apiversion)){ if(!in_array((string) CURRENT_API_VERSION, $apiversion)){
console("[WARNING] Plugin \"".$info["name"]."\" may not be compatible with the API (".$info["apiversion"]." != ".CURRENT_API_VERSION.")! It can crash or corrupt the server!"); console("[WARNING] Plugin \"" . $info["name"] . "\" may not be compatible with the API (" . $info["apiversion"] . " != " . CURRENT_API_VERSION . ")! It can crash or corrupt the server!");
} }
$identifier = $this->getIdentifier($info["name"], $info["author"]); $identifier = $this->getIdentifier($info["name"], $info["author"]);
@ -135,17 +206,17 @@ class PluginAPI extends stdClass{
if($info["class"] !== "none"){ if($info["class"] !== "none"){
$object = new $className($this->server->api, false); $object = new $className($this->server->api, false);
if(!($object instanceof Plugin)){ if(!($object instanceof Plugin)){
console("[ERROR] Plugin \"".$info["name"]."\" doesn't use the Plugin Interface"); console("[ERROR] Plugin \"" . $info["name"] . "\" doesn't use the Plugin Interface");
if(method_exists($object, "__destruct")){ if(method_exists($object, "__destruct")){
$object->__destruct(); $object->__destruct();
} }
$object = null; $object = null;
unset($object); unset($object);
}else{ }else{
$this->plugins[$identifier] = array($object, $info); $this->plugins[$identifier] = [$object, $info];
} }
}else{ }else{
$this->plugins[$identifier] = array(new DummyPlugin($this->server->api, false), $info); $this->plugins[$identifier] = [new DummyPlugin($this->server->api, false), $info];
} }
return true; return true;
} }
@ -154,93 +225,10 @@ class PluginAPI extends stdClass{
return sha1(trim(strtolower($name)), true) ^ sha1(trim(strtolower($author)), true) ^ sha1($this->randomNonce, true); return sha1(trim(strtolower($name)), true) ^ sha1(trim(strtolower($author)), true) ^ sha1($this->randomNonce, true);
} }
public function get($identifier){
if($identifier instanceof Plugin){
foreach($this->plugins as $p){
if($p[0] === $identifier){
return $p;
}
}
return false;
}
if(isset($this->plugins[$identifier])){
return $this->plugins[$identifier];
}
return false;
}
public function pluginsPath(){
$path = join(DIRECTORY_SEPARATOR, array(DATA_PATH."plugins", ""));
@mkdir($path);
return $path;
}
public function configPath(Plugin $plugin){
$p = $this->get($plugin);
$identifier = $this->getIdentifier($p[1]["name"], $p[1]["author"]);
if($p === false){
return false;
}
$path = $this->pluginsPath() . $p[1]["name"] . DIRECTORY_SEPARATOR;
$this->plugins[$identifier][1]["path"] = $path;
@mkdir($path);
return $path;
}
public function createConfig(Plugin $plugin, $default = array()){
$p = $this->get($plugin);
if($p === false){
return false;
}
$path = $this->configPath($plugin);
$cnf = new Config($path."config.yml", CONFIG_YAML, $default);
$cnf->save();
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){
return yaml_parse(preg_replace("#^([ ]*)([a-zA-Z_]{1}[^\:]*)\:#m", "$1\"$2\":", file_get_contents($file)));
}
public function writeYAML($file, $data){
return file_put_contents($file, yaml_emit($data, YAML_UTF8_ENCODING));
}
public function init(){
$this->server->event("server.start", array($this, "initAll"));
$this->loadAll();
}
private function loadAll(){
$dir = dir($this->pluginsPath());
while(false !== ($file = $dir->read())){
if($file[0] !== "."){
$ext = strtolower(substr($file, -3));
if($ext === "php" or $ext === "pmf"){
$this->load($dir->path . $file);
}
}
}
}
public function initAll(){ public function initAll(){
console("[INFO] Starting plugins..."); console("[INFO] Starting plugins...");
$names = array(); $names = [];
$versions = array(); $versions = [];
foreach($this->plugins as $p){ foreach($this->plugins as $p){
$names[] = $p[1]["name"]; $names[] = $p[1]["name"];
$versions[] = $p[1]["version"]; $versions[] = $p[1]["version"];
@ -250,10 +238,10 @@ class PluginAPI extends stdClass{
foreach($p[0]->getRequiredPlugins() as $required){ foreach($p[0]->getRequiredPlugins() as $required){
if(in_array($required->pluginName, $names)){ if(in_array($required->pluginName, $names)){
if(!in_array($required->version, $versions) && $required->version !== false){ if(!in_array($required->version, $versions) && $required->version !== false){
console("[WARNING] Plugin \"".$required->pluginName."\" needed by \"".$p[1]["name"]."\" is incorrect version."); console("[WARNING] Plugin \"" . $required->pluginName . "\" needed by \"" . $p[1]["name"] . "\" is incorrect version.");
} }
}else{ }else{
console("[ERROR] Plugin \"".$required->pluginName."\" needed by \"".$p[1]["name"]."\" is not found."); console("[ERROR] Plugin \"" . $required->pluginName . "\" needed by \"" . $p[1]["name"] . "\" is not found.");
ServerAPI::request()->close(); ServerAPI::request()->close();
} }
@ -262,28 +250,34 @@ class PluginAPI extends stdClass{
$p[0]->init(); //ARGHHH!!! Plugin loading randomly fails!! $p[0]->init(); //ARGHHH!!! Plugin loading randomly fails!!
} }
} }
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] = [];
}
$this->fillDefaults($v, $yaml[$k]);
}elseif(!isset($yaml[$k])){
$yaml[$k] = $v;
}
}
}
} }
class RequiredPluginEntry{ //Use this as object of requirements array class RequiredPluginEntry{ //Use this as object of requirements array
public $pluginName; public $pluginName;
public $version; public $version;
public function __construct($name, $version = false){ public function __construct($name, $version = false){
$this->pluginName = $name; $this->pluginName = $name;
$this->version = $version; $this->version = $version;
} }
} }
interface OtherPluginRequirement{
public function getRequiredPlugins();
}
interface Plugin{
public function __construct(ServerAPI $api, $server = false);
public function init();
public function __destruct();
}
class DummyPlugin implements Plugin{ class DummyPlugin implements Plugin{
public function __construct(ServerAPI $api, $server = false){ public function __construct(ServerAPI $api, $server = false){
} }

View file

@ -1,38 +1,42 @@
<?php <?php
class QueryAPI{ class QueryAPI{
private $queryData;
public static $NOT_FOUND_VALUE; public static $NOT_FOUND_VALUE;
private $queryData;
private $server; private $server;
public function __construct(){ public function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
QueryAPI::$NOT_FOUND_VALUE = new NFV(); QueryAPI::$NOT_FOUND_VALUE = new NFV();
$this->updateQueryData("splitnum", chr(128)); $this->updateQueryData("splitnum", chr(128));
$this->updateQueryData("hostname", $this->server->name); $this->updateQueryData("hostname", $this->server->name);
$this->updateQueryData("gametype", ($this->server->gamemode & 0x01) === 0 ? "SMP":"CMP"); $this->updateQueryData("gametype", ($this->server->gamemode & 0x01) === 0 ? "SMP" : "CMP");
$this->updateQueryData("game_id", "MINECRAFTPE"); $this->updateQueryData("game_id", "MINECRAFTPE");
$this->updateQueryData("version", CURRENT_MINECRAFT_VERSION); $this->updateQueryData("version", CURRENT_MINECRAFT_VERSION);
$this->updateQueryData("server_engine", "NostalgiaCore ".MAJOR_VERSION); $this->updateQueryData("server_engine", "NostalgiaCore " . MAJOR_VERSION);
$this->addToQuery("plugins"); $this->addToQuery("plugins");
$this->addToQuery("map"); $this->addToQuery("map");
$this->addToQuery("numplayers"); $this->addToQuery("numplayers");
$this->updateQueryData("maxplayers", $this->server->maxClients); $this->updateQueryData("maxplayers", $this->server->maxClients);
$this->updateQueryData("whitelist", $this->server->api->getProperty("white-list") === true ? "on":"off"); $this->updateQueryData("whitelist", $this->server->api->getProperty("white-list") === true ? "on" : "off");
$this->updateQueryData("hostport", $this->server->api->getProperty("server-port")); $this->updateQueryData("hostport", $this->server->api->getProperty("server-port"));
$this->addToQuery("tps"); $this->addToQuery("tps");
} }
public function getQueryData(){ public function updateQueryData($name, $value){
return $this->queryData; $this->queryData[$name] = $value;
} }
public function addToQuery($name){ public function addToQuery($name){
$this->updateQueryData($name, QueryAPI::$NOT_FOUND_VALUE); $this->updateQueryData($name, QueryAPI::$NOT_FOUND_VALUE);
} }
public function updateQueryData($name, $value){ public function getQueryData(){
$this->queryData[$name] = $value; return $this->queryData;
} }
} }
class NFV{} class NFV{
}

View file

@ -1,81 +1,55 @@
<?php <?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/
*
*
*/
class ServerAPI{ class ServerAPI{
public $restart = false;
private static $serverRequest = false;
private $asyncCalls = array();
private $server;
private $config;
private $apiList = array();
private $asyncCnt = 0;
private $rcon;
public $queryAPI;
//TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs. private static $serverRequest = false;
public $restart = false;
public $queryAPI;
/** /**
* @var ConsoleAPI * @var ConsoleAPI
*/ */
public $console; public $console;
/** /**
* @var LevelAPI * @var LevelAPI
*/ */
public $level; public $level;
/** /**
* @var BlockAPI * @var BlockAPI
*/ */
public $block; public $block;
/** /**
* @var ChatAPI * @var ChatAPI
*/ */
public $chat; public $chat;
/** /**
* @var BanAPI * @var BanAPI
*/ */
public $ban; public $ban;
/** /**
* @var EntityAPI * @var EntityAPI
*/ */
public $entity; public $entity;
//TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs.
/** /**
* @var TimeAPI * @var TimeAPI
*/ */
public $time; public $time;
/** /**
* @var PlayerAPI * @var PlayerAPI
*/ */
public $player; public $player;
/** /**
* @var TileAPI * @var TileAPI
*/ */
public $tile; public $tile;
private $asyncCalls = [];
private $server;
private $config;
private $apiList = [];
private $asyncCnt = 0;
private $rcon;
/** /**
* @return PocketMinecraftServer * @return PocketMinecraftServer
@ -94,9 +68,17 @@ class ServerAPI{
} }
public function load(){ public function load(){
@mkdir(DATA_PATH."players/", 0755); if(!file_exists(DATA_PATH . "worlds/")){
@mkdir(DATA_PATH."worlds/", 0755); mkdir(DATA_PATH . "worlds/", 0777);
@mkdir(DATA_PATH."plugins/", 0755); }
if(!file_exists(DATA_PATH . "players/")){
mkdir(DATA_PATH . "players/", 0777);
}
if(!file_exists(DATA_PATH . "plugins/")){
mkdir(DATA_PATH . "plugins/", 0777);
}
//Init all the events //Init all the events
foreach(get_declared_classes() as $class){ foreach(get_declared_classes() as $class){
@ -106,10 +88,10 @@ class ServerAPI{
} }
$version = new VersionString(); $version = new VersionString();
console("[INFO] Starting Minecraft PE server version ".FORMAT_AQUA.CURRENT_MINECRAFT_VERSION); console("[INFO] Starting Minecraft PE server version " . FORMAT_AQUA . CURRENT_MINECRAFT_VERSION);
console("[INFO] Loading properties..."); console("[INFO] Loading properties...");
$this->config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES, array( $this->config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES, [
"server-name" => "Minecraft: PE Server", "server-name" => "Minecraft: PE Server",
"description" => "Server made using NostalgiaCore", "description" => "Server made using NostalgiaCore",
"motd" => "Welcome @player to this server!", "motd" => "Welcome @player to this server!",
@ -137,7 +119,7 @@ class ServerAPI{
"enable-rcon" => false, "enable-rcon" => false,
"rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10), "rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10),
"auto-save" => true, "auto-save" => true,
)); ]);
$this->parseProperties(); $this->parseProperties();
@ -154,11 +136,11 @@ class ServerAPI{
UPnP_PortForward($this->getProperty("server-port")); UPnP_PortForward($this->getProperty("server-port"));
} }
$this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed:false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0"); $this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed : false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip : "0.0.0.0");
$this->server->api = $this; $this->server->api = $this;
self::$serverRequest = $this->server; self::$serverRequest = $this->server;
$this->server->send2Discord("[INFO] Starting Minecraft PE server version ".CURRENT_MINECRAFT_VERSION); $this->server->send2Discord("[INFO] Starting Minecraft PE server version " . CURRENT_MINECRAFT_VERSION);
console("[INFO] This server is running NostalgiaCore version ".($version->isDev() ? FORMAT_YELLOW:"").MAJOR_VERSION.FORMAT_RESET." \"".CODENAME."\" (MCPE: ".CURRENT_MINECRAFT_VERSION.") (API ".CURRENT_API_VERSION.") (PHP ".PHP_VERSION.")", true, true, 0); console("[INFO] This server is running NostalgiaCore version " . ($version->isDev() ? FORMAT_YELLOW : "") . MAJOR_VERSION . FORMAT_RESET . " \"" . CODENAME . "\" (MCPE: " . CURRENT_MINECRAFT_VERSION . ") (API " . CURRENT_API_VERSION . ") (PHP " . PHP_VERSION . ")", true, true, 0);
console("[INFO] NostalgiaCore is distributed under the LGPL License", true, true, 0); console("[INFO] NostalgiaCore is distributed under the LGPL License", true, true, 0);
$this->loadProperties(); $this->loadProperties();
@ -175,7 +157,7 @@ class ServerAPI{
$this->loadAPI("time", "TimeAPI"); $this->loadAPI("time", "TimeAPI");
$this->loadAPI("queryAPI", "QueryAPI"); $this->loadAPI("queryAPI", "QueryAPI");
foreach($this->apiList as $ob){ foreach($this->apiList as $ob){
if(is_callable(array($ob, "init"))){ if(is_callable([$ob, "init"])){
$ob->init(); //Fails sometimes!!! $ob->init(); //Fails sometimes!!!
} }
} }
@ -184,38 +166,78 @@ class ServerAPI{
} }
public function async(callable $callable, $params = array(), $remove = false){ private function parseProperties(){
$cnt = $this->asyncCnt++; foreach($this->config->getAll() as $n => $v){
$this->asyncCalls[$cnt] = new Async($callable, $params); switch($n){
return $remove === true ? $this->getAsync($cnt):$cnt; case "gamemode":
case "max-players":
case "server-port":
case "debug":
case "difficulty":
$v = (int) $v;
break;
case "server-id":
if($v !== false){
$v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)) : $v;
} }
break;
public function getAsync($id){
if(!isset($this->asyncCalls[$id])){
return false;
} }
$ob = $this->asyncCalls[$id]; $this->config->set($n, $v);
unset($this->asyncCalls[$id]);
return $ob;
}
public function autoSave(){
console("[DEBUG] Saving....", true, true, 2);
$this->server->api->level->saveAll();
}
public function __destruct(){
foreach($this->apiList as $i => $ob){
if(method_exists($ob, "__destruct")){
$ob->__destruct();
unset($this->apiList[$i]);
} }
if($this->getProperty("hardcore") == 1 and $this->getProperty("difficulty") < 3){
$this->setProperty("difficulty", 3);
} }
} }
public function getProperty($name, $default = false){
if(($v = arg($name)) !== false){ //Allow for command-line arguments
switch(strtolower(trim($v))){
case "on":
case "true":
case "yes":
$v = true;
break;
case "off":
case "false":
case "no":
$v = false;
break;
}
switch($name){
case "gamemode":
case "max-players":
case "server-port":
case "debug":
case "difficulty":
case "time-per-second":
$v = (int) $v;
break;
case "server-id":
if($v !== false){
$v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)) : $v;
}
break;
}
return $v;
}
return ($this->config->exists($name) ? $this->config->get($name) : $default);
}
public function setProperty($name, $value, $save = true){
$this->config->set($name, $value);
if($save == true){
$this->writeProperties();
}
$this->loadProperties();
}
private function writeProperties(){
$this->config->save();
}
private function loadProperties(){ private function loadProperties(){
if(($memory = str_replace("B", "", strtoupper($this->getProperty("memory-limit")))) !== false){ if(($memory = str_replace("B", "", strtoupper($this->getProperty("memory-limit")))) !== false){
$value = array("M" => 1, "G" => 1024); $value = ["M" => 1, "G" => 1024];
$real = ((int) substr($memory, 0, -1)) * $value[substr($memory, -1)]; $real = ((int) substr($memory, 0, -1)) * $value[substr($memory, -1)];
if($real < 128){ if($real < 128){
console("[WARNING] NostalgiaCore may not work right with less than 128MB of RAM", true, true, 0); console("[WARNING] NostalgiaCore may not work right with less than 128MB of RAM", true, true, 0);
@ -236,31 +258,27 @@ class ServerAPI{
} }
} }
private function writeProperties(){ public function loadAPI($name, $class, $dir = false){
$this->config->save(); if(isset($this->$name)){
return false;
}elseif(!class_exists($class)){
$internal = false;
if($dir === false){
$internal = true;
$dir = FILE_PATH . "src/API/";
} }
$file = $dir . $class . ".php";
private function parseProperties(){ if(!file_exists($file)){
foreach($this->config->getAll() as $n => $v){ console("[ERROR] API " . $name . " [" . $class . "] in " . $dir . " doesn't exist", true, true, 0);
switch($n){ return false;
case "gamemode":
case "max-players":
case "server-port":
case "debug":
case "difficulty":
$v = (int) $v;
break;
case "server-id":
if($v !== false){
$v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)):$v;
} }
break; require_once($file);
} }else{
$this->config->set($n, $v); $internal = true;
}
if($this->getProperty("hardcore") == 1 and $this->getProperty("difficulty") < 3){
$this->setProperty("difficulty", 3);
} }
$this->$name = new $class();
$this->apiList[] = $this->$name;
console("[" . ($internal === true ? "INTERNAL" : "DEBUG") . "] API \x1b[36m" . $name . "\x1b[0m [\x1b[30;1m" . $class . "\x1b[0m] loaded", true, true, ($internal === true ? 3 : 2));
} }
public function init(){ public function init(){
@ -269,10 +287,10 @@ class ServerAPI{
} }
if($this->getProperty("auto-save") === true){ if($this->getProperty("auto-save") === true){
$this->server->schedule(18000, array($this, "autoSave"), array(), true); $this->server->schedule(18000, [$this, "autoSave"], [], true);
} }
if(!defined("NO_THREADS") and $this->getProperty("enable-rcon") === true){ if(!defined("NO_THREADS") and $this->getProperty("enable-rcon") === true){
$this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50)); $this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip : "0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50));
} }
if($this->getProperty("enable-query") === true){ if($this->getProperty("enable-query") === true){
@ -280,21 +298,50 @@ class ServerAPI{
} }
CraftingRecipes::init(); CraftingRecipes::init();
$this->server->init(); $this->server->init();
unregister_tick_function(array($this->server, "tick")); unregister_tick_function([$this->server, "tick"]);
$this->console->__destruct(); $this->console->__destruct();
if($this->rcon instanceof RCON){ if($this->rcon instanceof RCON){
$this->rcon->stop(); $this->rcon->stop();
} }
$this->__destruct(); $this->__destruct();
if($this->getProperty("upnp-forwarding") === true ){ if($this->getProperty("upnp-forwarding") === true){
console("[INFO] [UPnP] Removing port forward..."); console("[INFO] [UPnP] Removing port forward...");
UPnP_RemovePortForward($this->getProperty("server-port")); UPnP_RemovePortForward($this->getProperty("server-port"));
} }
return $this->restart; return $this->restart;
} }
public function __destruct(){
foreach($this->apiList as $i => $ob){
if(method_exists($ob, "__destruct")){
$ob->__destruct();
unset($this->apiList[$i]);
}
}
}
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
public function async(callable $callable, $params = [], $remove = false){
$cnt = $this->asyncCnt++;
$this->asyncCalls[$cnt] = new Async($callable, $params);
return $remove === true ? $this->getAsync($cnt) : $cnt;
}
public function getAsync($id){
if(!isset($this->asyncCalls[$id])){
return false;
}
$ob = $this->asyncCalls[$id];
unset($this->asyncCalls[$id]);
return $ob;
}
public function autoSave(){
console("[DEBUG] Saving....", true, true, 2);
$this->server->api->level->saveAll();
}
public function asyncOperation($t, $d, $c = null){ public function asyncOperation($t, $d, $c = null){
return $this->server->asyncOperation($t, $d, $c); return $this->server->asyncOperation($t, $d, $c);
} }
@ -331,73 +378,8 @@ class ServerAPI{
return $this->config->getAll(); return $this->config->getAll();
} }
public function getProperty($name, $default = false){
if(($v = arg($name)) !== false){ //Allow for command-line arguments
switch(strtolower(trim($v))){
case "on":
case "true":
case "yes":
$v = true;
break;
case "off":
case "false":
case "no":
$v = false;
break;
}
switch($name){
case "gamemode":
case "max-players":
case "server-port":
case "debug":
case "difficulty":
case "time-per-second":
$v = (int) $v;
break;
case "server-id":
if($v !== false){
$v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)):$v;
}
break;
}
return $v;
}
return ($this->config->exists($name) ? $this->config->get($name):$default);
}
public function setProperty($name, $value, $save = true){
$this->config->set($name, $value);
if($save == true){
$this->writeProperties();
}
$this->loadProperties();
}
public function getList(){ public function getList(){
return $this->apiList; return $this->apiList;
} }
public function loadAPI($name, $class, $dir = false){
if(isset($this->$name)){
return false;
}elseif(!class_exists($class)){
$internal = false;
if($dir === false){
$internal = true;
$dir = FILE_PATH."src/API/";
}
$file = $dir.$class.".php";
if(!file_exists($file)){
console("[ERROR] API ".$name." [".$class."] in ".$dir." doesn't exist", true, true, 0);
return false;
}
require_once($file);
}else{
$internal = true;
}
$this->$name = new $class();
$this->apiList[] = $this->$name;
console("[".($internal === true ? "INTERNAL":"DEBUG")."] API \x1b[36m".$name."\x1b[0m [\x1b[30;1m".$class."\x1b[0m] loaded", true, true, ($internal === true ? 3:2));
}
} }

View file

@ -1,35 +1,18 @@
<?php <?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/
*
*
*/
class TileAPI{ class TileAPI{
private $server; private $server;
private $tiles; private $tiles;
private $tCnt = 1; private $tCnt = 1;
function __construct(){ function __construct(){
$this->tiles = array(); $this->tiles = [];
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
public function get(Position $pos){ public function get(Position $pos){
$tile = $this->server->query("SELECT * FROM tiles WHERE level = '".$pos->level->getName()."' AND x = {$pos->x} AND y = {$pos->y} AND z = {$pos->z};", true); $tile = $this->server->query("SELECT * FROM tiles WHERE level = '" . $pos->level->getName() . "' AND x = {$pos->x} AND y = {$pos->y} AND z = {$pos->z};", true);
if($tile !== false and $tile !== true and ($tile = $this->getByID($tile["ID"])) !== false){ if($tile !== false and $tile !== true and ($tile = $this->getByID($tile["ID"])) !== false){
return $tile; return $tile;
} }
@ -49,32 +32,8 @@ class TileAPI{
} }
public function getAll($level = null){ public function addSign(Level $level, $x, $y, $z, $lines = ["", "", "", ""]){
if($level instanceof Level){ return $this->add($level, TILE_SIGN, $x, $y, $z, $data = [
$tiles = array();
$l = $this->server->query("SELECT ID FROM tiles WHERE level = '".$level->getName()."';");
if($l !== false and $l !== true){
while(($t = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$t = $this->getByID($t["ID"]);
if($t instanceof Tile){
$tiles[$t->id] = $t;
}
}
}
return $tiles;
}
return $this->tiles;
}
public function add(Level $level, $class, $x, $y, $z, $data = array()){
$id = $this->tCnt++;
$this->tiles[$id] = new Tile($level, $id, $class, $x, $y, $z, $data);
$this->spawnToAll($this->tiles[$id]);
return $this->tiles[$id];
}
public function addSign(Level $level, $x, $y, $z, $lines = array("", "", "", "")){
return $this->add($level, TILE_SIGN, $x, $y, $z, $data = array(
"id" => "Sign", "id" => "Sign",
"x" => $x, "x" => $x,
"y" => $y, "y" => $y,
@ -83,7 +42,14 @@ class TileAPI{
"Text2" => $lines[1], "Text2" => $lines[1],
"Text3" => $lines[2], "Text3" => $lines[2],
"Text4" => $lines[3], "Text4" => $lines[3],
)); ]);
}
public function add(Level $level, $class, $x, $y, $z, $data = []){
$id = $this->tCnt++;
$this->tiles[$id] = new Tile($level, $id, $class, $x, $y, $z, $data);
$this->spawnToAll($this->tiles[$id]);
return $this->tiles[$id];
} }
public function spawnToAll(Tile $t){ public function spawnToAll(Tile $t){
@ -100,6 +66,23 @@ class TileAPI{
} }
} }
public function getAll($level = null){
if($level instanceof Level){
$tiles = [];
$l = $this->server->query("SELECT ID FROM tiles WHERE level = '" . $level->getName() . "';");
if($l !== false and $l !== true){
while(($t = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$t = $this->getByID($t["ID"]);
if($t instanceof Tile){
$tiles[$t->id] = $t;
}
}
}
return $tiles;
}
return $this->tiles;
}
public function remove($id){ public function remove($id){
if(isset($this->tiles[$id])){ if(isset($this->tiles[$id])){
$t = $this->tiles[$id]; $t = $this->tiles[$id];
@ -107,7 +90,7 @@ class TileAPI{
unset($this->tiles[$id]); unset($this->tiles[$id]);
$t->closed = true; $t->closed = true;
$t->close(); $t->close();
$this->server->query("DELETE FROM tiles WHERE ID = ".$id.";"); $this->server->query("DELETE FROM tiles WHERE ID = " . $id . ";");
$this->server->api->dhandle("tile.remove", $t); $this->server->api->dhandle("tile.remove", $t);
$t = null; $t = null;
unset($t); unset($t);

View file

@ -1,38 +1,21 @@
<?php <?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/
*
*
*/
class TimeAPI{ class TimeAPI{
public static $phases = array(
public static $phases = [
"day" => 0, "day" => 0,
"sunset" => 9500, "sunset" => 9500,
"night" => 10900, "night" => 10900,
"sunrise" => 17800, "sunrise" => 17800,
); ];
private $server; private $server;
function __construct(){ function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
public function init(){ public function init(){
$this->server->api->console->register("time", "<check|set|add> [time]", array($this, "commandHandler")); $this->server->api->console->register("time", "<check|set|add> [time]", [$this, "commandHandler"]);
} }
public function commandHandler($cmd, $args, $issuer, $alias){ public function commandHandler($cmd, $args, $issuer, $alias){
@ -42,8 +25,7 @@ class TimeAPI{
$level = false; $level = false;
if($issuer instanceof Player){ if($issuer instanceof Player){
$level = $issuer->level; $level = $issuer->level;
} }else{
else{
$level = $this->server->api->level->getDefault(); $level = $this->server->api->level->getDefault();
} }
$p = strtolower(array_shift($args)); $p = strtolower(array_shift($args));
@ -54,14 +36,12 @@ class TimeAPI{
$level = $this->server->api->level->get($levelName); $level = $this->server->api->level->get($levelName);
if($level instanceof Level){ if($level instanceof Level){
$world = " in world \"$levelName\""; $world = " in world \"$levelName\"";
} }else{
else{
$output .= "World \"$levelName\" doesn't exist or loaded!"; $output .= "World \"$levelName\" doesn't exist or loaded!";
break; break;
} }
} }else $world = " in world \"" . $level->getName() . "\"";
else $world = " in world \"".$level->getName()."\""; $output .= "Time" . $world . ": " . $this->getDate($level) . ", " . $this->getPhase($level) . " (" . $this->get(true, $level) . " ticks)\n";
$output .= "Time".$world.": ".$this->getDate($level).", ".$this->getPhase($level)." (".$this->get(true, $level)." ticks)\n";
break; break;
case "add": case "add":
if(substr($args[1], 0, 2) === "w:"){ if(substr($args[1], 0, 2) === "w:"){
@ -69,22 +49,20 @@ class TimeAPI{
$level = $this->server->api->level->get($levelName); $level = $this->server->api->level->get($levelName);
if($level instanceof Level){ if($level instanceof Level){
$world = " to the time of world \"$levelName\""; $world = " to the time of world \"$levelName\"";
} }else{
else{
$output .= "World \"$levelName\" doesn't exist or loaded!"; $output .= "World \"$levelName\" doesn't exist or loaded!";
break; break;
} }
} }else $world = " to the time of world \"" . $level->getName() . "\"";
else $world = " to the time of world \"".$level->getName()."\"";
$addTime = array_shift($args); $addTime = array_shift($args);
if(!is_numeric($addTime)){ if(!is_numeric($addTime)){
$output .= "Time must be an integer!"; $output .= "Time must be an integer!";
break; break;
} }
$addTime = (int)$addTime; $addTime = (int) $addTime;
$this->add($addTime, $level); $this->add($addTime, $level);
$output .= "Added $addTime ticks".$world."\n"; $output .= "Added $addTime ticks" . $world . "\n";
break; break;
case "set": case "set":
if(substr($args[1], 0, 2) === "w:"){ if(substr($args[1], 0, 2) === "w:"){
@ -92,24 +70,22 @@ class TimeAPI{
$level = $this->server->api->level->get($levelName); $level = $this->server->api->level->get($levelName);
if($level instanceof Level){ if($level instanceof Level){
$world = " in world \"$levelName\""; $world = " in world \"$levelName\"";
} }else{
else{
$output .= "World \"$levelName\" doesn't exist or loaded!"; $output .= "World \"$levelName\" doesn't exist or loaded!";
break; break;
} }
} }else $world = " in world \"" . $level->getName() . "\"";
else $world = " in world \"".$level->getName()."\"";
$setTime = array_shift($args); $setTime = array_shift($args);
if(is_numeric($setTime)){ if(is_numeric($setTime)){
$setTime = (int)$setTime; $setTime = (int) $setTime;
} }elseif($setTime == 'sunrise' or $setTime == 'day' or $setTime == 'sunset' or $setTime == 'night')
elseif($setTime == 'sunrise' or $setTime == 'day' or $setTime == 'sunset' or $setTime == 'night'); ;
else{ else{
$output .= "Wrong time!"; $output .= "Wrong time!";
} }
$this->set($setTime, $level); $this->set($setTime, $level);
$output .= "Set the time to ".$setTime.$world."\n"; $output .= "Set the time to " . $setTime . $world . "\n";
break; break;
case "sunrise": case "sunrise":
case "day": case "day":
@ -120,16 +96,14 @@ class TimeAPI{
$level = $this->server->api->level->get($levelName); $level = $this->server->api->level->get($levelName);
if($level instanceof Level){ if($level instanceof Level){
$world = " in world \"$levelName\""; $world = " in world \"$levelName\"";
} }else{
else{
$output .= "World \"$levelName\" doesn't exist or loaded!"; $output .= "World \"$levelName\" doesn't exist or loaded!";
break; break;
} }
} }else $world = " in world \"" . $level->getName() . "\"";
else $world = " in world \"".$level->getName()."\"";
$this->set($p, $level); $this->set($p, $level);
$output .= "Set the time to ".$p.$world."\n"; $output .= "Set the time to " . $p . $world . "\n";
break; break;
default: default:
$output .= "Usage: /time <check|set|add> [time] [w:world]\n"; $output .= "Usage: /time <check|set|add> [time] [w:world]\n";
@ -140,40 +114,20 @@ class TimeAPI{
return $output; return $output;
} }
public function night(){ public function getDate($time = false){
return $this->set("night"); $time = !is_integer($time) ? $this->get(false, $time) : $time;
} return str_pad(strval((floor($time / 800) + 6) % 24), 2, "0", STR_PAD_LEFT) . ":" . str_pad(strval(floor(($time % 800) / 13.33)), 2, "0", STR_PAD_LEFT);
public function day(){
return $this->set("day");
}
public function sunrise(){
return $this->set("sunrise");
}
public function sunset(){
return $this->set("sunset");
} }
public function get($raw = false, $level = false){ public function get($raw = false, $level = false){
if(!($level instanceof Level)){ if(!($level instanceof Level)){
$level = $this->server->api->level->getDefault(); $level = $this->server->api->level->getDefault();
} }
return $raw === true ? $level->getTime():abs($level->getTime()) % 19200; return $raw === true ? $level->getTime() : abs($level->getTime()) % 19200;
}
public function add($time, $level = false){
if(!($level instanceof Level)){
$level = $this->server->api->level->getDefault();
}
$level->setTime($level->getTime() + (int) $time);
}
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);
} }
public function getPhase($time = false){ public function getPhase($time = false){
$time = !is_integer($time) ? $this->get(false, $time):$time; $time = !is_integer($time) ? $this->get(false, $time) : $time;
if($time < TimeAPI::$phases["sunset"]){ if($time < TimeAPI::$phases["sunset"]){
$time = "day"; $time = "day";
}elseif($time < TimeAPI::$phases["night"]){ }elseif($time < TimeAPI::$phases["night"]){
@ -186,6 +140,13 @@ class TimeAPI{
return $time; return $time;
} }
public function add($time, $level = false){
if(!($level instanceof Level)){
$level = $this->server->api->level->getDefault();
}
$level->setTime($level->getTime() + (int) $time);
}
public function set($time, $level = false){ public function set($time, $level = false){
if(!($level instanceof Level)){ if(!($level instanceof Level)){
$level = $this->server->api->level->getDefault(); $level = $this->server->api->level->getDefault();
@ -198,5 +159,21 @@ class TimeAPI{
return $level->getTime(); return $level->getTime();
} }
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");
}
} }

View file

@ -1,25 +1,7 @@
<?php <?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 BaseEvent{ abstract class BaseEvent{
const ALLOW = 0; const ALLOW = 0;
const DENY = 1; const DENY = 1;
const NORMAL = 2; const NORMAL = 2;
@ -38,18 +20,68 @@ abstract class BaseEvent{
private $status = BaseEvent::NORMAL; private $status = BaseEvent::NORMAL;
private $prioritySlot; private $prioritySlot;
final public function getEventName(){ public static function getHandlerList(){
return $this->eventName !== null ? get_class($this) : $this->eventName; return static::$handlers;
} }
final public function setPrioritySlot($slot){ public static function getPriorityList(){
$this->prioritySlot = (int) $slot; return static::$handlerPriority;
}
public static function unregisterAll(){
static::$handlers = [];
static::$handlerPriority = [];
}
public static function register(callable $handler, $priority = EventPriority::NORMAL){
if($priority < EventPriority::MONITOR or $priority > EventPriority::LOWEST){
return false;
}
$identifier = Utils::getCallableIdentifier($handler);
if(isset(static::$handlers[$identifier])){ //Already registered
return false;
}else{
static::$handlers[$identifier] = $handler;
if(!isset(static::$handlerPriority[(int) $priority])){
static::$handlerPriority[(int) $priority] = [];
krsort(static::$handlerPriority);
}
static::$handlerPriority[(int) $priority][$identifier] = $handler;
return true;
}
}
public static function unregister(callable $handler, $priority = EventPriority::NORMAL){
$identifier = Utils::getCallableIdentifier($handler);
if(isset(static::$handlers[$identifier])){
if(isset(static::$handlerPriority[(int) $priority][$identifier])){
unset(static::$handlerPriority[(int) $priority][$identifier]);
}else{
for($priority = EventPriority::MONITOR; $priority <= EventPriority::LOWEST; ++$priority){
unset(static::$handlerPriority[$priority][$identifier]);
if(count(static::$handlerPriority[$priority]) === 0){
unset(static::$handlerPriority[$priority]);
}
}
}
unset(static::$handlers[$identifier]);
return true;
}else{
return false;
}
}
final public function getEventName(){
return $this->eventName !== null ? get_class($this) : $this->eventName;
} }
final public function getPrioritySlot(){ final public function getPrioritySlot(){
return (int) $this->prioritySlot; return (int) $this->prioritySlot;
} }
final public function setPrioritySlot($slot){
$this->prioritySlot = (int) $slot;
}
public function isAllowed(){ public function isAllowed(){
return ($this->status & 0x7FFFFFFF) === BaseEvent::ALLOW; return ($this->status & 0x7FFFFFFF) === BaseEvent::ALLOW;
@ -81,56 +113,4 @@ abstract class BaseEvent{
public function isForced(){ public function isForced(){
return ($this->status & BaseEvent::FORCE) > 0; return ($this->status & BaseEvent::FORCE) > 0;
} }
public static function getHandlerList(){
return static::$handlers;
}
public static function getPriorityList(){
return static::$handlerPriority;
}
public static function unregisterAll(){
static::$handlers = array();
static::$handlerPriority = array();
}
public static function register(callable $handler, $priority = EventPriority::NORMAL){
if($priority < EventPriority::MONITOR or $priority > EventPriority::LOWEST){
return false;
}
$identifier = Utils::getCallableIdentifier($handler);
if(isset(static::$handlers[$identifier])){ //Already registered
return false;
}else{
static::$handlers[$identifier] = $handler;
if(!isset(static::$handlerPriority[(int) $priority])){
static::$handlerPriority[(int) $priority] = array();
krsort(static::$handlerPriority);
}
static::$handlerPriority[(int) $priority][$identifier] = $handler;
return true;
}
}
public static function unregister(callable $handler, $priority = EventPriority::NORMAL){
$identifier = Utils::getCallableIdentifier($handler);
if(isset(static::$handlers[$identifier])){
if(isset(static::$handlerPriority[(int) $priority][$identifier])){
unset(static::$handlerPriority[(int) $priority][$identifier]);
}else{
for($priority = EventPriority::MONITOR; $priority <= EventPriority::LOWEST; ++$priority){
unset(static::$handlerPriority[$priority][$identifier]);
if(count(static::$handlerPriority[$priority]) === 0){
unset(static::$handlerPriority[$priority]);
}
}
}
unset(static::$handlers[$identifier]);
return true;
}else{
return false;
}
}
} }

View file

@ -1,27 +1,9 @@
<?php <?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/
*
*
*/
class Deprecation{ class Deprecation{
public static $events = array(
public static $events = [
"server.tick" => "ServerAPI::schedule()", "server.tick" => "ServerAPI::schedule()",
"server.time" => "time.change", "server.time" => "time.change",
"world.block.change" => "block.change", "world.block.change" => "block.change",
@ -29,7 +11,5 @@ class Deprecation{
"api.op.check" => "op.check", "api.op.check" => "op.check",
"api.player.offline.get" => "player.offline.get", "api.player.offline.get" => "player.offline.get",
"api.player.offline.save" => "player.offline.save", "api.player.offline.save" => "player.offline.save",
); ];
} }

File diff suppressed because it is too large Load diff

View file

@ -1,33 +1,26 @@
<?php <?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/
*
*
*/
class PocketMinecraftServer{ class PocketMinecraftServer{
public $tCnt; public $tCnt;
public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $ticks, $memoryStats, $async = array(), $asyncID = 0;
/** /**
* @var ServerAPI * @var ServerAPI
*/ */
public $api; public $api;
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $ticks, $memoryStats, $async = [], $asyncID = 0;
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
$this->port = (int) $port;
$this->doTick = true;
$this->gamemode = (int) $gamemode;
$this->name = $name;
$this->motd = "Welcome to " . $name;
$this->serverID = false;
$this->seed = $seed;
$this->serverip = $serverip;
$this->load();
}
private function load(){ private function load(){
global $dolog; global $dolog;
@ -36,32 +29,32 @@ class PocketMinecraftServer{
/*if(defined("DEBUG") and DEBUG >= 0){ /*if(defined("DEBUG") and DEBUG >= 0){
@cli_set_process_title("NostalgiaCore ".MAJOR_VERSION); @cli_set_process_title("NostalgiaCore ".MAJOR_VERSION);
}*/ }*/
console("[INFO] Starting Minecraft PE server on ".($this->serverip === "0.0.0.0" ? "*":$this->serverip).":".$this->port); console("[INFO] Starting Minecraft PE server on " . ($this->serverip === "0.0.0.0" ? "*" : $this->serverip) . ":" . $this->port);
define("BOOTUP_RANDOM", Utils::getRandomBytes(16)); define("BOOTUP_RANDOM", Utils::getRandomBytes(16));
$this->serverID = $this->serverID === false ? Utils::readLong(substr(Utils::getUniqueID(true, $this->serverip . $this->port), 8)):$this->serverID; $this->serverID = $this->serverID === false ? Utils::readLong(substr(Utils::getUniqueID(true, $this->serverip . $this->port), 8)) : $this->serverID;
$this->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):$this->seed; $this->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : $this->seed;
$this->startDatabase(); $this->startDatabase();
$this->api = false; $this->api = false;
$this->tCnt = 1; $this->tCnt = 1;
$this->events = array(); $this->events = [];
$this->eventsID = array(); $this->eventsID = [];
$this->handlers = array(); $this->handlers = [];
$this->invisible = false; $this->invisible = false;
$this->levelData = false; $this->levelData = false;
$this->difficulty = 1; $this->difficulty = 1;
$this->tiles = array(); $this->tiles = [];
$this->entities = array(); $this->entities = [];
$this->custom = array(); $this->custom = [];
$this->evCnt = 1; $this->evCnt = 1;
$this->handCnt = 1; $this->handCnt = 1;
$this->eidCnt = 1; $this->eidCnt = 1;
$this->maxClients = 20; $this->maxClients = 20;
$this->schedule = array(); $this->schedule = [];
$this->scheduleCnt = 1; $this->scheduleCnt = 1;
$this->description = ""; $this->description = "";
$this->whitelist = false; $this->whitelist = false;
$this->memoryStats = array(); $this->memoryStats = [];
$this->clients = array(); $this->clients = [];
$this->spawn = false; $this->spawn = false;
$this->saveEnabled = true; $this->saveEnabled = true;
$this->tickMeasure = array_fill(0, 40, 0); $this->tickMeasure = array_fill(0, 40, 0);
@ -73,7 +66,7 @@ class PocketMinecraftServer{
$this->asyncThread = new AsyncMultipleQueue(); $this->asyncThread = new AsyncMultipleQueue();
} }
console("[INFO] Loading extra.properties..."); console("[INFO] Loading extra.properties...");
$this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, array( $this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, [
"version" => "5", "version" => "5",
"enable-nether-reactor" => true, "enable-nether-reactor" => true,
"enable-explosions" => true, "enable-explosions" => true,
@ -85,82 +78,24 @@ class PocketMinecraftServer{
"discord-ru-smiles" => false, "discord-ru-smiles" => false,
"discord-webhook-url" => "none", "discord-webhook-url" => "none",
"discord-bot-name" => "NostalgiaCore Logger" "discord-bot-name" => "NostalgiaCore Logger"
)); ]);
Explosion::$enableExplosions = $this->extraprops->get("enable-explosions"); Explosion::$enableExplosions = $this->extraprops->get("enable-explosions");
RailBlock::$shouldconnectrails = $this->extraprops->get("enable-rail-connection"); //Rail connection in config RailBlock::$shouldconnectrails = $this->extraprops->get("enable-rail-connection"); //Rail connection in config
NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor"); NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor");
if($this->extraprops->get("discord-msg") == true){ if($this->extraprops->get("discord-msg") == true){
if($this->extraprops->get("discord-webhook-url") !== "none"){ if($this->extraprops->get("discord-webhook-url") !== "none"){
console("[INFO] Discord Logger is enabled."); console("[INFO] Discord Logger is enabled.");
} else { }else{
console("[WARNING] Discord Logger is enabled in extra.properties,"); console("[WARNING] Discord Logger is enabled in extra.properties,");
console("[WARNING] but you didn't put the webhook url, so it won't work."); console("[WARNING] but you didn't put the webhook url, so it won't work.");
} }
} elseif($this->extraprops->get("version") == null){ }elseif($this->extraprops->get("version") == null){
console("[WARNING] Your extra.properties file is corrupted!"); console("[WARNING] Your extra.properties file is corrupted!");
console("To fix it - just remove it! Server will generate it again automatically."); console("To fix it - just remove it! Server will generate it again automatically.");
} }
$dolog = $this->extraprops->get("save-console-data"); $dolog = $this->extraprops->get("save-console-data");
} }
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
$this->port = (int) $port;
$this->doTick = true;
$this->gamemode = (int) $gamemode;
$this->name = $name;
$this->motd = "Welcome to ".$name;
$this->serverID = false;
$this->seed = $seed;
$this->serverip = $serverip;
$this->load();
}
/**
* @return float
*/
public function getTPS(){
$v = array_values($this->tickMeasure);
$divval = ($v[39] - $v[0]);
if($divval === 0){
return 0;
}
$tps = 40 / $divval;
return round($tps, 4);
}
public function titleTick(){
$time = microtime(true);
if(defined("DEBUG") and DEBUG >= 0 and ENABLE_ANSI === true){
echo "\x1b]0;NostalgiaCore ".MAJOR_VERSION." | Online ". count($this->clients)."/".$this->maxClients." | RAM ".round((memory_get_usage() / 1024) / 1024, 2)."MB | U ".round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2)." D ".round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2)." kB/s | TPS ".$this->getTPS()."\x07";
}
$this->interface->bandwidth = array(0, 0, $time);
}
public function loadEvents(){
if(ENABLE_ANSI === true){
$this->schedule(30, array($this, "titleTick"), array(), true);
}
$this->schedule(20 * 15, array($this, "checkTicks"), array(), true);
$this->schedule(20 * 60, array($this, "checkMemory"), array(), true);
$this->schedule(20 * 45, "Cache::cleanup", array(), true);
$this->schedule(20, array($this, "asyncOperationChecker"), array(), true);
}
public function checkTicks(){
if($this->getTPS() < 12){
console("[WARNING] Can't keep up! Is the server overloaded?");
}
}
public function checkMemory(){
$info = $this->debugInfo();
$data = $info["memory_usage"].",".$info["players"].",".$info["entities"];
$i = count($this->memoryStats) - 1;
if($i < 0 or $this->memoryStats[$i] !== $data){
$this->memoryStats[] = $data;
}
}
public function startDatabase(){ public function startDatabase(){
$this->preparedSQL = new stdClass(); $this->preparedSQL = new stdClass();
$this->preparedSQL->entity = new stdClass(); $this->preparedSQL->entity = new stdClass();
@ -184,33 +119,52 @@ class PocketMinecraftServer{
} }
public function query($sql, $fetch = false){ public function query($sql, $fetch = false){
$result = $this->database->query($sql) or console("[ERROR] [SQL Error] ".$this->database->lastErrorMsg().". Query: ".$sql, true, true, 0); $result = $this->database->query($sql) or console("[ERROR] [SQL Error] " . $this->database->lastErrorMsg() . ". Query: " . $sql, true, true, 0);
if($fetch === true and ($result instanceof SQLite3Result)){ if($fetch === true and ($result instanceof SQLite3Result)){
$result = $result->fetchArray(SQLITE3_ASSOC); $result = $result->fetchArray(SQLITE3_ASSOC);
} }
return $result; return $result;
} }
public function debugInfo($console = false){ public function setType($type = "normal"){
$info = array(); switch(trim(strtolower($type))){
$info["tps"] = $this->getTPS(); case "normal":
$info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2)."MB"; case "demo":
$info["memory_peak_usage"] = round((memory_get_peak_usage() / 1024) / 1024, 2)."MB"; $this->serverType = "MCCPP;Demo;";
$info["entities"] = $this->query("SELECT count(EID) as count FROM entities;", true); break;
$info["entities"] = $info["entities"]["count"]; case "minecon":
$info["players"] = $this->query("SELECT count(CID) as count FROM players;", true); $this->serverType = "MCCPP;MINECON;";
$info["players"] = $info["players"]["count"]; break;
$info["events"] = count($this->eventsID); }
$info["handlers"] = $this->query("SELECT count(ID) as count FROM handlers;", true);
$info["handlers"] = $info["handlers"]["count"]; }
$info["actions"] = $this->query("SELECT count(ID) as count FROM actions;", true);
$info["actions"] = $info["actions"]["count"]; public function titleTick(){
$info["garbage"] = gc_collect_cycles(); $time = microtime(true);
$this->handle("server.debug", $info); if(defined("DEBUG") and DEBUG >= 0 and ENABLE_ANSI === true){
if($console === true){ echo "\x1b]0;NostalgiaCore " . MAJOR_VERSION . " | Online " . count($this->clients) . "/" . $this->maxClients . " | RAM " . round((memory_get_usage() / 1024) / 1024, 2) . "MB | U " . round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " D " . round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " kB/s | TPS " . $this->getTPS() . "\x07";
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); }
$this->interface->bandwidth = [0, 0, $time];
}
/**
* @return float
*/
public function getTPS(){
$v = array_values($this->tickMeasure);
$divval = ($v[39] - $v[0]);
if($divval === 0){
return 0;
}
$tps = 40 / $divval;
return round($tps, 4);
}
public function checkTicks(){
if($this->getTPS() < 12){
console("[WARNING] Can't keep up! Is the server overloaded?");
} }
return $info;
} }
/** /**
@ -238,17 +192,18 @@ class PocketMinecraftServer{
} }
} }
public function setType($type = "normal"){ public function send2Discord($msg){
switch(trim(strtolower($type))){ if($this->extraprops->get("discord-msg") == true and $this->extraprops->get("discord-webhook-url") !== "none"){
case "normal": $url = $this->extraprops->get("discord-webhook-url");
case "demo": $name = $this->extraprops->get("discord-bot-name");
$this->serverType = "MCCPP;Demo;"; $this->asyncOperation(ASYNC_CURL_POST, [
break; "url" => $url,
case "minecon": "data" => [
$this->serverType = "MCCPP;MINECON;"; "username" => $name,
break; "content" => $this->extraprops->get("discord-ru-smiles") ? str_replace("@", " ", str_replace("Ы", "<:ru_cool:960113011383738369>", str_replace("Ь", "<:ru_cry:960112920346390548>", str_replace("Ъ", "<:ru_happy:960112868601237504>", $msg)))) : str_replace("@", "", $msg)
],
], null);
} }
} }
public function asyncOperation($type, array $data, callable $callable = null){ public function asyncOperation($type, array $data, callable $callable = null){
@ -259,13 +214,13 @@ class PocketMinecraftServer{
$type = (int) $type; $type = (int) $type;
switch($type){ switch($type){
case ASYNC_CURL_GET: case ASYNC_CURL_GET:
$d .= Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10)); $d .= Utils::writeShort(strlen($data["url"])) . $data["url"] . (isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
break; break;
case ASYNC_CURL_POST: case ASYNC_CURL_POST:
$d .= Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10)); $d .= Utils::writeShort(strlen($data["url"])) . $data["url"] . (isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
$d .= Utils::writeShort(count($data["data"])); $d .= Utils::writeShort(count($data["data"]));
foreach($data["data"] as $key => $value){ foreach($data["data"] as $key => $value){
$d .= Utils::writeShort(strlen($key)).$key . Utils::writeInt(strlen($value)).$value; $d .= Utils::writeShort(strlen($key)) . $key . Utils::writeInt(strlen($value)) . $value;
} }
break; break;
default: default:
@ -273,10 +228,47 @@ class PocketMinecraftServer{
} }
$ID = $this->asyncID++; $ID = $this->asyncID++;
$this->async[$ID] = $callable; $this->async[$ID] = $callable;
$this->asyncThread->input .= Utils::writeInt($ID).Utils::writeShort($type).$d; $this->asyncThread->input .= Utils::writeInt($ID) . Utils::writeShort($type) . $d;
return $ID; return $ID;
} }
public function trigger($event, $data = ""){
if(isset($this->events[$event])){
foreach($this->events[$event] as $evid => $ev){
if(!is_callable($ev)){
$this->deleteEvent($evid);
continue;
}
if(is_array($ev)){
$method = $ev[1];
$ev[0]->$method($data, $event);
}else{
$ev($data, $event);
}
}
}elseif(isset(Deprecation::$events[$event])){
$sub = "";
if(Deprecation::$events[$event] !== false){
$sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
}
console("[ERROR] Event \"$event\" has been deprecated.$sub [Trigger]");
}
}
public function deleteEvent($id){
$id = (int) $id;
if(isset($this->eventsID[$id])){
$ev = $this->eventsID[$id];
$this->eventsID[$id] = null;
unset($this->eventsID[$id]);
$this->events[$ev][$id] = null;
unset($this->events[$ev][$id]);
if(count($this->events[$ev]) === 0){
unset($this->events[$ev]);
}
}
}
public function asyncOperationChecker(){ public function asyncOperationChecker(){
if(defined("NO_THREADS")){ if(defined("NO_THREADS")){
return false; return false;
@ -287,7 +279,7 @@ class PocketMinecraftServer{
$offset += 4; $offset += 4;
$type = Utils::readShort(substr($this->asyncThread->output, $offset, 2)); $type = Utils::readShort(substr($this->asyncThread->output, $offset, 2));
$offset += 2; $offset += 2;
$data = array(); $data = [];
switch($type){ switch($type){
case ASYNC_CURL_GET: case ASYNC_CURL_GET:
case ASYNC_CURL_POST: case ASYNC_CURL_POST:
@ -297,6 +289,7 @@ class PocketMinecraftServer{
$offset += $len; $offset += $len;
break; break;
} }
$this->asyncThread->output = substr($this->asyncThread->output, $offset); $this->asyncThread->output = substr($this->asyncThread->output, $offset);
if(isset($this->async[$ID]) and $this->async[$ID] !== null and is_callable($this->async[$ID])){ if(isset($this->async[$ID]) and $this->async[$ID] !== null and is_callable($this->async[$ID])){
if(is_array($this->async[$ID])){ if(is_array($this->async[$ID])){
@ -317,21 +310,21 @@ class PocketMinecraftServer{
* *
* @return boolean * @return boolean
*/ */
public function addHandler($event,callable $callable, $priority = 5){ public function addHandler($event, callable $callable, $priority = 5){
if(!is_callable($callable)){ if(!is_callable($callable)){
return false; return false;
}elseif(isset(Deprecation::$events[$event])){ }elseif(isset(Deprecation::$events[$event])){
$sub = ""; $sub = "";
if(Deprecation::$events[$event] !== false){ if(Deprecation::$events[$event] !== false){
$sub = " Substitute \"".Deprecation::$events[$event]."\" found."; $sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
} }
console("[ERROR] Event \"$event\" has been deprecated.$sub [Adding handle to ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)."]"); console("[ERROR] Event \"$event\" has been deprecated.$sub [Adding handle to " . (is_array($callable) ? get_class($callable[0]) . "::" . $callable[1] : $callable) . "]");
} }
$priority = (int) $priority; $priority = (int) $priority;
$hnid = $this->handCnt++; $hnid = $this->handCnt++;
$this->handlers[$hnid] = $callable; $this->handlers[$hnid] = $callable;
$this->query("INSERT INTO handlers (ID, name, priority) VALUES (".$hnid.", '".str_replace("'", "\\'", $event)."', ".$priority.");"); $this->query("INSERT INTO handlers (ID, name, priority) VALUES (" . $hnid . ", '" . str_replace("'", "\\'", $event) . "', " . $priority . ");");
console("[INTERNAL] New handler ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)." to special event ".$event." (ID ".$hnid.")", true, true, 3); console("[INTERNAL] New handler " . (is_array($callable) ? get_class($callable[0]) . "::" . $callable[1] : $callable) . " to special event " . $event . " (ID " . $hnid . ")", true, true, 3);
return $hnid; return $hnid;
} }
@ -346,7 +339,7 @@ class PocketMinecraftServer{
$handlers = $this->preparedSQL->selectHandlers->execute(); $handlers = $this->preparedSQL->selectHandlers->execute();
$result = null; $result = null;
if($handlers instanceof SQLite3Result){ if($handlers instanceof SQLite3Result){
$call = array(); $call = [];
while(($hn = $handlers->fetchArray(SQLITE3_ASSOC)) !== false){ while(($hn = $handlers->fetchArray(SQLITE3_ASSOC)) !== false){
$call[(int) $hn["ID"]] = true; $call[(int) $hn["ID"]] = true;
} }
@ -368,7 +361,7 @@ class PocketMinecraftServer{
}elseif(isset(Deprecation::$events[$event])){ }elseif(isset(Deprecation::$events[$event])){
$sub = ""; $sub = "";
if(Deprecation::$events[$event] !== false){ if(Deprecation::$events[$event] !== false){
$sub = " Substitute \"".Deprecation::$events[$event]."\" found."; $sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
} }
console("[ERROR] Event \"$event\" has been deprecated.$sub [Handler]"); console("[ERROR] Event \"$event\" has been deprecated.$sub [Handler]");
} }
@ -385,6 +378,45 @@ class PocketMinecraftServer{
} }
} }
public function init(){
register_tick_function([$this, "tick"]);
declare(ticks=5000); //Minimum TPS for main thread locks
$this->loadEvents();
register_shutdown_function([$this, "dumpError"]);
register_shutdown_function([$this, "close"]);
if(function_exists("pcntl_signal")){
pcntl_signal(SIGTERM, [$this, "close"]);
pcntl_signal(SIGINT, [$this, "close"]);
pcntl_signal(SIGHUP, [$this, "close"]);
}
console("[INFO] Default game type: " . strtoupper($this->getGamemode()));
$this->trigger("server.start", microtime(true));
console('[INFO] Done (' . round(microtime(true) - START_TIME, 3) . 's)! For help, type "help" or "?"');
$this->process();
}
public function loadEvents(){
if(ENABLE_ANSI === true){
$this->schedule(30, [$this, "titleTick"], [], true);
}
$this->schedule(20 * 15, [$this, "checkTicks"], [], true);
$this->schedule(20 * 60, [$this, "checkMemory"], [], true);
$this->schedule(20 * 45, "Cache::cleanup", [], true);
$this->schedule(20, [$this, "asyncOperationChecker"], [], true);
}
public function schedule($ticks, callable $callback, $data = [], $repeat = false, $eventName = "server.schedule"){
if(!is_callable($callback)){
return false;
}
$chcnt = $this->scheduleCnt++;
$this->schedule[$chcnt] = [$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;
}
/** /**
* @return string * @return string
*/ */
@ -401,125 +433,29 @@ class PocketMinecraftServer{
} }
} }
public function process(){
$lastLoop = 0;
public function init(){ while($this->stop === false){
register_tick_function(array($this, "tick")); $packet = $this->interface->readPacket();
declare(ticks=5000); //Minimum TPS for main thread locks if($packet instanceof Packet){
$this->packetHandler($packet);
$this->loadEvents(); $lastLoop = 0;
register_shutdown_function(array($this, "dumpError")); }elseif($this->tick() > 0){
register_shutdown_function(array($this, "close")); $lastLoop = 0;
if(function_exists("pcntl_signal")){ }else{
pcntl_signal(SIGTERM, array($this, "close")); ++$lastLoop;
pcntl_signal(SIGINT, array($this, "close")); if($lastLoop < 16){
pcntl_signal(SIGHUP, array($this, "close")); usleep(1);
}elseif($lastLoop < 128){
usleep(100);
}elseif($lastLoop < 256){
usleep(512);
}else{
usleep(10000);
} }
console("[INFO] Default game type: ".strtoupper($this->getGamemode()));
$this->trigger("server.start", microtime(true));
console('[INFO] Done ('.round(microtime(true) - START_TIME, 3).'s)! For help, type "help" or "?"');
$this->process();
} }
$this->tick();
public function dumpError(){
if($this->stop === true){
return;
} }
ini_set("memory_limit", "-1"); //Fix error dump not dumped on memory problems
console("[SEVERE] An unrecovereable has ocurred and the server has crashed. Creating an error dump");
$dump = "```\r\n# NostalgiaCore Error Dump ".date("D M j H:i:s T Y")."\r\n";
$er = error_get_last();
$errorConversion = array(
E_ERROR => "E_ERROR",
E_WARNING => "E_WARNING",
E_PARSE => "E_PARSE",
E_NOTICE => "E_NOTICE",
E_CORE_ERROR => "E_CORE_ERROR",
E_CORE_WARNING => "E_CORE_WARNING",
E_COMPILE_ERROR => "E_COMPILE_ERROR",
E_COMPILE_WARNING => "E_COMPILE_WARNING",
E_USER_ERROR => "E_USER_ERROR",
E_USER_WARNING => "E_USER_WARNING",
E_USER_NOTICE => "E_USER_NOTICE",
E_STRICT => "E_STRICT",
E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR",
E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED",
);
$er["type"] = isset($errorConversion[$er["type"]]) ? $errorConversion[$er["type"]]:$er["type"];
$dump .= "Error: ".var_export($er, true)."\r\n\r\n";
if(stripos($er["file"], "plugin") !== false){
$dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n";
}
$dump .= "Code: \r\n";
$file = @file($er["file"], FILE_IGNORE_NEW_LINES);
for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l){
$dump .= "[".($l + 1)."] ".@$file[$l]."\r\n";
}
$dump .= "\r\n\r\n";
$dump .= "Backtrace: \r\n";
foreach(getTrace() as $line){
$dump .= "$line\r\n";
}
$dump .= "\r\n\r\n";
$version = new VersionString();
$dump .= "NostalgiaCore version: ".$version." #".$version->getNumber()." [Protocol ".ProtocolInfo::CURRENT_PROTOCOL."; API ".CURRENT_API_VERSION."]\r\n";
$dump .= "Git commit: ".GIT_COMMIT."\r\n";
$dump .= "Source SHA1 sum: ".SOURCE_SHA1SUM."\r\n";
$dump .= "uname -a: ".php_uname("a")."\r\n";
$dump .= "PHP Version: " .phpversion()."\r\n";
$dump .= "Zend version: ".zend_version()."\r\n";
$dump .= "OS : " .PHP_OS.", ".Utils::getOS()."\r\n";
$dump .= "Debug Info: ".var_export($this->debugInfo(false), true)."\r\n\r\n\r\n";
global $arguments;
$dump .= "Parameters: ".var_export($arguments, true)."\r\n\r\n\r\n";
$p = $this->api->getProperties();
if($p["rcon.password"] != ""){
$p["rcon.password"] = "******";
}
$dump .= "server.properties: ".var_export($p, true)."\r\n\r\n\r\n";
if($this->api->plugin instanceof PluginAPI){
$plist = $this->api->plugin->getList();
$dump .= "Loaded plugins:\r\n";
foreach($plist as $p){
$dump .= $p["name"]." ".$p["version"]." by ".$p["author"]."\r\n";
}
$dump .= "\r\n\r\n";
}
$extensions = array();
foreach(get_loaded_extensions() as $ext){
$extensions[$ext] = phpversion($ext);
}
$dump .= "Loaded Modules: ".var_export($extensions, true)."\r\n";
$this->checkMemory();
$dump .= "Memory Usage Tracking: \r\n".chunk_split(base64_encode(gzdeflate(implode(";", $this->memoryStats), 9)))."\r\n";
ob_start();
phpinfo();
$dump .= "\r\nphpinfo(): \r\n".chunk_split(base64_encode(gzdeflate(ob_get_contents(), 9)))."\r\n";
ob_end_clean();
$dump .= "\r\n```";
$name = "Error_Dump_".date("D_M_j-H.i.s-T_Y");
logg($dump, $name, true, 0, true);
console("[SEVERE] Please submit the \"{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0);
}
public function tick(){
$time = microtime(true);
if($this->lastTick <= ($time - 0.05)){
$this->tickMeasure[] = $this->lastTick = $time;
unset($this->tickMeasure[key($this->tickMeasure)]);
++$this->ticks;
return $this->tickerFunction($time);
}
return 0;
}
public static function clientID($ip, $port){
return crc32($ip . $port) ^ crc32($port . $ip . BOOTUP_RANDOM);
//return $ip . ":" . $port;
} }
public function packetHandler(Packet $packet){ public function packetHandler(Packet $packet){
@ -528,7 +464,7 @@ class PocketMinecraftServer{
if(isset($this->clients[$CID])){ if(isset($this->clients[$CID])){
$this->clients[$CID]->handlePacket($packet); $this->clients[$CID]->handlePacket($packet);
}else{ }else{
if($this->handle("server.noauthpacket.".$packet->pid(), $packet) === false){ if($this->handle("server.noauthpacket." . $packet->pid(), $packet) === false){
return; return;
} }
switch($packet->pid()){ switch($packet->pid()){
@ -544,27 +480,27 @@ class PocketMinecraftServer{
$this->send($pk); $this->send($pk);
break; break;
} }
if(!isset($this->custom["times_".$CID])){ if(!isset($this->custom["times_" . $CID])){
$this->custom["times_".$CID] = 0; $this->custom["times_" . $CID] = 0;
} }
$ln = 15; $ln = 15;
if($this->description == "" or substr($this->description, -1) != " "){ if($this->description == "" or substr($this->description, -1) != " "){
$this->description .= " "; $this->description .= " ";
} }
$txt = substr($this->description, $this->custom["times_".$CID], $ln); $txt = substr($this->description, $this->custom["times_" . $CID], $ln);
$txt .= substr($this->description, 0, $ln - strlen($txt)); $txt .= substr($this->description, 0, $ln - strlen($txt));
$pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG); $pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
$pk->pingID = $packet->pingID; $pk->pingID = $packet->pingID;
$pk->serverID = $this->serverID; $pk->serverID = $this->serverID;
$pk->serverType = $this->serverType . $this->name . " [".count($this->clients)."/".$this->maxClients."] ".$txt; $pk->serverType = $this->serverType . $this->name . " [" . count($this->clients) . "/" . $this->maxClients . "] " . $txt;
$pk->ip = $packet->ip; $pk->ip = $packet->ip;
$pk->port = $packet->port; $pk->port = $packet->port;
$this->send($pk); $this->send($pk);
$this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description); $this->custom["times_" . $CID] = ($this->custom["times_" . $CID] + 1) % strlen($this->description);
break; break;
case RakNetInfo::OPEN_CONNECTION_REQUEST_1: case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
if($packet->structure !== RakNetInfo::STRUCTURE){ if($packet->structure !== RakNetInfo::STRUCTURE){
console("[DEBUG] Incorrect structure #".$packet->structure." from ".$packet->ip.":".$packet->port, true, true, 2); console("[DEBUG] Incorrect structure #" . $packet->structure . " from " . $packet->ip . ":" . $packet->port, true, true, 2);
$pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION); $pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION);
$pk->serverID = $this->serverID; $pk->serverID = $this->serverID;
$pk->ip = $packet->ip; $pk->ip = $packet->ip;
@ -597,66 +533,24 @@ class PocketMinecraftServer{
} }
} }
public static function clientID($ip, $port){
return crc32($ip . $port) ^ crc32($port . $ip . BOOTUP_RANDOM);
//return $ip . ":" . $port;
}
public function send(Packet $packet){ public function send(Packet $packet){
return $this->interface->writePacket($packet); return $this->interface->writePacket($packet);
} }
public function process(){ public function tick(){
$lastLoop = 0; $time = microtime(true);
while($this->stop === false){ if($this->lastTick <= ($time - 0.05)){
$packet = $this->interface->readPacket(); $this->tickMeasure[] = $this->lastTick = $time;
if($packet instanceof Packet){ unset($this->tickMeasure[key($this->tickMeasure)]);
$this->packetHandler($packet); ++$this->ticks;
$lastLoop = 0; return $this->tickerFunction($time);
}elseif($this->tick() > 0){
$lastLoop = 0;
}else{
++$lastLoop;
if($lastLoop < 16){
usleep(1);
}elseif($lastLoop < 128){
usleep(100);
}elseif($lastLoop < 256){
usleep(512);
}else{
usleep(10000);
} }
} return 0;
$this->tick();
}
}
public function trigger($event, $data = ""){
if(isset($this->events[$event])){
foreach($this->events[$event] as $evid => $ev){
if(!is_callable($ev)){
$this->deleteEvent($evid);
continue;
}
if(is_array($ev)){
$method = $ev[1];
$ev[0]->$method($data, $event);
}else{
$ev($data, $event);
}
}
}elseif(isset(Deprecation::$events[$event])){
$sub = "";
if(Deprecation::$events[$event] !== false){
$sub = " Substitute \"".Deprecation::$events[$event]."\" found.";
}
console("[ERROR] Event \"$event\" has been deprecated.$sub [Trigger]");
}
}
public function schedule($ticks, callable $callback, $data = array(), $repeat = false, $eventName = "server.schedule"){
if(!is_callable($callback)){
return false;
}
$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;
} }
public function tickerFunction($time){ public function tickerFunction($time){
@ -681,7 +575,7 @@ class PocketMinecraftServer{
} }
if($action["repeat"] == 0 or $return === false){ if($action["repeat"] == 0 or $return === false){
$this->query("DELETE FROM actions WHERE ID = ".$action["ID"].";"); $this->query("DELETE FROM actions WHERE ID = " . $action["ID"] . ";");
$this->schedule[$cid] = null; $this->schedule[$cid] = null;
unset($this->schedule[$cid]); unset($this->schedule[$cid]);
} }
@ -691,51 +585,139 @@ class PocketMinecraftServer{
return $actionCount; return $actionCount;
} }
public function event($event,callable $func){ public function dumpError(){
if($this->stop === true){
return;
}
ini_set("memory_limit", "-1"); //Fix error dump not dumped on memory problems
console("[SEVERE] An unrecovereable has ocurred and the server has crashed. Creating an error dump");
$dump = "```\r\n# NostalgiaCore Error Dump " . date("D M j H:i:s T Y") . "\r\n";
$er = error_get_last();
$errorConversion = [
E_ERROR => "E_ERROR",
E_WARNING => "E_WARNING",
E_PARSE => "E_PARSE",
E_NOTICE => "E_NOTICE",
E_CORE_ERROR => "E_CORE_ERROR",
E_CORE_WARNING => "E_CORE_WARNING",
E_COMPILE_ERROR => "E_COMPILE_ERROR",
E_COMPILE_WARNING => "E_COMPILE_WARNING",
E_USER_ERROR => "E_USER_ERROR",
E_USER_WARNING => "E_USER_WARNING",
E_USER_NOTICE => "E_USER_NOTICE",
E_STRICT => "E_STRICT",
E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR",
E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED",
];
$er["type"] = isset($errorConversion[$er["type"]]) ? $errorConversion[$er["type"]] : $er["type"];
$dump .= "Error: " . var_export($er, true) . "\r\n\r\n";
if(stripos($er["file"], "plugin") !== false){
$dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n";
}
$dump .= "Code: \r\n";
$file = @file($er["file"], FILE_IGNORE_NEW_LINES);
for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l){
$dump .= "[" . ($l + 1) . "] " . @$file[$l] . "\r\n";
}
$dump .= "\r\n\r\n";
$dump .= "Backtrace: \r\n";
foreach(getTrace() as $line){
$dump .= "$line\r\n";
}
$dump .= "\r\n\r\n";
$version = new VersionString();
$dump .= "NostalgiaCore version: " . $version . " #" . $version->getNumber() . " [Protocol " . ProtocolInfo::CURRENT_PROTOCOL . "; API " . CURRENT_API_VERSION . "]\r\n";
$dump .= "Git commit: " . GIT_COMMIT . "\r\n";
$dump .= "Source SHA1 sum: " . SOURCE_SHA1SUM . "\r\n";
$dump .= "uname -a: " . php_uname("a") . "\r\n";
$dump .= "PHP Version: " . phpversion() . "\r\n";
$dump .= "Zend version: " . zend_version() . "\r\n";
$dump .= "OS : " . PHP_OS . ", " . Utils::getOS() . "\r\n";
$dump .= "Debug Info: " . var_export($this->debugInfo(false), true) . "\r\n\r\n\r\n";
global $arguments;
$dump .= "Parameters: " . var_export($arguments, true) . "\r\n\r\n\r\n";
$p = $this->api->getProperties();
if($p["rcon.password"] != ""){
$p["rcon.password"] = "******";
}
$dump .= "server.properties: " . var_export($p, true) . "\r\n\r\n\r\n";
if($this->api->plugin instanceof PluginAPI){
$plist = $this->api->plugin->getList();
$dump .= "Loaded plugins:\r\n";
foreach($plist as $p){
$dump .= $p["name"] . " " . $p["version"] . " by " . $p["author"] . "\r\n";
}
$dump .= "\r\n\r\n";
}
$extensions = [];
foreach(get_loaded_extensions() as $ext){
$extensions[$ext] = phpversion($ext);
}
$dump .= "Loaded Modules: " . var_export($extensions, true) . "\r\n";
$this->checkMemory();
$dump .= "Memory Usage Tracking: \r\n" . chunk_split(base64_encode(gzdeflate(implode(";", $this->memoryStats), 9))) . "\r\n";
ob_start();
phpinfo();
$dump .= "\r\nphpinfo(): \r\n" . chunk_split(base64_encode(gzdeflate(ob_get_contents(), 9))) . "\r\n";
ob_end_clean();
$dump .= "\r\n```";
$name = "Error_Dump_" . date("D_M_j-H.i.s-T_Y");
logg($dump, $name, true, 0, true);
console("[SEVERE] Please submit the \"{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0);
}
public function debugInfo($console = false){
$info = [];
$info["tps"] = $this->getTPS();
$info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2) . "MB";
$info["memory_peak_usage"] = round((memory_get_peak_usage() / 1024) / 1024, 2) . "MB";
$info["entities"] = $this->query("SELECT count(EID) as count FROM entities;", true);
$info["entities"] = $info["entities"]["count"];
$info["players"] = $this->query("SELECT count(CID) as count FROM players;", true);
$info["players"] = $info["players"]["count"];
$info["events"] = count($this->eventsID);
$info["handlers"] = $this->query("SELECT count(ID) as count FROM handlers;", true);
$info["handlers"] = $info["handlers"]["count"];
$info["actions"] = $this->query("SELECT count(ID) as count FROM actions;", true);
$info["actions"] = $info["actions"]["count"];
$info["garbage"] = gc_collect_cycles();
$this->handle("server.debug", $info);
if($console === true){
console("[DEBUG] TPS: " . $info["tps"] . ", Memory usage: " . $info["memory_usage"] . " (Peak " . $info["memory_peak_usage"] . "), Entities: " . $info["entities"] . ", Events: " . $info["events"] . ", Handlers: " . $info["handlers"] . ", Actions: " . $info["actions"] . ", Garbage: " . $info["garbage"], true, true, 2);
}
return $info;
}
public function checkMemory(){
$info = $this->debugInfo();
$data = $info["memory_usage"] . "," . $info["players"] . "," . $info["entities"];
$i = count($this->memoryStats) - 1;
if($i < 0 or $this->memoryStats[$i] !== $data){
$this->memoryStats[] = $data;
}
}
public function event($event, callable $func){
if(!is_callable($func)){ if(!is_callable($func)){
return false; return false;
}elseif(isset(Deprecation::$events[$event])){ }elseif(isset(Deprecation::$events[$event])){
$sub = ""; $sub = "";
if(Deprecation::$events[$event] !== false){ if(Deprecation::$events[$event] !== false){
$sub = " Substitute \"".Deprecation::$events[$event]."\" found."; $sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
} }
console("[ERROR] Event \"$event\" has been deprecated.$sub [Attach to ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)."]"); console("[ERROR] Event \"$event\" has been deprecated.$sub [Attach to " . (is_array($func) ? get_class($func[0]) . "::" . $func[1] : $func) . "]");
} }
$evid = $this->evCnt++; $evid = $this->evCnt++;
if(!isset($this->events[$event])){ if(!isset($this->events[$event])){
$this->events[$event] = array(); $this->events[$event] = [];
} }
$this->events[$event][$evid] = $func; $this->events[$event][$evid] = $func;
$this->eventsID[$evid] = $event; $this->eventsID[$evid] = $event;
console("[INTERNAL] Attached ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)." to event ".$event." (ID ".$evid.")", true, true, 3); console("[INTERNAL] Attached " . (is_array($func) ? get_class($func[0]) . "::" . $func[1] : $func) . " to event " . $event . " (ID " . $evid . ")", true, true, 3);
return $evid; return $evid;
} }
public function deleteEvent($id){
$id = (int) $id;
if(isset($this->eventsID[$id])){
$ev = $this->eventsID[$id];
$this->eventsID[$id] = null;
unset($this->eventsID[$id]);
$this->events[$ev][$id] = null;
unset($this->events[$ev][$id]);
if(count($this->events[$ev]) === 0){
unset($this->events[$ev]);
}
}
}
public function send2Discord($msg){
if($this->extraprops->get("discord-msg") == true and $this->extraprops->get("discord-webhook-url") !== "none"){
$url = $this->extraprops->get("discord-webhook-url");
$name = $this->extraprops->get("discord-bot-name");
$this->asyncOperation(ASYNC_CURL_POST, array(
"url" => $url,
"data" => array(
"username" => $name,
"content" => $this->extraprops->get("discord-ru-smiles") ? str_replace("@", " ", str_replace("Ы", "<:ru_cool:960113011383738369>", str_replace("Ь", "<:ru_cry:960112920346390548>", str_replace("Ъ","<:ru_happy:960112868601237504>", $msg)))) : str_replace("@", "", $msg)
),
), NULL);
}
}
} }

View file

@ -1,29 +1,10 @@
<?php <?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/
*
*
*/
set_time_limit(0); set_time_limit(0);
if(ini_get("date.timezone") == ""){ //No Timezone set if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set("GMT"); date_default_timezone_set("GMT");
if(strpos(" ".strtoupper(php_uname("s")), " WIN") !== false){ if(strpos(" " . strtoupper(php_uname("s")), " WIN") !== false){
$time = time(); $time = time();
$time -= $time % 60; $time -= $time % 60;
//TODO: Parse different time & date formats by region. ¬¬ world //TODO: Parse different time & date formats by region. ¬¬ world
@ -58,9 +39,9 @@ ini_set("display_errors", 1);
ini_set("display_startup_errors", 1); ini_set("display_startup_errors", 1);
ini_set("default_charset", "utf-8"); ini_set("default_charset", "utf-8");
if(defined("POCKETMINE_COMPILE") and POCKETMINE_COMPILE === true){ if(defined("POCKETMINE_COMPILE") and POCKETMINE_COMPILE === true){
define("FILE_PATH", realpath(dirname(__FILE__))."/"); define("FILE_PATH", realpath(dirname(__FILE__)) . "/");
}else{ }else{
define("FILE_PATH", realpath(dirname(__FILE__)."/../")."/"); define("FILE_PATH", realpath(dirname(__FILE__) . "/../") . "/");
} }
set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH); set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH);
@ -73,8 +54,8 @@ define("CURRENT_MINECRAFT_VERSION", "v0.8.1 alpha");
define("CURRENT_API_VERSION", '12.1'); define("CURRENT_API_VERSION", '12.1');
define("CURRENT_PHP_VERSION", "5.5"); define("CURRENT_PHP_VERSION", "5.5");
$gitsha1 = false; $gitsha1 = false;
if(file_exists(FILE_PATH.".git/refs/heads/master")){ //Found Git information! if(file_exists(FILE_PATH . ".git/refs/heads/master")){ //Found Git information!
define("GIT_COMMIT", strtolower(trim(file_get_contents(FILE_PATH.".git/refs/heads/master")))); define("GIT_COMMIT", strtolower(trim(file_get_contents(FILE_PATH . ".git/refs/heads/master"))));
}else{ //Unknown :( }else{ //Unknown :(
define("GIT_COMMIT", str_repeat("00", 20)); define("GIT_COMMIT", str_repeat("00", 20));
} }

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
define("AIR", 0); define("AIR", 0);
define("STONE", 1); define("STONE", 1);
define("GRASS", 2); define("GRASS", 2);

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
//Entities //Entities
define("ENTITY_PLAYER", 1); define("ENTITY_PLAYER", 1);

View file

@ -1,25 +1,5 @@
<?php <?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/
*
*
*/
define("PMF_LEVEL_DEFLATE_LEVEL", 6); define("PMF_LEVEL_DEFLATE_LEVEL", 6);
//Gamemodes //Gamemodes
@ -30,7 +10,6 @@ define("VIEW", 3);
define("VIEWER", 3); define("VIEWER", 3);
define("SPECTATOR", 3); define("SPECTATOR", 3);
//Players //Players
define("MAX_CHUNK_RATE", 20 / arg("max-chunks-per-second", 4)); //Default rate ~256 kB/s define("MAX_CHUNK_RATE", 20 / arg("max-chunks-per-second", 4)); //Default rate ~256 kB/s
define("PLAYER_MAX_QUEUE", 1024); define("PLAYER_MAX_QUEUE", 1024);
@ -38,7 +17,6 @@ define("PLAYER_MAX_QUEUE", 1024);
define("PLAYER_SURVIVAL_SLOTS", 36); define("PLAYER_SURVIVAL_SLOTS", 36);
define("PLAYER_CREATIVE_SLOTS", 112); define("PLAYER_CREATIVE_SLOTS", 112);
//Block Updates //Block Updates
define("BLOCK_UPDATE_NORMAL", 1); define("BLOCK_UPDATE_NORMAL", 1);
define("BLOCK_UPDATE_RANDOM", 2); define("BLOCK_UPDATE_RANDOM", 2);

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
define("IRON_SHOVEL", 256); define("IRON_SHOVEL", 256);
define("IRON_PICKAXE", 257); define("IRON_PICKAXE", 257);
define("IRON_AXE", 258); define("IRON_AXE", 258);

View file

@ -1,32 +1,13 @@
<?php <?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***/ /***REM_START***/
require_once(dirname(__FILE__)."/config.php"); require_once(dirname(__FILE__) . "/config.php");
require_once(FILE_PATH."/src/utils/TextFormat.php"); require_once(FILE_PATH . "/src/utils/TextFormat.php");
require_once(FILE_PATH."/src/functions.php"); require_once(FILE_PATH . "/src/functions.php");
/***REM_END***/ /***REM_END***/
define("DATA_PATH", realpath(arg("data-path", FILE_PATH))."/"); define("DATA_PATH", realpath(arg("data-path", FILE_PATH)) . "/");
if(arg("enable-ansi", strpos(strtoupper(php_uname("s")), "WIN") === 0 ? false:true) === true and arg("disable-ansi", false) !== true){ if(arg("enable-ansi", strpos(strtoupper(php_uname("s")), "WIN") === 0 ? false : true) === true and arg("disable-ansi", false) !== true){
define("ENABLE_ANSI", true); define("ENABLE_ANSI", true);
}else{ }else{
define("ENABLE_ANSI", false); define("ENABLE_ANSI", false);
@ -46,12 +27,12 @@ if(php_sapi_name() !== "cli"){
++$errors; ++$errors;
} }
if(!extension_loaded("sockets") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "sockets." . PHP_SHLIB_SUFFIX) === false){ if(!extension_loaded("sockets") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_" : "") . "sockets." . PHP_SHLIB_SUFFIX) === false){
console("[ERROR] Unable to find the Socket extension.", true, true, 0); console("[ERROR] Unable to find the Socket extension.", true, true, 0);
++$errors; ++$errors;
} }
if(!extension_loaded("pthreads") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "pthreads." . PHP_SHLIB_SUFFIX) === false){ if(!extension_loaded("pthreads") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_" : "") . "pthreads." . PHP_SHLIB_SUFFIX) === false){
console("[ERROR] Unable to find the pthreads extension.", true, true, 0); console("[ERROR] Unable to find the pthreads extension.", true, true, 0);
++$errors; ++$errors;
}else{ }else{
@ -65,22 +46,22 @@ if(!extension_loaded("pthreads") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":""
} }
} }
if(!extension_loaded("curl") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "curl." . PHP_SHLIB_SUFFIX) === false){ if(!extension_loaded("curl") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_" : "") . "curl." . PHP_SHLIB_SUFFIX) === false){
console("[ERROR] Unable to find the cURL extension.", true, true, 0); console("[ERROR] Unable to find the cURL extension.", true, true, 0);
++$errors; ++$errors;
} }
if(!extension_loaded("sqlite3") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "sqlite3." . PHP_SHLIB_SUFFIX) === false){ if(!extension_loaded("sqlite3") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_" : "") . "sqlite3." . PHP_SHLIB_SUFFIX) === false){
console("[ERROR] Unable to find the SQLite3 extension.", true, true, 0); console("[ERROR] Unable to find the SQLite3 extension.", true, true, 0);
++$errors; ++$errors;
} }
if(!extension_loaded("yaml") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "yaml." . PHP_SHLIB_SUFFIX) === false){ if(!extension_loaded("yaml") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_" : "") . "yaml." . PHP_SHLIB_SUFFIX) === false){
console("[ERROR] Unable to find the YAML extension.", true, true, 0); console("[ERROR] Unable to find the YAML extension.", true, true, 0);
++$errors; ++$errors;
} }
if(!extension_loaded("zlib") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "zlib." . PHP_SHLIB_SUFFIX) === false){ if(!extension_loaded("zlib") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_" : "") . "zlib." . PHP_SHLIB_SUFFIX) === false){
console("[ERROR] Unable to find the Zlib extension.", true, true, 0); console("[ERROR] Unable to find the Zlib extension.", true, true, 0);
++$errors; ++$errors;
} }
@ -92,22 +73,22 @@ if($errors > 0){
$sha1sum = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; $sha1sum = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
/***REM_START***/ /***REM_START***/
require_once(FILE_PATH."/src/math/Vector3.php"); require_once(FILE_PATH . "/src/math/Vector3.php");
require_once(FILE_PATH."/src/world/Position.php"); require_once(FILE_PATH . "/src/world/Position.php");
require_once(FILE_PATH."/src/pmf/PMF.php"); require_once(FILE_PATH . "/src/pmf/PMF.php");
require_once(FILE_PATH."/src/entity/Entity.php"); require_once(FILE_PATH . "/src/entity/Entity.php");
require_once(FILE_PATH."/src/entity/Damageable.php"); require_once(FILE_PATH . "/src/entity/Damageable.php");
require_once(FILE_PATH."/src/entity/Breedable.php"); require_once(FILE_PATH . "/src/entity/Breedable.php");
require_once(FILE_PATH."/src/entity/Living.php"); require_once(FILE_PATH . "/src/entity/Living.php");
require_once(FILE_PATH."/src/entity/Creature.php"); require_once(FILE_PATH . "/src/entity/Creature.php");
require_once(FILE_PATH."/src/entity/Ageable.php"); require_once(FILE_PATH . "/src/entity/Ageable.php");
require_once(FILE_PATH."/src/entity/Animal.php"); require_once(FILE_PATH . "/src/entity/Animal.php");
require_all(FILE_PATH . "src/"); require_all(FILE_PATH . "src/");
$inc = get_included_files(); $inc = get_included_files();
$inc[] = array_shift($inc); $inc[] = array_shift($inc);
$srcdir = realpath(FILE_PATH."src/"); $srcdir = realpath(FILE_PATH . "src/");
foreach($inc as $s){ foreach($inc as $s){
if(strpos(realpath(dirname($s)), $srcdir) === false and strtolower(basename($s)) !== "pocketmine-mp.php"){ if(strpos(realpath(dirname($s)), $srcdir) === false and strtolower(basename($s)) !== "pocketmine-mp.php"){
continue; continue;
@ -119,7 +100,7 @@ ini_set("opcache.mmap_base", bin2hex(Utils::getRandomBytes(8, false))); //Fix OP
define("SOURCE_SHA1SUM", bin2hex($sha1sum)); define("SOURCE_SHA1SUM", bin2hex($sha1sum));
/***REM_START***/ /***REM_START***/
if(!file_exists(DATA_PATH."server.properties") and arg("no-wizard", false) != true){ if(!file_exists(DATA_PATH . "server.properties") and arg("no-wizard", false) != true){
$installer = new Installer(); $installer = new Installer();
} }
/***REM_END***/ /***REM_END***/

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class Entity extends Position{ class Entity extends Position{
const TYPE = -1; const TYPE = -1;
const CLASS_TYPE = -1; const CLASS_TYPE = -1;

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
/** /**
* Events that can be cancelled must use the interface CancellableEvent * Events that can be cancelled must use the interface CancellableEvent
*/ */

View file

@ -1,24 +1,5 @@
<?php <?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 EventHandler{ abstract class EventHandler{
public static function callEvent(BaseEvent $event){ public static function callEvent(BaseEvent $event){

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
/** /**
* Plugins that create events must use this class as the base * Plugins that create events must use this class as the base

View file

@ -1,28 +1,9 @@
<?php <?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/
*
*
*/
if(!function_exists("cli_set_process_title")){ if(!function_exists("cli_set_process_title")){
function cli_set_process_title($title){ function cli_set_process_title($title){
if(ENABLE_ANSI === true){ if(ENABLE_ANSI === true){
echo "\x1b]0;".$title."\x07"; echo "\x1b]0;" . $title . "\x07";
return true; return true;
}else{ }else{
return false; return false;
@ -37,33 +18,33 @@ function dummy(){
function safe_var_dump($var, $cnt = 0){ function safe_var_dump($var, $cnt = 0){
switch(true){ switch(true){
case is_array($var): case is_array($var):
echo str_repeat(" ", $cnt)."array(".count($var).") {".PHP_EOL; echo str_repeat(" ", $cnt) . "array(" . count($var) . ") {" . PHP_EOL;
foreach($var as $key => $value){ foreach($var as $key => $value){
echo str_repeat(" ", $cnt + 1)."[".(is_integer($key) ? $key:'"'.$key.'"')."]=>".PHP_EOL; echo str_repeat(" ", $cnt + 1) . "[" . (is_integer($key) ? $key : '"' . $key . '"') . "]=>" . PHP_EOL;
safe_var_dump($value, $cnt + 1); safe_var_dump($value, $cnt + 1);
} }
echo str_repeat(" ", $cnt)."}".PHP_EOL; echo str_repeat(" ", $cnt) . "}" . PHP_EOL;
break; break;
case is_integer($var): case is_integer($var):
echo str_repeat(" ", $cnt)."int(".$var.")".PHP_EOL; echo str_repeat(" ", $cnt) . "int(" . $var . ")" . PHP_EOL;
break; break;
case is_float($var): case is_float($var):
echo str_repeat(" ", $cnt)."float(".$var.")".PHP_EOL; echo str_repeat(" ", $cnt) . "float(" . $var . ")" . PHP_EOL;
break; break;
case is_bool($var): case is_bool($var):
echo str_repeat(" ", $cnt)."bool(".($var === true ? "true":"false").")".PHP_EOL; echo str_repeat(" ", $cnt) . "bool(" . ($var === true ? "true" : "false") . ")" . PHP_EOL;
break; break;
case is_string($var): case is_string($var):
echo str_repeat(" ", $cnt)."string(".strlen($var).") \"$var\"".PHP_EOL; echo str_repeat(" ", $cnt) . "string(" . strlen($var) . ") \"$var\"" . PHP_EOL;
break; break;
case is_resource($var): case is_resource($var):
echo str_repeat(" ", $cnt)."resource() of type (".get_resource_type($var).")".PHP_EOL; echo str_repeat(" ", $cnt) . "resource() of type (" . get_resource_type($var) . ")" . PHP_EOL;
break; break;
case is_object($var): case is_object($var):
echo str_repeat(" ", $cnt)."object(".get_class($var).")".PHP_EOL; echo str_repeat(" ", $cnt) . "object(" . get_class($var) . ")" . PHP_EOL;
break; break;
case is_null($var): case is_null($var):
echo str_repeat(" ", $cnt)."NULL".PHP_EOL; echo str_repeat(" ", $cnt) . "NULL" . PHP_EOL;
break; break;
} }
} }
@ -71,26 +52,26 @@ function safe_var_dump($var, $cnt = 0){
function kill($pid){ function kill($pid){
switch(Utils::getOS()){ switch(Utils::getOS()){
case "win": case "win":
exec("taskkill.exe /F /PID ".((int) $pid)." > NUL"); exec("taskkill.exe /F /PID " . ((int) $pid) . " > NUL");
break; break;
case "mac": case "mac":
case "linux": case "linux":
default: default:
exec("kill -9 ".((int) $pid)." > /dev/null 2>&1"); exec("kill -9 " . ((int) $pid) . " > /dev/null 2>&1");
} }
} }
function require_all($path, &$count = 0){ function require_all($path, &$count = 0){
$dir = dir($path."/"); $dir = dir($path . "/");
$dirs = array(); $dirs = [];
while(false !== ($file = $dir->read())){ while(false !== ($file = $dir->read())){
if($file !== "." and $file !== ".."){ if($file !== "." and $file !== ".."){
if(!is_dir($path.$file) and strtolower(substr($file, -3)) === "php"){ if(!is_dir($path . $file) and strtolower(substr($file, -3)) === "php"){
require_once($path.$file); require_once($path . $file);
++$count; ++$count;
}elseif(is_dir($path.$file)){ }elseif(is_dir($path . $file)){
$dirs[] = $path.$file."/"; $dirs[] = $path . $file . "/";
} }
} }
} }
@ -135,29 +116,29 @@ function arg($name, $default = false){
} }
} }
function arguments ( $args ){ function arguments($args){
if(!is_array($args)){ if(!is_array($args)){
$args = array(); $args = [];
} }
array_shift( $args ); array_shift($args);
$args = join(' ', $args); $args = join(' ', $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);
$ret = array( $ret = [
'input' => array(), 'input' => [],
'commands' => array(), 'commands' => [],
'flags' => array() 'flags' => []
); ];
foreach ( $args as $arg ) { foreach($args as $arg){
// Is it a command? (prefixed with --) // Is it a command? (prefixed with --)
if ( substr( $arg, 0, 2 ) === '--' ) { if(substr($arg, 0, 2) === '--'){
$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 = join($value);
$ret['commands'][$com] = !empty($value) ? $value : true; $ret['commands'][$com] = !empty($value) ? $value : true;
@ -166,8 +147,8 @@ function arguments ( $args ){
} }
// Is it a flag? (prefixed with -) // Is it a flag? (prefixed with -)
if ( substr( $arg, 0, 1 ) === '-' ) { if(substr($arg, 0, 1) === '-'){
$ret['flags'][] = substr( $arg, 1 ); $ret['flags'][] = substr($arg, 1);
continue; continue;
} }
@ -181,11 +162,11 @@ function arguments ( $args ){
function console($message, $EOL = true, $log = true, $level = 1){ function console($message, $EOL = true, $log = true, $level = 1){
if(!defined("DEBUG") or DEBUG >= $level){ if(!defined("DEBUG") or DEBUG >= $level){
$message .= $EOL === true ? PHP_EOL:""; $message .= $EOL === true ? PHP_EOL : "";
$time = (ENABLE_ANSI === true ? FORMAT_AQUA . date("H:i:s") . FORMAT_RESET:date("H:i:s")) . " "; $time = (ENABLE_ANSI === true ? FORMAT_AQUA . date("H:i:s") . FORMAT_RESET : date("H:i:s")) . " ";
$replaced = TextFormat::clean(preg_replace('/\x1b\[[0-9;]*m/', "", $time . $message)); $replaced = TextFormat::clean(preg_replace('/\x1b\[[0-9;]*m/', "", $time . $message));
if($log === true and (!defined("LOG") or LOG === true)){ if($log === true and (!defined("LOG") or LOG === true)){
logg(date("Y-m-d")." ".$replaced, "console", false, $level); logg(date("Y-m-d") . " " . $replaced, "console", false, $level);
} }
if(ENABLE_ANSI === true){ if(ENABLE_ANSI === true){
$add = ""; $add = "";
@ -221,14 +202,14 @@ function console($message, $EOL = true, $log = true, $level = 1){
function getTrace($start = 1){ function getTrace($start = 1){
$e = new Exception(); $e = new Exception();
$trace = $e->getTrace(); $trace = $e->getTrace();
$messages = array(); $messages = [];
$j = 0; $j = 0;
for($i = (int) $start; isset($trace[$i]); ++$i, ++$j){ for($i = (int) $start; isset($trace[$i]); ++$i, ++$j){
$params = ""; $params = "";
foreach($trace[$i]["args"] as $name => $value){ foreach($trace[$i]["args"] as $name => $value){
$params .= (is_object($value) ? get_class($value)." ".(method_exists($value, "__toString") ? $value->__toString() : "object"):gettype($value)." ".@strval($value)).", "; $params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . @strval($value)) . ", ";
} }
$messages[] = "#$j ".(isset($trace[$i]["file"]) ? $trace[$i]["file"]:"")."(".(isset($trace[$i]["line"]) ? $trace[$i]["line"]:"")."): ".(isset($trace[$i]["class"]) ? $trace[$i]["class"].$trace[$i]["type"]:"").$trace[$i]["function"]."(".substr($params, 0, -2).")"; $messages[] = "#$j " . (isset($trace[$i]["file"]) ? $trace[$i]["file"] : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . $trace[$i]["type"] : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")";
} }
return $messages; return $messages;
} }
@ -237,7 +218,7 @@ function error_handler($errno, $errstr, $errfile, $errline){
if(error_reporting() === 0){ //@ error-control if(error_reporting() === 0){ //@ error-control
return false; return false;
} }
$errorConversion = array( $errorConversion = [
E_ERROR => "E_ERROR", E_ERROR => "E_ERROR",
E_WARNING => "E_WARNING", E_WARNING => "E_WARNING",
E_PARSE => "E_PARSE", E_PARSE => "E_PARSE",
@ -253,9 +234,9 @@ function error_handler($errno, $errstr, $errfile, $errline){
E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR",
E_DEPRECATED => "E_DEPRECATED", E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED",
); ];
$errno = isset($errorConversion[$errno]) ? $errorConversion[$errno]:$errno; $errno = isset($errorConversion[$errno]) ? $errorConversion[$errno] : $errno;
console("[ERROR] A ".$errno." error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0); console("[ERROR] A " . $errno . " error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0);
foreach(getTrace() as $i => $line){ foreach(getTrace() as $i => $line){
console("[TRACE] $line"); console("[TRACE] $line");
} }
@ -265,14 +246,14 @@ function error_handler($errno, $errstr, $errfile, $errline){
function logg($message, $name, $EOL = true, $level = 2, $close = false){ function logg($message, $name, $EOL = true, $level = 2, $close = false){
global $fpointers, $dolog; global $fpointers, $dolog;
if((!defined("DEBUG") or DEBUG >= $level) and (!defined("LOG") or LOG === true)){ if((!defined("DEBUG") or DEBUG >= $level) and (!defined("LOG") or LOG === true)){
$message .= $EOL === true ? PHP_EOL:""; $message .= $EOL === true ? PHP_EOL : "";
if(!isset($fpointers)){ if(!isset($fpointers)){
$fpointers = array(); $fpointers = [];
} }
if(!isset($fpointers[$name]) or $fpointers[$name] === false){ if(!isset($fpointers[$name]) or $fpointers[$name] === false){
$fpointers[$name] = @fopen(DATA_PATH."/".$name.".log", "ab"); $fpointers[$name] = @fopen(DATA_PATH . "/" . $name . ".log", "ab");
} }
if($dolog) { if($dolog){
@fwrite($fpointers[$name], $message); @fwrite($fpointers[$name], $message);
} }
if($close === true){ if($close === true){

View file

@ -1,24 +1,5 @@
<?php <?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***/ /***REM_START***/
class Installer{ class Installer{

View file

@ -1,31 +1,14 @@
<?php <?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/
*
*
*/
define("WINDOW_CHEST", 0); define("WINDOW_CHEST", 0);
define("WINDOW_WORKBENCH", 1); define("WINDOW_WORKBENCH", 1);
define("WINDOW_FURNACE", 2); define("WINDOW_FURNACE", 2);
define("WINDOW_STONECUTTER", 3); define("WINDOW_STONECUTTER", 3);
class Window{ class Window{
private $server; private $server;
public function __construct(){ public function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }

View file

@ -1,24 +1,5 @@
<?php <?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 Block extends Position{ abstract class Block extends Position{
public static $class = array( public static $class = array(
AIR => "AirBlock", AIR => "AirBlock",

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class Item{ class Item{
public static $class = array( public static $class = array(

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class DoorBlock extends TransparentBlock{ class DoorBlock extends TransparentBlock{
/** /**
* @param int $id * @param int $id

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class FallableBlock extends SolidBlock{ class FallableBlock extends SolidBlock{
/** /**
* @param int $id * @param int $id

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class FlowableBlock extends TransparentBlock{ class FlowableBlock extends TransparentBlock{
/** /**
* @param int $id * @param int $id

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class GenericBlock extends Block{ class GenericBlock extends Block{
/** /**

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class LiquidBlock extends TransparentBlock{ class LiquidBlock extends TransparentBlock{
/** /**
* @param int $id * @param int $id

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class SolidBlock extends GenericBlock{ class SolidBlock extends GenericBlock{
/** /**
* @param int $id * @param int $id

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class StairBlock extends TransparentBlock{ class StairBlock extends TransparentBlock{
/** /**
* @param int $id * @param int $id

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class TransparentBlock extends GenericBlock{ class TransparentBlock extends GenericBlock{
/** /**
* @param int $id * @param int $id

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class LadderBlock extends TransparentBlock{ class LadderBlock extends TransparentBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(LADDER, $meta, "Ladder"); parent::__construct(LADDER, $meta, "Ladder");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class SignPostBlock extends TransparentBlock{ class SignPostBlock extends TransparentBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(SIGN_POST, $meta, "Sign Post"); parent::__construct(SIGN_POST, $meta, "Sign Post");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class TorchBlock extends FlowableBlock implements LightingBlock{ class TorchBlock extends FlowableBlock implements LightingBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(TORCH, $meta, "Torch"); parent::__construct(TORCH, $meta, "Torch");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class TrapdoorBlock extends TransparentBlock{ class TrapdoorBlock extends TransparentBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(TRAPDOOR, $meta, "Trapdoor"); parent::__construct(TRAPDOOR, $meta, "Trapdoor");

View file

@ -1,24 +1,5 @@
<?php <?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***/ /***REM_START***/
require_once("SignPost.php"); require_once("SignPost.php");
/***REM_END***/ /***REM_END***/

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class LavaBlock extends LiquidBlock implements LightingBlock{ class LavaBlock extends LiquidBlock implements LightingBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(LAVA, $meta, "Lava"); parent::__construct(LAVA, $meta, "Lava");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class StillLavaBlock extends LiquidBlock{ class StillLavaBlock extends LiquidBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(STILL_LAVA, $meta, "Still Lava"); parent::__construct(STILL_LAVA, $meta, "Still Lava");

View file

@ -1,24 +1,5 @@
<?php <?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***/ /***REM_START***/
require_once("Water.php"); require_once("Water.php");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class WaterBlock extends LiquidBlock{ class WaterBlock extends LiquidBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(WATER, $meta, "Water"); parent::__construct(WATER, $meta, "Water");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class AirBlock extends TransparentBlock{ class AirBlock extends TransparentBlock{
public function __construct(){ public function __construct(){
parent::__construct(AIR, 0, "Air"); parent::__construct(AIR, 0, "Air");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class BedBlock extends TransparentBlock{ class BedBlock extends TransparentBlock{
public function __construct($type = 0){ public function __construct($type = 0){
parent::__construct(BED_BLOCK, $type, "Bed Block"); parent::__construct(BED_BLOCK, $type, "Bed Block");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class FireBlock extends FlowableBlock implements LightingBlock{ class FireBlock extends FlowableBlock implements LightingBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(FIRE, $meta, "Fire"); parent::__construct(FIRE, $meta, "Fire");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class NetherReactorBlock extends SolidBlock{ class NetherReactorBlock extends SolidBlock{
public static $enableReactor = true; public static $enableReactor = true;
public function __construct($meta = 0){ public function __construct($meta = 0){

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class TNTBlock extends SolidBlock{ class TNTBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(TNT, 0, "TNT"); parent::__construct(TNT, 0, "TNT");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class CakeBlock extends TransparentBlock{ class CakeBlock extends TransparentBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(CAKE_BLOCK, 0, "Cake Block"); parent::__construct(CAKE_BLOCK, 0, "Cake Block");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class CarpetBlock extends FlowableBlock{ class CarpetBlock extends FlowableBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(CARPET, $meta, "Carpet"); parent::__construct(CARPET, $meta, "Carpet");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class ChestBlock extends TransparentBlock{ class ChestBlock extends TransparentBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(CHEST, $meta, "Chest"); parent::__construct(CHEST, $meta, "Chest");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class CobwebBlock extends FlowableBlock{ class CobwebBlock extends FlowableBlock{
public function __construct(){ public function __construct(){
parent::__construct(COBWEB, 0, "Cobweb"); parent::__construct(COBWEB, 0, "Cobweb");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class FarmlandBlock extends TransparentBlock{ class FarmlandBlock extends TransparentBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(FARMLAND, $meta, "Farmland"); parent::__construct(FARMLAND, $meta, "Farmland");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class FenceBlock extends TransparentBlock{ class FenceBlock extends TransparentBlock{
public function __construct(){ public function __construct(){
parent::__construct(FENCE, 0, "Fence"); parent::__construct(FENCE, 0, "Fence");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class FenceGateBlock extends TransparentBlock{ class FenceGateBlock extends TransparentBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(FENCE_GATE, $meta, "Fence Gate"); parent::__construct(FENCE_GATE, $meta, "Fence Gate");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class GlassPaneBlock extends TransparentBlock{ class GlassPaneBlock extends TransparentBlock{
public function __construct(){ public function __construct(){
parent::__construct(GLASS_PANE, 0, "Glass Pane"); parent::__construct(GLASS_PANE, 0, "Glass Pane");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class IronBarsBlock extends TransparentBlock{ class IronBarsBlock extends TransparentBlock{
public function __construct(){ public function __construct(){
parent::__construct(IRON_BARS, 0, "Iron Bars"); parent::__construct(IRON_BARS, 0, "Iron Bars");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class IronDoorBlock extends DoorBlock{ class IronDoorBlock extends DoorBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(IRON_DOOR_BLOCK, $meta, "Iron Door Block"); parent::__construct(IRON_DOOR_BLOCK, $meta, "Iron Door Block");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class PoweredRailBlock extends FlowableBlock{ class PoweredRailBlock extends FlowableBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(POWERED_RAIL, 0, "PoweredRailBlock"); parent::__construct(POWERED_RAIL, 0, "PoweredRailBlock");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class RailBlock extends FlowableBlock{ class RailBlock extends FlowableBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(RAIL, 0, "Rail"); parent::__construct(RAIL, 0, "Rail");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class SlabBlock extends TransparentBlock{ class SlabBlock extends TransparentBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(SLAB, $meta, "Slab"); parent::__construct(SLAB, $meta, "Slab");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class SnowLayerBlock extends FlowableBlock{ class SnowLayerBlock extends FlowableBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(SNOW_LAYER, $meta, "Snow Layer"); parent::__construct(SNOW_LAYER, $meta, "Snow Layer");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class StoneWallBlock extends TransparentBlock{ class StoneWallBlock extends TransparentBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
$meta &= 0x01; $meta &= 0x01;

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class WoodDoorBlock extends DoorBlock{ class WoodDoorBlock extends DoorBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(WOOD_DOOR_BLOCK, $meta, "Wood Door Block"); parent::__construct(WOOD_DOOR_BLOCK, $meta, "Wood Door Block");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class WoodSlabBlock extends TransparentBlock{ class WoodSlabBlock extends TransparentBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(WOOD_SLAB, $meta, "Wooden Slab"); parent::__construct(WOOD_SLAB, $meta, "Wooden Slab");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class BirchWoodStairsBlock extends StairBlock{ class BirchWoodStairsBlock extends StairBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(BIRCH_WOOD_STAIRS, $meta, "Birch Wood Stairs"); parent::__construct(BIRCH_WOOD_STAIRS, $meta, "Birch Wood Stairs");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class BrickStairsBlock extends StairBlock{ class BrickStairsBlock extends StairBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(BRICK_STAIRS, $meta, "Brick Stairs"); parent::__construct(BRICK_STAIRS, $meta, "Brick Stairs");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class CobblestoneStairsBlock extends StairBlock{ class CobblestoneStairsBlock extends StairBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(COBBLESTONE_STAIRS, $meta, "Cobblestone Stairs"); parent::__construct(COBBLESTONE_STAIRS, $meta, "Cobblestone Stairs");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class JungleWoodStairsBlock extends StairBlock{ class JungleWoodStairsBlock extends StairBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(JUNGLE_WOOD_STAIRS, $meta, "Jungle Wood Stairs"); parent::__construct(JUNGLE_WOOD_STAIRS, $meta, "Jungle Wood Stairs");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class NetherBricksStairsBlock extends StairBlock{ class NetherBricksStairsBlock extends StairBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(NETHER_BRICKS_STAIRS, $meta, "Nether Bricks Stairs"); parent::__construct(NETHER_BRICKS_STAIRS, $meta, "Nether Bricks Stairs");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class QuartzStairsBlock extends StairBlock{ class QuartzStairsBlock extends StairBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(QUARTZ_STAIRS, $meta, "Quartz Stairs"); parent::__construct(QUARTZ_STAIRS, $meta, "Quartz Stairs");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class SandstoneStairsBlock extends StairBlock{ class SandstoneStairsBlock extends StairBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(SANDSTONE_STAIRS, $meta, "Sandstone Stairs"); parent::__construct(SANDSTONE_STAIRS, $meta, "Sandstone Stairs");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class SpruceWoodStairsBlock extends StairBlock{ class SpruceWoodStairsBlock extends StairBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(SPRUCE_WOOD_STAIRS, $meta, "Spruce Wood Stairs"); parent::__construct(SPRUCE_WOOD_STAIRS, $meta, "Spruce Wood Stairs");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class StoneBrickStairsBlock extends StairBlock{ class StoneBrickStairsBlock extends StairBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(STONE_BRICK_STAIRS, $meta, "Stone Brick Stairs"); parent::__construct(STONE_BRICK_STAIRS, $meta, "Stone Brick Stairs");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class WoodStairsBlock extends StairBlock{ class WoodStairsBlock extends StairBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(WOOD_STAIRS, $meta, "Wood Stairs"); parent::__construct(WOOD_STAIRS, $meta, "Wood Stairs");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class CoalOreBlock extends SolidBlock{ class CoalOreBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(COAL_ORE, 0, "Coal Ore"); parent::__construct(COAL_ORE, 0, "Coal Ore");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class DiamondOreBlock extends SolidBlock{ class DiamondOreBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(DIAMOND_ORE, 0, "Diamond Ore"); parent::__construct(DIAMOND_ORE, 0, "Diamond Ore");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
public function __construct(){ public function __construct(){
parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore"); parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class GoldOreBlock extends SolidBlock{ class GoldOreBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(GOLD_ORE, 0, "Gold Ore"); parent::__construct(GOLD_ORE, 0, "Gold Ore");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class IronOreBlock extends SolidBlock{ class IronOreBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(IRON_ORE, 0, "Iron Ore"); parent::__construct(IRON_ORE, 0, "Iron Ore");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class LapisOreBlock extends SolidBlock{ class LapisOreBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(LAPIS_ORE, 0, "Lapis Ore"); parent::__construct(LAPIS_ORE, 0, "Lapis Ore");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class RedstoneOreBlock extends SolidBlock{ class RedstoneOreBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(REDSTONE_ORE, 0, "Redstone Ore"); parent::__construct(REDSTONE_ORE, 0, "Redstone Ore");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class BeetrootBlock extends FlowableBlock{ class BeetrootBlock extends FlowableBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(BEETROOT_BLOCK, $meta, "Beetroot Block"); parent::__construct(BEETROOT_BLOCK, $meta, "Beetroot Block");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class BrownMushroomBlock extends FlowableBlock{ class BrownMushroomBlock extends FlowableBlock{
public function __construct(){ public function __construct(){
parent::__construct(BROWN_MUSHROOM, 0, "Brown Mushroom"); parent::__construct(BROWN_MUSHROOM, 0, "Brown Mushroom");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class CactusBlock extends TransparentBlock{ class CactusBlock extends TransparentBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(CACTUS, $meta, "Cactus"); parent::__construct(CACTUS, $meta, "Cactus");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class CarrotBlock extends FlowableBlock{ class CarrotBlock extends FlowableBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(CARROT_BLOCK, $meta, "Carrot Block"); parent::__construct(CARROT_BLOCK, $meta, "Carrot Block");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class CyanFlowerBlock extends FlowableBlock{ class CyanFlowerBlock extends FlowableBlock{
public function __construct(){ public function __construct(){
parent::__construct(CYAN_FLOWER, 0, "Cyan Flower"); parent::__construct(CYAN_FLOWER, 0, "Cyan Flower");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class DandelionBlock extends FlowableBlock{ class DandelionBlock extends FlowableBlock{
public function __construct(){ public function __construct(){
parent::__construct(DANDELION, 0, "Dandelion"); parent::__construct(DANDELION, 0, "Dandelion");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class DeadBushBlock extends FlowableBlock{ class DeadBushBlock extends FlowableBlock{
public function __construct(){ public function __construct(){
parent::__construct(DEAD_BUSH, 0, "Dead Bush"); parent::__construct(DEAD_BUSH, 0, "Dead Bush");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class MelonStemBlock extends FlowableBlock{ class MelonStemBlock extends FlowableBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(MELON_STEM, $meta, "Melon Stem"); parent::__construct(MELON_STEM, $meta, "Melon Stem");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class PotatoBlock extends FlowableBlock{ class PotatoBlock extends FlowableBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(POTATO_BLOCK, $meta, "Potato Block"); parent::__construct(POTATO_BLOCK, $meta, "Potato Block");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class PumpkinStemBlock extends FlowableBlock{ class PumpkinStemBlock extends FlowableBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(PUMPKIN_STEM, $meta, "Pumpkin Stem"); parent::__construct(PUMPKIN_STEM, $meta, "Pumpkin Stem");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class RedMushroomBlock extends FlowableBlock{ class RedMushroomBlock extends FlowableBlock{
public function __construct(){ public function __construct(){
parent::__construct(RED_MUSHROOM, 0, "Red Mushroom"); parent::__construct(RED_MUSHROOM, 0, "Red Mushroom");

View file

@ -1,24 +1,5 @@
<?php <?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/
*
*
*/
class SaplingBlock extends FlowableBlock{ class SaplingBlock extends FlowableBlock{
const OAK = 0; const OAK = 0;
const SPRUCE = 1; const SPRUCE = 1;

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