Merge branch 'Core-Rewrite'

Conflicts:
	src/API/PlayerAPI.php
	src/build/compile.sh
	src/build/jenkins.sh
This commit is contained in:
Shoghi Cervantes 2014-06-05 01:39:43 +02:00
commit ddf3e149c9
614 changed files with 38367 additions and 19242 deletions

1
.gitattributes vendored
View File

@ -5,6 +5,7 @@
*.txt text eol=lf
*.properties text eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf
# Custom for Visual Studio
*.cs diff=csharp

12
.gitignore vendored
View File

@ -1,18 +1,15 @@
players/*
worlds/*
plugins/*
logs/*
bin/*
.idea/*
*.log
*.pmf
*.txt
*.phar
server.properties
############
## Windows
############
# Common IDEs
.idea/*
nbproject/*
# Windows image file caches
Thumbs.db
@ -22,3 +19,4 @@ Desktop.ini
# Mac crap
.DS_Store
/nbproject/private/

8
.gitmodules vendored Normal file
View File

@ -0,0 +1,8 @@
[submodule "src/pocketmine/gui"]
path = src/pocketmine/gui
url = https://github.com/PocketMine/PocketMine-MP-GUI.git
branch = master
[submodule "src/raklib"]
path = src/raklib
url = https://github.com/PocketMine/RakLib.git
branch = master

View File

@ -4,9 +4,13 @@ php:
- 5.4
- 5.5
- 5.6
branches:
except:
- Core-Rewrite
before_script:
- pecl install channel://pecl.php.net/pthreads-0.1.0
- pecl install channel://pecl.php.net/pthreads-2.0.4
- echo | pecl install channel://pecl.php.net/yaml-1.1.1
script:

View File

@ -38,14 +38,15 @@ It is mainly [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accept
* Long arrays MAY be split across multiple lines, where each subsequent line is indented once.
* Files MUST use only the `<?php` tag.
* Files MUST NOT have an ending `?>` tag.
* Code MUST NOT use namespaces. Descriptive and unique class names are enforced.
* Code MUST use namespaces.
* Strings SHOULD use the double quote `"` except when the single quote is required.
* Arrays SHOULD be declared using `array()`, not the `[]` shortcut.
* Argument lists MAY NOT be split across multiple lines, except long arrays.
```php
<?php
namespace pocketmine\Example;
class ExampleClass{
const EXAMPLE_CLASS_CONSTANT = 1;
public $examplePublicVariable = "defaultValue";

View File

@ -1,41 +1,44 @@
![](http://www.pocketmine.net/favicon.png)
# ![PocketMine-MP](http://cdn.pocketmine.net/img/PocketMine-MP-h.png)
# PocketMine-MP [![Build Status](https://travis-ci.org/PocketMine/PocketMine-MP.png?branch=master)](https://travis-ci.org/PocketMine/PocketMine-MP)
```
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.
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
```
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
__PocketMine-MP is a sofware for creating Minecraft Pocket Edition servers__. It has a Plugin API that enables a developer to extend it and add new features, or change default ones.
The entire server is done in PHP, and has been tested, profiled and optimized to run smoothly.
__PocketMine-MP is a free, open-source software that creates Minecraft: Pocket Edition servers and allows extending its functionalities__
### [Homepage](http://www.pocketmine.net/)
### [Forums](http://forums.pocketmine.net/)
### [Wiki](https://github.com/PocketMine/PocketMine-MP/wiki/)
### [Plugin Repository](http://plugins.pocketmine.net/)
### [FAQ: Frequently Asked Questions](https://github.com/PocketMine/PocketMine-MP/wiki/Frequently-Asked-Questions)
<!--## [FAQ: Frequently Asked Questions](https://github.com/PocketMine/PocketMine-MP/wiki/Frequently-Asked-Questions)-->
### [Official Jenkins server](http://jenkins.pocketmine.net/)
### API Documentation
* [Official Doxygen-generated documentation](http://docs.pocketmine.net/)
* [Latest Doxygen generated from development](http://jenkins.pocketmine.net/job/PocketMine-MP-doc/doxygen/)
### [Twitter @PocketMine](https://twitter.com/PocketMine)
## IRC Chat #pocketmine (or #mcpedevs) @ irc.freenode.net
### IRC Chat #pocketmine (or #mcpedevs) @ irc.freenode.net
[#pocketmine + #mcpedevs channel WebIRC](http://webchat.freenode.net/?channels=pocketmine,mcpedevs)
### Want to contribute?
* Check the [Contributing Guidelines](CONTRIBUTING.md)
## Third-party Libraries/Protocols Used
* __[PHP Sockets](http://php.net/manual/en/book.sockets.php)__

View File

@ -1,164 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class AchievementAPI{
public static $achievements = array(
/*"openInventory" => array(
"name" => "Taking Inventory",
"requires" => array(),
),*/
"mineWood" => array(
"name" => "Getting Wood",
"requires" => array(
//"openInventory",
),
),
"buildWorkBench" => array(
"name" => "Benchmarking",
"requires" => array(
"mineWood",
),
),
"buildPickaxe" => array(
"name" => "Time to Mine!",
"requires" => array(
"buildWorkBench",
),
),
"buildFurnace" => array(
"name" => "Hot Topic",
"requires" => array(
"buildPickaxe",
),
),
"acquireIron" => array(
"name" => "Acquire hardware",
"requires" => array(
"buildFurnace",
),
),
"buildHoe" => array(
"name" => "Time to Farm!",
"requires" => array(
"buildWorkBench",
),
),
"makeBread" => array(
"name" => "Bake Bread",
"requires" => array(
"buildHoe",
),
),
"bakeCake" => array(
"name" => "The Lie",
"requires" => array(
"buildHoe",
),
),
"buildBetterPickaxe" => array(
"name" => "Getting an Upgrade",
"requires" => array(
"buildPickaxe",
),
),
"buildSword" => array(
"name" => "Time to Strike!",
"requires" => array(
"buildWorkBench",
),
),
"diamonds" => array(
"name" => "DIAMONDS!",
"requires" => array(
"acquireIron",
),
),
);
function __construct(){
}
public static function broadcastAchievement(Player $player, $achievementId){
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])){
self::$achievements[$achievementId] = array(
"name" => $achievementName,
"requires" => $requires,
);
return true;
}
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){
if(isset(self::$achievements[$achievementId]) and !self::hasAchievement($player, $achievementId)){
foreach(self::$achievements[$achievementId]["requires"] as $requerimentId){
if(!self::hasAchievement($player, $requerimentId)){
return false;
}
}
if(ServerAPI::request()->api->dhandle("achievement.grant", array("player" => $player, "achievementId" => $achievementId)) !== false){
$player->achievements[$achievementId] = true;
self::broadcastAchievement($player, $achievementId);
return true;
}else{
return false;
}
}
return false;
}
public static function removeAchievement(Player $player, $achievementId){
if(self::hasAchievement($player, $achievementId)){
$player->achievements[$achievementId] = false;
}
}
public function init(){
}
}

View File

@ -1,400 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class BanAPI{
private $server;
/*
* I would use PHPDoc Template here but PHPStorm does not recognise it. - @sekjun9878
*/
/** @var Config */
private $whitelist;
/** @var Config */
private $banned;
/** @var Config */
private $ops;
/** @var Config */
private $bannedIPs;
private $cmdWhitelist = array();//Command WhiteList
function __construct(){
$this->server = ServerAPI::request();
}
public function init(){
$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->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->server->api->console->register("banip", "<add|remove|list|reload> [IP|player]", array($this, "commandHandler"));
$this->server->api->console->register("ban", "<add|remove|list|reload> [username]", array($this, "commandHandler"));
$this->server->api->console->register("kick", "<player> [reason ...]", array($this, "commandHandler"));
$this->server->api->console->register("whitelist", "<on|off|list|add|remove|reload> [username]", array($this, "commandHandler"));
$this->server->api->console->register("op", "<player>", array($this, "commandHandler"));
$this->server->api->console->register("deop", "<player>", array($this, "commandHandler"));
$this->server->api->console->register("sudo", "<player> <command>", array($this, "commandHandler"));
$this->server->api->console->alias("ban-ip", "banip add");
$this->server->api->console->alias("banlist", "ban list");
$this->server->api->console->alias("pardon", "ban remove");
$this->server->api->console->alias("pardon-ip", "banip remove");
$this->server->addHandler("console.command", array($this, "permissionsCheck"), 1);//Event handler when commands are issued. Used to check permissions of commands that go through the server.
$this->server->addHandler("player.block.break", array($this, "permissionsCheck"), 1);//Event handler for blocks
$this->server->addHandler("player.block.place", array($this, "permissionsCheck"), 1);//Event handler for blocks
$this->server->addHandler("player.flying", array($this, "permissionsCheck"), 1);//Flying Event
}
/**
* @param string $cmd Command to Whitelist
*/
public function cmdWhitelist($cmd){//Whitelists a CMD so everyone can issue it - Even non OPs.
$this->cmdWhitelist[strtolower(trim($cmd))] = true;
}
/**
* @param string $username
*
* @return boolean
*/
public function isOp($username){//Is a player op?
$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 string $event
*
* @return boolean
*/
public function permissionsCheck($data, $event){
switch($event){
case "player.flying"://OPs can fly around the server.
if($this->isOp($data->iusername)){
return true;
}
break;
case "player.block.break":
case "player.block.place"://Spawn protection detection. Allows OPs to place/break blocks in the spawn area.
if(!$this->isOp($data["player"]->iusername)){
$t = new Vector2($data["target"]->x, $data["target"]->z);
$s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event.".spawn", $data) !== true){
return false;
}
}
return;
case "console.command"://Checks if a command is allowed with the current user permissions.
if(isset($this->cmdWhitelist[$data["cmd"]])){
return;
}
if($data["issuer"] instanceof Player){
if($this->server->api->handle("console.check", $data) === true or $this->isOp($data["issuer"]->iusername)){
return;
}
}elseif($data["issuer"] === "console" or $data["issuer"] === "rcon"){
return;
}
return false;
}
}
/**
* @param string $cmd
* @param array $params
* @param string $issuer
* @param string $alias
*
* @return string
*/
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "sudo":
$target = strtolower(array_shift($params));
$player = $this->server->api->player->get($target);
if(!($player instanceof Player)){
$output .= "Player not connected.\n";
break;
}
$this->server->api->console->run(implode(" ", $params), $player);
$output .= "Command ran as ".$player->username.".\n";
break;
case "op":
$user = strtolower($params[0]);
if($user == NULL){
$output .= "Usage: /op <player>\n";
break;
}
$player = $this->server->api->player->get($user);
if(!($player instanceof Player)){
$this->ops->set($user);
$this->ops->save();
$output .= $user." is now op\n";
break;
}
$this->ops->set($player->iusername);
$this->ops->save();
$output .= $player->iusername." is now op\n";
$this->server->api->chat->sendTo(false, "You are now op.", $player->iusername);
break;
case "deop":
$user = strtolower($params[0]);
$player = $this->server->api->player->get($user);
if(!($player instanceof Player)){
$this->ops->remove($user);
$this->ops->save();
$output .= $user." is no longer op\n";
break;
}
$this->ops->remove($player->iusername);
$this->ops->save();
$output .= $player->iusername." is no longer op\n";
$this->server->api->chat->sendTo(false, "You are no longer op.", $player->iusername);
break;
case "kick":
if(!isset($params[0])){
$output .= "Usage: /kick <player> [reason ...]\n";
}else{
$name = strtolower(array_shift($params));
$player = $this->server->api->player->get($name);
if($player === false){
$output .= "Player \"".$name."\" does not exist\n";
}else{
$reason = implode(" ", $params);
$reason = $reason == "" ? "No reason":$reason;
$this->server->schedule(60, array($player, "close"), "You have been kicked: ".$reason); //Forces a kick
$player->blocked = true;
if($issuer instanceof Player){
$this->server->api->chat->broadcast($player->username." has been kicked by ".$issuer->username.": $reason\n");
}else{
$this->server->api->chat->broadcast($player->username." has been kicked: $reason\n");
}
}
}
break;
case "whitelist":
$p = strtolower(array_shift($params));
switch($p){
case "remove":
$user = strtolower($params[0]);
$this->whitelist->remove($user);
$this->whitelist->save();
$output .= "Player \"$user\" removed from white-list\n";
break;
case "add":
$user = strtolower($params[0]);
$this->whitelist->set($user);
$this->whitelist->save();
$output .= "Player \"$user\" added to white-list\n";
break;
case "reload":
$this->whitelist = new Config(DATA_PATH."white-list.txt", CONFIG_LIST);
break;
case "list":
$output .= "White-list: ".implode(", ", $this->whitelist->getAll(true))."\n";
break;
case "on":
case "true":
case "1":
$output .= "White-list turned on\n";
$this->server->api->setProperty("white-list", true);
break;
case "off":
case "false":
case "0":
$output .= "White-list turned off\n";
$this->server->api->setProperty("white-list", false);
break;
default:
$output .= "Usage: /whitelist <on|off|list|add|remove|reload> [username]\n";
break;
}
break;
case "banip":
$p = strtolower(array_shift($params));
switch($p){
case "pardon":
case "remove":
$ip = strtolower($params[0]);
$this->bannedIPs->remove($ip);
$this->bannedIPs->save();
$output .= "IP \"$ip\" removed from ban list\n";
break;
case "add":
case "ban":
$ip = strtolower($params[0]);
$player = $this->server->api->player->get($ip);
if($player instanceof Player){
$ip = $player->ip;
$player->close("banned");
}
$this->bannedIPs->set($ip);
$this->bannedIPs->save();
$output .= "IP \"$ip\" added to ban list\n";
break;
case "reload":
$this->bannedIPs = new Config(DATA_PATH."banned-ips.txt", CONFIG_LIST);
break;
case "list":
$output .= "IP ban list: ".implode(", ", $this->bannedIPs->getAll(true))."\n";
break;
default:
$output .= "Usage: /banip <add|remove|list|reload> [IP|player]\n";
break;
}
break;
case "ban":
$p = strtolower(array_shift($params));
switch($p){
case "pardon":
case "remove":
$user = strtolower($params[0]);
$this->banned->remove($user);
$this->banned->save();
$output .= "Player \"$user\" removed from ban list\n";
break;
case "add":
case "ban":
$user = strtolower($params[0]);
$this->banned->set($user);
$this->banned->save();
$player = $this->server->api->player->get($user);
if($player !== false){
$player->close("You have been banned");
}
if($issuer instanceof Player){
$this->server->api->chat->broadcast($user." has been banned by ".$issuer->username."\n");
}else{
$this->server->api->chat->broadcast($user." has been banned\n");
}
$this->kick($user, "Banned");
$output .= "Player \"$user\" added to ban list\n";
break;
case "reload":
$this->banned = new Config(DATA_PATH."banned.txt", CONFIG_LIST);
break;
case "list":
$output .= "Ban list: ".implode(", ", $this->banned->getAll(true))."\n";
break;
default:
$output .= "Usage: /ban <add|remove|list|reload> [username]\n";
break;
}
break;
}
return $output;
}
/**
* @param string $username
*/
public function ban($username){
$this->commandHandler("ban", array("add", $username), "console", "");
}
/**
* @param string $username
*/
public function pardon($username){
$this->commandHandler("ban", array("pardon", $username), "console", "");
}
/**
* @param string $ip
*/
public function banIP($ip){
$this->commandHandler("banip", array("add", $ip), "console", "");
}
/**
* @param string $ip
*/
public function pardonIP($ip){
$this->commandHandler("banip", array("pardon", $ip), "console", "");
}
/**
* @param string $username
* @param string $reason
*/
public function kick($username, $reason = "No Reason"){
$this->commandHandler("kick", array($username, $reason), "console", "");
}
public function reload(){
$this->commandHandler("ban", array("reload"), "console", "");
$this->commandHandler("banip", array("reload"), "console", "");
$this->commandHandler("whitelist", array("reload"), "console", "");
}
/**
* @param string $ip
*
* @return boolean
*/
public function isIPBanned($ip){
if($this->server->api->dhandle("api.ban.ip.check", $ip) === false){
return true;
}elseif($this->bannedIPs->exists($ip, true)){
return true;
}else{
return false;
}
}
/**
* @param string $username
*
* @return boolean
*/
public function isBanned($username){
$username = strtolower($username);
if($this->server->api->dhandle("api.ban.check", $username) === false){
return true;
}elseif($this->banned->exists($username, true)){
return true;
}else{
return false;
}
}
/**
* @param string $username
*
* @return boolean
*/
public function inWhitelist($username){
$username = strtolower($username);
if($this->isOp($username)){
return true;
}elseif($this->server->api->dhandle("api.ban.whitelist.check", $username) === false){
return true;
}elseif($this->whitelist->exists($username, true)){
return true;
}
return false;
}
}

View File

@ -1,559 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class BlockAPI{
private $server;
private $scheduledUpdates = array();
private $randomUpdates = array();
public static $creative = array(
//Building
array(STONE, 0),
array(COBBLESTONE, 0),
array(STONE_BRICKS, 0),
array(STONE_BRICKS, 1),
array(STONE_BRICKS, 2),
array(MOSS_STONE, 0),
array(WOODEN_PLANKS, 0),
array(WOODEN_PLANKS, 1),
array(WOODEN_PLANKS, 2),
array(WOODEN_PLANKS, 3),
array(BRICKS, 0),
array(DIRT, 0),
array(GRASS, 0),
array(CLAY_BLOCK, 0),
array(SANDSTONE, 0),
array(SANDSTONE, 1),
array(SANDSTONE, 2),
array(SAND, 0),
array(GRAVEL, 0),
array(TRUNK, 0),
array(TRUNK, 1),
array(TRUNK, 2),
array(TRUNK, 3),
array(NETHER_BRICKS, 0),
array(NETHERRACK, 0),
array(BEDROCK, 0),
array(COBBLESTONE_STAIRS, 0),
array(OAK_WOODEN_STAIRS, 0),
array(SPRUCE_WOODEN_STAIRS, 0),
array(BIRCH_WOODEN_STAIRS, 0),
array(JUNGLE_WOODEN_STAIRS, 0),
array(BRICK_STAIRS, 0),
array(SANDSTONE_STAIRS, 0),
array(STONE_BRICK_STAIRS, 0),
array(NETHER_BRICKS_STAIRS, 0),
array(QUARTZ_STAIRS, 0),
array(SLAB, 0),
array(SLAB, 1),
array(WOODEN_SLAB, 0),
array(WOODEN_SLAB, 1),
array(WOODEN_SLAB, 2),
array(WOODEN_SLAB, 3),
array(SLAB, 3),
array(SLAB, 4),
array(SLAB, 5),
array(SLAB, 6),
array(QUARTZ_BLOCK, 0),
array(QUARTZ_BLOCK, 1),
array(QUARTZ_BLOCK, 2),
array(COAL_ORE, 0),
array(IRON_ORE, 0),
array(GOLD_ORE, 0),
array(DIAMOND_ORE, 0),
array(LAPIS_ORE, 0),
array(REDSTONE_ORE, 0),
array(OBSIDIAN, 0),
array(ICE, 0),
array(SNOW_BLOCK, 0),
//Decoration
array(COBBLESTONE_WALL, 0),
array(COBBLESTONE_WALL, 1),
array(GOLD_BLOCK, 0),
array(IRON_BLOCK, 0),
array(DIAMOND_BLOCK, 0),
array(LAPIS_BLOCK, 0),
array(COAL_BLOCK, 0),
array(SNOW_LAYER, 0),
array(GLASS, 0),
array(GLOWSTONE_BLOCK, 0),
array(NETHER_REACTOR, 0),
array(WOOL, 0),
array(WOOL, 7),
array(WOOL, 6),
array(WOOL, 5),
array(WOOL, 4),
array(WOOL, 3),
array(WOOL, 2),
array(WOOL, 1),
array(WOOL, 15),
array(WOOL, 14),
array(WOOL, 13),
array(WOOL, 12),
array(WOOL, 11),
array(WOOL, 10),
array(WOOL, 9),
array(WOOL, 8),
array(LADDER, 0),
array(SPONGE, 0),
array(GLASS_PANE, 0),
array(WOODEN_DOOR, 0),
array(TRAPDOOR, 0),
array(FENCE, 0),
array(FENCE_GATE, 0),
array(IRON_BARS, 0),
array(BED, 0),
array(BOOKSHELF, 0),
array(PAINTING, 0),
array(WORKBENCH, 0),
array(STONECUTTER, 0),
array(CHEST, 0),
array(FURNACE, 0),
array(DANDELION, 0),
array(CYAN_FLOWER, 0),
array(BROWN_MUSHROOM, 0),
array(RED_MUSHROOM, 0),
array(CACTUS, 0),
array(MELON_BLOCK, 0),
array(PUMPKIN, 0),
array(LIT_PUMPKIN, 0),
array(COBWEB, 0),
array(HAY_BALE, 0),
array(TALL_GRASS, 1),
array(TALL_GRASS, 2),
array(DEAD_BUSH, 0),
array(SAPLING, 0),
array(SAPLING, 1),
array(SAPLING, 2),
array(SAPLING, 3),
array(LEAVES, 0),
array(LEAVES, 1),
array(LEAVES, 2),
array(LEAVES, 3),
array(CAKE, 0),
array(SIGN, 0),
array(CARPET, 0),
array(CARPET, 7),
array(CARPET, 6),
array(CARPET, 5),
array(CARPET, 4),
array(CARPET, 3),
array(CARPET, 2),
array(CARPET, 1),
array(CARPET, 15),
array(CARPET, 14),
array(CARPET, 13),
array(CARPET, 12),
array(CARPET, 11),
array(CARPET, 10),
array(CARPET, 9),
array(CARPET, 8),
//Tools
//array(RAILS, 0),
//array(POWERED_RAILS, 0),
array(TORCH, 0),
array(BUCKET, 0),
array(BUCKET, 8),
array(BUCKET, 10),
array(TNT, 0),
array(IRON_HOE, 0),
array(IRON_SWORD, 0),
array(BOW, 0),
array(SHEARS, 0),
array(FLINT_AND_STEEL, 0),
array(CLOCK, 0),
array(COMPASS, 0),
array(MINECART, 0),
array(SPAWN_EGG, MOB_CHICKEN),
array(SPAWN_EGG, MOB_COW),
array(SPAWN_EGG, MOB_PIG),
array(SPAWN_EGG, MOB_SHEEP),
//Seeds
array(SUGARCANE, 0),
array(WHEAT, 0),
array(SEEDS, 0),
array(MELON_SEEDS, 0),
array(PUMPKIN_SEEDS, 0),
array(CARROT, 0),
array(POTATO, 0),
array(BEETROOT_SEEDS, 0),
array(EGG, 0),
array(DYE, 0),
array(DYE, 7),
array(DYE, 6),
array(DYE, 5),
array(DYE, 4),
array(DYE, 3),
array(DYE, 2),
array(DYE, 1),
array(DYE, 15),
array(DYE, 14),
array(DYE, 13),
array(DYE, 12),
array(DYE, 11),
array(DYE, 10),
array(DYE, 9),
array(DYE, 8),
);
public static function fromString($str, $multiple = false){
if($multiple === true){
$blocks = array();
foreach(explode(",",$str) as $b){
$blocks[] = BlockAPI::fromString($b, false);
}
return $blocks;
}else{
$b = explode(":", str_replace(" ", "_", trim($str)));
if(!isset($b[1])){
$meta = 0;
}else{
$meta = ((int) $b[1]) & 0xFFFF;
}
if(defined(strtoupper($b[0]))){
$item = BlockAPI::getItem(constant(strtoupper($b[0])), $meta);
if($item->getID() === AIR and strtoupper($b[0]) !== "AIR"){
$item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta);
}
}else{
$item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta);
}
return $item;
}
}
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){
$id = (int) $id;
if(isset(Item::$class[$id])){
$classname = Item::$class[$id];
$i = new $classname($meta, $count);
}else{
$i = new Item($id, $meta, $count);
}
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("give", "<player> <item[:damage]> [amount]", array($this, "commandHandler"));
}
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "give":
if(!isset($params[0]) or !isset($params[1])){
$output .= "Usage: /give <player> <item[:damage]> [amount]\n";
break;
}
$player = $this->server->api->player->get($params[0]);
$item = BlockAPI::fromString($params[1]);
if(!isset($params[2])){
$item->count = $item->getMaxStackSize();
}else{
$item->count = (int) $params[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){
$target = $player->level->getBlock($vector);
$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.break.bypass", array("player" => $player, "target" => $target, "item" => $item)) !== true){
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($this->server->api->dhandle("player.block.break.bypass", array("player" => $player, "target" => $target, "item" => $item)) !== true){
return $this->cancelAction($target, $player, false);
}
}
$player->lastBreak = microtime(true);
if($this->server->api->dhandle("player.block.break", array("player" => $player, "target" => $target, "item" => $item)) !== false){
$drops = $target->getDrops($item, $player);
if($target->onBreak($item, $player) === false){
return $this->cancelAction($target, $player, false);
}
if(($player->gamemode & 0x01) === 0 and $item->useOn($target) and $item->getMetadata() >= $item->getMaxDurability()){
$player->setSlot($player->slot, new Item(AIR, 0, 0), false);
}
}else{
return $this->cancelAction($target, $player, false);
}
if(($player->gamemode & 0x01) === 0x00 and count($drops) > 0){
foreach($drops as $drop){
$this->server->api->entity->drop(new Position($target->x + 0.5, $target->y, $target->z + 0.5, $target->level), BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2]));
}
}
return false;
}
public function playerBlockAction(Player $player, Vector3 $vector, $face, $fx, $fy, $fz){
if($face < 0 or $face > 5){
return false;
}
$target = $player->level->getBlock($vector);
$block = $target->getSide($face);
$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($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){
$this->cancelAction($target, $player);
return $this->cancelAction($block, $player);
}
}
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.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){
return $this->cancelAction($block, $player);
}
}
$this->blockUpdate($target, BLOCK_UPDATE_TOUCH);
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){
return false;
}
}
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){
return $this->cancelAction($block, $player, false);
}
}
if($block->y > 127 or $block->y < 0){
return false;
}
if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){
if($item->count <= 0){
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false);
}
return false;
}
if($item->isPlaceable()){
$hand = $item->getBlock();
$hand->position($block);
}elseif($block->getID() === FIRE){
$player->level->setBlock($block, new AirBlock(), true, false, true);
return false;
}else{
return $this->cancelAction($block, $player, false);
}
if(!($block->isReplaceable === true or ($hand->getID() === SLAB and $block->getID() === SLAB))){
return $this->cancelAction($block, $player, false);
}
if($target->isReplaceable === true){
$block = $target;
$hand->position($block);
//$face = -1;
}
if($hand->isSolid === true and $player->entity->inBlock($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){
return $this->cancelAction($block, $player);
}elseif($hand->place($item, $player, $block, $target, $face, $fx, $fy, $fz) === false){
return $this->cancelAction($block, $player, false);
}
if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){
$t = $this->server->api->tile->addSign($player->level, $block->x, $block->y, $block->z);
$t->data["creator"] = $player->username;
}
if(($player->gamemode & 0x01) === 0x00){
--$item->count;
if($item->count <= 0){
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), 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){
if(!($pos instanceof Block)){
$block = $pos->level->getBlock($pos);
}else{
$pos = new Position($pos->x, $pos->y, $pos->z, $pos->level);
$block = $pos->level->getBlock($pos);
}
if($block === false){
return false;
}
$level = $block->onUpdate($type);
if($level === BLOCK_UPDATE_NORMAL){
$this->blockUpdateAround($block, $level);
$this->server->api->entity->updateRadius($pos, 1);
}elseif($level === BLOCK_UPDATE_RANDOM){
$this->nextRandomUpdate($pos);
}
return $level;
}
public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){
$type = (int) $type;
if($delay < 0){
return false;
}
$index = $pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".$type;
$delay = microtime(true) + $delay * 0.05;
if(!isset($this->scheduledUpdates[$index])){
$this->scheduledUpdates[$index] = $pos;
$this->server->query("INSERT INTO blockUpdates (x, y, z, level, type, delay) VALUES (".$pos->x.", ".$pos->y.", ".$pos->z.", '".$pos->level->getName()."', ".$type.", ".$delay.");");
return true;
}
return false;
}
public function nextRandomUpdate(Position $pos){
if(!isset($this->scheduledUpdates[$pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".BLOCK_UPDATE_RANDOM])){
$time = microtime(true);
$offset = 0;
do{
$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).";");
if($update instanceof SQLite3Result){
$update = $update->fetchArray(SQLITE3_NUM);
if($update[0] < 3){
break;
}
}else{
break;
}
$offset += mt_rand(25, 75);
}while(true);
$this->scheduleBlockUpdate($pos, $t / 0.05, BLOCK_UPDATE_RANDOM);
}
}
public function blockUpdateTick(){
$time = microtime(true);
if(count($this->scheduledUpdates) > 0){
$update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE delay <= ".$time.";");
if($update instanceof SQLite3Result){
$upp = array();
while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){
$index = $up["x"].".".$up["y"].".".$up["z"].".".$up["level"].".".$up["type"];
if(isset($this->scheduledUpdates[$index])){
$upp[] = array((int) $up["type"], $this->scheduledUpdates[$index]);
unset($this->scheduledUpdates[$index]);
}
}
$this->server->query("DELETE FROM blockUpdates WHERE delay <= ".$time.";");
foreach($upp as $b){
$this->blockUpdate($b[1], $b[0]);
}
}
}
}
}

View File

@ -1,147 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class ChatAPI{
private $server;
function __construct(){
$this->server = ServerAPI::request();
}
public function init(){
$this->server->api->console->register("tell", "<player> <private message ...>", array($this, "commandHandler"));
$this->server->api->console->register("me", "<action ...>", array($this, "commandHandler"));
$this->server->api->console->register("say", "<message ...>", array($this, "commandHandler"));
$this->server->api->ban->cmdWhitelist("tell");
$this->server->api->ban->cmdWhitelist("me");
}
/**
* @param string $cmd
* @param array $params
* @param string $issuer
* @param string $alias
*
* @return string
*/
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "say":
$s = implode(" ", $params);
if(trim($s) == ""){
$output .= "Usage: /say <message>\n";
break;
}
$sender = ($issuer instanceof Player) ? "Server":ucfirst($issuer);
$this->server->api->chat->broadcast("[$sender] ".$s);
break;
case "me":
if(!($issuer instanceof Player)){
if($issuer === "rcon"){
$sender = "Rcon";
}else{
$sender = ucfirst($issuer);
}
}else{
$sender = $issuer->username;
}
$this->broadcast("* $sender ".implode(" ", $params));
break;
case "tell":
if(!isset($params[0]) or !isset($params[1])){
$output .= "Usage: /$cmd <player> <message>\n";
break;
}
if(!($issuer instanceof Player)){
$sender = ucfirst($issuer);
}else{
$sender = $issuer->username;
}
$n = array_shift($params);
$target = $this->server->api->player->get($n);
if($target instanceof Player){
$target = $target->username;
}else{
$target = strtolower($n);
if($target === "server" or $target === "console" or $target === "rcon"){
$target = "Console";
}
}
$mes = implode(" ", $params);
$output .= "[me -> ".$target."] ".$mes."\n";
if($target !== "Console" and $target !== "Rcon"){
$this->sendTo(false, "[".$sender." -> me] ".$mes, $target);
}
if($target === "Console" or $sender === "Console"){
console("[INFO] [".$sender." -> ".$target."] ".$mes);
}
break;
}
return $output;
}
/**
* @param string $message
*/
public function broadcast($message){
$this->send(false, $message);
}
/**
* @param string $owner
* @param string $text
* @param mixed $player Can be either Player object or string username. Boolean false for broadcast.
*/
public function sendTo($owner, $text, $player){
$this->send($owner, $text, array($player));
}
/**
* @param mixed $owner Can be either Player object or string username. Boolean false for broadcast.
* @param string $text
* @param $whitelist
* @param $blacklist
*/
public function send($owner, $text, $whitelist = false, $blacklist = false){
$message = array(
"player" => $owner,
"message" => $text,
);
if($owner !== false){
if($owner instanceof Player){
if($whitelist === false){
console("[INFO] <".$owner->username."> ".$text);
}
}else{
if($whitelist === false){
console("[INFO] <".$owner."> ".$text);
}
}
}else{
if($whitelist === false){
console("[INFO] $text");
}
$message["player"] = "";
}
$this->server->handle("server.chat", new Container($message, $whitelist, $blacklist));
}
}

View File

@ -1,332 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class ConsoleAPI{
private $loop, $server, $event, $help, $cmds, $alias;
function __construct(){
$this->help = array();
$this->cmds = array();
$this->alias = array();
$this->server = ServerAPI::request();
}
public function init(){
$this->server->schedule(2, array($this, "handle"), array(), true);
if(!defined("NO_THREADS")){
$this->loop = new ConsoleLoop();
}
$this->register("help", "[page|command name]", array($this, "defaultCommands"));
$this->register("status", "", array($this, "defaultCommands"));
$this->register("difficulty", "<0|1|2|3>", array($this, "defaultCommands"));
$this->register("stop", "", array($this, "defaultCommands"));
$this->register("defaultgamemode", "<mode>", array($this, "defaultCommands"));
$this->server->api->ban->cmdWhitelist("help");
}
function __destruct(){
$this->server->deleteEvent($this->event);
if(!defined("NO_THREADS")){
$this->loop->stop();
$this->loop->notify();
//@fclose($this->loop->fp);
usleep(50000);
$this->loop->kill();
//$this->loop->join();
}
}
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){
$this->alias[strtolower(trim($alias))] = trim($cmd);
return true;
}
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);
}
public function run($line = "", $issuer = "console", $alias = false){
if($line != ""){
$output = "";
$end = strpos($line, " ");
if($end === false){
$end = strlen($line);
}
$cmd = strtolower(substr($line, 0, $end));
$params = (string) substr($line, $end + 1);
if(isset($this->alias[$cmd])){
return $this->run($this->alias[$cmd] . ($params !== "" ? " " .$params:""), $issuer, $cmd);
}
if($issuer instanceof Player){
console("[DEBUG] ".FORMAT_AQUA.$issuer->username.FORMAT_RESET." issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2);
}else{
console("[DEBUG] ".FORMAT_YELLOW."*".$issuer.FORMAT_RESET." issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2);
}
if(preg_match_all('#@([@a-z]{1,})#', $params, $matches, PREG_OFFSET_CAPTURE) > 0){
$offsetshift = 0;
foreach($matches[1] as $selector){
if($selector[0]{0} === "@"){ //Escape!
$params = substr_replace($params, $selector[0], $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1);
--$offsetshift;
continue;
}
switch(strtolower($selector[0])){
case "u":
case "player":
case "username":
$p = ($issuer instanceof Player) ? $issuer->username:$issuer;
$params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1);
$offsetshift -= strlen($selector[0]) - strlen($p) + 1;
break;
case "w":
case "world":
$p = ($issuer instanceof Player) ? $issuer->level->getName():$this->server->api->level->getDefault()->getName();
$params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1);
$offsetshift -= strlen($selector[0]) - strlen($p) + 1;
break;
case "a":
case "all":
if($issuer instanceof Player){
if($this->server->api->ban->isOp($issuer->username)){
$output = "";
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);
}
}else{
$issuer->sendChat("You don't have permissions to use this command.\n");
}
}else{
$output = "";
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);
}
}
return $output;
case "r":
case "random":
$l = array();
foreach($this->server->api->player->getAll() as $p){
if($p !== $issuer){
$l[] = $p;
}
}
if(count($l) === 0){
return;
}
$p = $l[mt_rand(0, count($l) - 1)]->username;
$params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1);
$offsetshift -= strlen($selector[0]) - strlen($p) + 1;
break;
}
}
}
$params = explode(" ", $params);
if(count($params) === 1 and $params[0] === ""){
$params = array();
}
if(($d1 = $this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false
or ($d2 = $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false){
$output = "You don't have permissions to use this command.\n";
}elseif($d1 !== true and (!isset($d2) or $d2 !== true)){
if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){
$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){
$output = $this->defaultCommands($cmd, $params, $issuer, $alias);
}
}
if($output != "" and ($issuer instanceof Player)){
$issuer->sendChat(trim($output));
}
return $output;
}
}
public function handle($time){
if(defined("NO_THREADS")){
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();
}
}
}
class ConsoleLoop extends Thread{
public $line;
public $stop;
public $base;
public $ev;
public $fp;
public function __construct(){
$this->line = false;
$this->stop = false;
$this->start();
}
public function stop(){
$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(){
if(!extension_loaded("readline")){
$this->fp = fopen("php://stdin", "r");
}
while($this->stop === false){
$this->line = $this->readLine();
$this->wait();
$this->line = false;
}
if(!extension_loaded("readline")){
@fclose($this->fp);
}
exit(0);
}
}

View File

@ -1,174 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class EntityAPI{
private $server;
private $entities;
private $eCnt = 1;
function __construct(){
$this->entities = array();
$this->server = ServerAPI::request();
}
public function get($eid){
if(isset($this->entities[$eid])){
return $this->entities[$eid];
}
return false;
}
public function init(){
$this->server->schedule(25, array($this, "updateEntities"), array(), true);
}
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 = 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++;
$this->entities[$eid] = new Entity($level, $eid, $class, $type, $data);
$this->server->handle("entity.add", $this->entities[$eid]);
return $this->entities[$eid];
}
public function spawnToAll(Entity $e){
foreach($this->server->api->player->getAll($e->level) as $player){
if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER and $e instanceof Entity){
$e->spawn($player);
}
}
}
public function drop(Position $pos, Item $item){
if($item->getID() === AIR or $item->count <= 0){
return;
}
$data = array(
"x" => $pos->x + mt_rand(-10, 10) / 50,
"y" => $pos->y + 0.19,
"z" => $pos->z + mt_rand(-10, 10) / 50,
"level" => $pos->level,
//"speedX" => mt_rand(-3, 3) / 8,
"speedY" => mt_rand(5, 8) / 2,
//"speedZ" => mt_rand(-3, 3) / 8,
"item" => $item,
);
if($this->server->api->handle("item.drop", $data) !== false){
for($count = $item->count; $count > 0; ){
$item->count = min($item->getMaxStackSize(), $count);
$count -= $item->count;
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
$this->spawnToAll($e);
$this->server->api->handle("entity.motion", $e);
}
}
}
public function spawnAll(Player $player){
foreach($this->getAll($player->level) as $e){
if($e->class !== ENTITY_PLAYER){
$e->spawn($player);
}
}
}
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);
}
}
}

View File

@ -1,233 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class LevelAPI{
private $server, $levels, $default;
public function __construct(){
$this->server = ServerAPI::request();
$this->levels = array();
}
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(){
$this->server->api->console->register("seed", "[world]", array($this, "commandHandler"));
$this->server->api->console->register("save-all", "", array($this, "commandHandler"));
$this->server->api->console->register("save-on", "", array($this, "commandHandler"));
$this->server->api->console->register("save-off", "", array($this, "commandHandler"));
$this->default = $this->server->api->getProperty("level-name");
if($this->loadLevel($this->default) === false){
$this->generateLevel($this->default, $this->server->seed);
$this->loadLevel($this->default);
}
$this->server->spawn = $this->getDefault()->getSafeSpawn();
}
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "save-all":
$save = $this->server->saveEnabled;
$this->server->saveEnabled = true;
$this->saveAll();
$this->server->saveEnabled = $save;
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 NormalGenerator($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){
if($this->get($name) !== false){
return true;
}elseif($this->levelExists($name) === false){
console("[NOTICE] Level \"".$name."\" not found");
return false;
}
$path = DATA_PATH."worlds/".$name."/";
console("[INFO] Preparing level \"".$name."\"");
$level = new PMFLevel($path."level.pmf");
if(!$level->isLoaded){
console("[ERROR] Could not load level \"".$name."\"");
return false;
}
$entities = new Config($path."entities.yml", CONFIG_YAML);
if(file_exists($path."tileEntities.yml")){
@rename($path."tileEntities.yml", $path."tiles.yml");
}
$tiles = new Config($path."tiles.yml", CONFIG_YAML);
$blockUpdates = new Config($path."bupdates.yml", CONFIG_YAML);
$this->levels[$name] = new Level($level, $entities, $tiles, $blockUpdates, $name);
foreach($entities->getAll() as $entity){
if(!isset($entity["id"])){
break;
}
if($entity["id"] === 64){ //Item Drop
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_ITEM, $entity["Item"]["id"], array(
"meta" => $entity["Item"]["Damage"],
"stack" => $entity["Item"]["Count"],
"x" => $entity["Pos"][0],
"y" => $entity["Pos"][1],
"z" => $entity["Pos"][2],
"yaw" => $entity["Rotation"][0],
"pitch" => $entity["Rotation"][1],
));
}elseif($entity["id"] === FALLING_SAND){
$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->setHealth($entity["Health"]);
}elseif($entity["id"] === OBJECT_PAINTING or $entity["id"] === OBJECT_ARROW){ //Painting
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_OBJECT, $entity["id"], $entity);
$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
$e->setHealth(1);
}else{
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_MOB, $entity["id"], $entity);
$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
$e->setHealth($entity["Health"]);
}
}
foreach($tiles->getAll() as $tile){
if(!isset($tile["id"])){
break;
}
$t = $this->server->api->tile->add($this->levels[$name], $tile["id"], $tile["x"], $tile["y"], $tile["z"], $tile);
}
foreach($blockUpdates->getAll() as $bupdate){
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
}
return true;
}
public function handle($data, $event){
switch($event){
}
}
public function saveAll(){
foreach($this->levels as $level){
$level->save();
}
}
public function __destruct(){
$this->saveAll();
foreach($this->levels as $level){
$this->unloadLevel($level, true);
}
}
public function getSpawn(){
return $this->server->spawn;
}
public function getAll(){
return $this->levels;
}
}

View File

@ -1,522 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class PlayerAPI{
private $server;
function __construct(){
$this->server = ServerAPI::request();
}
public function init(){
$this->server->schedule(20 * 15, array($this, "handle"), 1, true, "server.regeneration");
$this->server->addHandler("player.death", array($this, "handle"), 1);
$this->server->api->console->register("list", "", array($this, "commandHandler"));
$this->server->api->console->register("kill", "<player>", array($this, "commandHandler"));
$this->server->api->console->register("gamemode", "<mode> [player]", array($this, "commandHandler"));
$this->server->api->console->register("tp", "[target player] <destination player | w:world> OR /tp [target player] <x> <y> <z>", array($this, "commandHandler"));
$this->server->api->console->register("spawnpoint", "[player | w:world] [x] [y] [z]", array($this, "commandHandler"));
$this->server->api->console->register("spawn", "", array($this, "commandHandler"));
$this->server->api->console->register("ping", "", array($this, "commandHandler"));
$this->server->api->console->alias("lag", "ping");
$this->server->api->console->alias("suicide", "kill");
$this->server->api->console->alias("tppos", "tp");
$this->server->api->ban->cmdWhitelist("list");
$this->server->api->ban->cmdWhitelist("ping");
$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;");
}
public function handle($data, $event){
switch($event){
case "server.regeneration":
if($this->server->difficulty === 0){
$result = $this->server->preparedSQL->selectPlayersToHeal->execute();
if($result !== false){
while(($player = $result->fetchArray()) !== false){
if(($player = $this->server->api->entity->get($player["EID"])) !== false){
if($player->getHealth() <= 0){
continue;
}
$player->setHealth(min(20, $player->getHealth() + $data), "regeneration");
}
}
return true;
}
}
break;
case "player.death":
if(is_numeric($data["cause"])){
$e = $this->server->api->entity->get($data["cause"]);
if($e instanceof Entity){
switch($e->class){
case ENTITY_PLAYER:
$message = " was killed by ".$e->name;
break;
default:
$message = " was killed";
break;
}
}
}else{
switch($data["cause"]){
case "cactus":
$message = " was pricked to death";
break;
case "lava":
$message = " tried to swim in lava";
break;
case "fire":
$message = " went up in flames";
break;
case "burning":
$message = " burned to death";
break;
case "suffocation":
$message = " suffocated in a wall";
break;
case "water":
$message = " drowned";
break;
case "void":
$message = " fell out of the world";
break;
case "fall":
$message = " hit the ground too hard";
break;
case "explosion":
$message = " blew up";
break;
default:
$message = " died";
break;
}
}
$this->server->api->chat->broadcast($data["player"]->username . $message);
return true;
}
}
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "spawnpoint":
if(count($params) === 0){
$output .= "Usage: /$cmd [player | w:world] [x] [y] [z]\n";
break;
}
if(!($issuer instanceof Player) and count($params) < 4){
$output .= "Please run this command in-game.\n";
break;
}
if(count($params) === 1 or count($params) === 4){
$tg = array_shift($params);
if(count($params) === 3 and substr($tg, 0, 2) === "w:"){
$target = $this->server->api->level->get(substr($tg, 2));
}else{
$target = $this->server->api->player->get($tg);
}
}else{
$target = $issuer;
}
if(!($target instanceof Player) and !($target instanceof Level)){
$output .= "That player cannot be found.\n";
break;
}
if(count($params) === 3){
if($target instanceof Level){
$spawn = new Vector3(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)));
}else{
$spawn = new Position(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)), $issuer->level);
}
}else{
$spawn = new Position($issuer->entity->x, $issuer->entity->y, $issuer->entity->z, $issuer->entity->level);
}
$target->setSpawn($spawn);
if($target instanceof Level){
$output .= "Spawnpoint of world ".$target->getName()." set correctly!\n";
}elseif($target !== $issuer){
$output .= "Spawnpoint of ".$target->username." set correctly!\n";
}else{
$output .= "Spawnpoint set correctly!\n";
}
break;
case "spawn":
if(!($issuer instanceof Player)){
$output .= "Please run this command in-game.\n";
break;
}
$issuer->teleport($this->server->spawn);
break;
case "ping":
if(!($issuer instanceof Player)){
$output .= "Please run this command in-game.\n";
break;
}
$output .= "ping ".round($issuer->getLag(), 2)."ms, packet loss ".round($issuer->getPacketLoss() * 100, 2)."%, ".round($issuer->getBandwidth() / 1024, 2)." KB/s\n";
break;
case "gamemode":
$player = false;
$setgm = false;
$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($params[1])){
if($this->server->api->player->get($params[1]) instanceof Player){
$player = $this->server->api->player->get($params[1]);
$setgm = $params[0];
}elseif($this->server->api->player->get($params[0]) instanceof Player){
$player = $this->server->api->player->get($params[0]);
$setgm = $params[1];
}else{
$output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n";
break;
}
}elseif(isset($params[0])){
if(!($this->server->api->player->get($params[0]) instanceof Player)){
if($issuer instanceof Player){
$setgm = $params[0];
$player = $issuer;
}
}
}
if(!($player instanceof Player) or !isset($gms[strtolower($setgm)])){
$output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n";
break;
}
if($player->setGamemode($gms[strtolower($setgm)])){
$output .= "Gamemode of ".$player->username." changed to ".$player->getGamemode()."\n";
}
break;
case "tp":
if(count($params) <= 2 or substr($params[0], 0, 2) === "w:" or substr($params[1], 0, 2) === "w:"){
if((!isset($params[1]) or substr($params[0], 0, 2) === "w:") and isset($params[0]) and ($issuer instanceof Player)){
$name = $issuer->username;
$target = implode(" ", $params);
}elseif(isset($params[1]) and isset($params[0])){
$name = array_shift($params);
$target = implode(" ", $params);
}else{
$output .= "Usage: /$cmd [target player] <destination player | w:world>\n";
break;
}
if($this->teleport($name, $target) !== false){
$output .= "\"$name\" teleported to \"$target\"\n";
}else{
$output .= "Couldn't teleport.\n";
}
}else{
if(!isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0]) and ($issuer instanceof Player)){
$name = $issuer->username;
$x = $params[0];
$y = $params[1];
$z = $params[2];
}elseif(isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0])){
$name = $params[0];
$x = $params[1];
$y = $params[2];
$z = $params[3];
}else{
$output .= "Usage: /$cmd [player] <x> <y> <z>\n";
break;
}
if($this->tppos($name, $x, $y, $z)){
$output .= "\"$name\" teleported to ($x, $y, $z)\n";
}else{
$output .= "Couldn't teleport.\n";
}
}
break;
case "kill":
case "suicide":
if(!isset($params[0]) and ($issuer instanceof Player)){
$player = $issuer;
}else{
$player = $this->get($params[0]);
}
if($player instanceof Player){
$player->entity->harm(1000, "console", true);
$player->sendChat("Ouch. That looks like it hurt.\n");
}else{
$output .= "Usage: /$cmd [player]\n";
}
break;
case "list":
$cmd_output .= "There are ".count($this->server->clients)."/".$this->server->maxClients." players online:\n";
if(count($this->server->clients) == 0){
break;
}
foreach($this->server->clients as $c){
$cmd_output .= $c->username.", ";
}
$output = substr($cmd_output, 0, -2)."\n";
break;
}
return $output;
}
public function teleport(&$name, &$target){
if(substr($target, 0, 2) === "w:"){
$lv = $this->server->api->level->get(substr($target, 2));
if($lv instanceof Level){
$origin = $this->get($name);
if($origin instanceof Player){
$name = $origin->username;
return $origin->teleport($lv->getSafeSpawn());
}
}else{
return false;
}
}
$player = $this->get($target);
if(($player instanceof Player) and ($player->entity instanceof Entity)){
$target = $player->username;
$origin = $this->get($name);
if($origin instanceof Player){
$name = $origin->username;
return $origin->teleport($player->entity);
}
}
return false;
}
public function tppos(&$name, &$x, &$y, &$z){
$player = $this->get($name);
if(($player instanceof Player) and ($player->entity instanceof Entity)){
$name = $player->username;
$x = $x{0} === "~" ? $player->entity->x + floatval(substr($x, 1)):floatval($x);
$y = $y{0} === "~" ? $player->entity->y + floatval(substr($y, 1)):floatval($y);
$z = $z{0} === "~" ? $player->entity->z + floatval(substr($z, 1)):floatval($z);
$player->teleport(new Vector3($x, $y, $z));
return true;
}
return false;
}
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 = MainServer::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){
foreach($players as $p){
$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 = MainServer::clientID($CID["ip"], $CID["port"]);
if(isset($this->server->clients[$CID])){
return $this->server->clients[$CID];
}
return false;
}
public function online(){
$o = array();
foreach($this->server->clients as $p){
if($p->auth === true){
$o[] = $p->username;
}
}
return $o;
}
public function add($CID){
if(isset($this->server->clients[$CID])){
$player = $this->server->clients[$CID];
$player->data = $this->getOffline($player->username);
$player->gamemode = $player->data->get("gamemode");
if(($player->level = $this->server->api->level->get($player->data->get("position")["level"])) === false){
$player->level = $this->server->api->level->getDefault();
$player->data->set("position", array(
"level" => $player->level->getName(),
"x" => $player->level->getSpawn()->x,
"y" => $player->level->getSpawn()->y,
"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)."');");
}
}
public function spawnAllPlayers(Player $player){
foreach($this->getAll() as $p){
if($p !== $player and ($p->entity instanceof Entity)){
$p->entity->spawn($player);
if($p->level !== $player->level){
$pk = new MoveEntityPacket_PosRot;
$pk->eid = $p->entity->eid;
$pk->x = -256;
$pk->y = 128;
$pk->z = -256;
$pk->yaw = 0;
$pk->pitch = 0;
$player->dataPacket($pk);
}
}
}
}
public function spawnToAllPlayers(Player $player){
foreach($this->getAll() as $p){
if($p !== $player and ($p->entity instanceof Entity) and ($player->entity instanceof Entity)){
$player->entity->spawn($p);
if($p->level !== $player->level){
$pk = new MoveEntityPacket_PosRot;
$pk->eid = $player->entity->eid;
$pk->x = -256;
$pk->y = 128;
$pk->z = -256;
$pk->yaw = 0;
$pk->pitch = 0;
$p->dataPacket($pk);
}
}
}
}
public function remove($CID){
if(isset($this->server->clients[$CID])){
$player = $this->server->clients[$CID];
unset($this->server->clients[$CID]);
$player->close();
if($player->username != "" and ($player->data instanceof Config)){
$this->saveOffline($player->data);
}
$this->server->query("DELETE FROM players WHERE name = '".$player->username."';");
if($player->entity instanceof Entity){
unset($player->entity->player);
//unset($player->entity);
}
$this->server->api->entity->remove($player->eid);
$player = null;
unset($player);
}
}
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")){
console("[NOTICE] Player data not found for \"".$iname."\", creating new profile");
$data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default);
$data->save();
}else{
$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){
$this->server->handle("player.offline.save", $data);
$data->save();
}
}

View File

@ -1,248 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class PluginAPI extends stdClass{
private $server;
private $plugins = array();
private $randomNonce;
public function __construct(){
$this->server = ServerAPI::request();
$this->randomNonce = Utils::getRandomBytes(16, false);
$this->server->api->console->register("plugins", "", array($this, "commandHandler"));
$this->server->api->console->register("version", "", array($this, "commandHandler"));
$this->server->api->ban->cmdWhitelist("version");
}
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "plugins":
$output = "Plugins: ";
foreach($this->getList() as $plugin){
$output .= $plugin["name"] . ": ".$plugin["version"] .", ";
}
$output = $output === "Plugins: " ? "No plugins installed.\n" : substr($output, 0, -2)."\n";
break;
case "version":
$output = "PocketMine-MP ".MAJOR_VERSION."".CODENAME."」 API #".CURRENT_API_VERSION." for Minecraft: PE ".CURRENT_MINECRAFT_VERSION." protocol #".ProtocolInfo::CURRENT_PROTOCOL;
if(GIT_COMMIT !== str_repeat("00", 20)){
$output .= " (git ".GIT_COMMIT.")";
}
$output .= "\n";
break;
}
return $output;
}
public function __destruct(){
foreach($this->plugins as $p){
$p[0]->__destruct();
}
unset($plugins);
}
public function getList(){
$list = array();
foreach($this->plugins as $p){
$list[] = $p[1];
}
return $list;
}
public function getAll(){
return $this->plugins;
}
public function load($file){
if(is_link($file) or is_dir($file) or !file_exists($file)){
console("[ERROR] ".basename($file)." is not a file");
return false;
}
if(strtolower(substr($file, -3)) === "pmf"){
$pmf = new PMFPlugin($file);
$info = $pmf->getPluginInfo();
}else{
$content = file_get_contents($file);
$info = strstr($content, "*/", true);
$content = str_repeat(PHP_EOL, substr_count($info, "\n")).substr(strstr($content, "*/"),2);
if(preg_match_all('#([a-zA-Z0-9\-_]*)=([^\r\n]*)#u', $info, $matches) == 0){ //false or 0 matches
console("[ERROR] Failed parsing of ".basename($file));
return false;
}
$info = array();
foreach($matches[1] as $k => $i){
$v = $matches[2][$k];
switch(strtolower($v)){
case "on":
case "true":
case "yes":
$v = true;
break;
case "off":
case "false":
case "no":
$v = false;
break;
}
$info[$i] = $v;
}
$info["code"] = $content;
$info["class"] = trim(strtolower($info["class"]));
}
if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"]) or !isset($info["author"])){
console("[ERROR] Failed parsing of ".basename($file));
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);
if($info["class"] !== "none" and class_exists($info["class"])){
console("[ERROR] Failed loading plugin: class already exists");
return false;
}
if(((!isset($pmf) and (include $file) === false) or (isset($pmf) and eval($info["code"]) === false)) and $info["class"] !== "none" and !class_exists($info["class"])){
console("[ERROR] Failed loading {$info['name']}: evaluation error");
return false;
}
$className = $info["class"];
$apiversion = array_map("intval", explode(",", (string) $info["apiversion"]));
if(!in_array((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!");
}
$identifier = $this->getIdentifier($info["name"], $info["author"]);
if($info["class"] !== "none"){
$object = new $className($this->server->api, false);
if(!($object instanceof Plugin)){
console("[ERROR] Plugin \"".$info["name"]."\" doesn't use the Plugin Interface");
if(method_exists($object, "__destruct")){
$object->__destruct();
}
$object = null;
unset($object);
}else{
$this->plugins[$identifier] = array($object, $info);
}
}else{
$this->plugins[$identifier] = array(new DummyPlugin($this->server->api, false), $info);
}
return true;
}
public function getIdentifier($name, $author){
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;
}
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(){
console("[INFO] Starting plugins...");
foreach($this->plugins as $p){
$p[0]->init(); //ARGHHH!!! Plugin loading randomly fails!!
}
}
}
interface Plugin{
public function __construct(ServerAPI $api, $server = false);
public function init();
public function __destruct();
}
class DummyPlugin implements Plugin{
public function __construct(ServerAPI $api, $server = false){
}
public function init(){
}
public function __destruct(){
}
}

View File

@ -1,488 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
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 $query;
//TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs.
/**
* @var ConsoleAPI
*/
public $console;
/**
* @var LevelAPI
*/
public $level;
/**
* @var BlockAPI
*/
public $block;
/**
* @var ChatAPI
*/
public $chat;
/**
* @var BanAPI
*/
public $ban;
/**
* @var EntityAPI
*/
public $entity;
/**
* @var TimeAPI
*/
public $time;
/**
* @var PlayerAPI
*/
public $player;
/**
* @var TileAPI
*/
public $tile;
/**
* @return MainServer
*/
public static function request(){
return self::$serverRequest;
}
public function start(){
return $this->run();
}
public function run(){
$this->load();
return $this->init();
}
public function load(){
@mkdir(DATA_PATH."players/", 0755);
@mkdir(DATA_PATH."worlds/", 0755);
@mkdir(DATA_PATH."plugins/", 0755);
//Init all the events
foreach(get_declared_classes() as $class){
if(is_subclass_of($class, "BaseEvent") and property_exists($class, "handlers") and property_exists($class, "handlerPriority")){
$class::unregisterAll();
}
}
$version = new VersionString();
console("[INFO] Starting Minecraft PE server version ".FORMAT_AQUA.CURRENT_MINECRAFT_VERSION);
console("[INFO] Loading properties...");
$this->config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES, array(
"server-name" => "Minecraft: PE Server",
"description" => "Server made using PocketMine-MP",
"motd" => "Welcome @player to this server!",
"server-ip" => "",
"server-port" => 19132,
"server-type" => "normal",
"memory-limit" => "128M",
"last-update" => false,
"white-list" => false,
"announce-player-achievements" => true,
"spawn-protection" => 16,
"view-distance" => 10,
"max-players" => 20,
"allow-flight" => false,
"spawn-animals" => true,
"spawn-mobs" => true,
"gamemode" => SURVIVAL,
"hardcore" => false,
"pvp" => true,
"difficulty" => 1,
"generator-settings" => "",
"level-name" => "world",
"level-seed" => "",
"level-type" => "DEFAULT",
"enable-query" => true,
"enable-rcon" => false,
"rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10),
"auto-save" => true,
));
$this->parseProperties();
//Load advanced properties
define("DEBUG", $this->getProperty("debug", 1));
define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false));
define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 7)); //Default rate ~448 kB/s
if(ADVANCED_CACHE == true){
console("[INFO] Advanced cache enabled");
}
if($this->getProperty("upnp-forwarding") == true){
console("[INFO] [UPnP] Trying to port forward...");
UPnP_PortForward($this->getProperty("server-port"));
}
$this->server = new MainServer($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed:false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0");
$this->server->api = $this;
self::$serverRequest = $this->server;
console("[INFO] This server is running PocketMine-MP version ".($version->isDev() ? FORMAT_YELLOW:"").MAJOR_VERSION.FORMAT_RESET." \"".CODENAME."\" (MCPE: ".CURRENT_MINECRAFT_VERSION.") (API ".CURRENT_API_VERSION.")", true, true, 0);
console("[INFO] PocketMine-MP is distributed under the LGPL License", true, true, 0);
if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){
console("[INFO] Checking for new server version");
console("[INFO] Last check: ".FORMAT_AQUA.date("Y-m-d H:i:s", $this->getProperty("last-update"))."\x1b[0m");
if($this->server->version->isDev()){
$info = json_decode(Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/commits"), true);
if($info === false or !isset($info[0])){
console("[ERROR] Github API error");
}else{
$last = new DateTime($info[0]["commit"]["committer"]["date"]);
$last = $last->getTimestamp();
if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false and GIT_COMMIT != $info[0]["sha"]){
console("[NOTICE] ".FORMAT_YELLOW."A new DEVELOPMENT version of PocketMine-MP has been released!");
console("[NOTICE] ".FORMAT_YELLOW."Commit \"".$info[0]["commit"]["message"]."\" [".substr($info[0]["sha"], 0, 10)."] by ".$info[0]["commit"]["committer"]["name"]);
console("[NOTICE] ".FORMAT_YELLOW."Get it at PocketMine.net or at https://github.com/PocketMine/PocketMine-MP/archive/".$info[0]["sha"].".zip");
console("[NOTICE] This message will dissapear after issuing the command \"/update-done\"");
}else{
$this->setProperty("last-update", time());
console("[INFO] ".FORMAT_AQUA."This is the latest DEVELOPMENT version");
}
}
}else{
$info = json_decode(Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/tags"), true);
if($info === false or !isset($info[0])){
console("[ERROR] Github API error");
}else{
$newest = new VersionString(MAJOR_VERSION);
$newestN = $newest->getNumber();
$update = new VersionString($info[0]["name"]);
$updateN = $update->getNumber();
if($updateN > $newestN){
console("[NOTICE] ".FORMAT_GREEN."A new STABLE version of PocketMine-MP has been released!");
console("[NOTICE] ".FORMAT_GREEN."Version \"".$info[0]["name"]."\" #".$updateN);
console("[NOTICE] Get it at PocketMine.net or at ".$info[0]["zipball_url"]);
console("[NOTICE] This message will dissapear as soon as you update");
}else{
$this->setProperty("last-update", time());
console("[INFO] ".FORMAT_AQUA."This is the latest STABLE version");
}
}
}
}
$this->loadProperties();
$this->loadAPI("console", "ConsoleAPI");
$this->loadAPI("level", "LevelAPI");
$this->loadAPI("block", "BlockAPI");
$this->loadAPI("chat", "ChatAPI");
$this->loadAPI("ban", "BanAPI");
$this->loadAPI("entity", "EntityAPI");
$this->loadAPI("tile", "TileAPI");
$this->loadAPI("player", "PlayerAPI");
$this->loadAPI("time", "TimeAPI");
foreach($this->apiList as $ob){
if(is_callable(array($ob, "init"))){
$ob->init(); //Fails sometimes!!!
}
}
$this->loadAPI("plugin", "PluginAPI"); //fix :(
$this->plugin->init();
}
public function async(callable $callable, $params = array(), $remove = false){
$cnt = $this->asyncCnt++;
$this->asyncCalls[$cnt] = new Async($callable, $params);
return $remove === true ? $this->getAsync($cnt):$cnt;
}
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 sendUsage(){
console("[DEBUG] Sending usage data...", true, true, 2);
$plist = "";
foreach($this->plugin->getList() as $p){
$plist .= str_replace(array(";", ":"), "", $p["name"]).":".str_replace(array(";", ":"), "", $p["version"]).";";
}
$this->asyncOperation(ASYNC_CURL_POST, array(
"url" => "http://stats.pocketmine.net/usage.php",
"data" => array(
"serverid" => $this->server->serverID,
"port" => $this->server->port,
"os" => Utils::getOS(),
"memory_total" => $this->getProperty("memory-limit"),
"memory_usage" => memory_get_usage(true),
"php_version" => PHP_VERSION,
"version" => MAJOR_VERSION,
"mc_version" => CURRENT_MINECRAFT_VERSION,
"protocol" => ProtocolInfo::CURRENT_PROTOCOL,
"online" => count($this->server->clients),
"max" => $this->server->maxClients,
"plugins" => $plist,
),
), NULL);
}
public function __destruct(){
foreach($this->apiList as $i => $ob){
if(method_exists($ob, "__destruct")){
$ob->__destruct();
unset($this->apiList[$i]);
}
}
}
private function loadProperties(){
if(($memory = str_replace("B", "", strtoupper($this->getProperty("memory-limit")))) !== false){
$value = array("M" => 1, "G" => 1024);
$real = ((int) substr($memory, 0, -1)) * $value[substr($memory, -1)];
if($real < 128){
console("[WARNING] PocketMine-MP may not work right with less than 128MB of RAM", true, true, 0);
}
@ini_set("memory_limit", $memory);
}else{
$this->setProperty("memory-limit", "128M");
}
if($this->server instanceof MainServer){
$this->server->setType($this->getProperty("server-type"));
$this->server->maxClients = $this->getProperty("max-players");
$this->server->description = $this->getProperty("description");
$this->server->motd = $this->getProperty("motd");
$this->server->gamemode = $this->getProperty("gamemode");
$this->server->difficulty = $this->getProperty("difficulty");
$this->server->whitelist = $this->getProperty("white-list");
}
}
private function writeProperties(){
$this->config->save();
}
private function parseProperties(){
foreach($this->config->getAll() as $n => $v){
switch($n){
case "last-update":
if($v === false){
$v = time();
}else{
$v = (int) $v;
}
break;
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;
}
$this->config->set($n, $v);
}
if($this->getProperty("hardcore") == 1 and $this->getProperty("difficulty") < 3){
$this->setProperty("difficulty", 3);
}
}
public function init(){
if(!(self::$serverRequest instanceof MainServer)){
self::$serverRequest = $this->server;
}
if($this->getProperty("send-usage", true) !== false){
$this->server->schedule(6000, array($this, "sendUsage"), array(), true); //Send the info after 5 minutes have passed
$this->sendUsage();
}
if($this->getProperty("auto-save") === true){
$this->server->schedule(18000, array($this, "autoSave"), array(), true);
}
if(!defined("NO_THREADS") and $this->getProperty("enable-rcon") === true){
$this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50));
}
if($this->getProperty("enable-query") === true){
$this->query = new QueryHandler();
}
CraftingRecipes::init();
$this->server->init();
unregister_tick_function(array($this->server, "tick"));
$this->console->__destruct();
if($this->rcon instanceof RCON){
$this->rcon->stop();
}
$this->__destruct();
if($this->getProperty("upnp-forwarding") === true ){
console("[INFO] [UPnP] Removing port forward...");
UPnP_RemovePortForward($this->getProperty("server-port"));
}
return $this->restart;
}
/*-------------------------------------------------------------*/
public function asyncOperation($t, $d, $c = null){
return $this->server->asyncOperation($t, $d, $c);
}
public function addHandler($e, $c, $p = 5){
return $this->server->addHandler($e, $c, $p);
}
public function dhandle($e, $d){
return $this->server->handle($e, $d);
}
public function handle($e, &$d){
return $this->server->handle($e, $d);
}
public function schedule($t, $c, $d, $r = false, $e = "server.schedule"){
return $this->server->schedule($t, $c, $d, $r, $e);
}
public function event($e, $d){
return $this->server->event($e, $d);
}
public function trigger($e, $d){
return $this->server->trigger($e, $d);
}
public function deleteEvent($id){
return $this->server->deleteEvent($id);
}
public function getProperties(){
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 "last-update":
if($v === false){
$v = time();
}else{
$v = (int) $v;
}
break;
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(){
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,116 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class TileAPI{
private $server;
private $tiles;
private $tCnt = 1;
function __construct(){
$this->tiles = array();
$this->server = ServerAPI::request();
}
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);
if($tile !== false and $tile !== true and ($tile = $this->getByID($tile["ID"])) !== false){
return $tile;
}
return false;
}
public function getByID($id){
if($id instanceof Tile){
return $id;
}elseif(isset($this->tiles[$id])){
return $this->tiles[$id];
}
return false;
}
public function init(){
}
public function getAll($level = null){
if($level instanceof Level){
$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",
"x" => $x,
"y" => $y,
"z" => $z,
"Text1" => $lines[0],
"Text2" => $lines[1],
"Text3" => $lines[2],
"Text4" => $lines[3],
));
}
public function spawnToAll(Tile $t){
foreach($this->server->api->player->getAll($t->level) as $player){
if($player->eid !== false){
$t->spawn($player);
}
}
}
public function spawnAll(Player $player){
foreach($this->getAll($player->level) as $t){
$t->spawn($player);
}
}
public function remove($id){
if(isset($this->tiles[$id])){
$t = $this->tiles[$id];
$this->tiles[$id] = null;
unset($this->tiles[$id]);
$t->closed = true;
$t->close();
$this->server->query("DELETE FROM tiles WHERE ID = ".$id.";");
$this->server->api->dhandle("tile.remove", $t);
$t = null;
unset($t);
}
}
}

View File

@ -1,131 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class TimeAPI{
public static $phases = array(
"day" => 0,
"sunset" => 9500,
"night" => 10900,
"sunrise" => 17800,
);
private $server;
function __construct(){
$this->server = ServerAPI::request();
}
public function init(){
$this->server->api->console->register("time", "<check|set|add> [time]", array($this, "commandHandler"));
}
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "time":
$level = false;
if($issuer instanceof Player){
$level = $issuer->level;
}
$p = strtolower(array_shift($params));
switch($p){
case "check":
$output .= "Time: ".$this->getDate($level).", ".$this->getPhase($level)." (".$this->get(true, $level).")\n";
break;
case "add":
$output .= "Set the time to ".$this->add(array_shift($params), $level)."\n";
break;
case "set":
$output .= "Set the time to ".$this->set(array_shift($params), $level)."\n";
break;
case "sunrise":
case "day":
case "sunset":
case "night":
$output .= "Set the time to ".$this->set($p, $level)."\n";
break;
default:
$output .= "Usage: /time <check|set|add> [time]\n";
break;
}
break;
}
return $output;
}
public function night(){
return $this->set("night");
}
public function day(){
return $this->set("day");
}
public function sunrise(){
return $this->set("sunrise");
}
public function sunset(){
return $this->set("sunset");
}
public function get($raw = false, $level = false){
if(!($level instanceof Level)){
$level = $this->server->api->level->getDefault();
}
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){
$time = !is_integer($time) ? $this->get(false, $time):$time;
if($time < TimeAPI::$phases["sunset"]){
$time = "day";
}elseif($time < TimeAPI::$phases["night"]){
$time = "sunset";
}elseif($time < TimeAPI::$phases["sunrise"]){
$time = "night";
}else{
$time = "sunrise";
}
return $time;
}
public function set($time, $level = false){
if(!($level instanceof Level)){
$level = $this->server->api->level->getDefault();
}
if(is_string($time) and isset(TimeAPI::$phases[$time])){
$level->setTime(TimeAPI::$phases[$time]);
}else{
$level->setTime((int) $time);
}
return $level->getTime();
}
}

View File

@ -1,136 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
abstract class BaseEvent{
const ALLOW = 0;
const DENY = 1;
const NORMAL = 2;
const FORCE = 0x80000000;
/**
* Any callable event must declare the static variables
*
* public static $handlers;
* public static $handlerPriority;
*
* Not doing so will deny the proper event initialization
*/
protected $eventName = null;
private $status = BaseEvent::NORMAL;
private $prioritySlot;
final public function getEventName(){
return $this->eventName !== null ? get_class($this) : $this->eventName;
}
final public function setPrioritySlot($slot){
$this->prioritySlot = (int) $slot;
}
final public function getPrioritySlot(){
return (int) $this->prioritySlot;
}
public function isAllowed(){
return ($this->status & 0x7FFFFFFF) === BaseEvent::ALLOW;
}
public function setAllowed($forceAllow = false){
$this->status = BaseEvent::ALLOW | ($forceAllow === true ? BaseEvent::FORCE : 0);
}
public function isCancelled(){
return ($this->status & 0x7FFFFFFF) === BaseEvent::DENY;
}
public function setCancelled($forceCancel = false){
if($this instanceof CancellableEvent){
$this->status = BaseEvent::DENY | ($forceCancel === true ? BaseEvent::FORCE : 0);
}
return false;
}
public function isNormal(){
return $this->status === BaseEvent::NORMAL;
}
public function setNormal(){
$this->status = BaseEvent::NORMAL;
}
public function isForced(){
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;
}
}
}

1063
src/EntityOLD.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,691 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class MainServer{
public $tCnt;
public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $spawn, $whitelist, $seed, $stop, $gamemode, $difficulty, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $doTick, $ticks, $memoryStats, $schedule, $asyncThread, $async = array(), $asyncID = 0;
/**
* @var ServerAPI
*/
public $api;
private function load(){
$this->version = new VersionString();
/*if(defined("DEBUG") and DEBUG >= 0){
@cli_set_process_title("PocketMine-MP ".MAJOR_VERSION);
}*/
console("[INFO] Starting Minecraft PE server on ".($this->serverip === "0.0.0.0" ? "*":$this->serverip).":".$this->port);
define("BOOTUP_RANDOM", Utils::getRandomBytes(16));
$this->serverID = $this->serverID === false ? Utils::readLong(substr(Utils::getUniqueID(true, $this->serverip . $this->port), 8)):$this->serverID;
$this->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):$this->seed;
$this->startDatabase();
$this->api = false;
$this->tCnt = 1;
$this->events = array();
$this->eventsID = array();
$this->handlers = array();
$this->invisible = false;
$this->difficulty = 1;
$this->custom = array();
$this->evCnt = 1;
$this->handCnt = 1;
$this->eidCnt = 1;
$this->maxClients = 20;
$this->schedule = array();
$this->scheduleCnt = 1;
$this->description = "";
$this->memoryStats = array();
$this->clients = array();
$this->spawn = false;
$this->saveEnabled = true;
$this->whitelist = false;
$this->tickMeasure = array_fill(0, 40, 0);
$this->setType("normal");
$this->interface = new MinecraftInterface("255.255.255.255", $this->port, $this->serverip);
$this->stop = false;
$this->ticks = 0;
if(!defined("NO_THREADS")){
$this->asyncThread = new AsyncMultipleQueue();
}
}
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);
$tps = 40 / ($v[39] - $v[0]);
return round($tps, 4);
}
public function titleTick(){
$time = microtime(true);
if(defined("DEBUG") and DEBUG >= 0 and ENABLE_ANSI === true){
echo "\x1b]0;PocketMine-MP ".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(){
$this->preparedSQL = new stdClass();
$this->preparedSQL->entity = new stdClass();
$this->database = new SQLite3(":memory:", SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
$this->query("PRAGMA journal_mode = OFF;");
$this->query("PRAGMA encoding = \"UTF-8\";");
$this->query("PRAGMA secure_delete = OFF;");
$this->query("CREATE TABLE players (CID INTEGER PRIMARY KEY, EID NUMERIC, ip TEXT, port NUMERIC, name TEXT UNIQUE COLLATE NOCASE);");
$this->query("CREATE TABLE entities (EID INTEGER PRIMARY KEY, level TEXT, type NUMERIC, class NUMERIC, hasUpdate NUMERIC, name TEXT, x NUMERIC, y NUMERIC, z NUMERIC, yaw NUMERIC, pitch NUMERIC, health NUMERIC);");
$this->query("CREATE TABLE tiles (ID INTEGER PRIMARY KEY, level TEXT, class TEXT, x NUMERIC, y NUMERIC, z NUMERIC, spawnable NUMERIC);");
$this->query("CREATE TABLE actions (ID INTEGER PRIMARY KEY, interval NUMERIC, last NUMERIC, code TEXT, repeat NUMERIC);");
$this->query("CREATE TABLE handlers (ID INTEGER PRIMARY KEY, name TEXT, priority NUMERIC);");
$this->query("CREATE TABLE blockUpdates (level TEXT, x INTEGER, y INTEGER, z INTEGER, type INTEGER, delay NUMERIC);");
$this->query("CREATE TABLE recipes (id INTEGER PRIMARY KEY, type NUMERIC, recipe TEXT);");
$this->query("PRAGMA synchronous = OFF;");
$this->preparedSQL->selectHandlers = $this->database->prepare("SELECT DISTINCT ID FROM handlers WHERE name = :name ORDER BY priority DESC;");
$this->preparedSQL->selectActions = $this->database->prepare("SELECT ID,code,repeat FROM actions WHERE last <= (:time - interval);");
$this->preparedSQL->updateAction = $this->database->prepare("UPDATE actions SET last = :time WHERE ID = :id;");
$this->preparedSQL->entity->setPosition = $this->database->prepare("UPDATE entities SET x = :x, y = :y, z = :z, pitch = :pitch, yaw = :yaw WHERE EID = :eid ;");
$this->preparedSQL->entity->setLevel = $this->database->prepare("UPDATE entities SET level = :level WHERE EID = :eid ;");
}
public function query($sql, $fetch = false){
$result = $this->database->query($sql) or console("[ERROR] [SQL Error] ".$this->database->lastErrorMsg().". Query: ".$sql, true, true, 0);
if($fetch === true and ($result instanceof SQLite3Result)){
$result = $result->fetchArray(SQLITE3_ASSOC);
}
return $result;
}
public function debugInfo($console = false){
$info = array();
$info["tps"] = $this->getTPS();
$info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2)."MB";
$info["memory_peak_usage"] = round((memory_get_peak_usage() / 1024) / 1024, 2)."MB";
$info["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;
}
/**
* @param string $reason
*/
public function close($reason = "server stop"){
if($this->stop !== true){
if(is_int($reason)){
$reason = "signal stop";
}
if(($this->api instanceof ServerAPI) === true){
if(($this->api->chat instanceof ChatAPI) === true){
$this->api->chat->broadcast("Stopping server...");
}
}
$this->stop = true;
$this->trigger("server.close", $reason);
$this->interface->close();
if(!defined("NO_THREADS")){
@$this->asyncThread->stop = true;
}
}
}
public function setType($type = "normal"){
switch(trim(strtolower($type))){
case "normal":
case "demo":
$this->serverType = "MCCPP;Demo;";
break;
case "minecon":
$this->serverType = "MCCPP;MINECON;";
break;
}
}
public function asyncOperation($type, array $data, callable $callable = null){
if(defined("NO_THREADS")){
return false;
}
$d = "";
$type = (int) $type;
switch($type){
case ASYNC_CURL_GET:
$d .= Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
break;
case ASYNC_CURL_POST:
$d .= Utils::writeShort(strlen($data["url"])).$data["url"].(isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
$d .= Utils::writeShort(count($data["data"]));
foreach($data["data"] as $key => $value){
$d .= Utils::writeShort(strlen($key)).$key . Utils::writeInt(strlen($value)).$value;
}
break;
case ASYNC_FUNCTION:
$params = serialize($data["arguments"]);
$d .= Utils::writeShort(strlen($data["function"])).$data["function"] . Utils::writeInt(strlen($params)) . $params;
break;
default:
return false;
}
$ID = $this->asyncID++;
$this->async[$ID] = $callable;
$this->asyncThread->input .= Utils::writeInt($ID).Utils::writeShort($type).$d;
return $ID;
}
public function asyncOperationChecker(){
if(defined("NO_THREADS")){
return false;
}
if(isset($this->asyncThread->output{5})){
$offset = 0;
$ID = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
$offset += 4;
$type = Utils::readShort(substr($this->asyncThread->output, $offset, 2));
$offset += 2;
$data = array();
switch($type){
case ASYNC_CURL_GET:
case ASYNC_CURL_POST:
$len = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
$offset += 4;
$data["result"] = substr($this->asyncThread->output, $offset, $len);
$offset += $len;
break;
case ASYNC_FUNCTION:
$len = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
$offset += 4;
$data["result"] = unserialize(substr($this->asyncThread->output, $offset, $len));
$offset += $len;
break;
}
$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(is_array($this->async[$ID])){
$method = $this->async[$ID][1];
$result = $this->async[$ID][0]->$method($data, $type, $ID);
}else{
$result = $this->async[$ID]($data, $type, $ID);
}
}
unset($this->async[$ID]);
}
}
/**
* @param string $event
* @param callable $callable
* @param integer $priority
*
* @return boolean
*/
public function addHandler($event,callable $callable, $priority = 5){
if(!is_callable($callable)){
return false;
}elseif(isset(Deprecation::$events[$event])){
$sub = "";
if(Deprecation::$events[$event] !== false){
$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)."]");
}
$priority = (int) $priority;
$hnid = $this->handCnt++;
$this->handlers[$hnid] = $callable;
$this->query("INSERT INTO handlers (ID, name, priority) VALUES (".$hnid.", '".str_replace("'", "\\'", $event)."', ".$priority.");");
console("[INTERNAL] New handler ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)." to special event ".$event." (ID ".$hnid.")", true, true, 3);
return $hnid;
}
public function dhandle($e, $d){
return $this->handle($e, $d);
}
public function handle($event, &$data){
$this->preparedSQL->selectHandlers->reset();
$this->preparedSQL->selectHandlers->clear();
$this->preparedSQL->selectHandlers->bindValue(":name", $event, SQLITE3_TEXT);
$handlers = $this->preparedSQL->selectHandlers->execute();
$result = null;
if($handlers instanceof SQLite3Result){
$call = array();
while(($hn = $handlers->fetchArray(SQLITE3_ASSOC)) !== false){
$call[(int) $hn["ID"]] = true;
}
$handlers->finalize();
foreach($call as $hnid => $boolean){
if($result !== false and $result !== true){
$handler = $this->handlers[$hnid];
if(is_array($handler)){
$method = $handler[1];
$result = $handler[0]->$method($data, $event);
}else{
$result = $handler($data, $event);
}
}else{
break;
}
}
}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 [Handler]");
}
if($result !== false){
$this->trigger($event, $data);
}
return $result;
}
public function eventHandler($data, $event){
switch($event){
}
}
/**
* @return string
*/
public function getGamemode(){
switch($this->gamemode){
case SURVIVAL:
return "survival";
case CREATIVE:
return "creative";
case ADVENTURE:
return "adventure";
case VIEW:
return "view";
}
}
public function init(){
register_tick_function(array($this, "tick"));
declare(ticks=5000); //Minimum TPS for main thread locks
$this->loadEvents();
register_shutdown_function(array($this, "dumpError"));
register_shutdown_function(array($this, "close"));
if(function_exists("pcntl_signal")){
pcntl_signal(SIGTERM, array($this, "close"));
pcntl_signal(SIGINT, array($this, "close"));
pcntl_signal(SIGHUP, array($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 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# PocketMine-MP Error Dump ".date("D M j H:i:s T Y")."\r\n";
$er = error_get_last();
$errorConversion = array(
E_ERROR => "E_ERROR",
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 .= "PocketMine-MP 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;
$this->tickerFunction($time);
}
}
public static function clientID($ip, $port){
return crc32($ip . $port) ^ crc32($port . $ip . BOOTUP_RANDOM);
//return $ip . ":" . $port;
}
public function packetHandler(Packet $packet){
$data =& $packet;
$CID = MainServer::clientID($packet->ip, $packet->port);
if(isset($this->clients[$CID])){
$this->clients[$CID]->handlePacket($packet);
}else{
if($this->handle("server.noauthpacket.".$packet->pid(), $packet) === false){
return;
}
switch($packet->pid()){
case RakNetInfo::UNCONNECTED_PING:
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
if($this->invisible === true){
$pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
$pk->pingID = $packet->pingID;
$pk->serverID = $this->serverID;
$pk->serverType = $this->serverType;
$pk->ip = $packet->ip;
$pk->port = $packet->port;
$this->send($pk);
break;
}
if(!isset($this->custom["times_".$CID])){
$this->custom["times_".$CID] = 0;
}
$ln = 15;
if($this->description == "" or substr($this->description, -1) != " "){
$this->description .= " ";
}
$txt = substr($this->description, $this->custom["times_".$CID], $ln);
$txt .= substr($this->description, 0, $ln - strlen($txt));
$pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
$pk->pingID = $packet->pingID;
$pk->serverID = $this->serverID;
$pk->serverType = $this->serverType . $this->name . " [".count($this->clients)."/".$this->maxClients."] ".$txt;
$pk->ip = $packet->ip;
$pk->port = $packet->port;
$this->send($pk);
$this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description);
break;
case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
if($packet->structure !== RakNetInfo::STRUCTURE){
console("[DEBUG] Incorrect structure #".$packet->structure." from ".$packet->ip.":".$packet->port, true, true, 2);
$pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION);
$pk->serverID = $this->serverID;
$pk->ip = $packet->ip;
$pk->port = $packet->port;
$this->send($pk);
}else{
$pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1);
$pk->serverID = $this->serverID;
$pk->mtuSize = strlen($packet->buffer);
$pk->ip = $packet->ip;
$pk->port = $packet->port;
$this->send($pk);
}
break;
case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
if($this->invisible === true){
break;
}
$this->clients[$CID] = new Player($packet->clientID, $packet->ip, $packet->port, $packet->mtuSize); //New Session!
$pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_2);
$pk->serverID = $this->serverID;
$pk->port = $this->port;
$pk->mtuSize = $packet->mtuSize;
$pk->ip = $packet->ip;
$pk->port = $packet->port;
$this->send($pk);
break;
}
}
}
public function send(Packet $packet){
return $this->interface->writePacket($packet);
}
public function process(){
$lastLoop = 0;
while($this->stop === false){
$packet = $this->interface->readPacket();
if($packet instanceof Packet){
$this->packetHandler($packet);
$lastLoop = 0;
}else{
++$lastLoop;
if($lastLoop < 16){
usleep(1);
}elseif($lastLoop < 128){
usleep(100);
}elseif($lastLoop < 256){
usleep(512);
}else{
usleep(10000);
}
}
$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){
//actions that repeat every x time will go here
$this->preparedSQL->selectActions->reset();
$this->preparedSQL->selectActions->bindValue(":time", $time, SQLITE3_FLOAT);
$actions = $this->preparedSQL->selectActions->execute();
if($actions instanceof SQLite3Result){
while(($action = $actions->fetchArray(SQLITE3_ASSOC)) !== false){
$cid = $action["ID"];
$this->preparedSQL->updateAction->reset();
$this->preparedSQL->updateAction->bindValue(":time", $time, SQLITE3_FLOAT);
$this->preparedSQL->updateAction->bindValue(":id", $cid, SQLITE3_INTEGER);
$this->preparedSQL->updateAction->execute();
if(!@is_callable($this->schedule[$cid][0])){
$return = false;
}else{
$return = call_user_func($this->schedule[$cid][0], $this->schedule[$cid][1], $this->schedule[$cid][2]);
}
if($action["repeat"] == 0 or $return === false){
$this->query("DELETE FROM actions WHERE ID = ".$action["ID"].";");
$this->schedule[$cid] = null;
unset($this->schedule[$cid]);
}
}
$actions->finalize();
}
}
public function event($event,callable $func){
if(!is_callable($func)){
return false;
}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 [Attach to ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)."]");
}
$evid = $this->evCnt++;
if(!isset($this->events[$event])){
$this->events[$event] = array();
}
$this->events[$event][$evid] = $func;
$this->eventsID[$evid] = $event;
console("[INTERNAL] Attached ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)." to event ".$event." (ID ".$evid.")", true, true, 3);
return $evid;
}
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]);
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,17 @@
#!/bin/bash
PHP_VERSION="5.5.10"
PHP_VERSION="5.5.13"
ZEND_VM="GOTO"
ZLIB_VERSION="1.2.8"
OPENSSL_VERSION="1.0.0l"
CURL_VERSION="curl-7_35_0"
OPENSSL_VERSION="1.0.1g"
CURL_VERSION="curl-7_36_0"
READLINE_VERSION="6.3"
NCURSES_VERSION="5.9"
PHPNCURSES_VERSION="1.0.2"
PTHREADS_VERSION="2.0.4"
WEAKREF_VERSION="0.2.2"
PTHREADS_VERSION="2.0.7"
PHP_POCKETMINE_VERSION="0.0.6"
UOPZ_VERSION="2.0.4"
WEAKREF_VERSION="0.2.4"
PHPYAML_VERSION="1.1.1"
YAML_VERSION="0.1.4"
LIBXML_VERSION="2.9.1"
@ -18,7 +20,7 @@ BCOMPILER_VERSION="1.0.2"
echo "[PocketMine] PHP compiler for Linux, MacOS and Android"
DIR="$(pwd)"
date > "$DIR/install.log" 2>&1
trap "echo \"# \$(eval echo \$BASH_COMMAND)\" >> \"$DIR/install.log\" 2>&1" DEBUG
trap "echo \"# \$(eval echo \$BASH_COMMAND)\" >> \"$DIR/install.log\" 2>&1" DEBUG
uname -a >> "$DIR/install.log" 2>&1
echo "[INFO] Checking dependecies"
type make >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"make\""; read -p "Press [Enter] to continue..."; exit 1; }
@ -51,11 +53,13 @@ COMPILE_TARGET=""
COMPILE_OPENSSL="no"
COMPILE_CURL="default"
COMPILE_FANCY="no"
HAS_ZEPHIR="no"
IS_CROSSCOMPILE="no"
IS_WINDOWS="no"
DO_OPTIMIZE="no"
DO_STATIC="no"
while getopts "::t:oj:srcxff:" OPTION; do
while getopts "::t:oj:srcxzff:" OPTION; do
case $OPTION in
t)
echo "[opt] Set target to $OPTARG"
@ -85,17 +89,21 @@ while getopts "::t:oj:srcxff:" OPTION; do
echo "[opt] Will compile everything statically"
DO_STATIC="yes"
;;
z)
echo "[opt] Will add PocketMine C PHP extension"
HAS_ZEPHIR="yes"
;;
f)
echo "[opt] Enabling abusive optimizations..."
DO_OPTIMIZE="yes"
ffast_math="-fno-math-errno -funsafe-math-optimizations -fno-trapping-math -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fcx-limited-range" #workaround SQLite3 fail
CFLAGS="$CFLAGS -O2 -DSQLITE_HAVE_ISNAN $ffast_math -fno-signed-zeros -finline-functions -funsafe-loop-optimizations -fomit-frame-pointer -frename-registers -funroll-loops -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -ftracer -ftree-loop-im -fivopts -ftree-parallelize-loops=4 -fomit-frame-pointer"
ffast_math="-fno-math-errno -funsafe-math-optimizations -fno-signed-zeros -fno-trapping-math -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fcx-limited-range" #workaround SQLite3 fail
CFLAGS="$CFLAGS -O2 -DSQLITE_HAVE_ISNAN $ffast_math -funsafe-loop-optimizations -fomit-frame-pointer -frename-registers -funswitch-loops -fpredictive-commoning -ftree-vectorize -ftracer -ftree-loop-im -fivopts"
if [ "$OPTARG" == "arm" ]; then
CFLAGS="$CFLAGS -mfloat-abi=softfp -mfpu=vfp"
elif [ "$OPTARG" == "x86_64" ]; then
CFLAGS="$CFLAGS -mmx -msse -msse2 -msse3 -mfpmath=sse -free -msahf"
CFLAGS="$CFLAGS -mmx -msse -msse2 -msse3 -mfpmath=sse -free -msahf -ftree-parallelize-loops=4"
elif [ "$OPTARG" == "x86" ]; then
CFLAGS="$CFLAGS -mmx -msse -msse2 -mfpmath=sse -m128bit-long-double -malign-double"
CFLAGS="$CFLAGS -mmx -msse -msse2 -mfpmath=sse -m128bit-long-double -malign-double -ftree-parallelize-loops=4"
fi
;;
\?)
@ -136,7 +144,6 @@ if [ "$IS_CROSSCOMPILE" == "yes" ]; then
CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS"
echo "[INFO] Cross-compiling for Android ARMv6"
OPENSSL_TARGET="android"
HAVE_MYSQLI="--without-mysqli"
elif [ "$COMPILE_TARGET" == "android-armv7" ]; then
COMPILE_FOR_ANDROID=yes
[ -z "$march" ] && march=armv7-a;
@ -147,7 +154,6 @@ if [ "$IS_CROSSCOMPILE" == "yes" ]; then
CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS"
echo "[INFO] Cross-compiling for Android ARMv7"
OPENSSL_TARGET="android-armv7"
HAVE_MYSQLI="--without-mysqli"
elif [ "$COMPILE_TARGET" == "rpi" ]; then
TOOLCHAIN_PREFIX="arm-linux-gnueabihf"
[ -z "$march" ] && march=armv6zk;
@ -181,7 +187,6 @@ if [ "$IS_CROSSCOMPILE" == "yes" ]; then
export CC="$TOOLCHAIN_PREFIX-gcc"
CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=$TOOLCHAIN_PREFIX -miphoneos-version-min=4.2"
OPENSSL_TARGET="BSD-generic32"
HAVE_MYSQLI="--without-mysqli"
elif [ "$COMPILE_TARGET" == "ios-armv7" ]; then
[ -z "$march" ] && march=armv7-a;
[ -z "$mtune" ] && mtune=cortex-a8;
@ -189,7 +194,6 @@ if [ "$IS_CROSSCOMPILE" == "yes" ]; then
export CC="$TOOLCHAIN_PREFIX-gcc"
CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=$TOOLCHAIN_PREFIX -miphoneos-version-min=4.2"
OPENSSL_TARGET="BSD-generic32"
HAVE_MYSQLI="--without-mysqli"
if [ "$DO_OPTIMIZE" == "yes" ]; then
CFLAGS="$CFLAGS -mfpu=neon"
fi
@ -508,12 +512,28 @@ download_file "http://pecl.php.net/get/pthreads-$PTHREADS_VERSION.tgz" | tar -zx
mv pthreads-$PTHREADS_VERSION "$DIR/install_data/php/ext/pthreads"
echo " done!"
#WeakRef
#echo -n "[PHP WeakRef] downloading $WEAKREF_VERSION..."
#download_file "http://pecl.php.net/get/Weakref-$WEAKREF_VERSION.tgz" | tar -zx >> "$DIR/install.log" 2>&1
#mv Weakref-$WEAKREF_VERSION "$DIR/install_data/php/ext/weakref"
HAS_POCKETMINE=""
if [ "$HAS_ZEPHIR" == "yes" ]; then
echo -n "[C PocketMine extension] downloading $PHP_POCKETMINE_VERSION..."
download_file https://github.com/PocketMine/PocketMine-MP-Zephir/archive/$PHP_POCKETMINE_VERSION.tar.gz | tar -zx >> "$DIR/install.log" 2>&1
mv PocketMine-MP-Zephir-$PHP_POCKETMINE_VERSION/pocketmine/ext "$DIR/install_data/php/ext/pocketmine"
rm -r PocketMine-MP-Zephir-$PHP_POCKETMINE_VERSION/
HAS_POCKETMINE="--enable-pocketmine"
echo " done!"
fi
#uopz
#echo -n "[PHP uopz] downloading $UOPZ_VERSION..."
#download_file "http://pecl.php.net/get/uopz-$UOPZ_VERSION.tgz" | tar -zx >> "$DIR/install.log" 2>&1
#mv uopz-$UOPZ_VERSION "$DIR/install_data/php/ext/uopz"
#echo " done!"
#WeakRef
echo -n "[PHP Weakref] downloading $WEAKREF_VERSION..."
download_file "http://pecl.php.net/get/Weakref-$WEAKREF_VERSION.tgz" | tar -zx >> "$DIR/install.log" 2>&1
mv Weakref-$WEAKREF_VERSION "$DIR/install_data/php/ext/weakref"
echo " done!"
#PHP YAML
echo -n "[PHP YAML] downloading $PHPYAML_VERSION..."
download_file "http://pecl.php.net/get/yaml-$PHPYAML_VERSION.tgz" | tar -zx >> "$DIR/install.log" 2>&1
@ -606,6 +626,9 @@ if [ "$IS_CROSSCOMPILE" == "yes" ]; then
else
export LIBS="$LIBS -lpthread"
fi
mv ext/mysqlnd/config9.m4 ext/mysqlnd/config.m4
sed -i=".backup" "s{ext/mysqlnd/php_mysqlnd_config.h{config.h{" ext/mysqlnd/mysqlnd_portability.h
CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-opcache=no"
fi
@ -625,8 +648,10 @@ RANLIB=$RANLIB ./configure $PHP_OPTIMIZATION --prefix="$DIR/bin/php5" \
--with-yaml="$DIR/bin/php5" \
$HAVE_NCURSES \
$HAVE_READLINE \
$HAS_POCKETMINE \
--enable-mbstring \
--enable-calendar \
--enable-weakref \
--enable-pthreads \
--enable-pthreads-pedantic \
--disable-libxml \
@ -693,13 +718,14 @@ if [ "$(uname -s)" == "Darwin" ] && [ "$IS_CROSSCOMPILE" != "yes" ]; then
fi
echo -n " generating php.ini..."
trap - DEBUG
TIMEZONE=$(date +%Z)
echo "date.timezone=$TIMEZONE" > "$DIR/bin/php5/bin/php.ini"
echo "short_open_tag=0" >> "$DIR/bin/php5/bin/php.ini"
echo "asp_tags=0" >> "$DIR/bin/php5/bin/php.ini"
echo "phar.readonly=0" >> "$DIR/bin/php5/bin/php.ini"
echo "phar.require_hash=1" >> "$DIR/bin/php5/bin/php.ini"
#echo "zend_extension=uopz.so" >> "$DIR/bin/php5/bin/php.ini"
if [ "$IS_CROSSCOMPILE" != "crosscompile" ]; then
echo "zend_extension=opcache.so" >> "$DIR/bin/php5/bin/php.ini"
echo "opcache.enable=1" >> "$DIR/bin/php5/bin/php.ini"

View File

@ -1,14 +1,14 @@
#!/bin/bash
PMMP_VERSION=""
LINUX_32_BUILD="PHP_5.5.10_x86_Linux"
LINUX_64_BUILD="PHP_5.5.10_x86-64_Linux"
MAC_32_BUILD="PHP_5.5.10_x86_MacOS"
MAC_64_BUILD="PHP_5.5.10_x86-64_MacOS"
RPI_BUILD="PHP_5.5.9_ARM_Raspbian_hard"
LINUX_32_BUILD="PHP_5.5.13_x86_Linux"
LINUX_64_BUILD="PHP_5.5.13_x86-64_Linux"
MAC_32_BUILD="PHP_5.5.13_x86_MacOS"
MAC_64_BUILD="PHP_5.5.13_x86-64_MacOS"
RPI_BUILD="PHP_5.5.13_ARM_Raspbian_hard"
# Temporal build
ODROID_BUILD="PHP_5.5.9_ARM_Raspbian_hard"
AND_BUILD="PHP_5.5.9_ARMv7_Android"
IOS_BUILD="PHP_5.5.9_ARMv6_iOS"
ODROID_BUILD="PHP_5.5.13_ARM_Raspbian_hard"
AND_BUILD="PHP_5.5.13_ARMv7_Android"
IOS_BUILD="PHP_5.5.13_ARMv6_iOS"
update=off
forcecompile=off
alldone=no
@ -59,7 +59,7 @@ fi
echo "[INFO] PocketMine-MP $PMMP_VERSION downloader & installer for Linux & Mac"
echo "[0/3] Cleaning..."
echo "[1/3] Cleaning..."
rm -r -f src/
rm -f PocketMine-MP.php
rm -f README.md
@ -67,13 +67,24 @@ rm -f CONTRIBUTING.md
rm -f LICENSE
rm -f start.sh
rm -f start.bat
echo "[1/3] Downloading PocketMine-MP $PMMP_VERSION..."
download_file "https://github.com/PocketMine/PocketMine-MP/archive/$PMMP_VERSION.tar.gz" | tar -zx > /dev/null
mv -f PocketMine-MP-$PMMP_VERSION/* ./
rm -f -r PocketMine-MP-$PMMP_VERSION/
rm -f ./start.cmd
echo "[2/3] Downloading PocketMine-MP $PMMP_VERSION..."
set +e
download_file "https://github.com/PocketMine/PocketMine-MP/releases/download/$PMMP_VERSION/PocketMine-MP.phar" > PocketMine-MP.phar
if ! [ -s "PocketMine-MP.phar" ] || [ "$(head -n 1 PocketMine-MP.phar)" == '<!DOCTYPE html>' ]; then
rm "PocketMine-MP.phar" > /dev/null
download_file "https://github.com/PocketMine/PocketMine-MP/archive/$PMMP_VERSION.tar.gz" | tar -zx > /dev/null
COMPILE_SCRIPT="./src/build/compile.sh"
mv -f PocketMine-MP-$PMMP_VERSION/* ./
rm -f -r PocketMine-MP-$PMMP_VERSION/
rm -f ./start.cmd
else
download_file "https://raw.githubusercontent.com/PocketMine/PocketMine-MP/$PMMP_VERSION/start.sh" > start.sh
download_file "https://raw.githubusercontent.com/PocketMine/PocketMine-MP/$PMMP_VERSION/src/build/compile.sh" > compile.sh
COMPILE_SCRIPT="./compile.sh"
fi
chmod +x "$COMPILE_SCRIPT"
chmod +x ./start.sh
chmod +x ./src/build/compile.sh
if [ "$update" == "on" ]; then
echo "[3/3] Skipping PHP recompilation due to user request"
else
@ -93,6 +104,9 @@ else
if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then
echo -n " regenerating php.ini..."
TIMEZONE=$(date +%Z)
echo "" > "./bin/php5/bin/php.ini"
#UOPZ_PATH="$(find $(pwd) -name uopz.so)"
#echo "zend_extension=\"$UOPZ_PATH\"" >> "./bin/php5/bin/php.ini"
echo "date.timezone=$TIMEZONE" >> "./bin/php5/bin/php.ini"
echo "short_open_tag=0" >> "./bin/php5/bin/php.ini"
echo "asp_tags=0" >> "./bin/php5/bin/php.ini"
@ -119,7 +133,10 @@ else
echo -n " regenerating php.ini..."
TIMEZONE=$(date +%Z)
OPCACHE_PATH="$(find $(pwd) -name opcache.so)"
echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/bin/php.ini"
echo "" > "./bin/php5/bin/php.ini"
#UOPZ_PATH="$(find $(pwd) -name uopz.so)"
#echo "zend_extension=\"$UOPZ_PATH\"" >> "./bin/php5/bin/php.ini"
echo "zend_extension=\"$OPCACHE_PATH\"" >> "./bin/php5/bin/php.ini"
echo "opcache.enable=1" >> "./bin/php5/bin/php.ini"
echo "opcache.enable_cli=1" >> "./bin/php5/bin/php.ini"
echo "opcache.save_comments=0" >> "./bin/php5/bin/php.ini"
@ -154,7 +171,10 @@ else
echo -n " regenerating php.ini..."
TIMEZONE=$(date +%Z)
OPCACHE_PATH="$(find $(pwd) -name opcache.so)"
echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/bin/php.ini"
echo "" > "./bin/php5/bin/php.ini"
#UOPZ_PATH="$(find $(pwd) -name uopz.so)"
#echo "zend_extension=\"$UOPZ_PATH\"" >> "./bin/php5/bin/php.ini"
echo "zend_extension=\"$OPCACHE_PATH\"" >> "./bin/php5/bin/php.ini"
echo "opcache.enable=1" >> "./bin/php5/bin/php.ini"
echo "opcache.enable_cli=1" >> "./bin/php5/bin/php.ini"
echo "opcache.save_comments=0" >> "./bin/php5/bin/php.ini"
@ -182,7 +202,10 @@ else
if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then
echo -n " regenerating php.ini..."
OPCACHE_PATH="$(find $(pwd) -name opcache.so)"
echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/bin/php.ini"
echo "" > "./bin/php5/bin/php.ini"
#UOPZ_PATH="$(find $(pwd) -name uopz.so)"
#echo "zend_extension=\"$UOPZ_PATH\"" >> "./bin/php5/bin/php.ini"
echo "zend_extension=\"$OPCACHE_PATH\"" >> "./bin/php5/bin/php.ini"
echo "opcache.enable=1" >> "./bin/php5/bin/php.ini"
echo "opcache.enable_cli=1" >> "./bin/php5/bin/php.ini"
echo "opcache.save_comments=0" >> "./bin/php5/bin/php.ini"
@ -216,7 +239,10 @@ else
if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then
echo -n " regenerating php.ini..."
OPCACHE_PATH="$(find $(pwd) -name opcache.so)"
echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/bin/php.ini"
echo "" > "./bin/php5/bin/php.ini"
#UOPZ_PATH="$(find $(pwd) -name uopz.so)"
#echo "zend_extension=\"$UOPZ_PATH\"" >> "./bin/php5/bin/php.ini"
echo "zend_extension=\"$OPCACHE_PATH\"" >> "./bin/php5/bin/php.ini"
echo "opcache.enable=1" >> "./bin/php5/bin/php.ini"
echo "opcache.enable_cli=1" >> "./bin/php5/bin/php.ini"
echo "opcache.save_comments=0" >> "./bin/php5/bin/php.ini"
@ -239,9 +265,12 @@ else
if [ "$alldone" == "no" ]; then
set -e
echo "[3/3] no build found, compiling PHP"
exec ./src/build/compile.sh
exec "$COMPILE_SCRIPT"
fi
fi
fi
if [ "$COMPILE_SCRIPT" == "./compile.sh" ]; then
rm "$COMPILE_SCRIPT"
fi
echo "[INFO] Everything done! Run ./start.sh to start PocketMine-MP"
exit 0

View File

@ -1,7 +1,7 @@
#!/bin/bash -x
export PATH="/opt/arm-2013.05/bin:/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:/opt/arm-unknown-linux-uclibcgnueabi/bin:$PATH"
export THREADS=2
PHP_VERSION="5.5.10"
PHP_VERSION="5.5.13"
#Needed to use aliases
shopt -s expand_aliases
@ -18,7 +18,7 @@ else
fi
rm -rf $WORKSPACE/compile.sh
download_file "https://github.com/PocketMine/PocketMine-MP/raw/master/src/build/compile.sh" > $WORKSPACE/compile.sh
download_file "https://github.com/PocketMine/PocketMine-MP/raw/$BRANCH/src/build/compile.sh" > $WORKSPACE/compile.sh
chmod +x $WORKSPACE/compile.sh
SCRIPT="$WORKSPACE/compile.sh"
ARCHIVE="$WORKSPACE/archive"
@ -31,11 +31,11 @@ if [ "$COMPILE_LINUX_32BIT" = "true" ];
then
mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit
cd $COMPILEDIR/linux/32bit
$SCRIPT -t linux32 -o -j 1 -c -f x86
$SCRIPT -t linux32 -o -j 2 -c $EXTRA_FLAGS -f x86
tar -czf PHP_${PHP_VERSION}_x86_Linux.tar.gz bin/
cp -r $COMPILEDIR/linux/32bit/{install.log,PHP_${PHP_VERSION}_x86_Linux.tar.gz,install_data/*} $ARCHIVE/linux/32bit/
cp -r $COMPILEDIR/linux/32bit/{install.log,PHP_${PHP_VERSION}_x86_Linux.tar.gz} $ARCHIVE/linux/32bit/
if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then
exit 1
fi
@ -45,11 +45,11 @@ if [ "$COMPILE_LINUX_64BIT" = "true" ];
then
mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit
cd $COMPILEDIR/linux/64bit
$SCRIPT -t linux64 -o -j 1 -c -f x86_64
$SCRIPT -t linux64 -o -j 2 -c $EXTRA_FLAGS -f x86_64
tar -czf PHP_${PHP_VERSION}_x86-64_Linux.tar.gz bin/
cp -r $COMPILEDIR/linux/64bit/{install.log,PHP_${PHP_VERSION}_x86-64_Linux.tar.gz,install_data/*} $ARCHIVE/linux/64bit/
cp -r $COMPILEDIR/linux/64bit/{install.log,PHP_${PHP_VERSION}_x86-64_Linux.tar.gz} $ARCHIVE/linux/64bit/
if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then
exit 1
fi
@ -69,10 +69,10 @@ then
rm -rf libtool-2.4.2
export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool"
export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize"
$SCRIPT -t mac32 -o -j 1 -c -f
$SCRIPT -t mac32 -o -j 1 -c $EXTRA_FLAGS -f
tar -czf PHP_${PHP_VERSION}_x86_MacOS.tar.gz bin/
cp -r $COMPILEDIR/mac32/{install.log,PHP_${PHP_VERSION}_x86_MacOS.tar.gz,install_data/*} $ARCHIVE/mac32/
cp -r $COMPILEDIR/mac32/{install.log,PHP_${PHP_VERSION}_x86_MacOS.tar.gz} $ARCHIVE/mac32/
if [ ! -f $COMPILEDIR/mac32/bin/php5/bin/php ]; then
exit 1
fi
@ -92,10 +92,10 @@ then
rm -rf libtool-2.4.2
export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool"
export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize"
$SCRIPT -t mac64 -o -j 1 -c -f
$SCRIPT -t mac64 -o -j 1 -c $EXTRA_FLAGS -f
tar -czf PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz bin/
cp -r $COMPILEDIR/mac64/{install.log,PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz,install_data/*} $ARCHIVE/mac64
cp -r $COMPILEDIR/mac64/{install.log,PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz} $ARCHIVE/mac64
if [ ! -f $COMPILEDIR/mac64/bin/php5/bin/php ]; then
exit 1
fi
@ -106,10 +106,10 @@ then
mkdir -p {$COMPILEDIR,$ARCHIVE}/rpi
cd $COMPILEDIR/rpi
$SCRIPT -t rpi -o -j 1 -c -f arm
$SCRIPT -t rpi -o -j 1 -c $EXTRA_FLAGS -f arm
tar -czf PHP_${PHP_VERSION}_ARM_Raspbian_hard.tar.gz bin/
cp -r $COMPILEDIR/rpi/{install.log,PHP_${PHP_VERSION}_ARM_Raspbian_hard.tar.gz,install_data/*} $ARCHIVE/rpi/
cp -r $COMPILEDIR/rpi/{install.log,PHP_${PHP_VERSION}_ARM_Raspbian_hard.tar.gz} $ARCHIVE/rpi/
if [ ! -f $COMPILEDIR/rpi/bin/php5/bin/php ]; then
exit 1
fi
@ -119,11 +119,11 @@ if [ "$CROSSCOMPILE_ANDROID_ARMV6" = "true" ];
then
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv6
cd $COMPILEDIR/crosscompile/android-armv6
$SCRIPT -t android-armv6 -o -j 1 -c -x -s -f arm
$SCRIPT -t android-armv6 -o -j 1 -c -x -s $EXTRA_FLAGS -f arm
tar -czf PHP_${PHP_VERSION}_ARMv6_Android.tar.gz bin/
cp -r $COMPILEDIR/crosscompile/android-armv6/{install.log,PHP_${PHP_VERSION}_ARMv6_Android.tar.gz,install_data/*} $ARCHIVE/crosscompile/android-armv6/
cp -r $COMPILEDIR/crosscompile/android-armv6/{install.log,PHP_${PHP_VERSION}_ARMv6_Android.tar.gz} $ARCHIVE/crosscompile/android-armv6/
if [ ! -f $COMPILEDIR/crosscompile/android-armv6/bin/php5/bin/php ]; then
exit 1
fi
@ -133,11 +133,11 @@ if [ "$CROSSCOMPILE_ANDROID_ARMV7" = "true" ];
then
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv7
cd $COMPILEDIR/crosscompile/android-armv7
$SCRIPT -t android-armv7 -o -j 1 -c -x -s -f arm
$SCRIPT -t android-armv7 -o -j 1 -c -x -s $EXTRA_FLAGS -f arm
tar -czf PHP_${PHP_VERSION}_ARMv7_Android.tar.gz bin/
cp -r $COMPILEDIR/crosscompile/android-armv7/{install.log,PHP_${PHP_VERSION}_ARMv7_Android.tar.gz,install_data/*} $ARCHIVE/crosscompile/android-armv7/
cp -r $COMPILEDIR/crosscompile/android-armv7/{install.log,PHP_${PHP_VERSION}_ARMv7_Android.tar.gz} $ARCHIVE/crosscompile/android-armv7/
if [ ! -f $COMPILEDIR/crosscompile/android-armv7/bin/php5/bin/php ]; then
exit 1
fi
@ -156,9 +156,9 @@ then
rm -rf libtool-2.4.2
export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtool"
export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtoolize"
PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT -t ios-armv6 -o -j 1 -c -x
PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT -t ios-armv6 -o -j 1 -c -x $EXTRA_FLAGS -f arm
cp -r $COMPILEDIR/crosscompile/ios-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv6/
cp -r $COMPILEDIR/crosscompile/ios-armv6/{install.log,bin/*} $ARCHIVE/crosscompile/ios-armv6/
if [ ! -f $COMPILEDIR/crosscompile/ios-armv6/bin/php5/bin/php ]; then
exit 1
fi
@ -177,9 +177,9 @@ then
rm -rf libtool-2.4.2
export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtool"
export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtoolize"
PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT -t ios-armv6 -o -j 1 -c -x
PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT -t ios-armv6 -o -j 1 -c -x $EXTRA_FLAGS -f arm
cp -r $COMPILEDIR/crosscompile/ios-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv7/
cp -r $COMPILEDIR/crosscompile/ios-armv7/{install.log,bin/*} $ARCHIVE/crosscompile/ios-armv7/
if [ ! -f $COMPILEDIR/crosscompile/ios-armv7/bin/php5/bin/php ]; then
exit 1
fi
@ -190,10 +190,10 @@ then
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/rpi
cd $COMPILEDIR/crosscompile/rpi
$SCRIPT -t rpi -o -j 1 -c -x -f arm
$SCRIPT -t rpi -o -j 1 -c -x $EXTRA_FLAGS -f arm
tar -czf PHP_${PHP_VERSION}_ARM_Raspbian_hard.tar.gz bin/
cp -r $COMPILEDIR/crosscompile/rpi/{install.log,PHP_${PHP_VERSION}_ARM_Raspbian_hard.tar.gz,install_data/*} $ARCHIVE/crosscompile/rpi/
cp -r $COMPILEDIR/crosscompile/rpi/{install.log,PHP_${PHP_VERSION}_ARM_Raspbian_hard.tar.gz} $ARCHIVE/crosscompile/rpi/
if [ ! -f $COMPILEDIR/crosscompile/rpi/bin/php5/bin/php ]; then
exit 1
fi
@ -204,9 +204,9 @@ then
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/mac
cd $COMPILEDIR/crosscompile/mac
$SCRIPT -t mac -o -j 1 -c -f -x
$SCRIPT -t mac -o -j 1 -c $EXTRA_FLAGS -f -x
cp -r $COMPILEDIR/crosscompile/mac/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/mac/
cp -r $COMPILEDIR/crosscompile/mac/{install.log,bin/*} $ARCHIVE/crosscompile/mac/
if [ ! -f $COMPILEDIR/crosscompile/mac/bin/php5/bin/php ]; then
exit 1
fi

View File

@ -1,80 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
set_time_limit(0);
if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set("GMT");
if(strpos(" ".strtoupper(php_uname("s")), " WIN") !== false){
$time = time();
$time -= $time % 60;
//TODO: Parse different time & date formats by region. ¬¬ world
//Example: USA
exec("time.exe /T", $hour);
$i = array_map("intval", explode(":", trim($hour[0])));
exec("date.exe /T", $date);
$j = array_map("intval", explode(substr($date[0], 2, 1), trim($date[0])));
$offset = round((mktime($i[0], $i[1], 0, $j[1], $j[0], $j[2]) - $time) / 60) * 60;
}else{
exec("date +%s", $t);
$offset = round((intval(trim($t[0])) - time()) / 60) * 60;
}
$daylight = (int) date("I");
$d = timezone_name_from_abbr("", $offset, $daylight);
@ini_set("date.timezone", $d);
date_default_timezone_set($d);
}else{
$d = @date_default_timezone_get();
if(strpos($d, "/") === false){
$d = timezone_name_from_abbr($d);
@ini_set("date.timezone", $d);
date_default_timezone_set($d);
}
}
gc_enable();
error_reporting(E_ALL | E_STRICT);
ini_set("allow_url_fopen", 1);
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
ini_set("default_charset", "utf-8");
if(defined("POCKETMINE_COMPILE") and POCKETMINE_COMPILE === true){
define("FILE_PATH", realpath(dirname(__FILE__))."/");
}else{
define("FILE_PATH", realpath(dirname(__FILE__)."/../")."/");
}
set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH);
ini_set("memory_limit", "128M"); //Default
define("LOG", true);
define("START_TIME", microtime(true));
define("MAJOR_VERSION", "Alpha_1.4dev");
define("CODENAME", "絶好(Zekkou)ケーキ(Cake)");
define("CURRENT_MINECRAFT_VERSION", "v0.8.1 alpha");
define("CURRENT_API_VERSION", 13);
define("CURRENT_PHP_VERSION", "5.5");
$gitsha1 = false;
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"))));
}else{ //Unknown :(
define("GIT_COMMIT", str_repeat("00", 20));
}

View File

@ -1,193 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
define("AIR", 0);
define("STONE", 1);
define("GRASS", 2);
define("DIRT", 3);
define("COBBLESTONE", 4);
define("COBBLE", 4);
define("PLANK", 5);
define("PLANKS", 5);
define("WOODEN_PLANK", 5);
define("WOODEN_PLANKS", 5);
define("SAPLING", 6);
define("SAPLINGS", 6);
define("BEDROCK", 7);
define("WATER", 8);
define("STILL_WATER", 9);
define("LAVA", 10);
define("STILL_LAVA", 11);
define("SAND", 12);
define("GRAVEL", 13);
define("GOLD_ORE", 14);
define("IRON_ORE", 15);
define("COAL_ORE", 16);
define("WOOD", 17);
define("TRUNK", 17);
define("LEAVES", 18);
define("LEAVE", 18);
define("SPONGE", 19);
define("GLASS", 20);
define("LAPIS_ORE", 21);
define("LAPIS_BLOCK", 22);
define("SANDSTONE", 24);
define("BED_BLOCK", 26);
define("COBWEB", 30);
define("TALL_GRASS", 31);
define("BUSH", 32);
define("DEAD_BUSH", 32);
define("WOOL", 35);
define("DANDELION", 37);
define("ROSE", 38);
define("CYAN_FLOWER", 38);
define("BROWN_MUSHROOM", 39);
define("RED_MUSHROOM", 40);
define("GOLD_BLOCK", 41);
define("IRON_BLOCK", 42);
define("DOUBLE_SLAB", 43);
define("DOUBLE_SLABS", 43);
define("SLAB", 44);
define("SLABS", 44);
define("BRICKS", 45);
define("BRICKS_BLOCK", 45);
define("TNT", 46);
define("BOOKSHELF", 47);
define("MOSS_STONE", 48);
define("MOSSY_STONE", 48);
define("OBSIDIAN", 49);
define("TORCH", 50);
define("FIRE", 51);
define("WOOD_STAIRS", 53);
define("WOODEN_STAIRS", 53);
define("OAK_WOOD_STAIRS", 53);
define("OAK_WOODEN_STAIRS", 53);
define("CHEST", 54);
define("DIAMOND_ORE", 56);
define("DIAMOND_BLOCK", 57);
define("CRAFTING_TABLE", 58);
define("WORKBENCH", 58);
define("WHEAT_BLOCK", 59);
define("FARMLAND", 60);
define("FURNACE", 61);
define("BURNING_FURNACE", 62);
define("LIT_FURNACE", 62);
define("SIGN_POST", 63);
define("DOOR_BLOCK", 64);
define("WOODEN_DOOR_BLOCK", 64);
define("WOOD_DOOR_BLOCK", 64);
define("LADDER", 65);
define("COBBLE_STAIRS", 67);
define("COBBLESTONE_STAIRS", 67);
define("WALL_SIGN", 68);
define("IRON_DOOR_BLOCK", 71);
define("REDSTONE_ORE", 73);
define("GLOWING_REDSTONE_ORE", 74);
define("LIT_REDSTONE_ORE", 74);
define("SNOW", 78);
define("SNOW_LAYER", 78);
define("ICE", 79);
define("SNOW_BLOCK", 80);
define("CACTUS", 81);
define("CLAY_BLOCK", 82);
define("REEDS", 83);
define("SUGARCANE_BLOCK", 83);
define("FENCE", 85);
define("PUMPKIN", 86);
define("NETHERRACK", 87);
define("SOUL_SAND", 88);
define("GLOWSTONE", 89);
define("GLOWSTONE_BLOCK", 89);
define("LIT_PUMPKIN", 91);
define("JACK_O_LANTERN", 91);
define("CAKE_BLOCK", 92);
define("TRAPDOOR", 96);
define("STONE_BRICKS", 98);
define("STONE_BRICK", 98);
define("IRON_BAR", 101);
define("IRON_BARS", 101);
define("GLASS_PANE", 102);
define("GLASS_PANEL", 102);
define("MELON_BLOCK", 103);
define("PUMPKIN_STEM", 104);
define("MELON_STEM", 105);
define("FENCE_GATE", 107);
define("BRICK_STAIRS", 108);
define("STONE_BRICK_STAIRS", 109);
define("NETHER_BRICKS", 112);
define("NETHER_BRICK_BLOCK", 112);
define("NETHER_BRICKS_STAIRS", 114);
define("SANDSTONE_STAIRS", 128);
define("SPRUCE_WOOD_STAIRS", 134);
define("SPRUCE_WOODEN_STAIRS", 134);
define("BIRCH_WOOD_STAIRS", 135);
define("BIRCH_WOODEN_STAIRS", 135);
define("JUNGLE_WOOD_STAIRS", 136);
define("JUNGLE_WOODEN_STAIRS", 136);
define("COBBLE_WALL", 139);
define("STONE_WALL", 139);
define("COBBLESTONE_WALL", 139);
define("CARROT_BLOCK", 141);
define("POTATO_BLOCK", 142);
define("QUARTZ_BLOCK", 155);
define("QUARTZ_STAIRS", 156);
define("DOUBLE_WOOD_SLAB", 157);
define("DOUBLE_WOODEN_SLAB", 157);
define("DOUBLE_WOOD_SLABS", 157);
define("DOUBLE_WOODEN_SLABS", 157);
define("WOOD_SLAB", 158);
define("WOODEN_SLAB", 158);
define("WOOD_SLABS", 158);
define("WOODEN_SLABS", 158);
define("HAY_BALE", 170);
define("CARPET", 171);
define("COAL_BLOCK", 173);
define("BEETROOT_BLOCK", 244);
define("STONECUTTER", 245);
define("GLOWING_OBSIDIAN", 246);
define("NETHER_REACTOR", 247);

View File

@ -1,79 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
define("PMF_LEVEL_DEFLATE_LEVEL", 6);
//Gamemodes
define("SURVIVAL", 0);
define("CREATIVE", 1);
define("ADVENTURE", 2);
define("VIEW", 3);
define("VIEWER", 3);
//Players
define("PLAYER_MAX_QUEUE", 1024);
define("PLAYER_SURVIVAL_SLOTS", 36);
define("PLAYER_CREATIVE_SLOTS", 112);
//Block Updates
define("BLOCK_UPDATE_NORMAL", 1);
define("BLOCK_UPDATE_RANDOM", 2);
define("BLOCK_UPDATE_SCHEDULED", 3);
define("BLOCK_UPDATE_WEAK", 4);
define("BLOCK_UPDATE_TOUCH", 5);
//Entities
define("ENTITY_PLAYER", 1);
define("ENTITY_MOB", 2);
define("MOB_CHICKEN", 10);
define("MOB_COW", 11);
define("MOB_PIG", 12);
define("MOB_SHEEP", 13);
define("MOB_ZOMBIE", 32);
define("MOB_CREEPER", 33);
define("MOB_SKELETON", 34);
define("MOB_SPIDER", 35);
define("MOB_PIGMAN", 36);
define("ENTITY_OBJECT", 3);
define("OBJECT_PRIMEDTNT", 65);
define("OBJECT_ARROW", 80);
define("OBJECT_PAINTING", 83);
define("ENTITY_ITEM", 4);
define("ENTITY_FALLING", 5);
define("FALLING_SAND", 66);
//TileEntities
define("TILE_SIGN", "Sign");
define("TILE_CHEST", "Chest");
define("CHEST_SLOTS", 27);
define("TILE_FURNACE", "Furnace");
define("FURNACE_SLOTS", 3);

View File

@ -1,167 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
define("IRON_SHOVEL", 256);//Implemented
define("IRON_PICKAXE", 257);//Implemented
define("IRON_AXE", 258);//Implemented
define("FLINT_STEEL", 259);
define("FLINT_AND_STEEL", 259);
define("APPLE", 260);//Implemented
define("BOW", 261);
define("ARROW", 262);
define("COAL", 263);//Implemented
define("DIAMOND", 264);//Implemented
define("IRON_INGOT", 265);//Implemented
define("GOLD_INGOT", 266);//Implemented
define("IRON_SWORD", 267);
define("WOODEN_SWORD", 268);//Implemented
define("WOODEN_SHOVEL", 269);//Implemented
define("WOODEN_PICKAXE", 270);//Implemented
define("WOODEN_AXE", 271);//Implemented
define("STONE_SWORD", 272);
define("STONE_SHOVEL", 273);
define("STONE_PICKAXE", 274);
define("STONE_AXE", 275);
define("DIAMOND_SWORD", 276);
define("DIAMOND_SHOVEL", 277);
define("DIAMOND_PICKAXE", 278);
define("DIAMOND_AXE", 279);
define("STICK", 280);//Implemented
define("STICKS", 280);
define("BOWL", 281);//Implemented
define("MUSHROOM_STEW", 282);
define("GOLD_SWORD", 283);
define("GOLD_SHOVEL", 284);
define("GOLD_PICKAXE", 285);
define("GOLD_AXE", 286);
define("GOLDEN_SWORD", 283);
define("GOLDEN_SHOVEL", 284);
define("GOLDEN_PICKAXE", 285);
define("GOLDEN_AXE", 286);
define("STRING", 287);
define("FEATHER", 288);//Implemented
define("GUNPOWDER", 289);
define("WOODEN_HOE", 290);
define("STONE_HOE", 291);
define("IRON_HOE", 292);//Implemented
define("DIAMOND_HOE", 293);
define("GOLD_HOE", 294);
define("GOLDEN_HOE", 294);
define("SEEDS", 295);
define("WHEAT_SEEDS", 295);
define("WHEAT", 296);
define("BREAD", 297);
define("LEATHER_CAP", 298);
define("LEATHER_TUNIC", 299);
define("LEATHER_PANTS", 300);
define("LEATHER_BOOTS", 301);
define("CHAIN_HELMET", 302);
define("CHAIN_CHESTPLATE", 303);
define("CHAIN_LEGGINGS", 304);
define("CHAIN_BOOTS", 305);
define("IRON_HELMET", 306);
define("IRON_CHESTPLATE", 307);
define("IRON_LEGGINGS", 308);
define("IRON_BOOTS", 309);
define("DIAMOND_HELMET", 310);
define("DIAMOND_CHESTPLATE", 311);
define("DIAMOND_LEGGINGS", 312);
define("DIAMOND_BOOTS", 313);
define("GOLD_HELMET", 314);
define("GOLD_CHESTPLATE", 315);
define("GOLD_LEGGINGS", 316);
define("GOLD_BOOTS", 317);
define("FLINT", 318);
define("RAW_PORKCHOP", 319);
define("COOKED_PORKCHOP", 320);
define("PAINTING", 321);
define("GOLDEN_APPLE", 322);
define("SIGN", 323);
define("WOODEN_DOOR", 324);
define("BUCKET", 325);
define("MINECART", 329);
define("IRON_DOOR", 330);
define("REDSTONE", 331);
define("REDSTONE_DUST", 331);
define("SNOWBALL", 332);
define("LEATHER", 334);
define("BRICK", 336);
define("CLAY", 337);
define("SUGARCANE", 338);
define("SUGAR_CANE", 338);
define("SUGAR_CANES", 338);
define("PAPER", 339);
define("BOOK", 340);
define("SLIMEBALL", 341);
define("EGG", 344);
define("COMPASS", 345);
define("CLOCK", 347);
define("GLOWSTONE_DUST", 348);
//define("RAW_FISH", 349);
//define("COOKED_FISH", 350);
define("DYE", 351);
define("BONE", 352);
define("SUGAR", 353);
define("CAKE", 354);
define("BED", 355);
//define("COOKIE", 357);
define("SHEARS", 359);
define("MELON", 360);
define("MELON_SLICE", 360);
define("PUMPKIN_SEEDS", 361);
define("MELON_SEEDS", 362);
define("RAW_BEEF", 363);
define("STEAK", 364);
define("COOKED_BEEF", 364);
define("RAW_CHICKEN", 365);
define("COOKED_CHICKEN", 366);
define("SPAWN_EGG", 383);
define("CARROT", 391);
define("CARROTS", 391);
define("POTATO", 392);
define("POTATOES", 392);//@shoghicp Why the heck do we need plural redundant Item ID here????
define("BAKED_POTATO", 393);
define("BAKED_POTATOES", 393);
define("PUMPKIN_PIE", 400);
define("NETHER_BRICK", 405);
define("QUARTZ", 406);
define("NETHER_QUARTZ", 406);
define("CAMERA", 456);
define("BEETROOT", 457);
define("BEETROOT_SEEDS", 458);
define("BEETROOT_SEED", 458);
define("BEETROOT_SOUP", 459);

View File

@ -1,117 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/***REM_START***/
require_once(dirname(__FILE__)."/config.php");
require_once(FILE_PATH."/src/utils/TextFormat.php");
require_once(FILE_PATH."/src/functions.php");
/***REM_END***/
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){
define("ENABLE_ANSI", true);
}else{
define("ENABLE_ANSI", false);
}
set_error_handler("error_handler", E_ALL);
$errors = 0;
if(version_compare("5.4.0", PHP_VERSION) > 0){
console("[ERROR] Use PHP >= 5.4.0", true, true, 0);
++$errors;
}
if(php_sapi_name() !== "cli"){
console("[ERROR] You must run PocketMine-MP using the CLI.", true, true, 0);
++$errors;
}
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);
++$errors;
}
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);
++$errors;
}else{
$pthreads_version = phpversion("pthreads");
if(substr_count($pthreads_version, ".") < 2){
$pthreads_version = "0.$pthreads_version";
}
if(version_compare($pthreads_version, "0.1.0") < 0){
console("[ERROR] pthreads >= 0.1.0 is required, while you have $pthreads_version.", true, true, 0);
++$errors;
}
}
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);
++$errors;
}
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);
++$errors;
}
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);
++$errors;
}
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);
++$errors;
}
if($errors > 0){
console("[ERROR] Please use the installer provided on the homepage, or recompile PHP again.", true, true, 0);
exit(1); //Exit with error
}
$sha1sum = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
/***REM_START***/
require_once(FILE_PATH."/src/math/Vector3.php");
require_once(FILE_PATH."/src/world/Position.php");
require_once(FILE_PATH."/src/pmf/PMF.php");
require_all(FILE_PATH . "src/");
$inc = get_included_files();
$inc[] = array_shift($inc);
$srcdir = realpath(FILE_PATH."src/");
foreach($inc as $s){
if(strpos(realpath(dirname($s)), $srcdir) === false and strtolower(basename($s)) !== "pocketmine-mp.php"){
continue;
}
$sha1sum ^= sha1_file($s, true);
}
/***REM_END***/
define("SOURCE_SHA1SUM", bin2hex($sha1sum));
/***REM_START***/
if(!file_exists(DATA_PATH."server.properties") and arg("no-wizard", false) != true){
$installer = new Installer();
}
/***REM_END***/

View File

@ -1,51 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
abstract class EventHandler{
public static function callEvent(BaseEvent $event){
foreach($event::$handlerPriority as $priority => $handlerList){
if(count($handlerList) > 0){
$event->setPrioritySlot($priority);
foreach($handlerList as $handler){
call_user_func($handler, $event);
}
if($event->isForced()){
if($event instanceof CancellableEvent and $event->isCancelled()){
return BaseEvent::DENY;
}else{
return BaseEvent::ALLOW;
}
}
}
}
if($event instanceof CancellableEvent and $event->isCancelled()){
return BaseEvent::DENY;
}elseif($event->isAllowed()){
return BaseEvent::ALLOW;
}else{
return BaseEvent::NORMAL;
}
}
}

View File

@ -1,24 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
abstract class ServerEvent extends BaseEvent{
}

View File

@ -1,36 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class PacketReceiveEvent extends ServerEvent implements CancellableEvent{
public static $handlers;
public static $handlerPriority;
private $packet;
public function __construct(Packet $packet){
$this->packet = $packet;
}
public function getPacket(){
return $this->packet;
}
}

View File

@ -1,36 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class PacketSendEvent extends ServerEvent implements CancellableEvent{
public static $handlers;
public static $handlerPriority;
private $packet;
public function __construct(Packet $packet){
$this->packet = $packet;
}
public function getPacket(){
return $this->packet;
}
}

View File

@ -1,281 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
if(!function_exists("cli_set_process_title")){
function cli_set_process_title($title){
if(ENABLE_ANSI === true){
echo "\x1b]0;".$title."\x07";
return true;
}else{
return false;
}
}
}
function dummy(){
}
function safe_var_dump($var, $cnt = 0){
switch(true){
case is_array($var):
echo str_repeat(" ", $cnt)."array(".count($var).") {".PHP_EOL;
foreach($var as $key => $value){
echo str_repeat(" ", $cnt + 1)."[".(is_integer($key) ? $key:'"'.$key.'"')."]=>".PHP_EOL;
safe_var_dump($value, $cnt + 1);
}
echo str_repeat(" ", $cnt)."}".PHP_EOL;
break;
case is_integer($var):
echo str_repeat(" ", $cnt)."int(".$var.")".PHP_EOL;
break;
case is_float($var):
echo str_repeat(" ", $cnt)."float(".$var.")".PHP_EOL;
break;
case is_bool($var):
echo str_repeat(" ", $cnt)."bool(".($var === true ? "true":"false").")".PHP_EOL;
break;
case is_string($var):
echo str_repeat(" ", $cnt)."string(".strlen($var).") \"$var\"".PHP_EOL;
break;
case is_resource($var):
echo str_repeat(" ", $cnt)."resource() of type (".get_resource_type($var).")".PHP_EOL;
break;
case is_object($var):
echo str_repeat(" ", $cnt)."object(".get_class($var).")".PHP_EOL;
break;
case is_null($var):
echo str_repeat(" ", $cnt)."NULL".PHP_EOL;
break;
}
}
function kill($pid){
switch(Utils::getOS()){
case "win":
exec("taskkill.exe /F /PID ".((int) $pid)." > NUL");
break;
case "mac":
case "linux":
default:
exec("kill -9 ".((int) $pid)." > /dev/null 2>&1");
}
}
function require_all($path, &$count = 0){
$dir = dir($path."/");
$dirs = array();
while(false !== ($file = $dir->read())){
if($file !== "." and $file !== ".."){
if(!is_dir($path.$file) and strtolower(substr($file, -3)) === "php"){
require_once($path.$file);
++$count;
}elseif(is_dir($path.$file)){
$dirs[] = $path.$file."/";
}
}
}
foreach($dirs as $dir){
require_all($dir, $count);
}
}
function hard_unset(&$var){
if(is_object($var)){
$unset = new ReflectionClass($var);
foreach($unset->getProperties() as $prop){
$prop->setAccessible(true);
@hard_unset($prop->getValue($var));
$prop->setValue($var, null);
}
$var = null;
unset($var);
}elseif(is_array($var)){
foreach($var as $i => $v){
hard_unset($var[$i]);
}
$var = null;
unset($var);
}else{
$var = null;
unset($var);
}
}
function arg($name, $default = false){
global $arguments, $argv;
if(!isset($arguments)){
$arguments = arguments($argv);
}
if(isset($arguments["commands"][$name])){
return $arguments["commands"][$name];
}else{
return $default;
}
}
function arguments ( $args ){
if(!is_array($args)){
$args = array();
}
array_shift( $args );
$args = implode(' ', $args);
preg_match_all('/ (--[\w\-]+ (?:[= ] [^-\s]+ )? ) | (-\w+) | (\w+) /x', $args, $match );
$args = array_shift( $match );
$ret = array(
'input' => array(),
'commands' => array(),
'flags' => array()
);
foreach ( $args as $arg ) {
// Is it a command? (prefixed with --)
if ( substr( $arg, 0, 2 ) === '--' ) {
$value = preg_split( '/[= ]/', $arg, 2 );
$com = substr( array_shift($value), 2 );
$value = implode($value);
$ret['commands'][$com] = !empty($value) ? $value : true;
continue;
}
// Is it a flag? (prefixed with -)
if ( substr( $arg, 0, 1 ) === '-' ) {
$ret['flags'][] = substr( $arg, 1 );
continue;
}
$ret['input'][] = $arg;
continue;
}
return $ret;
}
function console($message, $EOL = true, $log = true, $level = 1){
if(!defined("DEBUG") or DEBUG >= $level){
$message .= $EOL === true ? PHP_EOL:"";
$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));
if($log === true and (!defined("LOG") or LOG === true)){
logg(date("Y-m-d")." ".$replaced, "console", false, $level);
}
if(ENABLE_ANSI === true){
$add = "";
if(preg_match("/\[([a-zA-Z0-9]*)\]/", $message, $matches) > 0){
switch($matches[1]){
case "ERROR":
case "SEVERE":
$add .= FORMAT_RED;
break;
case "INTERNAL":
case "DEBUG":
$add .= FORMAT_GRAY;
break;
case "WARNING":
$add .= FORMAT_YELLOW;
break;
case "NOTICE":
$add .= FORMAT_AQUA;
break;
default:
$add = "";
break;
}
}
$message = TextFormat::toANSI($time . $add . $message . FORMAT_RESET);
}else{
$message = $replaced;
}
echo $message;
}
}
function getTrace($start = 1){
$e = new Exception();
$trace = $e->getTrace();
$messages = array();
$j = 0;
for($i = (int) $start; isset($trace[$i]); ++$i, ++$j){
$params = "";
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)).", ";
}
$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;
}
function error_handler($errno, $errstr, $errfile, $errline){
if(error_reporting() === 0){ //@ error-control
return false;
}
$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",
);
$errno = isset($errorConversion[$errno]) ? $errorConversion[$errno]:$errno;
console("[ERROR] A ".$errno." error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0);
foreach(getTrace() as $i => $line){
console("[TRACE] $line");
}
return true;
}
function logg($message, $name, $EOL = true, $level = 2, $close = false){
global $fpointers;
if((!defined("DEBUG") or DEBUG >= $level) and (!defined("LOG") or LOG === true)){
$message .= $EOL === true ? PHP_EOL:"";
if(!isset($fpointers)){
$fpointers = array();
}
if(!isset($fpointers[$name]) or $fpointers[$name] === false){
$fpointers[$name] = @fopen(DATA_PATH."/".$name.".log", "ab");
}
@fwrite($fpointers[$name], $message);
if($close === true){
fclose($fpointers[$name]);
unset($fpointers[$name]);
}
}
}

View File

@ -1,45 +1,45 @@
language_has_been_selected=English has been correctly selected.
skip_installer=Do you want to skip the set-up wizard?
language_has_been_selected = English has been correctly selected.
skip_installer = Do you want to skip the set-up wizard?
welcome_to_pocketmine=Welcome to PocketMine-MP!\nBefore starting setting up your new server you have to accept the license.\nPocketMine-MP is licensed under the LGPL License,\nthat you can read opening the LICENSE file on this folder.
accept_license=Do you accept the License?
you_have_to_accept_the_license=You have to accept the LGPL license to continue using PocketMine-MP
welcome_to_pocketmine = Welcome to PocketMine-MP!\nBefore starting setting up your new server you have to accept the license.\nPocketMine-MP is licensed under the LGPL License,\nthat you can read opening the LICENSE file on this folder.
accept_license = Do you accept the License?
you_have_to_accept_the_license = You have to accept the LGPL license to continue using PocketMine-MP
setting_up_server_now=You are going to set up your server now.
default_values_info=If you don't want to change the default value, just press Enter.
server_properties=You can edit them later on the server.properties file.
setting_up_server_now = You are going to set up your server now.
default_values_info = If you don't want to change the default value, just press Enter.
server_properties = You can edit them later on the server.properties file.
name_your_server=Give a name to your server
port_warning=Do not change the default port value if this is your first server.
server_port=Server port
invalid_port=Invalid server port
ram_warning=The RAM is the maximum amount of memory PocketMine-MP will use. A value of 128-256 MB is recommended
server_ram=Server RAM in MB
gamemode_info=Choose between Creative (1) or Survival (0)
default_gamemode=Default Game mode
max_players=Max. online players
spawn_protection_info=The spawn protection disallows placing/breaking blocks in the spawn zone except for OPs
spawn_protection=Enable spawn protection?
name_your_server = Give a name to your server
port_warning = Do not change the default port value if this is your first server.
server_port = Server port
invalid_port = Invalid server port
ram_warning = The RAM is the maximum amount of memory PocketMine-MP will use. A value of 128-256 MB is recommended
server_ram = Server RAM in MB
gamemode_info = Choose between Creative (1) or Survival (0)
default_gamemode = Default Game mode
max_players = Max. online players
spawn_protection_info = The spawn protection disallows placing/breaking blocks in the spawn zone except for OPs
spawn_protection = Enable spawn protection?
op_info=An OP is the player admin of the server. OPs can run more commands than normal players
op_who=OP player name (example, your game name)
op_warning=You will be able to add an OP user later using /op <player>
whitelist_info=The white-list only allows players in it to join.
whitelist_enable=Do you want to enable the white-list?
whitelist_warning=You will have to add the players to the white-list
op_info = An OP is the player admin of the server. OPs can run more commands than normal players
op_who = OP player name (example, your game name)
op_warning = You will be able to add an OP user later using /op <player>
whitelist_info = The white-list only allows players in it to join.
whitelist_enable = Do you want to enable the white-list?
whitelist_warning = You will have to add the players to the white-list
query_warning1=Query is a protocol used by diferent tools to get information of your server and players logged in.
query_warning2=If you disable it, you won't be able to use server lists.
query_disable=Do you want to disable Query?
rcon_info=RCON is a protocol to remote connect with the server console using a password.
rcon_enable=Do you want to enable RCON?
rcon_password=RCON password (you can change it later)
usage_info=The anonymous usage data allows us to calculate global statistics for PocketMine-MP and its plugins. You can view them on stats.pocketmine.net
usage_disable=Do you want to disable the anonymous usage?
ip_get=Getting your external IP and internal IP
ip_warning=Your external IP is {{EXTERNAL_IP}}. You may have to port-forward to your internal IP {{INTERNAL_IP}}
ip_confirm=Be sure to check it, if you have to forward and you skip that, no external players will be able to join. [Press Enter]
query_warning1 = Query is a protocol used by diferent tools to get information of your server and players logged in.
query_warning2 = If you disable it, you won't be able to use server lists.
query_disable = Do you want to disable Query?
rcon_info = RCON is a protocol to remote connect with the server console using a password.
rcon_enable = Do you want to enable RCON?
rcon_password = RCON password (you can change it later)
usage_info = The anonymous usage data allows us to calculate global statistics for PocketMine-MP and its plugins. You can view them on stats.pocketmine.net
usage_disable = Do you want to disable the anonymous usage?
ip_get = Getting your external IP and internal IP
ip_warning = Your external IP is {{EXTERNAL_IP}}. You may have to port-forward to your internal IP {{INTERNAL_IP}}
ip_confirm = Be sure to check it, if you have to forward and you skip that, no external players will be able to join. [Press Enter]
you_have_finished=You have finished the set-up wizard correctly
pocketmine_will_start=PocketMine-MP will now start. Type /help to view the list of available commands.
pocketmine_plugins=Check the Plugin Repository to add new features, minigames, or advanced protection to your server
you_have_finished = You have finished the set-up wizard correctly
pocketmine_will_start = PocketMine-MP will now start. Type /help to view the list of available commands.
pocketmine_plugins = Check the Plugin Repository to add new features, minigames, or advanced protection to your server

View File

@ -9,35 +9,37 @@ setting_up_server_now=You are going to set up your server now.
default_values_info=If you don't want to change the default value, just press Enter.
server_properties=You can edit them later on the server.properties file.
name_your_server=Give a name to your server
name_your_server=Give your server a name
port_warning=Do not change the default port value if this is your first server.
server_port=Server port
invalid_port=Invalid server port
ram_warning=The RAM is the maximum amount of memory PocketMine-MP will use. A value of 128-256 MB is recommended
ram_warning=The RAM is the maximum amount of memory PocketMine-MP can use. A value of 128-256 MB is recommended
server_ram=Server RAM in MB
gamemode_info=Choose between Creative (1) or Survival (0)
default_gamemode=Default Game mode
max_players=Max. online players
spawn_protection_info=The spawn protection disallows placing/breaking blocks in the spawn zone except for OPs
gamemode_info=Choose between Survival Mode (0), Creative Mode (1), or Adventure Mode (2)
default_gamemode=Default gamemode
max_players=Maximum online players at one time
spawn_protection_info=The spawn protection prevents the placing/breaking of blocks in the spawn area for all players with the exception of operators
spawn_protection=Enable spawn protection?
op_info=An OP is the player admin of the server. OPs can run more commands than normal players
op_who=OP player name (example, your game name)
op_warning=You will be able to add an OP user later using /op <player>
whitelist_info=The white-list only allows players in it to join.
whitelist_enable=Do you want to enable the white-list?
whitelist_warning=You will have to add the players to the white-list
op_info=An 'op' is the admin of the server. Ops can run more commands than normal players (like /ban, etc.)
op_who=Operator player name (e.g. Steve)
op_warning=
You will be able to add an operators later using /op <player>
query_warning1=Query is a protocol used by diferent tools to get information of your server and players logged in.
whitelist_info=When enabled, only players in the whitelist will have access to the server.
whitelist_enable=Do you want to enable the whitelist?
whitelist_warning=You will have to add the players to the whitelist
query_warning1=Query is a protocol used by different tools to obtain information about the server and the players logged in.
query_warning2=If you disable it, you won't be able to use server lists.
query_disable=Do you want to disable Query?
rcon_info=RCON is a protocol to remote connect with the server console using a password.
rcon_info=RCON is a protocol that allows remote connections with the server console using a password.
rcon_enable=Do you want to enable RCON?
rcon_password=RCON password (you can change it later)
rcon_password=RCON password (can be changed later)
usage_info=The anonymous usage data allows us to calculate global statistics for PocketMine-MP and its plugins. You can view them on stats.pocketmine.net
usage_disable=Do you want to disable the anonymous usage?
ip_get=Getting your external IP and internal IP
ip_warning=Your external IP is {{EXTERNAL_IP}}. You may have to port-forward to your internal IP {{INTERNAL_IP}}
ip_get=Finding your external and internal IP adresses
ip_warning=Your current external IP is {{EXTERNAL_IP}}. In some cases, you may have to port-forward to your internal IP ({{INTERNAL_IP}})
ip_confirm=Be sure to check it, if you have to forward and you skip that, no external players will be able to join. [Press Enter]
you_have_finished=You have finished the set-up wizard correctly

View File

@ -1,5 +1,5 @@
language_has_been_selected=Español sido seleccionado correctamente.
skip_installer=Quieres saltarte el asistente de configuración?
skip_installer=¿Quieres saltarte el asistente de configuración?
welcome_to_pocketmine=Bienvenido a PocketMine-MP!\nAntes de comenzar a configurar tu nuevo servidor, tienes que aceptar la licencia.\nPocketMine-MP está licenciado con la licencia LGPL,\nque puedes leer abriendo el archivo LICENSE en esta carpeta.
accept_license=¿Aceptas la Licencia?
@ -13,7 +13,7 @@ name_your_server=Nombre del servidor
port_warning=No cambies el puerto por defecto si este es tu primer servidor.
server_port=Puerto del servidor
invalid_port=Puerto inválido
ram_warning=La RAM esla máxima memoria que PocketMine-MP usará. Es recomendado usar un valor de 128-256 MB
ram_warning=La RAM es la máxima memoria que PocketMine-MP usará. Es recomendado usar un valor de 128-256 MB
server_ram=RAM del servidor en MB
gamemode_info=Elige entre Creativo (1) o Supervivencia (0)
default_gamemode=Modo de juego por defecto

View File

@ -1,5 +1,5 @@
language_has_been_selected=Español sido seleccionado correctamente.
skip_installer=Quieres saltarte el asistente de configuración?
skip_installer=¿Quieres saltarte el asistente de configuración?
welcome_to_pocketmine=Bienvenido a PocketMine-MP!\nAntes de comenzar a configurar tu nuevo servidor, tienes que aceptar la licencia.\nPocketMine-MP está licenciado con la licencia LGPL,\nque puedes leer abriendo el archivo LICENSE en esta carpeta.
accept_license=¿Aceptas la Licencia?
@ -13,7 +13,7 @@ name_your_server=Nombre del servidor
port_warning=No cambies el puerto por defecto si este es tu primer servidor.
server_port=Puerto del servidor
invalid_port=Puerto inválido
ram_warning=La RAM esla máxima memoria que PocketMine-MP usará. Es recomendado usar un valor de 128-256 MB
ram_warning=La RAM es la máxima memoria que PocketMine-MP usará. Es recomendado usar un valor de 128-256 MB
server_ram=RAM del servidor en MB
gamemode_info=Elige entre Creativo (1) o Supervivencia (0)
default_gamemode=Modo de juego por defecto

View File

@ -14,10 +14,10 @@ port_warning=만약 당신이 서버를 처음 설정한다면 포트 값을 변
server_port=서버 포트
invalid_port=서버 포트가 잘못 입력되었습니다.
ram_warning=RAM 값은 PocketMine-MP에 할당할 메모리의 크기입니다. 128~256MB를 권장합니다.
server_ram=서버 RAM (MB)
server_ram=서버 램(RAM) (MB)
gamemode_info=크리에이티브 (1) 또는 서바이벌 (0) 게임모드 중 하나를 고르세요.
default_gamemode=기본 게임 모드
max_players=최대 동시 접속 인원 수
max_players=최대 동시접속 인원 수
spawn_protection_info=스폰 보호는 OP를 제외한 유저들이 스폰 지역 근처에서 블럭을 놓거나 부수는것을 방지합니다.
spawn_protection=스폰 지역 보호를 사용하겠습니까?

View File

@ -1,5 +1,5 @@
language_has_been_selected=Norsk har blitt valgt.
skip_installer=Vil du hoppe over utpakking trollmannen?
skip_installer=Vil du hoppe over installasjons veiviseren?
welcome_to_pocketmine=Velkommen til PocketMine-MP!\nFør vi starter med å sette opp din nye server må du akseptere vår lisens.\nPocketMine-MP er lisensiert under LGPL lisensen,\nat du kan lese LISENS filen i denne mappen.
accept_license=Aksepterer du lisensen?
@ -15,6 +15,31 @@ server_port=Server port
invalid_port=Ugyldig server port
ram_warning=RAMMEN er den maksimale beløpet PocketMine-MP vil bruke. A verdien av 128-256 MB er anbefalt
server_ram=Server RAMMEN i MB
gamemode_info=Velg mellom Kreativ (1) eller Overlevelse (0)
default_gamemode=Standard spill modus
max_players=Maks online spillere
spawn_protection_info=Spawn-beskyttelsen deaktiverer plassering/ødeleggelse av blokker i spawn sonen bortsett fra for Operatører
spawn_protection=Aktiver spawn-beskyttelse?
op_info=En Operatør er en administrator spiller av serveren. Operatører kan bruke mer kommandoer enn vanlige spillere
op_who=Operatør spiller navn (eksempel, ditt spill-navn)
op_warning=Du vil ha muligheten til å legge til en Operatør bruker senere med /op <spiller>
whitelist_info=Hvitelisten tillater bare brukere som er i den å bli med.
whitelist_enable=Vil du aktivere hvitelisten?
whitelist_warning=Du må legge til spillere til hvitelisten
query_warning1=Query er en protokoll brukt av forskjellige verktøy for å få informasjon fra din server og spillere som er logget inn.
query_warning2=Hvis du deaktiverer det, kan du ikke bruke server lister.
query_disable=Vil du deaktivere Query?
rcon_info=RCON er en protokoll for ekstern kobling til server konsollen med et passord.
rcon_enable=Vil du aktivere RCON?
rcon_password=RCON passord (du kan endre det senere)
usage_info=Den anonyme bruksdata gir oss mulighet til å kalkulere global statistikk for PocketMine-MP og dens utvidelser. Du kan se dette på stats.pocketmine.net
usage_disable=Vil du deaktivere den anonyme bruksdata?
ip_get=Henter din eksterne IP og interne IP
ip_warning=Din eksterne IP er {{EXTERNAL_IP}}. Du må kanskje port forwarde til din interne IP {{INTERNAL_IP}}
ip_confirm=Pass på å sjekke det, hvis du må port forwarde og du skipper det, kan ingen eksterne spillere koble til serveren. [Trykk på Enter]
you_have_finished=Du er nå klar. Alt har blitt gjort korrekt
pocketmine_will_start=PocketMine-MP vil nå starte. Skriv /help for å se en liste av alle tilgjengelige kommandoer.
pocketmine_plugins=Sjekk utvidelse depotet for å legge til nye funksjoner, minispill, eller avansert beskyttelse for din server

View File

@ -1,4 +1,4 @@
language_has_been_selected=Английский был выбран правильно.
language_has_been_selected=Был выбран русский язык.
skip_installer=Вы хотите пропустить мастер настройки?
welcome_to_pocketmine=Добро пожаловать в PocketMine-MP!\nПеред началом установки нового сервера, вы должны согласиться с лицензией. \nPocketMine-MP лицензировано на условиях LGPL лицензии, \nс которой вы можете ознакомиться, открыв файл LICENSE в этой папке.

View File

@ -1,12 +1,45 @@
language_has_been_selected=İngilizce seçildi.
language_has_been_selected=İngilizce başarıyla seçildi.
skip_installer=Kurulum yazılımını atlamak istiyormusunuz?
accept_license=Lisansı kabul ediyormusunuz?
welcome_to_pocketmine=PocketMine-MP dünyasına hoşgeldin.\nYeni sunucunu ayarlamaya başlamadan önce lisans sözleşmesini kabul etmelisin.\nPocketMine-MP LGPL Linsansı altında lisanslıdır,\nBu klasörden LİSANS dosyasınııp okuyabilirsin.
accept_license=Lisans sözleşmesini kabul ediyor musunuz?
you_have_to_accept_the_license=PocketMine-MP'yi kullanabilmeniz için LGPL lisansını kabul etmeniz gereklidir
setting_up_server_now=Sunucunuz şimdi kurulacak, Devam edilsin mi?
default_values_info=Varsayılan değeri değiştirmek istemiyorsan Enter'a bas.
server_properties=Bunları daha sonra server.properties dosyasından düzenleyebilirsin.
invalid_port=Yanlış sunucu port'u
name_your_server=Sunucuna bir isim ver
port_warning=Eğer bu senin ilk sunucun ise varsayılan port değerini değiştirme.
server_port=Sunucu portu
invalid_port=Hatalı sunucu portu
ram_warning=PocketMine-MP için ayrılan maksimum RAM değeri. 128-256 MB yapman önerilir
server_ram=Kullanılan RAM (MB)
gamemode_info=Yaratıcılık (1) ve Hayatta Kalma (0) arasından seçim yap
default_gamemode=Varsayılan oyun modu
max_players=Max. online oyuncu
spawn_protection_info=Spawn koruması, OP olmayan oyuncuların spawn bölgesinde blok kırmasını/koymasını engeller
spawn_protection=Spawn korumasını aktif et?
op_info=Bir OP sunucunun admin oyuncusudur. OPlar normal oyunculardan daha fazla komut kullanabilir
op_who=OP oyuncu adı (örnek, senin oyun adın)
op_warning=Daha sonra /op <player> yazarak oyuncuları OP yapabilirsin
whitelist_info=White-list yalnızca izin verilen oyuncuların giriş yapmasını sağlar.
whitelist_enable=White-list özelliğini aktif etmek ister misin?
whitelist_warning=White-list'e oyuncu eklemelisin
query_warning1=Query, farklı araçların sunucu ve bağlı oyuncu bilgilerini çekebilmesi için var olan bir protokoldür.
query_warning2=Eğer devre dışı bırakırsan, sunucu listelerini kullanamayacaksın.
query_disable=Query'i devre dışı bırakmak ister misin?
rcon_info=RCON, sunucu konsoluna şifre ile bağlanmak için kullanılan bir protokoldür.
rcon_enable=RCON'u aktif etmek ister misin?
rcon_password=RCON şifresi (daha sonra değiştirebilirsin)
usage_info=Anonim kullanım, PocketMine-MP ve eklentileri için global istatistikleri hesaplar. Bu istatistiklere stats.pocketmine.net adresinden bakabilirsin
usage_disable=Anonim kullanımı kapatmak ister misin?
ip_get=Dış IP adresi ve iç IP adresi tespit ediliyor
ip_warning=Dış IP adresin {{EXTERNAL_IP}}. İç IP adresin olan {{INTERNAL_IP}} adresine port yönlendirme yapmalısın
ip_confirm=Lütfen bu adımı gözden geçirin. Bu adımı atlarsanız, Lokal olmayan oyuncular sunucuya bağlanamayacak. [Enter'a Bas]
you_have_finished=Kurulum başarıyla tamamlandı.
pocketmine_will_start=PocketMine-MP şimdi başlayacak. /help yazarak kullanılbilir komutların listesini görebilirsin.
pocketmine_plugins=Sunucuna minigames veya gelişmiş korumalar eklemek için eklenti kütüphanesine bak

View File

@ -1,4 +1,7 @@
language_has_been_selected=Английский был правильно выбран.
skip_installer=Вы хотите пропустить мастер настройки?
welcome_to_pocketmine=Добро пожаловать в PocketMine-MP!\nПеред началом установки нового сервера, вы должны согласиться с лицензией.\nPocketMine-MP лицензирована под LGPL лицензии, \nчто вы можете прочитать, открыв файл лицензии на эту папку.

View File

@ -1,24 +1,24 @@
language_has_been_selected=您现在选择了简体中文.
skip_installer=您想跳过安装向导吗?
welcome_to_pocketmine=欢迎来到PocketMine-MP!\n在开始使用您的新服务器之前您需要接受以下协议\nPocketMine-MP使用了LGPL协议,\n你可以在这个文件夹中找到LICENCE文件.
accept_license=您接受协议内容吗?
you_have_to_accept_the_license=接受了LGPL协议来继续使用PocketMine-MP
welcome_to_pocketmine=欢迎来到PocketMine-MP!\n在开始使用您的新服务器之前您需要接受以下协议\nPocketMine-MP使用了LGPL协议\n你可以在这个文件夹中找到LICENCE文件。
accept_license=您接受协议内容吗
you_have_to_accept_the_license=要接受LGPL协议才可继续使用PocketMine-MP
setting_up_server_now=你现在要开始设置您的服务器了
default_values_info=如果您希望留住默认设置请直接按下回车键.
setting_up_server_now=你现在要开始设置您的服务器了
default_values_info=如果您希望留住默认设置,请直接按下回车键。
server_properties=您以后可以在server.properties中修改设置.
name_your_server=命名您的服务器:
port_warning=尽量不要改变端口如果这是您第一次设置服务器.
port_warning=如果这是您第一次设置服务器,尽量不要改变端口。
server_port=服务器端口:
invalid_port=不正确的服务器端口.
invalid_port=服务器端口不正确。
ram_warning=RAM是PocketMine-MP可用的最大内存. 推荐范围: 128-256 MB
server_ram=分配给服务器的内存(MB):
server_ram=分配给服务器的内存(RAM)(MB):
gamemode_info=选择模式: (1)生存模式 或 (2)创造模式
default_gamemode=默认游戏模式
max_players=在线人数
spawn_protection_info=出生点保护可以在出生点范围内保护所有方块不被摆放/破坏.
max_players=在线人数
spawn_protection_info=出生点保护可以在出生点范围内保护所有方块不被改變。
spawn_protection=启用出生点保护?
op_info=OP是一个服务器的管理员, 可以执行比普通玩家更多的命令.

View File

@ -1,248 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
abstract class Block extends Position{
public static $class = array(
AIR => "AirBlock",
STONE => "StoneBlock",
GRASS => "GrassBlock",
DIRT => "DirtBlock",
COBBLESTONE => "CobblestoneBlock",
PLANKS => "PlanksBlock",
SAPLING => "SaplingBlock",
BEDROCK => "BedrockBlock",
WATER => "WaterBlock",
STILL_WATER => "StillWaterBlock",
LAVA => "LavaBlock",
STILL_LAVA => "StillLavaBlock",
SAND => "SandBlock",
GRAVEL => "GravelBlock",
GOLD_ORE => "GoldOreBlock",
IRON_ORE => "IronOreBlock",
COAL_ORE => "CoalOreBlock",
WOOD => "WoodBlock",
LEAVES => "LeavesBlock",
SPONGE => "SpongeBlock",
GLASS => "GlassBlock",
LAPIS_ORE => "LapisOreBlock",
LAPIS_BLOCK => "LapisBlock",
SANDSTONE => "SandstoneBlock",
BED_BLOCK => "BedBlock",
COBWEB => "CobwebBlock",
TALL_GRASS => "TallGrassBlock",
DEAD_BUSH => "DeadBushBlock",
WOOL => "WoolBlock",
DANDELION => "DandelionBlock",
CYAN_FLOWER => "CyanFlowerBlock",
BROWN_MUSHROOM => "BrownMushroomBlock",
RED_MUSHROOM => "RedMushRoomBlock",
GOLD_BLOCK => "GoldBlock",
IRON_BLOCK => "IronBlock",
DOUBLE_SLAB => "DoubleSlabBlock",
SLAB => "SlabBlock",
BRICKS_BLOCK => "BricksBlock",
TNT => "TNTBlock",
BOOKSHELF => "BookshelfBlock",
MOSS_STONE => "MossStoneBlock",
OBSIDIAN => "ObsidianBlock",
TORCH => "TorchBlock",
FIRE => "FireBlock",
WOOD_STAIRS => "WoodStairsBlock",
CHEST => "ChestBlock",
DIAMOND_ORE => "DiamondOreBlock",
DIAMOND_BLOCK => "DiamondBlock",
WORKBENCH => "WorkbenchBlock",
WHEAT_BLOCK => "WheatBlock",
FARMLAND => "FarmlandBlock",
FURNACE => "FurnaceBlock",
BURNING_FURNACE => "BurningFurnaceBlock",
SIGN_POST => "SignPostBlock",
WOOD_DOOR_BLOCK => "WoodDoorBlock",
LADDER => "LadderBlock",
COBBLESTONE_STAIRS => "CobblestoneStairsBlock",
WALL_SIGN => "WallSignBlock",
IRON_DOOR_BLOCK => "IronDoorBlock",
REDSTONE_ORE => "RedstoneOreBlock",
GLOWING_REDSTONE_ORE => "GlowingRedstoneOreBlock",
SNOW_LAYER => "SnowLayerBlock",
ICE => "IceBlock",
SNOW_BLOCK => "SnowBlock",
CACTUS => "CactusBlock",
CLAY_BLOCK => "ClayBlock",
SUGARCANE_BLOCK => "SugarcaneBlock",
FENCE => "FenceBlock",
PUMPKIN => "PumpkinBlock",
NETHERRACK => "NetherrackBlock",
SOUL_SAND => "SoulSandBlock",
GLOWSTONE_BLOCK => "GlowstoneBlock",
LIT_PUMPKIN => "LitPumpkinBlock",
CAKE_BLOCK => "CakeBlock",
TRAPDOOR => "TrapdoorBlock",
STONE_BRICKS => "StoneBricksBlock",
IRON_BARS => "IronBarsBlock",
GLASS_PANE => "GlassPaneBlock",
MELON_BLOCK => "MelonBlock",
PUMPKIN_STEM => "PumpkinStemBlock",
MELON_STEM => "MelonStemBlock",
FENCE_GATE => "FenceGateBlock",
BRICK_STAIRS => "BrickStairsBlock",
STONE_BRICK_STAIRS => "StoneBrickStairsBlock",
NETHER_BRICKS => "NetherBricksBlock",
NETHER_BRICKS_STAIRS => "NetherBricksStairsBlock",
SANDSTONE_STAIRS => "SandstoneStairsBlock",
SPRUCE_WOOD_STAIRS => "SpruceWoodStairsBlock",
BIRCH_WOOD_STAIRS => "BirchWoodStairsBlock",
JUNGLE_WOOD_STAIRS => "JungleWoodStairsBlock",
STONE_WALL => "StoneWallBlock",
CARROT_BLOCK => "CarrotBlock",
POTATO_BLOCK => "PotatoBlock",
QUARTZ_BLOCK => "QuartzBlock",
QUARTZ_STAIRS => "QuartzStairsBlock",
DOUBLE_WOOD_SLAB => "DoubleWoodSlabBlock",
WOOD_SLAB => "WoodSlabBlock",
HAY_BALE => "HayBaleBlock",
CARPET => "CarpetBlock",
COAL_BLOCK => "CoalBlock",
BEETROOT_BLOCK => "BeetrootBlock",
STONECUTTER => "StonecutterBlock",
GLOWING_OBSIDIAN => "GlowingObsidianBlock",
NETHER_REACTOR => "NetherReactorBlock",
);
protected $id;
protected $meta;
protected $name;
protected $breakTime;
protected $hardness;
public $isActivable = false;
public $breakable = true;
public $isFlowable = false;
public $isSolid = true;
public $isTransparent = false;
public $isReplaceable = false;
public $isPlaceable = true;
public $level = false;
public $hasPhysics = false;
public $isLiquid = false;
public $isFullBlock = true;
public $x = 0;
public $y = 0;
public $z = 0;
public function __construct($id, $meta = 0, $name = "Unknown"){
$this->id = (int) $id;
$this->meta = (int) $meta;
$this->name = $name;
$this->breakTime = 0.20;
$this->hardness = 10;
}
final public function getHardness(){
return ($this->hardness);
}
final public function getName(){
return $this->name;
}
final public function getID(){
return $this->id;
}
final public function getMetadata(){
return $this->meta & 0x0F;
}
final public function position(Position $v){
$this->level = $v->level;
$this->x = (int) $v->x;
$this->y = (int) $v->y;
$this->z = (int) $v->z;
}
public function getDrops(Item $item, Player $player){
if(!isset(Block::$class[$this->id])){ //Unknown blocks
return array();
}else{
return array(
array($this->id, $this->meta, 1),
);
}
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.15;
}
return $this->breakTime;
}
public function getSide($side){
$v = parent::getSide($side);
if($this->level instanceof Level){
return $this->level->getBlock($v);
}
return $v;
}
final public function __toString(){
return "Block ". $this->name ." (".$this->id.":".$this->meta.")";
}
abstract function isBreakable(Item $item, Player $player);
abstract function onBreak(Item $item, Player $player);
abstract function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz);
abstract function onActivate(Item $item, Player $player);
abstract function onUpdate($type);
}
/***REM_START***/
require_once("block/GenericBlock.php");
require_once("block/SolidBlock.php");
require_once("block/TransparentBlock.php");
require_once("block/FallableBlock.php");
require_once("block/LiquidBlock.php");
require_once("block/StairBlock.php");
require_once("block/DoorBlock.php");
/***REM_END***/

View File

@ -1,285 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class Item{
public static $class = array(
SUGARCANE => "SugarcaneItem",
WHEAT_SEEDS => "WheatSeedsItem",
PUMPKIN_SEEDS => "PumpkinSeedsItem",
MELON_SEEDS => "MelonSeedsItem",
MUSHROOM_STEW => "MushroomStewItem",
BEETROOT_SOUP => "BeetrootSoupItem",
CARROT => "CarrotItem",
POTATO => "PotatoItem",
BEETROOT_SEEDS => "BeetrootSeedsItem",
SIGN => "SignItem",
WOODEN_DOOR => "WoodenDoorItem",
BUCKET => "BucketItem",
IRON_DOOR => "IronDoorItem",
CAKE => "CakeItem",
BED => "BedItem",
PAINTING => "PaintingItem",
COAL => "CoalItem",
APPLE => "AppleItem",
SPAWN_EGG => "SpawnEggItem",
DIAMOND => "DiamondItem",
STICK => "StickItem",
BOWL => "BowlItem",
FEATHER => "FeatherItem",
BRICK => "BrickItem",
IRON_INGOT => "IronIngotItem",
GOLD_INGOT => "GoldIngotItem",
IRON_SHOVEL => "IronShovelItem",
IRON_PICKAXE => "IronPickaxeItem",
IRON_AXE => "IronAxeItem",
IRON_HOE => "IronHoeItem",
WOODEN_SWORD => "WoodenSwordItem",
WOODEN_SHOVEL => "WoodenShovelItem",
WOODEN_PICKAXE => "WoodenPickaxeItem",
WOODEN_AXE => "WoodenAxeItem",
FLINT_STEEL => "FlintSteelItem",
);
protected $block;
protected $id;
protected $meta;
public $count;
protected $maxStackSize = 64;
protected $durability = 0;
protected $name;
public $isActivable = false;
public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){
$this->id = (int) $id;
$this->meta = (int) $meta;
$this->count = (int) $count;
$this->name = $name;
if(!isset($this->block) and $this->id <= 0xff and isset(Block::$class[$this->id])){
$this->block = BlockAPI::get($this->id, $this->meta);
$this->name = $this->block->getName();
}
if($this->isTool() !== false){
$this->maxStackSize = 1;
}
}
final public function getName(){
return $this->name;
}
final public function isPlaceable(){
return (($this->block instanceof Block) and $this->block->isPlaceable === true);
}
final public function getBlock(){
if($this->block instanceof Block){
return $this->block;
}else{
return BlockAPI::get(AIR);
}
}
final public function getID(){
return $this->id;
}
final public function getMetadata(){
return $this->meta;
}
final public function getMaxStackSize(){
return $this->maxStackSize;
}
final public function getFuelTime(){
if(!isset(FuelData::$duration[$this->id])){
return false;
}
if($this->id !== BUCKET or $this->meta === 10){
return FuelData::$duration[$this->id];
}
return false;
}
final public function getSmeltItem(){
if(!isset(SmeltingData::$product[$this->id])){
return false;
}
if(isset(SmeltingData::$product[$this->id][0]) and !is_array(SmeltingData::$product[$this->id][0])){
return BlockAPI::getItem(SmeltingData::$product[$this->id][0], SmeltingData::$product[$this->id][1]);
}
if(!isset(SmeltingData::$product[$this->id][$this->meta])){
return false;
}
return BlockAPI::getItem(SmeltingData::$product[$this->id][$this->meta][0], SmeltingData::$product[$this->id][$this->meta][1]);
}
public function useOn($object, $force = false){
if($this->isTool() or $force === true){
if(($object instanceof Entity) and !$this->isSword()){
$this->meta += 2;
}else{
$this->meta++;
}
return true;
}elseif($this->isHoe()){
if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){
$this->meta++;
}
}
return false;
}
final public function isTool(){
return ($this->id === FLINT_STEEL or $this->id === SHEARS or $this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false or $this->isSword() !== false);
}
final public function getMaxDurability(){
if(!$this->isTool() and $this->isHoe() === false and $this->id !== BOW){
return false;
}
$levels = array(
2 => 33,
1 => 60,
3 => 132,
4 => 251,
5 => 1562,
FLINT_STEEL => 65,
SHEARS => 239,
BOW => 385,
);
if(($type = $this->isPickaxe()) === false){
if(($type = $this->isAxe()) === false){
if(($type = $this->isSword()) === false){
if(($type = $this->isShovel()) === false){
if(($type = $this->isHoe()) === false){
$type = $this->id;
}
}
}
}
}
return $levels[$type];
}
final public function isPickaxe(){ //Returns false or level of the pickaxe
switch($this->id){
case IRON_PICKAXE:
return 4;
case WOODEN_PICKAXE:
return 1;
case STONE_PICKAXE:
return 3;
case DIAMOND_PICKAXE:
return 5;
case GOLD_PICKAXE:
return 2;
default:
return false;
}
}
final public function isAxe(){
switch($this->id){
case IRON_AXE:
return 4;
case WOODEN_AXE:
return 1;
case STONE_AXE:
return 3;
case DIAMOND_AXE:
return 5;
case GOLD_AXE:
return 2;
default:
return false;
}
}
final public function isSword(){
switch($this->id){
case IRON_SWORD:
return 4;
case WOODEN_SWORD:
return 1;
case STONE_SWORD:
return 3;
case DIAMOND_SWORD:
return 5;
case GOLD_SWORD:
return 2;
default:
return false;
}
}
final public function isShovel(){
switch($this->id){
case IRON_SHOVEL:
return 4;
case WOODEN_SHOVEL:
return 1;
case STONE_SHOVEL:
return 3;
case DIAMOND_SHOVEL:
return 5;
case GOLD_SHOVEL:
return 2;
default:
return false;
}
}
public function isHoe(){
switch($this->id){
case IRON_HOE:
case WOODEN_HOE:
case STONE_HOE:
case DIAMOND_HOE:
case GOLD_HOE:
return true;
default:
return false;
}
}
public function isShears(){
return ($this->id === SHEARS);
}
final public function __toString(){
return "Item ". $this->name ." (".$this->id.":".$this->meta.")";
}
public function getDestroySpeed(Block $block, Player $player){
return 1;
}
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
return false;
}
}

View File

@ -1,153 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class DoorBlock extends TransparentBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isSolid = false;
}
/**
* @param int $type
*
* @return bool|int
*/
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false);
if($this->getSide(1) instanceof DoorBlock){
$this->level->setBlock($this->getSide(1), new AirBlock(), false);
}
return BLOCK_UPDATE_NORMAL;
}
}
return false;
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param integer $face
* @param integer $fx
* @param integer $fy
* @param integer $fz
*
* @return boolean
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($face === 1){
$blockUp = $this->getSide(1);
$blockDown = $this->getSide(0);
if($blockUp->isReplaceable === false or $blockDown->isTransparent === true){
return false;
}
$direction = $player->entity->getDirection();
$face = array(
0 => 3,
1 => 4,
2 => 2,
3 => 5,
);
$next = $this->getSide($face[(($direction + 2) % 4)]);
$next2 = $this->getSide($face[$direction]);
$metaUp = 0x08;
if($next->getID() === $this->id or ($next2->isTransparent === false and $next->isTransparent === true)){ //Door hinge
$metaUp |= 0x01;
}
$this->level->setBlock($blockUp, BlockAPI::get($this->id, $metaUp), true, false, true); //Top
$this->meta = $direction & 0x03;
$this->level->setBlock($block, $this, true, false, true); //Bottom
return true;
}
return false;
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function onBreak(Item $item, Player $player){
if(($this->meta & 0x08) === 0x08){
$down = $this->getSide(0);
if($down->getID() === $this->id){
$this->level->setBlock($down, new AirBlock(), true, false, true);
}
}else{
$up = $this->getSide(1);
if($up->getID() === $this->id){
$this->level->setBlock($up, new AirBlock(), true, false, true);
}
}
$this->level->setBlock($this, new AirBlock(), true, false, true);
return true;
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function onActivate(Item $item, Player $player){
if(($this->meta & 0x08) === 0x08){ //Top
$down = $this->getSide(0);
if($down->getID() === $this->id){
$meta = $down->getMetadata() ^ 0x04;
$this->level->setBlock($down, BlockAPI::get($this->id, $meta), true, false, true);
$players = ServerAPI::request()->api->player->getAll($this->level);
unset($players[$player->CID]);
$pk = new LevelEventPacket;
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->evid = 1003;
$pk->data = 0;
ServerAPI::request()->api->player->broadcastPacket($players, $pk);
return true;
}
return false;
}else{
$this->meta ^= 0x04;
$this->level->setBlock($this, $this, true, false, true);
$players = ServerAPI::request()->api->player->getAll($this->level);
unset($players[$player->CID]);
$pk = new LevelEventPacket;
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->evid = 1003;
$pk->data = 0;
ServerAPI::request()->api->player->broadcastPacket($players, $pk);
}
return true;
}
}

View File

@ -1,50 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class FallableBlock extends SolidBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->hasPhysics = true;
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param int $face
* @param int $fx
* @param int $fy
* @param int $fz
*
* @return mixed
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL);
return $ret;
}
}

View File

@ -1,104 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class GenericBlock extends Block{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param integer $face
* @param integer $fx
* @param integer $fy
* @param integer $fz
*
* @return mixed
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
return $this->level->setBlock($this, $this, true, false, true);
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function isBreakable(Item $item, Player $player){
return ($this->breakable);
}
/**
* @param Item $item
* @param Player $player
*
* @return mixed
*/
public function onBreak(Item $item, Player $player){
return $this->level->setBlock($this, new AirBlock(), true, false, true);
}
/**
* @param integer $type
*
* @return boolean
*/
public function onUpdate($type){
if($this->hasPhysics === true and $type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->getID() === AIR or ($down instanceof LiquidBlock)){
$data = array(
"x" => $this->x + 0.5,
"y" => $this->y + 0.5,
"z" => $this->z + 0.5,
"Tile" => $this->id,
);
$server = ServerAPI::request();
$this->level->setBlock($this, new AirBlock(), false, false, true);
$e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data);
$server->api->entity->spawnToAll($e);
$server->api->block->blockUpdateAround(clone $this, BLOCK_UPDATE_NORMAL, 1);
}
return false;
}
return false;
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function onActivate(Item $item, Player $player){
return $this->isActivable;
}
}

View File

@ -1,128 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class BedBlock extends TransparentBlock{
public function __construct($type = 0){
parent::__construct(BED_BLOCK, $type, "Bed Block");
$this->isActivable = true;
$this->isFullBlock = false;
$this->hardness = 1;
}
public function onActivate(Item $item, Player $player){
if(ServerAPI::request()->api->time->getPhase($player->level) !== "night"){
$pk = new ChatPacket;
$pk->message = "You can only sleep at night";
$player->dataPacket($pk);
return true;
}
$blockNorth = $this->getSide(2); //Gets the blocks around them
$blockSouth = $this->getSide(3);
$blockEast = $this->getSide(5);
$blockWest = $this->getSide(4);
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
$b = $this;
}else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$b = $blockNorth;
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$b = $blockSouth;
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$b = $blockEast;
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$b = $blockWest;
}else{
$pk = new ChatPacket;
$pk->message = "This bed is incomplete";
$player->dataPacket($pk);
return true;
}
}
if($player->sleepOn($b) === false){
$pk = new ChatPacket;
$pk->message = "This bed is occupied";
$player->dataPacket($pk);
}
return true;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->isTransparent === false){
$faces = array(
0 => 3,
1 => 4,
2 => 2,
3 => 5,
);
$d = $player->entity->getDirection();
$next = $this->getSide($faces[(($d + 3) % 4)]);
$downNext = $this->getSide(0);
if($next->isReplaceable === true and $downNext->isTransparent === false){
$meta = (($d + 3) % 4) & 0x03;
$this->level->setBlock($block, BlockAPI::get($this->id, $meta), true, false, true);
$this->level->setBlock($next, BlockAPI::get($this->id, $meta | 0x08), true, false, true);
return true;
}
}
return false;
}
public function onBreak(Item $item, Player $player){
$blockNorth = $this->getSide(2); //Gets the blocks around them
$blockSouth = $this->getSide(3);
$blockEast = $this->getSide(5);
$blockWest = $this->getSide(4);
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
}elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
}elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){
$this->level->setBlock($blockEast, new AirBlock(), true, false, true);
}elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){
$this->level->setBlock($blockWest, new AirBlock(), true, false, true);
}
}else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$this->level->setBlock($blockEast, new AirBlock(), true, false, true);
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$this->level->setBlock($blockWest, new AirBlock(), true, false, true);
}
}
$this->level->setBlock($this, new AirBlock(), true, false, true);
return true;
}
public function getDrops(Item $item, Player $player){
return array(
array(BED, 0, 1),
);
}
}

View File

@ -1,115 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class SlabBlock extends TransparentBlock{
public function __construct($meta = 0){
parent::__construct(SLAB, $meta, "Slab");
$names = array(
0 => "Stone",
1 => "Sandstone",
2 => "Wooden",
3 => "Cobblestone",
4 => "Brick",
5 => "Stone Brick",
6 => "Quartz",
7 => "",
);
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab";
if(($this->meta & 0x08) === 0x08){
$this->isFullBlock = true;
}else{
$this->isFullBlock = false;
}
$this->hardness = 30;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$this->meta &= 0x07;
if($face === 0){
if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}else{
$this->meta |= 0x08;
}
}elseif($face === 1){
if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}
}elseif(!$player->entity->inBlock($block)){
if($block->getID() === SLAB){
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}
return false;
}else{
if($fy > 0.5){
$this->meta |= 0x08;
}
}
}else{
return false;
}
if($block->getID() === SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
return false;
}
$this->level->setBlock($block, $this, true, false, true);
return true;
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array($this->id, $this->meta & 0x07, 1),
);
}else{
return array();
}
}
}

View File

@ -1,107 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class WoodSlabBlock extends TransparentBlock{
public function __construct($meta = 0){
parent::__construct(WOOD_SLAB, $meta, "Wooden Slab");
$names = array(
0 => "Oak",
1 => "Spruce",
2 => "Birch",
3 => "Jungle",
);
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Wooden Slab";
if(($this->meta & 0x08) === 0x08){
$this->isFullBlock = true;
}else{
$this->isFullBlock = false;
}
$this->hardness = 15;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$this->meta &= 0x07;
if($face === 0){
if($target->getID() === WOOD_SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true;
}elseif($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true;
}else{
$this->meta |= 0x08;
}
}elseif($face === 1){
if($target->getID() === WOOD_SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true;
}elseif($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true;
}
}elseif(!$player->entity->inBlock($block)){
if($block->getID() === WOOD_SLAB){
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true;
}
return false;
}else{
if($fy > 0.5){
$this->meta |= 0x08;
}
}
}else{
return false;
}
if($block->getID() === WOOD_SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
return false;
}
$this->level->setBlock($block, $this, true, false, true);
return true;
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isAxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 3;
}
}
public function getDrops(Item $item, Player $player){
return array(
array($this->id, $this->meta & 0x07, 1),
);
}
}

View File

@ -1,82 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class BeetrootBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(BEETROOT_BLOCK, $meta, "Beetroot Block");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
return true;
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(BEETROOT_SEEDS, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
}else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function getDrops(Item $item, Player $player){
$drops = array();
if($this->meta >= 0x07){
$drops[] = array(BEETROOT, 0, 1);
$drops[] = array(BEETROOT_SEEDS, 0, mt_rand(0, 3));
}else{
$drops[] = array(BEETROOT_SEEDS, 0, 1);
}
return $drops;
}
}

View File

@ -1,87 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class MelonStemBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(MELON_STEM, $meta, "Melon Stem");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}else{
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b->getID() === MELON_BLOCK){
return BLOCK_UPDATE_RANDOM;
}
}
$side = $this->getSide(mt_rand(2,5));
$d = $side->getSide(0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
$this->level->setBlock($side, new MelonBlock(), true, false, true);
}
}
}
return BLOCK_UPDATE_RANDOM;
}
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
return true;
}
return false;
}
public function getDrops(Item $item, Player $player){
return array(
array(MELON_SEEDS, 0, mt_rand(0, 2)),
);
}
}

View File

@ -1,87 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class PumpkinStemBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(PUMPKIN_STEM, $meta, "Pumpkin Stem");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}else{
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b->getID() === PUMPKIN){
return BLOCK_UPDATE_RANDOM;
}
}
$side = $this->getSide(mt_rand(2,5));
$d = $side->getSide(0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
$this->level->setBlock($side, new PumpkinBlock(), true, false, true);
}
}
}
return BLOCK_UPDATE_RANDOM;
}
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
return true;
}
return false;
}
public function getDrops(Item $item, Player $player){
return array(
array(PUMPKIN_SEEDS, 0, mt_rand(0, 2)),
);
}
}

View File

@ -1,103 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class SugarcaneBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(SUGARCANE_BLOCK, $meta, "Sugarcane");
$this->hardness = 0;
}
public function getDrops(Item $item, Player $player){
return array(
array(SUGARCANE, 0, 1),
);
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
if($this->getSide(0)->getID() !== SUGARCANE_BLOCK){
for($y = 1; $y < 3; ++$y){
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === AIR){
$this->level->setBlock($b, new SugarcaneBlock(), true, false, true);
break;
}
}
$this->meta = 0;
$this->level->setBlock($this, $this, true, false, true);
}
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
return true;
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->isTransparent === true and $down->getID() !== SUGARCANE_BLOCK){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== SUGARCANE_BLOCK){
if($this->meta === 0x0F){
for($y = 1; $y < 3; ++$y){
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === AIR){
$this->level->setBlock($b, new SugarcaneBlock(), true, false, true);
break;
}
}
$this->meta = 0;
$this->level->setBlock($this, $this, true, false, true);
}else{
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
}
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === SUGARCANE_BLOCK){
$this->level->setBlock($block, new SugarcaneBlock(), true, false, true);
return true;
}elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){
$block0 = $down->getSide(2);
$block1 = $down->getSide(3);
$block2 = $down->getSide(4);
$block3 = $down->getSide(5);
if(($block0 instanceof WaterBlock) or ($block1 instanceof WaterBlock) or ($block2 instanceof WaterBlock) or ($block3 instanceof WaterBlock)){
$this->level->setBlock($block, new SugarcaneBlock(), true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
}
return false;
}
}

View File

@ -1,82 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class WheatBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(WHEAT_BLOCK, $meta, "Wheat Block");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
return true;
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(WHEAT_SEEDS, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
}else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function getDrops(Item $item, Player $player){
$drops = array();
if($this->meta >= 0x07){
$drops[] = array(WHEAT, 0, 1);
$drops[] = array(WHEAT_SEEDS, 0, mt_rand(0, 3));
}else{
$drops[] = array(WHEAT_SEEDS, 0, 1);
}
return $drops;
}
}

View File

@ -1,107 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class BurningFurnaceBlock extends SolidBlock{
public function __construct($meta = 0){
parent::__construct(BURNING_FURNACE, $meta, "Burning Furnace");
$this->isActivable = true;
$this->hardness = 17.5;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array(
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
$this->meta = $faces[$player->entity->getDirection()];
$this->level->setBlock($block, $this, true, false, true);
return true;
}
public function onBreak(Item $item, Player $player){
$this->level->setBlock($this, new AirBlock(), true, true, true);
return true;
}
public function onActivate(Item $item, Player $player){
$server = ServerAPI::request();
$t = $server->api->tile->get($this);
$furnace = false;
if($t !== false){
$furnace = $t;
}else{
$furnace = $server->api->tile->add($this->level, TILE_FURNACE, $this->x, $this->y, $this->z, array(
"Items" => array(),
"id" => TILE_FURNACE,
"x" => $this->x,
"y" => $this->y,
"z" => $this->z
));
}
if(($player->gamemode & 0x01) === 0x01){
return true;
}
$furnace->openInventory($player);
return true;
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.7;
case 4:
return 0.9;
case 3:
return 1.35;
case 2:
return 0.45;
case 1:
return 2.65;
default:
return 17.5;
}
}
public function getDrops(Item $item, Player $player){
$drops = array();
if($item->isPickaxe() >= 1){
$drops[] = array(FURNACE, 0, 1);
}
$t = ServerAPI::request()->api->tile->get($this);
if($t !== false and $t->class === TILE_FURNACE){
for($s = 0; $s < FURNACE_SLOTS; ++$s){
$slot = $t->getSlot($s);
if($slot->getID() > AIR and $slot->count > 0){
$drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count);
}
}
}
return $drops;
}
}

View File

@ -1,126 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class ChestBlock extends TransparentBlock{
public function __construct($meta = 0){
parent::__construct(CHEST, $meta, "Chest");
$this->isActivable = true;
$this->hardness = 15;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$server = ServerAPI::request();
$faces = array(
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
$chest = false;
$this->meta = $faces[$player->entity->getDirection()];
for($side = 2; $side <= 5; ++$side){
if(($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)){
continue;
}elseif(($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)){
continue;
}
$c = $this->getSide($side);
if(($c instanceof ChestBlock) and $c->getMetadata() === $this->meta){
if((($tile = $server->api->tile->get($c)) instanceof Tile) and !$tile->isPaired()){
$chest = $tile;
break;
}
}
}
$this->level->setBlock($block, $this, true, false, true);
$tile = $server->api->tile->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, array(
"Items" => array(),
"id" => TILE_CHEST,
"x" => $this->x,
"y" => $this->y,
"z" => $this->z
));
if($chest instanceof Tile){
$chest->pairWith($tile);
$tile->pairWith($chest);
}
return true;
}
public function onBreak(Item $item, Player $player){
$t = ServerAPI::request()->api->tile->get($this);
if($t !== false){
$t->unpair();
}
$this->level->setBlock($this, new AirBlock(), true, true, true);
return true;
}
public function onActivate(Item $item, Player $player){
$top = $this->getSide(1);
if($top->isTransparent !== true){
return true;
}
$server = ServerAPI::request();
$t = $server->api->tile->get($this);
$chest = false;
if($t !== false){
$chest = $t;
}else{
$chest = $server->api->tile->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, array(
"Items" => array(),
"id" => TILE_CHEST,
"x" => $this->x,
"y" => $this->y,
"z" => $this->z
));
}
if(($player->gamemode & 0x01) === 0x01){
return true;
}
$chest->openInventory($player);
return true;
}
public function getDrops(Item $item, Player $player){
$drops = array(
array($this->id, 0, 1),
);
$t = ServerAPI::request()->api->tile->get($this);
if($t !== false and $t->class === TILE_CHEST){
for($s = 0; $s < CHEST_SLOTS; ++$s){
$slot = $t->getSlot($s);
if($slot->getID() > AIR and $slot->count > 0){
$drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count);
}
}
}
return $drops;
}
}

View File

@ -1,224 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class NBT{
const LITTLE_ENDIAN = 0;
const BIG_ENDIAN = 1;
private $buffer;
private $offset;
private $endianness;
private $data;
public function get($len){
if($len < 0){
$this->offset = strlen($this->buffer) - 1;
return "";
}
if($len === true){
return substr($this->buffer, $this->offset);
}
$this->offset += $len;
return substr($this->buffer, $this->offset - $len, $len);
}
public function put($v){
$this->buffer .= $v;
}
public function feof(){
return !isset($this->buffer{$this->offset});
}
public function __construct($endianness = NBT::LITTLE_ENDIAN){
$this->offset = 0;
$this->endianness = $endianness & 0x01;
}
public function read($buffer){
$this->offset = 0;
$this->buffer = $buffer;
$this->data = $this->readTag();
}
public function write(){
$this->offset = 0;
if($this->data instanceof NBTTag_Compound){
$this->writeTag($this->data);
return $this->buffer;
}else{
return false;
}
}
public function readTag(){
switch($this->getByte()){
case NBTTag::TAG_Byte:
$tag = new NBTTag_Byte($this->getString());
$tag->read($this);
break;
case NBTTag::TAG_Byte:
$tag = new NBTTag_Byte($this->getString());
$tag->read($this);
break;
case NBTTag::TAG_Short:
$tag = new NBTTag_Short($this->getString());
$tag->read($this);
break;
case NBTTag::TAG_Int:
$tag = new NBTTag_Int($this->getString());
$tag->read($this);
break;
case NBTTag::TAG_Long:
$tag = new NBTTag_Long($this->getString());
$tag->read($this);
break;
case NBTTag::TAG_Float:
$tag = new NBTTag_Float($this->getString());
$tag->read($this);
break;
case NBTTag::TAG_Double:
$tag = new NBTTag_Double($this->getString());
$tag->read($this);
break;
case NBTTag::TAG_Byte_Array:
$tag = new NBTTag_Byte_Array($this->getString());
$tag->read($this);
break;
case NBTTag::TAG_String:
$tag = new NBTTag_String($this->getString());
$tag->read($this);
break;
case NBTTag::TAG_List:
$tag = new NBTTag_List($this->getString());
$tag->read($this);
break;
case NBTTag::TAG_Compound:
$tag = new NBTTag_Compound($this->getString());
$tag->read($this);
break;
case NBTTag::TAG_Int_Array:
$tag = new NBTTag_Int_Array($this->getString());
$tag->read($this);
break;
case NBTTag::TAG_End: //No named tag
default:
$tag = new NBTTag_End;
break;
}
return $tag;
}
public function writeTag(NBTTag $tag){
$this->putByte($tag->getType());
if($tag instanceof NamedNBTTag and $tag->getName() !== false){
$this->putString($tag->getName());
}
$tag->write($this);
}
public function getByte(){
return Utils::readByte($this->get(1), true);
}
public function putByte($v){
$this->buffer .= Utils::writeByte($v);
}
public function getShort(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readShort($this->get(2)) : Utils::readLShort($this->get(2));
}
public function putShort($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeShort($v) : Utils::writeLShort($v);
}
public function getInt(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readInt($this->get(4)) : Utils::readLInt($this->get(4));
}
public function putInt($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeInt($v) : Utils::writeLInt($v);
}
public function getLong(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readLong($this->get(8)) : Utils::readLLong($this->get(8));
}
public function putLong($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeLong($v) : Utils::writeLLong($v);
}
public function getFloat(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readFloat($this->get(4)) : Utils::readLFloat($this->get(4));
}
public function putFloat($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeFloat($v) : Utils::writeLFloat($v);
}
public function getDouble(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readDouble($this->get(8)) : Utils::readLDouble($this->get(8));
}
public function putDouble($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeDouble($v) : Utils::writeLDouble($v);
}
public function getString(){
return $this->get($this->getShort());
}
public function putString($v){
$this->putShort(strlen($v));
$this->buffer .= $v;
}
public function __get($name){
return $this->data instanceof NBTTag_Compound ? $this->data->{$name} : false;
}
public function __set($name, $value){
if($this->data instanceof NBTTag_Compound){
$this->data->{$name} = $value;
}
}
public function __isset($name){
return $this->data instanceof NBTTag_Compound ? isset($this->data->{$name}) : false;
}
public function __unset($name){
if($this->data instanceof NBTTag_Compound){
unset($this->data->{$name});
}
}
public function getData(){
return $this->data;
}
public function setData(NBTTag_Compound $data){
$this->data = $data;
}
}

View File

@ -1,63 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class NBTTag_Compound extends NamedNBTTag{
public function getType(){
return NBTTag::TAG_Compound;
}
public function __get($name){
return isset($this->value[$name]) ? $this->value[$name]->getValue() : false;
}
public function __set($name, $value){
if(isset($this->value[$name])){
$this->value[$name]->setValue($value);
}
}
public function __isset($name){
return isset($this->value[$name]);
}
public function __unset($name){
unset($this->value[$name]);
}
public function read(NBT $nbt){
$this->value = array();
do{
$tag = $nbt->readTag();
if($tag instanceof NamedNBTTag and $tag->getName() !== ""){
$this->value[$tag->getName()] = $tag;
}else{
$this->value[] = $tag;
}
}while(!($tag instanceof NBTTag_End) and !$nbt->feof());
}
public function write(NBT $nbt){
foreach($this->value as $tag){
$nbt->writeTag($tag);
}
}
}

View File

@ -1,126 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class NBTTag_List extends NamedNBTTag{
public function getType(){
return NBTTag::TAG_List;
}
public function __get($name){
return isset($this->value[$name]) ? $this->value[$name]->getValue() : false;
}
public function __set($name, $value){
if(isset($this->value[$name])){
$this->value[$name]->setValue($value);
}
}
public function __isset($name){
return isset($this->value[$name]);
}
public function __unset($name){
unset($this->value[$name]);
}
public function read(NBT $nbt){
$this->value = array();
$tagId = $nbt->getByte();
$this->value[-1] = $tagId;
$size = $nbt->getInt();
for($i = 0; $i < $size and !$nbt->feof(); ++$i){
switch($tagId){
case NBTTag::TAG_Byte:
$tag = new NBTTag_Byte(false);
$tag->read($nbt);
$this->value[] = $tag;
break;
case NBTTag::TAG_Byte:
$tag = new NBTTag_Byte(false);
$tag->read($nbt);
$this->value[] = $tag;
break;
case NBTTag::TAG_Short:
$tag = new NBTTag_Short(false);
$tag->read($nbt);
$this->value[] = $tag;
break;
case NBTTag::TAG_Int:
$tag = new NBTTag_Int(false);
$tag->read($nbt);
$this->value[] = $tag;
break;
case NBTTag::TAG_Long:
$tag = new NBTTag_Long(false);
$tag->read($nbt);
$this->value[] = $tag;
break;
case NBTTag::TAG_Float:
$tag = new NBTTag_Float(false);
$tag->read($nbt);
$this->value[] = $tag;
break;
case NBTTag::TAG_Double:
$tag = new NBTTag_Double(false);
$tag->read($nbt);
$this->value[] = $tag;
break;
case NBTTag::TAG_Byte_Array:
$tag = new NBTTag_Byte_Array(false);
$tag->read($nbt);
$this->value[] = $tag;
break;
case NBTTag::TAG_String:
$tag = new NBTTag_String(false);
$tag->read($nbt);
$this->value[] = $tag;
break;
case NBTTag::TAG_List:
$tag = new NBTTag_List(false);
$tag->read($nbt);
$this->value[] = $tag;
break;
case NBTTag::TAG_Compound:
$tag = new NBTTag_Compound(false);
$tag->read($nbt);
$this->value[] = $tag;
break;
case NBTTag::TAG_Int_Array:
$tag = new NBTTag_Int_Array(false);
$tag->read($nbt);
$this->value[] = $tag;
break;
}
}
}
public function write(NBT $nbt){
$nbt->putByte($this->value[-1]);
$nbt->putInt(count($this->value) - 1);
foreach($this->value as $tag){
if($tag instanceof NBTTag){
$nbt->writeTag($tag);
}
}
}
}

View File

@ -1,98 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class MinecraftInterface{
public $bandwidth;
private $socket;
private $packets;
function __construct($server, $port = 25565, $serverip = "0.0.0.0"){
$this->socket = new UDPSocket($server, $port, true, $serverip);
if($this->socket->connected === false){
console("[SEVERE] Couldn't bind to $serverip:".$port, true, true, 0);
exit(1);
}
$this->bandwidth = array(0, 0, microtime(true));
$this->packets = array();
}
public function close(){
return $this->socket->close(false);
}
public function readPacket(){
$buf = null;
$source = null;
$port = null;
$len = $this->socket->read($buf, $source, $port);
if($len === false or $len === 0){
return false;
}
$this->bandwidth[0] += $len;
return $this->parsePacket($buf, $source, $port);
}
private function parsePacket($buffer, $source, $port){
$pid = ord($buffer{0});
if(RakNetInfo::isValid($pid)){
$parser = new RakNetParser($buffer);
if($parser->packet !== false){
$parser->packet->ip = $source;
$parser->packet->port = $port;
if(EventHandler::callEvent(new PacketReceiveEvent($parser->packet)) === BaseEvent::DENY){
return false;
}
return $parser->packet;
}
return false;
}elseif($pid === 0xfe and $buffer{1} === "\xfd" and ServerAPI::request()->api->query instanceof QueryHandler){
$packet = new QueryPacket;
$packet->ip = $source;
$packet->port = $port;
$packet->buffer =& $buffer;
if(EventHandler::callEvent(new PacketReceiveEvent($packet)) === BaseEvent::DENY){
return false;
}
ServerAPI::request()->api->query->handle($packet);
}else{
$packet = new Packet();
$packet->ip = $source;
$packet->port = $port;
$packet->buffer =& $buffer;
EventHandler::callEvent(new PacketReceiveEvent($packet));
return false;
}
}
public function writePacket(Packet $packet){
if(EventHandler::callEvent(new PacketSendEvent($packet)) === BaseEvent::DENY){
return 0;
}elseif($packet instanceof RakNetPacket){
new RakNetCodec($packet);
}
$write = $this->socket->write($packet->buffer, $packet->ip, $packet->port);
$this->bandwidth[1] += $write;
return $write;
}
}
?>

View File

@ -1,69 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class UDPSocket{
public $connected, $sock, $server, $port;
function __construct($server, $port, $listen = false, $serverip = "0.0.0.0"){
$this->server = $server;
$this->port = $port;
$this->sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($this->sock, SOL_SOCKET, SO_BROADCAST, 1); //Allow sending broadcast messages
if($listen !== true){
$this->connected = true;
$this->unblock();
}else{
if(socket_bind($this->sock, $serverip, $port) === true){
socket_set_option($this->sock, SOL_SOCKET, SO_REUSEADDR, 0);
socket_set_option($this->sock, SOL_SOCKET, SO_SNDBUF, 1024 * 1024 * 2); //2MB
socket_set_option($this->sock, SOL_SOCKET, SO_RCVBUF, 1024 * 1024); //1MB
$this->unblock();
$this->connected = true;
}else{
$this->connected = false;
}
}
}
public function close($error = 125){
return @socket_close($this->sock);
}
public function block(){
socket_set_block($this->sock);
}
public function unblock(){
socket_set_nonblock($this->sock);
}
public function read(&$buf, &$source, &$port){
return @socket_recvfrom($this->sock, $buf, 65535, 0, $source, $port);
}
public function write($data, $dest, $port){
return @socket_sendto($this->sock, $data, strlen($data), 0, $dest, $port);
}
}
?>

View File

@ -1,51 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class ClientHandshakePacket extends RakNetDataPacket{
public $cookie;
public $security;
public $port;
public $dataArray0;
public $dataArray;
public $timestamp;
public $session2;
public $session;
public function pid(){
return ProtocolInfo::CLIENT_HANDSHAKE_PACKET;
}
public function decode(){
$this->cookie = $this->get(4);
$this->security = $this->get(1);
$this->port = $this->getShort(true);
$this->dataArray0 = $this->get($this->getByte());
$this->dataArray = $this->getDataArray(9);
$this->timestamp = $this->get(2);
$this->session2 = $this->getLong();
$this->session = $this->getLong();
}
public function encode(){
}
}

View File

@ -1,57 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class ServerHandshakePacket extends RakNetDataPacket{
public $port;
public $session;
public $session2;
public function pid(){
return ProtocolInfo::SERVER_HANDSHAKE_PACKET;
}
public function decode(){
}
public function encode(){
$this->reset();
$this->put("\x04\x3f\x57\xfe"); //cookie
$this->put("\xcd"); //Security flags
$this->putShort($this->port);
$this->putDataArray(array(
"\xf5\xff\xff\xf5",
"\xff\xff\xff\xff",
"\xff\xff\xff\xff",
"\xff\xff\xff\xff",
"\xff\xff\xff\xff",
"\xff\xff\xff\xff",
"\xff\xff\xff\xff",
"\xff\xff\xff\xff",
"\xff\xff\xff\xff",
"\xff\xff\xff\xff",
));
$this->put("\x00\x00");
$this->putLong($this->session);
$this->putLong($this->session2);
}
}

View File

@ -1,185 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class RakNetCodec{
public $packet;
private $buffer;
public function __construct(RakNetPacket $packet){
$this->packet = $packet;
$this->buffer =& $this->packet->buffer;
$this->encode();
}
private function encode(){
if(strlen($this->packet->buffer) > 0){
return;
}
$this->buffer .= chr($this->packet->pid());
switch($this->packet->pid()){
case RakNetInfo::OPEN_CONNECTION_REPLY_1:
$this->buffer .= RakNetInfo::MAGIC;
$this->putLong($this->packet->serverID);
$this->putByte(0); //server security
$this->putShort($this->packet->mtuSize);
break;
case RakNetInfo::OPEN_CONNECTION_REPLY_2:
$this->buffer .= RakNetInfo::MAGIC;
$this->putLong($this->packet->serverID);
$this->putShort($this->packet->port);
$this->putShort($this->packet->mtuSize);
$this->putByte(0); //Server security
break;
case RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION:
$this->putByte(RakNetInfo::STRUCTURE);
$this->buffer .= RakNetInfo::MAGIC;
$this->putLong($this->packet->serverID);
break;
case RakNetInfo::UNCONNECTED_PONG:
case RakNetInfo::ADVERTISE_SYSTEM:
$this->putLong($this->packet->pingID);
$this->putLong($this->packet->serverID);
$this->buffer .= RakNetInfo::MAGIC;
$this->putString($this->packet->serverType);
break;
case RakNetInfo::DATA_PACKET_0:
case RakNetInfo::DATA_PACKET_1:
case RakNetInfo::DATA_PACKET_2:
case RakNetInfo::DATA_PACKET_3:
case RakNetInfo::DATA_PACKET_4:
case RakNetInfo::DATA_PACKET_5:
case RakNetInfo::DATA_PACKET_6:
case RakNetInfo::DATA_PACKET_7:
case RakNetInfo::DATA_PACKET_8:
case RakNetInfo::DATA_PACKET_9:
case RakNetInfo::DATA_PACKET_A:
case RakNetInfo::DATA_PACKET_B:
case RakNetInfo::DATA_PACKET_C:
case RakNetInfo::DATA_PACKET_D:
case RakNetInfo::DATA_PACKET_E:
case RakNetInfo::DATA_PACKET_F:
$this->putLTriad($this->packet->seqNumber);
foreach($this->packet->data as $pk){
$this->encodeDataPacket($pk);
}
break;
case RakNetInfo::NACK:
case RakNetInfo::ACK:
$payload = b"";
$records = 0;
$pointer = 0;
sort($this->packet->packets, SORT_NUMERIC);
$max = count($this->packet->packets);
while($pointer < $max){
$type = true;
$curr = $start = $this->packet->packets[$pointer];
for($i = $start + 1; $i < $max; ++$i){
$n = $this->packet->packets[$i];
if(($n - $curr) === 1){
$curr = $end = $n;
$type = false;
$pointer = $i + 1;
}else{
break;
}
}
++$pointer;
if($type === false){
$payload .= "\x00";
$payload .= strrev(Utils::writeTriad($start));
$payload .= strrev(Utils::writeTriad($end));
}else{
$payload .= Utils::writeBool(true);
$payload .= strrev(Utils::writeTriad($start));
}
++$records;
}
$this->putShort($records);
$this->buffer .= $payload;
break;
default:
}
}
private function encodeDataPacket(RakNetDataPacket $pk){
$this->putByte(($pk->reliability << 5) | ($pk->hasSplit > 0 ? 0b00010000:0));
$this->putShort(strlen($pk->buffer) << 3);
if($pk->reliability === 2
or $pk->reliability === 3
or $pk->reliability === 4
or $pk->reliability === 6
or $pk->reliability === 7){
$this->putLTriad($pk->messageIndex);
}
if($pk->reliability === 1
or $pk->reliability === 3
or $pk->reliability === 4
or $pk->reliability === 7){
$this->putLTriad($pk->orderIndex);
$this->putByte($pk->orderChannel);
}
if($pk->hasSplit === true){
$this->putInt($pk->splitCount);
$this->putShort($pk->splitID);
$this->putInt($pk->splitIndex);
}
$this->buffer .= $pk->buffer;
}
protected function put($str){
$this->buffer .= $str;
}
protected function putLong($v){
$this->buffer .= Utils::writeLong($v);
}
protected function putInt($v){
$this->buffer .= Utils::writeInt($v);
}
protected function putShort($v){
$this->buffer .= Utils::writeShort($v);
}
protected function putTriad($v){
$this->buffer .= Utils::writeTriad($v);
}
protected function putLTriad($v){
$this->buffer .= strrev(Utils::writeTriad($v));
}
protected function putByte($v){
$this->buffer .= chr($v);
}
protected function putString($v){
$this->putShort(strlen($v));
$this->put($v);
}
}

View File

@ -1,94 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
abstract class RakNetInfo{
const STRUCTURE = 5;
const MAGIC = "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78";
const UNCONNECTED_PING = 0x01;
const UNCONNECTED_PING_OPEN_CONNECTIONS = 0x02;
const OPEN_CONNECTION_REQUEST_1 = 0x05;
const OPEN_CONNECTION_REPLY_1 = 0x06;
const OPEN_CONNECTION_REQUEST_2 = 0x07;
const OPEN_CONNECTION_REPLY_2 = 0x08;
const INCOMPATIBLE_PROTOCOL_VERSION = 0x1a; //CHECK THIS
const UNCONNECTED_PONG = 0x1c;
const ADVERTISE_SYSTEM = 0x1d;
const DATA_PACKET_0 = 0x80;
const DATA_PACKET_1 = 0x81;
const DATA_PACKET_2 = 0x82;
const DATA_PACKET_3 = 0x83;
const DATA_PACKET_4 = 0x84;
const DATA_PACKET_5 = 0x85;
const DATA_PACKET_6 = 0x86;
const DATA_PACKET_7 = 0x87;
const DATA_PACKET_8 = 0x88;
const DATA_PACKET_9 = 0x89;
const DATA_PACKET_A = 0x8a;
const DATA_PACKET_B = 0x8b;
const DATA_PACKET_C = 0x8c;
const DATA_PACKET_D = 0x8d;
const DATA_PACKET_E = 0x8e;
const DATA_PACKET_F = 0x8f;
const NACK = 0xa0;
const ACK = 0xc0;
public static function isValid($pid){
switch((int) $pid){
case RakNetInfo::UNCONNECTED_PING:
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
case RakNetInfo::OPEN_CONNECTION_REPLY_1:
case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
case RakNetInfo::OPEN_CONNECTION_REPLY_2:
case RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION:
case RakNetInfo::UNCONNECTED_PONG:
case RakNetInfo::ADVERTISE_SYSTEM:
case RakNetInfo::DATA_PACKET_0:
case RakNetInfo::DATA_PACKET_1:
case RakNetInfo::DATA_PACKET_2:
case RakNetInfo::DATA_PACKET_3:
case RakNetInfo::DATA_PACKET_4:
case RakNetInfo::DATA_PACKET_5:
case RakNetInfo::DATA_PACKET_6:
case RakNetInfo::DATA_PACKET_7:
case RakNetInfo::DATA_PACKET_8:
case RakNetInfo::DATA_PACKET_9:
case RakNetInfo::DATA_PACKET_A:
case RakNetInfo::DATA_PACKET_B:
case RakNetInfo::DATA_PACKET_C:
case RakNetInfo::DATA_PACKET_D:
case RakNetInfo::DATA_PACKET_E:
case RakNetInfo::DATA_PACKET_F:
case RakNetInfo::NACK:
case RakNetInfo::ACK:
return true;
default:
return false;
}
}
}

View File

@ -1,34 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class RakNetPacket extends Packet{
private $packetID;
public function __construct($packetID){
$this->packetID = (int) $packetID;
}
public function pid(){
return $this->packetID;
}
public function __destruct(){}
}

View File

@ -1,367 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class RakNetParser{
private $buffer;
private $offset;
public $packet;
public function __construct(&$buffer){
$this->buffer =& $buffer;
$this->offset = 0;
if(strlen($this->buffer) > 0){
$this->parse();
}else{
$this->packet = false;
}
}
private function get($len){
if($len <= 0){
$this->offset = strlen($this->buffer) - 1;
return "";
}
if($len === true){
return substr($this->buffer, $this->offset);
}
$this->offset += $len;
return substr($this->buffer, $this->offset - $len, $len);
}
private function getLong($unsigned = false){
return Utils::readLong($this->get(8), $unsigned);
}
private function getInt(){
return Utils::readInt($this->get(4));
}
private function getShort($unsigned = false){
return Utils::readShort($this->get(2), $unsigned);
}
private function getLTriad(){
return Utils::readTriad(strrev($this->get(3)));
}
private function getByte(){
return ord($this->get(1));
}
private function feof(){
return !isset($this->buffer{$this->offset});
}
private function parse(){
$this->packet = new RakNetPacket(ord($this->get(1)));
$this->packet->buffer =& $this->buffer;
$this->packet->length = strlen($this->buffer);
switch($this->packet->pid()){
case RakNetInfo::UNCONNECTED_PING:
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
$this->packet->pingID = $this->getLong();
$this->offset += 16; //Magic
break;
case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
$this->offset += 16; //Magic
$this->packet->structure = $this->getByte();
$this->packet->mtuSize = strlen($this->get(true));
break;
case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
$this->offset += 16; //Magic
$this->packet->security = $this->get(5);
$this->packet->port = $this->getShort(false);
$this->packet->mtuSize = $this->getShort(false);
$this->packet->clientID = $this->getLong();
break;
case RakNetInfo::DATA_PACKET_0:
case RakNetInfo::DATA_PACKET_1:
case RakNetInfo::DATA_PACKET_2:
case RakNetInfo::DATA_PACKET_3:
case RakNetInfo::DATA_PACKET_4:
case RakNetInfo::DATA_PACKET_5:
case RakNetInfo::DATA_PACKET_6:
case RakNetInfo::DATA_PACKET_7:
case RakNetInfo::DATA_PACKET_8:
case RakNetInfo::DATA_PACKET_9:
case RakNetInfo::DATA_PACKET_A:
case RakNetInfo::DATA_PACKET_B:
case RakNetInfo::DATA_PACKET_C:
case RakNetInfo::DATA_PACKET_D:
case RakNetInfo::DATA_PACKET_E:
case RakNetInfo::DATA_PACKET_F:
$this->packet->seqNumber = $this->getLTriad();
$this->packet->data = array();
while(!$this->feof() and ($pk = $this->parseDataPacket()) instanceof RakNetDataPacket){
$this->packet->data[] = $pk;
}
break;
case RakNetInfo::NACK:
case RakNetInfo::ACK:
$count = $this->getShort();
$this->packet->packets = array();
for($i = 0; $i < $count and !$this->feof(); ++$i){
if($this->getByte() === 0){
$start = $this->getLTriad();
$end = $this->getLTriad();
if(($end - $start) > 4096){
$end = $start + 4096;
}
for($c = $start; $c <= $end; ++$c){
$this->packet->packets[] = $c;
}
}else{
$this->packet->packets[] = $this->getLTriad();
}
}
break;
default:
$this->packet = false;
break;
}
}
private function parseDataPacket(){
$packetFlags = $this->getByte();
$reliability = ($packetFlags & 0b11100000) >> 5;
$hasSplit = ($packetFlags & 0b00010000) > 0;
$length = (int) ceil($this->getShort() / 8);
if($reliability === 2
or $reliability === 3
or $reliability === 4
or $reliability === 6
or $reliability === 7){
$messageIndex = $this->getLTriad();
}else{
$messageIndex = false;
}
if($reliability === 1
or $reliability === 3
or $reliability === 4
or $reliability === 7){
$orderIndex = $this->getLTriad();
$orderChannel = $this->getByte();
}else{
$orderIndex = false;
$orderChannel = false;
}
if($hasSplit == true){
$splitCount = $this->getInt();
$splitID = $this->getShort();
$splitIndex = $this->getInt();
}else{
$splitCount = false;
$splitID = false;
$splitIndex = false;
}
if($length <= 0
or $orderChannel >= 32
or ($hasSplit === true and $splitIndex >= $splitCount)){
return false;
}else{
$pid = $this->getByte();
$buffer = $this->get($length - 1);
if(strlen($buffer) < ($length - 1)){
return false;
}
switch($pid){
case ProtocolInfo::PING_PACKET:
$data = new PingPacket;
break;
case ProtocolInfo::PONG_PACKET:
$data = new PongPacket;
break;
case ProtocolInfo::CLIENT_CONNECT_PACKET:
$data = new ClientConnectPacket;
break;
case ProtocolInfo::SERVER_HANDSHAKE_PACKET:
$data = new ServerHandshakePacket;
break;
case ProtocolInfo::DISCONNECT_PACKET:
$data = new DisconnectPacket;
break;
case ProtocolInfo::LOGIN_PACKET:
$data = new LoginPacket;
break;
case ProtocolInfo::LOGIN_STATUS_PACKET:
$data = new LoginStatusPacket;
break;
case ProtocolInfo::READY_PACKET:
$data = new ReadyPacket;
break;
case ProtocolInfo::MESSAGE_PACKET:
$data = new MessagePacket;
break;
case ProtocolInfo::SET_TIME_PACKET:
$data = new SetTimePacket;
break;
case ProtocolInfo::START_GAME_PACKET:
$data = new StartGamePacket;
break;
case ProtocolInfo::ADD_MOB_PACKET:
$data = new AddMobPacket;
break;
case ProtocolInfo::ADD_PLAYER_PACKET:
$data = new AddPlayerPacket;
break;
case ProtocolInfo::REMOVE_PLAYER_PACKET:
$data = new RemovePlayerPacket;
break;
case ProtocolInfo::ADD_ENTITY_PACKET:
$data = new AddEntityPacket;
break;
case ProtocolInfo::REMOVE_ENTITY_PACKET:
$data = new RemoveEntityPacket;
break;
case ProtocolInfo::ADD_ITEM_ENTITY_PACKET:
$data = new AddItemEntityPacket;
break;
case ProtocolInfo::TAKE_ITEM_ENTITY_PACKET:
$data = new TakeItemEntityPacket;
break;
case ProtocolInfo::MOVE_ENTITY_PACKET:
$data = new MoveEntityPacket;
break;
case ProtocolInfo::MOVE_ENTITY_PACKET_POSROT:
$data = new MoveEntityPacket_PosRot;
break;
case ProtocolInfo::ROTATE_HEAD_PACKET:
$data = new RotateHeadPacket;
break;
case ProtocolInfo::MOVE_PLAYER_PACKET:
$data = new MovePlayerPacket;
break;
case ProtocolInfo::REMOVE_BLOCK_PACKET:
$data = new RemoveBlockPacket;
break;
case ProtocolInfo::UPDATE_BLOCK_PACKET:
$data = new UpdateBlockPacket;
break;
case ProtocolInfo::ADD_PAINTING_PACKET:
$data = new AddPaintingPacket;
break;
case ProtocolInfo::EXPLODE_PACKET:
$data = new ExplodePacket;
break;
case ProtocolInfo::LEVEL_EVENT_PACKET:
$data = new LevelEventPacket;
break;
case ProtocolInfo::TILE_EVENT_PACKET:
$data = new TileEventPacket;
break;
case ProtocolInfo::ENTITY_EVENT_PACKET:
$data = new EntityEventPacket;
break;
case ProtocolInfo::REQUEST_CHUNK_PACKET:
$data = new RequestChunkPacket;
break;
case ProtocolInfo::CHUNK_DATA_PACKET:
$data = new ChunkDataPacket;
break;
case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:
$data = new PlayerEquipmentPacket;
break;
case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET:
$data = new PlayerArmorEquipmentPacket;
break;
case ProtocolInfo::INTERACT_PACKET:
$data = new InteractPacket;
break;
case ProtocolInfo::USE_ITEM_PACKET:
$data = new UseItemPacket;
break;
case ProtocolInfo::PLAYER_ACTION_PACKET:
$data = new PlayerActionPacket;
break;
case ProtocolInfo::HURT_ARMOR_PACKET:
$data = new HurtArmorPacket;
break;
case ProtocolInfo::SET_ENTITY_DATA_PACKET:
$data = new SetEntityDataPacket;
break;
case ProtocolInfo::SET_ENTITY_MOTION_PACKET:
$data = new SetEntityMotionPacket;
break;
case ProtocolInfo::SET_HEALTH_PACKET:
$data = new SetHealthPacket;
break;
case ProtocolInfo::SET_SPAWN_POSITION_PACKET:
$data = new SetSpawnPositionPacket;
break;
case ProtocolInfo::ANIMATE_PACKET:
$data = new AnimatePacket;
break;
case ProtocolInfo::RESPAWN_PACKET:
$data = new RespawnPacket;
break;
case ProtocolInfo::SEND_INVENTORY_PACKET:
$data = new SendInventoryPacket;
break;
case ProtocolInfo::DROP_ITEM_PACKET:
$data = new DropItemPacket;
break;
case ProtocolInfo::CONTAINER_OPEN_PACKET:
$data = new ContainerOpenPacket;
break;
case ProtocolInfo::CONTAINER_CLOSE_PACKET:
$data = new ContainerClosePacket;
break;
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
$data = new ContainerSetSlotPacket;
break;
case ProtocolInfo::CONTAINER_SET_DATA_PACKET:
$data = new ContainerSetDataPacket;
break;
case ProtocolInfo::CONTAINER_SET_CONTENT_PACKET:
$data = new ContainerSetContentPacket;
break;
case ProtocolInfo::CHAT_PACKET:
$data = new ChatPacket;
break;
case ProtocolInfo::ADVENTURE_SETTINGS_PACKET:
$data = new AdventureSettingsPacket;
break;
case ProtocolInfo::ENTITY_DATA_PACKET:
$data = new EntityDataPacket;
break;
default:
$data = new UnknownPacket();
$data->packetID = $pid;
break;
}
$data->reliability = $reliability;
$data->hasSplit = $hasSplit;
$data->messageIndex = $messageIndex;
$data->orderIndex = $orderIndex;
$data->orderChannel = $orderChannel;
$data->splitCount = $splitCount;
$data->splitID = $splitID;
$data->splitIndex = $splitIndex;
$data->setBuffer($buffer);
}
return $data;
}
}

View File

@ -1,81 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/***REM_START***/
require_once(FILE_PATH."/src/pmf/PMF.php");
/***REM_END***/
define("PMF_CURRENT_PLUGIN_VERSION", 0x02);
class PMFPlugin extends PMF{
private $pluginData = array();
public function __construct($file){
$this->load($file);
$this->parseInfo();
$this->parsePlugin();
}
public function getPluginInfo(){
return $this->pluginData;
}
protected function parsePlugin(){
if($this->getType() !== 0x01){
return false;
}
$this->seek(5);
$this->pluginData["fversion"] = ord($this->read(1));
if($this->pluginData["fversion"] > PMF_CURRENT_PLUGIN_VERSION){
return false;
}
$this->pluginData["name"] = $this->read(Utils::readShort($this->read(2), false));
$this->pluginData["version"] = $this->read(Utils::readShort($this->read(2), false));
$this->pluginData["author"] = $this->read(Utils::readShort($this->read(2), false));
if($this->pluginData["fversion"] >= 0x01){
$this->pluginData["apiversion"] = $this->read(Utils::readShort($this->read(2), false));
}else{
$this->pluginData["apiversion"] = Utils::readShort($this->read(2), false);
}
$this->pluginData["class"] = $this->read(Utils::readShort($this->read(2), false));
$this->pluginData["identifier"] = $this->read(Utils::readShort($this->read(2), false)); //Will be used to check for updates
if($this->pluginData["fversion"] >= 0x02){
$data = explode(";", gzinflate($this->read(Utils::readInt($this->read(4)))));
$this->pluginData["extra"] = array();
foreach($data as $v){
$v = trim($v);
if($v != ""){
$v = base64_decode($v);
$kl = strpos($v, ":");
$this->pluginData["extra"][substr($v, 0, $kl)] = substr($v, $kl + 1);
}
}
}else{
$this->pluginData["extra"] = gzinflate($this->read(Utils::readShort($this->read(2), false)));
}
$this->pluginData["code"] = "";
while(!feof($this->fp)){
$this->pluginData["code"] .= $this->read(4096);
}
$this->pluginData["code"] = gzinflate($this->pluginData["code"]);
}
}

View File

@ -0,0 +1,135 @@
<?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
*
*
*/
namespace pocketmine;
use pocketmine\utils\TextFormat;
/**
* Handles the achievement list and a bit more
*/
abstract class Achievement{
/**
* @var array[]
*/
public static $list = array(
/*"openInventory" => array(
"name" => "Taking Inventory",
"requires" => [],
),*/
"mineWood" => array(
"name" => "Getting Wood",
"requires" => array( //"openInventory",
),
),
"buildWorkBench" => array(
"name" => "Benchmarking",
"requires" => array(
"mineWood",
),
),
"buildPickaxe" => array(
"name" => "Time to Mine!",
"requires" => array(
"buildWorkBench",
),
),
"buildFurnace" => array(
"name" => "Hot Topic",
"requires" => array(
"buildPickaxe",
),
),
"acquireIron" => array(
"name" => "Acquire hardware",
"requires" => array(
"buildFurnace",
),
),
"buildHoe" => array(
"name" => "Time to Farm!",
"requires" => array(
"buildWorkBench",
),
),
"makeBread" => array(
"name" => "Bake Bread",
"requires" => array(
"buildHoe",
),
),
"bakeCake" => array(
"name" => "The Lie",
"requires" => array(
"buildHoe",
),
),
"buildBetterPickaxe" => array(
"name" => "Getting an Upgrade",
"requires" => array(
"buildPickaxe",
),
),
"buildSword" => array(
"name" => "Time to Strike!",
"requires" => array(
"buildWorkBench",
),
),
"diamonds" => array(
"name" => "DIAMONDS!",
"requires" => array(
"acquireIron",
),
),
);
public static function broadcast(Player $player, $achievementId){
if(isset(Achievement::$list[$achievementId])){
if(Server::getInstance()->getConfigString("announce-player-achievements", true) === true){
Server::getInstance()->broadcastMessage($player->getDisplayName() . " has just earned the achievement " . TextFormat::GREEN . Achievement::$list[$achievementId]["name"]);
}else{
$player->sendMessage("You have just earned the achievement " . TextFormat::GREEN . Achievement::$list[$achievementId]["name"]);
}
return true;
}
return false;
}
public static function add($achievementId, $achievementName, array $requires = []){
if(!isset(Achievement::$list[$achievementId])){
Achievement::$list[$achievementId] = array(
"name" => $achievementName,
"requires" => $requires,
);
return true;
}
return false;
}
}

View File

@ -0,0 +1,78 @@
<?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/
*
*
*/
namespace pocketmine;
use pocketmine\permission\ServerOperator;
interface IPlayer extends ServerOperator{
/**
* @return bool
*/
public function isOnline();
/**
* @return string
*/
public function getName();
/**
* @return bool
*/
public function isBanned();
/**
* @param bool $banned
*/
public function setBanned($banned);
/**
* @return bool
*/
public function isWhitelisted();
/**
* @param bool $value
*/
public function setWhitelisted($value);
/**
* @return Player|null
*/
public function getPlayer();
/**
* @return int|double
*/
public function getFirstPlayed();
/**
* @return int|double
*/
public function getLastPlayed();
/**
* @return mixed
*/
public function hasPlayedBefore();
}

View File

@ -0,0 +1,134 @@
<?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/
*
*
*/
namespace pocketmine;
use pocketmine\metadata\MetadataValue;
use pocketmine\nbt\tag\Compound;
use pocketmine\plugin\Plugin;
class OfflinePlayer implements IPlayer{
private $name;
private $server;
private $namedtag;
/**
* @param Server $server
* @param string $name
*/
public function __construct(Server $server, $name){
$this->server = $server;
$this->name = $name;
if(file_exists($this->server->getDataPath() . "players/" . strtolower($this->getName()) . ".dat")){
$this->namedtag = $this->server->getOfflinePlayerData($this->name);
}else{
$this->namedtag = null;
}
}
public function isOnline(){
return $this->getPlayer() !== null;
}
public function getName(){
return $this->name;
}
public function getServer(){
return $this->server;
}
public function isOp(){
return $this->server->isOp(strtolower($this->getName()));
}
public function setOp($value){
if($value === $this->isOp()){
return;
}
if($value === true){
$this->server->addOp(strtolower($this->getName()));
}else{
$this->server->removeOp(strtolower($this->getName()));
}
}
public function isBanned(){
return $this->server->getNameBans()->isBanned(strtolower($this->getName()));
}
public function setBanned($value){
if($value === true){
$this->server->getNameBans()->addBan($this->getName(), null, null, null);
}else{
$this->server->getNameBans()->remove($this->getName());
}
}
public function isWhitelisted(){
return $this->server->isWhitelisted(strtolower($this->getName()));
}
public function setWhitelisted($value){
if($value === true){
$this->server->addWhitelist(strtolower($this->getName()));
}else{
$this->server->removeWhitelist(strtolower($this->getName()));
}
}
public function getPlayer(){
return $this->server->getPlayerExact($this->getName());
}
public function getFirstPlayed(){
return $this->namedtag instanceof Compound ? $this->namedtag["firstPlayed"] : null;
}
public function getLastPlayed(){
return $this->namedtag instanceof Compound ? $this->namedtag["lastPlayed"] : null;
}
public function hasPlayedBefore(){
return $this->namedtag instanceof Compound;
}
public function setMetadata($metadataKey, MetadataValue $metadataValue){
$this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue);
}
public function getMetadata($metadataKey){
return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey);
}
public function hasMetadata($metadataKey){
return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
}
public function removeMetadata($metadataKey, Plugin $plugin){
$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin);
}
}

2070
src/pocketmine/Player.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,332 @@
<?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/
*
*
*/
namespace {
function safe_var_dump(){
static $cnt = 0;
foreach(func_get_args() as $var){
switch(true){
case is_array($var):
echo str_repeat(" ", $cnt) . "array(" . count($var) . ") {" . PHP_EOL;
foreach($var as $key => $value){
echo str_repeat(" ", $cnt + 1) . "[" . (is_integer($key) ? $key : '"' . $key . '"') . "]=>" . PHP_EOL;
++$cnt;
safe_var_dump($value);
--$cnt;
}
echo str_repeat(" ", $cnt) . "}" . PHP_EOL;
break;
case is_integer($var):
echo str_repeat(" ", $cnt) . "int(" . $var . ")" . PHP_EOL;
break;
case is_float($var):
echo str_repeat(" ", $cnt) . "float(" . $var . ")" . PHP_EOL;
break;
case is_bool($var):
echo str_repeat(" ", $cnt) . "bool(" . ($var === true ? "true" : "false") . ")" . PHP_EOL;
break;
case is_string($var):
echo str_repeat(" ", $cnt) . "string(" . strlen($var) . ") \"$var\"" . PHP_EOL;
break;
case is_resource($var):
echo str_repeat(" ", $cnt) . "resource() of type (" . get_resource_type($var) . ")" . PHP_EOL;
break;
case is_object($var):
echo str_repeat(" ", $cnt) . "object(" . get_class($var) . ")" . PHP_EOL;
break;
case is_null($var):
echo str_repeat(" ", $cnt) . "NULL" . PHP_EOL;
break;
}
}
}
function dummy(){
}
}
namespace pocketmine {
use pocketmine\utils\Binary;
use \LogLevel;
use pocketmine\utils\MainLogger;
use pocketmine\utils\Utils;
use pocketmine\wizard\Installer;
use raklib\RakLib;
const VERSION = "Alpha_1.4dev";
const API_VERSION = "1.0.0";
const CODENAME = "絶好(Zekkou)ケーキ(Cake)";
const MINECRAFT_VERSION = "v0.8.1 alpha";
const PHP_VERSION = "5.5";
if(\Phar::running(true) !== ""){
@define("pocketmine\\PATH", \Phar::running(true) . "/");
}else{
@define("pocketmine\\PATH", \getcwd() . DIRECTORY_SEPARATOR);
}
if(!class_exists("SplClassLoader", false)){
require_once(\pocketmine\PATH . "src/spl/SplClassLoader.php");
}
if(!class_exists("Logger", false)){
require_once(\pocketmine\PATH . "src/spl/Logger.php");
require_once(\pocketmine\PATH . "src/spl/LogLevel.php");
}
if(!class_exists("ThreadedLogger", false)){
require_once(\pocketmine\PATH . "src/spl/ThreadedLogger.php");
}
$autoloader = new \SplClassLoader();
$autoloader->add("pocketmine", array(
\pocketmine\PATH . "src"
));
$autoloader->register(true);
if(!class_exists("raklib\\RakLib", false)){
require(\pocketmine\PATH . "src/raklib/raklib/RakLib.php");
}
RakLib::bootstrap($autoloader);
//Startup code. Do not look at it, it can harm you. Most of them are hacks to fix date-related bugs, or basic functions used after this
set_time_limit(0); //Who set it to 30 seconds?!?!
if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set("GMT");
if(strpos(" " . strtoupper(php_uname("s")), " WIN") !== false){
$time = time();
$time -= $time % 60;
//TODO: Parse different time & date formats by region. ¬¬ world
//Example: USA
exec("time.exe /T", $hour);
$i = array_map("intval", explode(":", trim($hour[0])));
exec("date.exe /T", $date);
$j = array_map("intval", explode(substr($date[0], 2, 1), trim($date[0])));
$offset = round((mktime($i[0], $i[1], 0, $j[1], $j[0], $j[2]) - $time) / 60) * 60;
}else{
exec("date +%s", $t);
$offset = round((intval(trim($t[0])) - time()) / 60) * 60;
}
$daylight = (int) date("I");
$d = timezone_name_from_abbr("", $offset, $daylight);
@ini_set("date.timezone", $d);
date_default_timezone_set($d);
}else{
$d = @date_default_timezone_get();
if(strpos($d, "/") === false){
$d = timezone_name_from_abbr($d);
@ini_set("date.timezone", $d);
date_default_timezone_set($d);
}
}
gc_enable();
error_reporting(E_ALL | E_STRICT);
ini_set("allow_url_fopen", 1);
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
ini_set("default_charset", "utf-8");
ini_set("memory_limit", "128M"); //Default
define("pocketmine\\START_TIME", microtime(true));
$opts = getopt("", array("enable-ansi", "disable-ansi", "data:", "plugins:", "no-wizard"));
define("pocketmine\\DATA", isset($opts["data"]) ? realpath($opts["data"]) . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR);
define("pocketmine\\PLUGIN_PATH", isset($opts["plugins"]) ? realpath($opts["plugins"]) . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR);
define("pocketmine\\ANSI", ((strpos(strtoupper(php_uname("s")), "WIN") === false or isset($opts["enable-ansi"])) and !isset($opts["disable-ansi"])));
$logger = new MainLogger(\pocketmine\DATA . "server.log", \pocketmine\ANSI);
function kill($pid){
switch(Utils::getOS()){
case "win":
exec("taskkill.exe /F /PID " . ((int) $pid) . " > NUL");
break;
case "mac":
case "linux":
default:
exec("kill -9 " . ((int) $pid) . " > /dev/null 2>&1");
}
}
function getTrace($start = 1){
$e = new \Exception();
$trace = $e->getTrace();
$messages = [];
$j = 0;
for($i = (int) $start; isset($trace[$i]); ++$i, ++$j){
$params = "";
if(isset($trace[$i]["args"])){
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)) . ", ";
}
}
$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;
}
function error_handler($errno, $errstr, $errfile, $errline){
if(error_reporting() === 0){ //@ error-control
return false;
}
$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",
);
$type = ($errno === E_ERROR or $errno === E_WARNING or $errno === E_USER_ERROR or $errno === E_USER_WARNING) ? LogLevel::ERROR : LogLevel::NOTICE;
$errno = isset($errorConversion[$errno]) ? $errorConversion[$errno] : $errno;
$logger = MainLogger::getLogger();
$logger->log($type, "A $errno error happened: \"$errstr\" in \"$errfile\" at line $errline");
foreach(getTrace() as $i => $line){
$logger->debug($line);
}
return true;
}
set_error_handler("\\pocketmine\\error_handler", E_ALL);
$errors = 0;
if(version_compare("5.4.0", PHP_VERSION) > 0){
$logger->critical("Use PHP >= 5.4.0");
++$errors;
}
if(php_sapi_name() !== "cli"){
$logger->critical("You must run PocketMine-MP using the CLI.");
++$errors;
}
if(!extension_loaded("sockets")){
$logger->critical("Unable to find the Socket extension.");
++$errors;
}
if(!extension_loaded("pthreads")){
$logger->critical("Unable to find the pthreads extension.");
++$errors;
}else{
$pthreads_version = phpversion("pthreads");
if(substr_count($pthreads_version, ".") < 2){
$pthreads_version = "0.$pthreads_version";
}
if(version_compare($pthreads_version, "2.0.4") < 0){
$logger->critical("pthreads >= 2.0.4 is required, while you have $pthreads_version.");
++$errors;
}
}
if(!extension_loaded("uopz")){
//$logger->notice("Couldn't find the uopz extension. Some functions may be limited");
}
if(extension_loaded("pocketmine")){
if(version_compare(phpversion("pocketmine"), "0.0.1") < 0){
$logger->critical("You have the native PocketMine extension, but your version is lower than 0.0.1.");
++$errors;
}elseif(version_compare(phpversion("pocketmine"), "0.0.4") > 0){
$logger->critical("You have the native PocketMine extension, but your version is higher than 0.0.4.");
++$errors;
}
}
if(!extension_loaded("Weakref") and !extension_loaded("weakref")){
$logger->critical("Unable to find the Weakref extension.");
++$errors;
}
if(!extension_loaded("curl")){
$logger->critical("Unable to find the cURL extension.");
++$errors;
}
if(!extension_loaded("sqlite3")){
$logger->critical("Unable to find the SQLite3 extension.");
++$errors;
}
if(!extension_loaded("yaml")){
$logger->critical("Unable to find the YAML extension.");
++$errors;
}
if(!extension_loaded("zlib")){
$logger->critical("Unable to find the Zlib extension.");
++$errors;
}
if($errors > 0){
$logger->critical("Please use the installer provided on the homepage, or recompile PHP again.");
$logger->shutdown();
$logger->join();
exit(1); //Exit with error
}
if(file_exists(\pocketmine\PATH . ".git/refs/heads/master")){ //Found Git information!
define("pocketmine\\GIT_COMMIT", strtolower(trim(file_get_contents(\pocketmine\PATH . ".git/refs/heads/master"))));
}else{ //Unknown :(
define("pocketmine\\GIT_COMMIT", str_repeat("00", 20));
}
@define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? Binary::BIG_ENDIAN : Binary::LITTLE_ENDIAN));
@define("INT32_MASK", is_int(0xffffffff) ? 0xffffffff : -1);
@ini_set("opcache.mmap_base", bin2hex(Utils::getRandomBytes(8, false))); //Fix OPCache address errors
if(!file_exists(\pocketmine\DATA . "server.properties") and !isset($opts["no-wizard"])){
new Installer();
}
if(substr(__FILE__, 0, 7) !== "phar://"){
$logger->warning("Non-packaged PocketMine-MP installation detected, do not use on production.");
}
$server = new Server($autoloader, $logger, \pocketmine\PATH, \pocketmine\DATA, \pocketmine\PLUGIN_PATH);
$server->start();
$logger->shutdown();
$logger->join();
kill(getmypid());
exit(0);
}

1872
src/pocketmine/Server.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,9 +19,17 @@
*
*/
class AirBlock extends TransparentBlock{
namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB;
/**
* Air block
*/
class Air extends Transparent{
public function __construct(){
parent::__construct(AIR, 0, "Air");
parent::__construct(self::AIR, 0, "Air");
$this->isActivable = false;
$this->breakable = false;
$this->isFlowable = true;
@ -32,7 +40,11 @@ class AirBlock extends TransparentBlock{
$this->isSolid = false;
$this->isFullBlock = true;
$this->hardness = 0;
}
public function getBoundingBox(){
return new AxisAlignedBB(0, 0, 0, 0, 0, 0);
}
}

View File

@ -0,0 +1,140 @@
<?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/
*
*
*/
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\network\protocol\ChatPacket;
use pocketmine\Player;
class Bed extends Transparent{
public function __construct($type = 0){
parent::__construct(self::BED_BLOCK, $type, "Bed Block");
$this->isActivable = true;
$this->isFullBlock = false;
$this->hardness = 1;
}
public function onActivate(Item $item, Player $player = null){
/*if($player instanceof Player and Server::getInstance()->api->time->getPhase($this->getLevel()) !== "night"){
$pk = new ChatPacket;
$pk->message = "You can only sleep at night";
$player->dataPacket($pk);
return true;
}*/
$blockNorth = $this->getSide(2); //Gets the blocks around them
$blockSouth = $this->getSide(3);
$blockEast = $this->getSide(5);
$blockWest = $this->getSide(4);
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
$b = $this;
}else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$b = $blockNorth;
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$b = $blockSouth;
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$b = $blockEast;
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$b = $blockWest;
}elseif($player instanceof Player){
$pk = new ChatPacket;
$pk->message = "This bed is incomplete";
$player->dataPacket($pk);
return true;
}
}
if($player instanceof Player and $player->sleepOn($b) === false){
$pk = new ChatPacket;
$pk->message = "This bed is occupied";
$player->dataPacket($pk);
}
return true;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->isTransparent === false){
$faces = array(
0 => 3,
1 => 4,
2 => 2,
3 => 5,
);
$d = $player instanceof Player ? $player->getDirection() : 0;
$next = $this->getSide($faces[(($d + 3) % 4)]);
$downNext = $this->getSide(0);
if($next->isReplaceable === true and $downNext->isTransparent === false){
$meta = (($d + 3) % 4) & 0x03;
$this->getLevel()->setBlock($block, Block::get($this->id, $meta), true, false, true);
$this->getLevel()->setBlock($next, Block::get($this->id, $meta | 0x08), true, false, true);
return true;
}
}
return false;
}
public function onBreak(Item $item){
$blockNorth = $this->getSide(2); //Gets the blocks around them
$blockSouth = $this->getSide(3);
$blockEast = $this->getSide(5);
$blockWest = $this->getSide(4);
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right
$this->getLevel()->setBlock($blockNorth, new Air(), true, false, true);
}elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){
$this->getLevel()->setBlock($blockSouth, new Air(), true, false, true);
}elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){
$this->getLevel()->setBlock($blockEast, new Air(), true, false, true);
}elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){
$this->getLevel()->setBlock($blockWest, new Air(), true, false, true);
}
}else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$this->getLevel()->setBlock($blockNorth, new Air(), true, false, true);
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$this->getLevel()->setBlock($blockSouth, new Air(), true, false, true);
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$this->getLevel()->setBlock($blockEast, new Air(), true, false, true);
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$this->getLevel()->setBlock($blockWest, new Air(), true, false, true);
}
}
$this->getLevel()->setBlock($this, new Air(), true, false, true);
return true;
}
public function getDrops(Item $item){
return array(
array(Item::BED, 0, 1),
);
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,18 +19,19 @@
*
*/
class BedrockBlock extends SolidBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
class Bedrock extends Solid{
public function __construct(){
parent::__construct(BEDROCK, 0, "Bedrock");
parent::__construct(self::BEDROCK, 0, "Bedrock");
$this->breakable = false;
$this->hardness = 18000000;
}
public function isBreakable(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return true;
}
public function isBreakable(Item $item){
return false;
}
}

View File

@ -0,0 +1,93 @@
<?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/
*
*
*/
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
class Beetroot extends Flowable{
public function __construct($meta = 0){
parent::__construct(self::BEETROOT_BLOCK, $meta, "Beetroot Block");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() === self::FARMLAND){
$this->getLevel()->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function onActivate(Item $item, Player $player = null){
if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->getLevel()->setBlock($this, $this, true, false, true);
$item->count--;
return true;
}
return false;
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //TODO: Replace with common break method
$this->getLevel()->dropItem($this, Item::get(Item::BEETROOT_SEEDS, 0, 1));
$this->getLevel()->setBlock($this, new Air(), false, false, true);
return Level::BLOCK_UPDATE_NORMAL;
}
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->getLevel()->setBlock($this, $this, true, false, true);
return Level::BLOCK_UPDATE_RANDOM;
}
}else{
return Level::BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function getDrops(Item $item){
$drops = [];
if($this->meta >= 0x07){
$drops[] = array(Item::BEETROOT, 0, 1);
$drops[] = array(Item::BEETROOT_SEEDS, 0, mt_rand(0, 3));
}else{
$drops[] = array(Item::BEETROOT_SEEDS, 0, 1);
}
return $drops;
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,12 +19,16 @@
*
*/
class BirchWoodStairsBlock extends StairBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
class BirchWoodStairs extends Stair{
public function __construct($meta = 0){
parent::__construct(BIRCH_WOOD_STAIRS, $meta, "Birch Wood Stairs");
parent::__construct(self::BIRCH_WOOD_STAIRS, $meta, "Birch Wood Stairs");
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item $item){
return array(
array($this->id, 0, 1),
);

View File

@ -0,0 +1,794 @@
<?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/
*
*
*/
/**
* All Block classes are in here
*/
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Position;
use pocketmine\math\AxisAlignedBB;
use pocketmine\metadata\Metadatable;
use pocketmine\metadata\MetadataValue;
use pocketmine\Player;
use pocketmine\plugin\Plugin;
abstract class Block extends Position implements Metadatable{
const AIR = 0;
const STONE = 1;
const GRASS = 2;
const DIRT = 3;
const COBBLESTONE = 4;
const COBBLE = 4;
const PLANK = 5;
const PLANKS = 5;
const WOODEN_PLANK = 5;
const WOODEN_PLANKS = 5;
const SAPLING = 6;
const SAPLINGS = 6;
const BEDROCK = 7;
const WATER = 8;
const STILL_WATER = 9;
const LAVA = 10;
const STILL_LAVA = 11;
const SAND = 12;
const GRAVEL = 13;
const GOLD_ORE = 14;
const IRON_ORE = 15;
const COAL_ORE = 16;
const WOOD = 17;
const TRUNK = 17;
const LOG = 17;
const LEAVES = 18;
const LEAVE = 18;
const SPONGE = 19;
const GLASS = 20;
const LAPIS_ORE = 21;
const LAPIS_BLOCK = 22;
const SANDSTONE = 24;
const BED_BLOCK = 26;
const COBWEB = 30;
const TALL_GRASS = 31;
const BUSH = 32;
const DEAD_BUSH = 32;
const WOOL = 35;
const DANDELION = 37;
const ROSE = 38;
const CYAN_FLOWER = 38;
const BROWN_MUSHROOM = 39;
const RED_MUSHROOM = 40;
const GOLD_BLOCK = 41;
const IRON_BLOCK = 42;
const DOUBLE_SLAB = 43;
const DOUBLE_SLABS = 43;
const SLAB = 44;
const SLABS = 44;
const BRICKS = 45;
const BRICKS_BLOCK = 45;
const TNT = 46;
const BOOKSHELF = 47;
const MOSS_STONE = 48;
const MOSSY_STONE = 48;
const OBSIDIAN = 49;
const TORCH = 50;
const FIRE = 51;
const WOOD_STAIRS = 53;
const WOODEN_STAIRS = 53;
const OAK_WOOD_STAIRS = 53;
const OAK_WOODEN_STAIRS = 53;
const CHEST = 54;
const DIAMOND_ORE = 56;
const DIAMOND_BLOCK = 57;
const CRAFTING_TABLE = 58;
const WORKBENCH = 58;
const WHEAT_BLOCK = 59;
const FARMLAND = 60;
const FURNACE = 61;
const BURNING_FURNACE = 62;
const LIT_FURNACE = 62;
const SIGN_POST = 63;
const DOOR_BLOCK = 64;
const WOODEN_DOOR_BLOCK = 64;
const WOOD_DOOR_BLOCK = 64;
const LADDER = 65;
const COBBLE_STAIRS = 67;
const COBBLESTONE_STAIRS = 67;
const WALL_SIGN = 68;
const IRON_DOOR_BLOCK = 71;
const REDSTONE_ORE = 73;
const GLOWING_REDSTONE_ORE = 74;
const LIT_REDSTONE_ORE = 74;
const SNOW = 78;
const SNOW_LAYER = 78;
const ICE = 79;
const SNOW_BLOCK = 80;
const CACTUS = 81;
const CLAY_BLOCK = 82;
const REEDS = 83;
const SUGARCANE_BLOCK = 83;
const FENCE = 85;
const PUMPKIN = 86;
const NETHERRACK = 87;
const SOUL_SAND = 88;
const GLOWSTONE = 89;
const GLOWSTONE_BLOCK = 89;
const LIT_PUMPKIN = 91;
const JACK_O_LANTERN = 91;
const CAKE_BLOCK = 92;
const TRAPDOOR = 96;
const STONE_BRICKS = 98;
const STONE_BRICK = 98;
const IRON_BAR = 101;
const IRON_BARS = 101;
const GLASS_PANE = 102;
const GLASS_PANEL = 102;
const MELON_BLOCK = 103;
const PUMPKIN_STEM = 104;
const MELON_STEM = 105;
const FENCE_GATE = 107;
const BRICK_STAIRS = 108;
const STONE_BRICK_STAIRS = 109;
const NETHER_BRICKS = 112;
const NETHER_BRICK_BLOCK = 112;
const NETHER_BRICKS_STAIRS = 114;
const SANDSTONE_STAIRS = 128;
const SPRUCE_WOOD_STAIRS = 134;
const SPRUCE_WOODEN_STAIRS = 134;
const BIRCH_WOOD_STAIRS = 135;
const BIRCH_WOODEN_STAIRS = 135;
const JUNGLE_WOOD_STAIRS = 136;
const JUNGLE_WOODEN_STAIRS = 136;
const COBBLE_WALL = 139;
const STONE_WALL = 139;
const COBBLESTONE_WALL = 139;
const CARROT_BLOCK = 141;
const POTATO_BLOCK = 142;
const QUARTZ_BLOCK = 155;
const QUARTZ_STAIRS = 156;
const DOUBLE_WOOD_SLAB = 157;
const DOUBLE_WOODEN_SLAB = 157;
const DOUBLE_WOOD_SLABS = 157;
const DOUBLE_WOODEN_SLABS = 157;
const WOOD_SLAB = 158;
const WOODEN_SLAB = 158;
const WOOD_SLABS = 158;
const WOODEN_SLABS = 158;
const HAY_BALE = 170;
const CARPET = 171;
const COAL_BLOCK = 173;
const BEETROOT_BLOCK = 244;
const STONECUTTER = 245;
const GLOWING_OBSIDIAN = 246;
const NETHER_REACTOR = 247;
public static $creative = array(
//Building
[Item::STONE, 0],
[Item::COBBLESTONE, 0],
[Item::STONE_BRICKS, 0],
[Item::STONE_BRICKS, 1],
[Item::STONE_BRICKS, 2],
[Item::MOSS_STONE, 0],
[Item::WOODEN_PLANKS, 0],
[Item::WOODEN_PLANKS, 1],
[Item::WOODEN_PLANKS, 2],
[Item::WOODEN_PLANKS, 3],
[Item::BRICKS, 0],
[Item::DIRT, 0],
[Item::GRASS, 0],
[Item::CLAY_BLOCK, 0],
[Item::SANDSTONE, 0],
[Item::SANDSTONE, 1],
[Item::SANDSTONE, 2],
[Item::SAND, 0],
[Item::GRAVEL, 0],
[Item::TRUNK, 0],
[Item::TRUNK, 1],
[Item::TRUNK, 2],
[Item::TRUNK, 3],
[Item::NETHER_BRICKS, 0],
[Item::NETHERRACK, 0],
[Item::BEDROCK, 0],
[Item::COBBLESTONE_STAIRS, 0],
[Item::OAK_WOODEN_STAIRS, 0],
[Item::SPRUCE_WOODEN_STAIRS, 0],
[Item::BIRCH_WOODEN_STAIRS, 0],
[Item::JUNGLE_WOODEN_STAIRS, 0],
[Item::BRICK_STAIRS, 0],
[Item::SANDSTONE_STAIRS, 0],
[Item::STONE_BRICK_STAIRS, 0],
[Item::NETHER_BRICKS_STAIRS, 0],
[Item::QUARTZ_STAIRS, 0],
[Item::SLAB, 0],
[Item::SLAB, 1],
[Item::WOODEN_SLAB, 0],
[Item::WOODEN_SLAB, 1],
[Item::WOODEN_SLAB, 2],
[Item::WOODEN_SLAB, 3],
[Item::SLAB, 3],
[Item::SLAB, 4],
[Item::SLAB, 5],
[Item::SLAB, 6],
[Item::QUARTZ_BLOCK, 0],
[Item::QUARTZ_BLOCK, 1],
[Item::QUARTZ_BLOCK, 2],
[Item::COAL_ORE, 0],
[Item::IRON_ORE, 0],
[Item::GOLD_ORE, 0],
[Item::DIAMOND_ORE, 0],
[Item::LAPIS_ORE, 0],
[Item::REDSTONE_ORE, 0],
[Item::OBSIDIAN, 0],
[Item::ICE, 0],
[Item::SNOW_BLOCK, 0],
//Decoration
[Item::COBBLESTONE_WALL, 0],
[Item::COBBLESTONE_WALL, 1],
[Item::GOLD_BLOCK, 0],
[Item::IRON_BLOCK, 0],
[Item::DIAMOND_BLOCK, 0],
[Item::LAPIS_BLOCK, 0],
[Item::COAL_BLOCK, 0],
[Item::SNOW_LAYER, 0],
[Item::GLASS, 0],
[Item::GLOWSTONE_BLOCK, 0],
[Item::NETHER_REACTOR, 0],
[Item::WOOL, 0],
[Item::WOOL, 7],
[Item::WOOL, 6],
[Item::WOOL, 5],
[Item::WOOL, 4],
[Item::WOOL, 3],
[Item::WOOL, 2],
[Item::WOOL, 1],
[Item::WOOL, 15],
[Item::WOOL, 14],
[Item::WOOL, 13],
[Item::WOOL, 12],
[Item::WOOL, 11],
[Item::WOOL, 10],
[Item::WOOL, 9],
[Item::WOOL, 8],
[Item::LADDER, 0],
[Item::SPONGE, 0],
[Item::GLASS_PANE, 0],
[Item::WOODEN_DOOR, 0],
[Item::TRAPDOOR, 0],
[Item::FENCE, 0],
[Item::FENCE_GATE, 0],
[Item::IRON_BARS, 0],
[Item::BED, 0],
[Item::BOOKSHELF, 0],
[Item::PAINTING, 0],
[Item::WORKBENCH, 0],
[Item::STONECUTTER, 0],
[Item::CHEST, 0],
[Item::FURNACE, 0],
[Item::DANDELION, 0],
[Item::CYAN_FLOWER, 0],
[Item::BROWN_MUSHROOM, 0],
[Item::RED_MUSHROOM, 0],
[Item::CACTUS, 0],
[Item::MELON_BLOCK, 0],
[Item::PUMPKIN, 0],
[Item::LIT_PUMPKIN, 0],
[Item::COBWEB, 0],
[Item::HAY_BALE, 0],
[Item::TALL_GRASS, 1],
[Item::TALL_GRASS, 2],
[Item::DEAD_BUSH, 0],
[Item::SAPLING, 0],
[Item::SAPLING, 1],
[Item::SAPLING, 2],
[Item::SAPLING, 3],
[Item::LEAVES, 0],
[Item::LEAVES, 1],
[Item::LEAVES, 2],
[Item::LEAVES, 3],
[Item::CAKE, 0],
[Item::SIGN, 0],
[Item::CARPET, 0],
[Item::CARPET, 7],
[Item::CARPET, 6],
[Item::CARPET, 5],
[Item::CARPET, 4],
[Item::CARPET, 3],
[Item::CARPET, 2],
[Item::CARPET, 1],
[Item::CARPET, 15],
[Item::CARPET, 14],
[Item::CARPET, 13],
[Item::CARPET, 12],
[Item::CARPET, 11],
[Item::CARPET, 10],
[Item::CARPET, 9],
[Item::CARPET, 8],
//Tools
//[Item::RAILS, 0],
//[Item::POWERED_RAILS, 0],
[Item::TORCH, 0],
[Item::BUCKET, 0],
[Item::BUCKET, 8],
[Item::BUCKET, 10],
[Item::TNT, 0],
[Item::IRON_HOE, 0],
[Item::IRON_SWORD, 0],
[Item::BOW, 0],
[Item::SHEARS, 0],
[Item::FLINT_AND_STEEL, 0],
[Item::CLOCK, 0],
[Item::COMPASS, 0],
[Item::MINECART, 0],
[Item::SPAWN_EGG, 10], //Chicken
[Item::SPAWN_EGG, 11], //Cow
[Item::SPAWN_EGG, 12], //Pig
[Item::SPAWN_EGG, 13], //Sheep
//TODO: Replace with Entity constants
//Seeds
[Item::SUGARCANE, 0],
[Item::WHEAT, 0],
[Item::SEEDS, 0],
[Item::MELON_SEEDS, 0],
[Item::PUMPKIN_SEEDS, 0],
[Item::CARROT, 0],
[Item::POTATO, 0],
[Item::BEETROOT_SEEDS, 0],
[Item::EGG, 0],
[Item::DYE, 0],
[Item::DYE, 7],
[Item::DYE, 6],
[Item::DYE, 5],
[Item::DYE, 4],
[Item::DYE, 3],
[Item::DYE, 2],
[Item::DYE, 1],
[Item::DYE, 15],
[Item::DYE, 14],
[Item::DYE, 13],
[Item::DYE, 12],
[Item::DYE, 11],
[Item::DYE, 10],
[Item::DYE, 9],
[Item::DYE, 8],
);
/** @var Block[] */
public static $list = [];
protected $id;
protected $meta;
protected $name;
protected $breakTime;
protected $hardness;
public $isActivable = false;
public $breakable = true;
public $isFlowable = false;
public $isSolid = true;
public $isTransparent = false;
public $isReplaceable = false;
public $isPlaceable = true;
public $hasPhysics = false;
public $isLiquid = false;
public $isFullBlock = true;
public $x = 0;
public $y = 0;
public $z = 0;
public $frictionFactor = 0.6;
public static function init(){
if(count(self::$list) === 0){
self::$list = array(
self::AIR => new Air(),
self::STONE => new Stone(),
self::GRASS => new Grass(),
self::DIRT => new Dirt(),
self::COBBLESTONE => new Cobblestone(),
self::PLANKS => new Planks(),
self::SAPLING => new Sapling(),
self::BEDROCK => new Bedrock(),
self::WATER => new Water(),
self::STILL_WATER => new StillWater(),
self::LAVA => new Lava(),
self::STILL_LAVA => new StillLava(),
self::SAND => new Sand(),
self::GRAVEL => new Gravel(),
self::GOLD_ORE => new GoldOre(),
self::IRON_ORE => new IronOre(),
self::COAL_ORE => new CoalOre(),
self::WOOD => new Wood(),
self::LEAVES => new Leaves(),
self::SPONGE => new Sponge(),
self::GLASS => new Glass(),
self::LAPIS_ORE => new LapisOre(),
self::LAPIS_BLOCK => new Lapis(),
self::SANDSTONE => new Sandstone(),
self::BED_BLOCK => new Bed(),
self::COBWEB => new Cobweb(),
self::TALL_GRASS => new TallGrass(),
self::DEAD_BUSH => new DeadBush(),
self::WOOL => new Wool(),
self::DANDELION => new Dandelion(),
self::CYAN_FLOWER => new CyanFlower(),
self::BROWN_MUSHROOM => new BrownMushroom(),
self::RED_MUSHROOM => new RedMushroom(),
self::GOLD_BLOCK => new Gold(),
self::IRON_BLOCK => new Iron(),
self::DOUBLE_SLAB => new DoubleSlab(),
self::SLAB => new Slab(),
self::BRICKS_BLOCK => new Bricks(),
self::TNT => new TNT(),
self::BOOKSHELF => new Bookshelf(),
self::MOSS_STONE => new MossStone(),
self::OBSIDIAN => new Obsidian(),
self::TORCH => new Torch(),
self::FIRE => new Fire(),
self::WOOD_STAIRS => new WoodStairs(),
self::CHEST => new Chest(),
self::DIAMOND_ORE => new DiamondOre(),
self::DIAMOND_BLOCK => new Diamond(),
self::WORKBENCH => new Workbench(),
self::WHEAT_BLOCK => new Wheat(),
self::FARMLAND => new Farmland(),
self::FURNACE => new Furnace(),
self::BURNING_FURNACE => new BurningFurnace(),
self::SIGN_POST => new SignPost(),
self::WOOD_DOOR_BLOCK => new WoodDoor(),
self::LADDER => new Ladder(),
self::COBBLESTONE_STAIRS => new CobblestoneStairs(),
self::WALL_SIGN => new WallSign(),
self::IRON_DOOR_BLOCK => new IronDoor(),
self::REDSTONE_ORE => new RedstoneOre(),
self::GLOWING_REDSTONE_ORE => new GlowingRedstoneOre(),
self::SNOW_LAYER => new SnowLayer(),
self::ICE => new Ice(),
self::SNOW_BLOCK => new Snow(),
self::CACTUS => new Cactus(),
self::CLAY_BLOCK => new Clay(),
self::SUGARCANE_BLOCK => new Sugarcane(),
self::FENCE => new Fence(),
self::PUMPKIN => new Pumpkin(),
self::NETHERRACK => new Netherrack(),
self::SOUL_SAND => new SoulSand(),
self::GLOWSTONE_BLOCK => new Glowstone(),
self::LIT_PUMPKIN => new LitPumpkin(),
self::CAKE_BLOCK => new Cake(),
self::TRAPDOOR => new Trapdoor(),
self::STONE_BRICKS => new StoneBricks(),
self::IRON_BARS => new IronBars(),
self::GLASS_PANE => new GlassPane(),
self::MELON_BLOCK => new Melon(),
self::PUMPKIN_STEM => new PumpkinStem(),
self::MELON_STEM => new MelonStem(),
self::FENCE_GATE => new FenceGate(),
self::BRICK_STAIRS => new BrickStairs(),
self::STONE_BRICK_STAIRS => new StoneBrickStairs(),
self::NETHER_BRICKS => new NetherBrick(),
self::NETHER_BRICKS_STAIRS => new NetherBrickStairs(),
self::SANDSTONE_STAIRS => new SandstoneStairs(),
self::SPRUCE_WOOD_STAIRS => new SpruceWoodStairs(),
self::BIRCH_WOOD_STAIRS => new BirchWoodStairs(),
self::JUNGLE_WOOD_STAIRS => new JungleWoodStairs(),
self::STONE_WALL => new StoneWall(),
self::CARROT_BLOCK => new Carrot(),
self::POTATO_BLOCK => new Potato(),
self::QUARTZ_BLOCK => new Quartz(),
self::QUARTZ_STAIRS => new QuartzStairs(),
self::DOUBLE_WOOD_SLAB => new DoubleWoodSlab(),
self::WOOD_SLAB => new WoodSlab(),
self::HAY_BALE => new HayBale(),
self::CARPET => new Carpet(),
self::COAL_BLOCK => new Coal(),
self::BEETROOT_BLOCK => new Beetroot(),
self::STONECUTTER => new Stonecutter(),
self::GLOWING_OBSIDIAN => new GlowingObsidian(),
);
}
}
/**
* @param int $id
* @param int $meta
* @param Position $pos
*
* @return Block
*/
public static function get($id, $meta = 0, Position $pos = null){
if(isset(self::$list[$id])){
$block = clone self::$list[$id];
$block->setDamage($meta);
}else{
$block = new Generic($id, $meta);
}
if($pos instanceof Position){
$block->position($pos);
}
return $block;
}
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
$this->id = (int) $id;
$this->meta = (int) $meta;
$this->name = $name;
$this->breakTime = 0.20;
$this->hardness = 10;
}
/**
* @return int
*/
final public function getHardness(){
return $this->hardness;
}
/**
* @return string
*/
final public function getName(){
return $this->name;
}
/**
* @return int
*/
final public function getID(){
return $this->id;
}
/**
* @return int
*/
final public function getDamage(){
return $this->meta;
}
/**
* @param int $meta
*/
final public function setDamage($meta){
$this->meta = $meta & 0x0F;
}
/**
* Sets the block position to a new Position object
*
* @param Position $v
*
* @throws \RuntimeException
*/
final public function position(Position $v){
if(!$v->isValid()){
throw new \RuntimeException("Undefined Level reference");
}
$this->x = (int) $v->x;
$this->y = (int) $v->y;
$this->z = (int) $v->z;
$this->setLevel($v->getLevel(), false);
}
/**
* Returns an array of Item objects to be dropped
*
* @param Item $item
*
* @return array
*/
public function getDrops(Item $item){
if(!isset(self::$list[$this->id])){ //Unknown blocks
return [];
}else{
return array(
array($this->id, $this->meta, 1),
);
}
}
/**
* Returns the seconds that this block takes to be broken using an specific Item
*
* @param Item $item
*
* @return float
*/
public function getBreakTime(Item $item){
return $this->breakTime;
}
/**
* Returns the Block on the side $side, works like Vector3::side()
*
* @param int $side
* @param int $step
*
* @return Block
*/
public function getSide($side, $step = 1){
$v = parent::getSide($side, $step);
if($this->isValid()){
return $this->getLevel()->getBlock($v);
}
return Block::get(Item::AIR, 0, $v);
}
/**
* @return string
*/
final public function __toString(){
return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")";
}
/**
* Returns if the item can be broken with an specific Item
*
* @param Item $item
*
* @return bool
*/
abstract function isBreakable(Item $item);
/**
* Do the actions needed so the block is broken with the Item
*
* @param Item $item
*
* @return mixed
*/
abstract function onBreak(Item $item);
/**
* Checks for collision against an AxisAlignedBB
*
* @param AxisAlignedBB $bb
* @param Block[] $list
*/
public function collidesWithBB(AxisAlignedBB $bb, &$list = array()){
$bb2 = $this->getBoundingBox();
if($bb2->intersectsWith($bb)){
$list[] = $bb2;
}
}
/**
* @return AxisAlignedBB
*/
public function getBoundingBox(){
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}
/**
* Places the Block, using block space and block target, and side. Returns if the block has been placed.
*
* @param Item $item
* @param Block $block
* @param Block $target
* @param int $face
* @param float $fx
* @param float $fy
* @param float $fz
* @param Player $player = null
*
* @return bool
*/
abstract function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null);
/**
* Do actions when activated by Item. Returns if it has done anything
*
* @param Item $item
* @param Player $player
*
* @return bool
*/
abstract function onActivate(Item $item, Player $player = null);
/**
* Fires a block update on the Block
*
* @param int $type
*
* @return void
*/
abstract function onUpdate($type);
//TODO: Level block metadata
public function setMetadata($metadataKey, MetadataValue $metadataValue){
//$this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue);
}
public function getMetadata($metadataKey){
return null; //return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey);
}
public function hasMetadata($metadataKey){
return false; //return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
}
public function removeMetadata($metadataKey, Plugin $plugin){
//$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin);
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,10 +19,13 @@
*
*/
class BookshelfBlock extends SolidBlock{
namespace pocketmine\block;
class Bookshelf extends Solid{
public function __construct(){
parent::__construct(BOOKSHELF, 0, "Bookshelf");
parent::__construct(self::BOOKSHELF, 0, "Bookshelf");
$this->hardness = 7.5;
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,9 +19,12 @@
*
*/
class BrickStairsBlock extends StairBlock{
namespace pocketmine\block;
class BrickStairs extends Stair{
public function __construct($meta = 0){
parent::__construct(BRICK_STAIRS, $meta, "Brick Stairs");
parent::__construct(self::BRICK_STAIRS, $meta, "Brick Stairs");
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,16 +19,17 @@
*
*/
class BricksBlock extends SolidBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
class Bricks extends Solid{
public function __construct(){
parent::__construct(BRICKS_BLOCK, 0, "Bricks");
parent::__construct(self::BRICKS_BLOCK, 0, "Bricks");
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
public function getBreakTime(Item $item){
switch($item->isPickaxe()){
case 5:
return 0.4;
@ -44,14 +45,14 @@ class BricksBlock extends SolidBlock{
return 10;
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(BRICKS_BLOCK, 0, 1),
array(Item::BRICKS_BLOCK, 0, 1),
);
}else{
return array();
return [];
}
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,29 +19,39 @@
*
*/
class RedMushroomBlock extends FlowableBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
class BrownMushroom extends Flowable{
public function __construct(){
parent::__construct(RED_MUSHROOM, 0, "Red Mushroom");
parent::__construct(self::BROWN_MUSHROOM, 0, "Brown Mushroom");
$this->hardness = 0;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;
$this->getLevel()->dropItem($this, Item::get($this->id));
$this->getLevel()->setBlock($this, new Air(), false, false, true);
return Level::BLOCK_UPDATE_NORMAL;
}
}
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->isTransparent === false){
$this->level->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,131 @@
<?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/
*
*
*/
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\String;
use pocketmine\Player;
use pocketmine\tile\Furnace;
use pocketmine\tile\Tile;
class BurningFurnace extends Solid{
public function __construct($meta = 0){
parent::__construct(self::BURNING_FURNACE, $meta, "Burning Furnace");
$this->isActivable = true;
$this->hardness = 17.5;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$faces = array(
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
$this->getLevel()->setBlock($block, $this, true, false, true);
$nbt = new Compound(false, array(
new Enum("Items", []),
new String("id", Tile::FURNACE),
new Int("x", $this->x),
new Int("y", $this->y),
new Int("z", $this->z)
));
$nbt->Items->setTagType(NBT::TAG_Compound);
new Furnace($this->getLevel(), $nbt);
return true;
}
public function onBreak(Item $item){
$this->getLevel()->setBlock($this, new Air(), true, true, true);
return true;
}
public function onActivate(Item $item, Player $player = null){
if($player instanceof Player){
$t = $this->getLevel()->getTile($this);
$furnace = false;
if($t instanceof Furnace){
$furnace = $t;
}else{
$nbt = new Compound(false, array(
new Enum("Items", []),
new String("id", Tile::FURNACE),
new Int("x", $this->x),
new Int("y", $this->y),
new Int("z", $this->z)
));
$nbt->Items->setTagType(NBT::TAG_Compound);
$furnace = new Furnace($this->getLevel(), $nbt);
}
if(($player->getGamemode() & 0x01) === 0x01){
return true;
}
$furnace->openInventory($player);
}
return true;
}
public function getBreakTime(Item $item){
switch($item->isPickaxe()){
case 5:
return 0.7;
case 4:
return 0.9;
case 3:
return 1.35;
case 2:
return 0.45;
case 1:
return 2.65;
default:
return 17.5;
}
}
public function getDrops(Item $item){
$drops = [];
if($item->isPickaxe() >= 1){
$drops[] = array(Item::FURNACE, 0, 1);
}
$t = $this->getLevel()->getTile($this);
if($t instanceof Furnace){
for($s = 0; $s < $t->getInventory()->getSize(); ++$s){
$slot = $t->getInventory()->getItem($s);
if($slot->getID() > Item::AIR and $slot->getCount() > 0){
$drops[] = array($slot->getID(), $slot->getDamage(), $slot->getCount());
}
}
}
return $drops;
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,60 +19,72 @@
*
*/
class CactusBlock extends TransparentBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\Vector3 as Vector3;
use pocketmine\Player;
use pocketmine\Server;
class Cactus extends Transparent{
public function __construct($meta = 0){
parent::__construct(CACTUS, $meta, "Cactus");
parent::__construct(self::CACTUS, $meta, "Cactus");
$this->isFullBlock = false;
$this->hardness = 2;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($type === Level::BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->getID() !== SAND and $down->getID() !== CACTUS){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false);
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
return BLOCK_UPDATE_NORMAL;
if($down->getID() !== self::SAND and $down->getID() !== self::CACTUS){ //Replace with common break method
$this->getLevel()->setBlock($this, new Air(), false);
Server::getInstance()->api->entity->drop($this, Item::get($this->id));
return Level::BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== CACTUS){
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== self::CACTUS){
if($this->meta == 0x0F){
for($y = 1; $y < 3; ++$y){
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === AIR){
$this->level->setBlock($b, new CactusBlock(), true, false, true);
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === self::AIR){
$this->getLevel()->setBlock($b, new Cactus(), true, false, true);
break;
}
}
$this->meta = 0;
$this->level->setBlock($this, $this, false);
$this->getLevel()->setBlock($this, $this, false);
}else{
++$this->meta;
$this->level->setBlock($this, $this, false);
$this->getLevel()->setBlock($this, $this, false);
}
return BLOCK_UPDATE_RANDOM;
return Level::BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() === SAND or $down->getID() === CACTUS){
if($down->getID() === self::SAND or $down->getID() === self::CACTUS){
$block0 = $this->getSide(2);
$block1 = $this->getSide(3);
$block2 = $this->getSide(4);
$block3 = $this->getSide(5);
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
$this->level->setBlock($this, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
$this->getLevel()->setBlock($this, $this, true, false, true);
return true;
}
}
return false;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item $item){
return array(
array($this->id, 0, 1),
);

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,50 +19,62 @@
*
*/
class CakeBlock extends TransparentBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
class Cake extends Transparent{
public function __construct($meta = 0){
parent::__construct(CAKE_BLOCK, 0, "Cake Block");
parent::__construct(self::CAKE_BLOCK, 0, "Cake Block");
$this->isFullBlock = false;
$this->isActivable = true;
$this->meta = $meta & 0x07;
$this->hardness = 2.5;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() !== AIR){
$this->level->setBlock($block, $this, true, false, true);
if($down->getID() !== self::AIR){
$this->getLevel()->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL;
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, new Air(), true, false, true);
return Level::BLOCK_UPDATE_NORMAL;
}
}
return false;
}
public function getDrops(Item $item, Player $player){
return array();
public function getDrops(Item $item){
return [];
}
public function onActivate(Item $item, Player $player){
if($player->entity->getHealth() < 20){
public function onActivate(Item $item, Player $player = null){
if($player instanceof Player and $player->getHealth() < 20){
++$this->meta;
$player->entity->heal(3, "cake");
$player->heal(3, "cake");
if($this->meta >= 0x06){
$this->level->setBlock($this, new AirBlock(), true, false, true);
$this->getLevel()->setBlock($this, new Air(), true, false, true);
}else{
$this->level->setBlock($this, $this, true, false, true);
$this->getLevel()->setBlock($this, $this, true, false, true);
}
return true;
}
return false;
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,9 +19,15 @@
*
*/
class CarpetBlock extends FlowableBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
class Carpet extends Flowable{
public function __construct($meta = 0){
parent::__construct(CARPET, $meta, "Carpet");
parent::__construct(self::CARPET, $meta, "Carpet");
$names = array(
0 => "White Carpet",
1 => "Orange Carpet",
@ -42,28 +48,32 @@ class CarpetBlock extends FlowableBlock{
);
$this->name = $names[$this->meta];
$this->hardness = 0;
$this->isFullBlock = false;
$this->isFullBlock = false;
$this->isSolid = true;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() !== AIR){
$this->level->setBlock($block, $this, true, false, true);
if($down->getID() !== self::AIR){
$this->getLevel()->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1));
$this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL;
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === self::AIR){ //TODO: Replace with common break method
$this->getLevel()->dropItem($this, Item::get($this->id, $this->meta, 1));
$this->getLevel()->setBlock($this, new Air(), true, false, true);
return Level::BLOCK_UPDATE_NORMAL;
}
}
return false;
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,63 +19,75 @@
*
*/
class PotatoBlock extends FlowableBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
class Carrot extends Flowable{
public function __construct($meta = 0){
parent::__construct(POTATO_BLOCK, $meta, "Potato Block");
parent::__construct(self::CARROT_BLOCK, $meta, "Carrot Block");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
if($down->getID() === self::FARMLAND){
$this->getLevel()->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
public function onActivate(Item $item, Player $player = null){
if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
$this->getLevel()->setBlock($this, $this, true, false, true);
$item->count--;
return true;
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(POTATO, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
//TODO
//Server::getInstance()->api->entity->drop($this, Item::get(CARROT, 0, 1));
$this->getLevel()->setBlock($this, new Air(), false, false, true);
return Level::BLOCK_UPDATE_NORMAL;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
$this->getLevel()->setBlock($this, $this, true, false, true);
return Level::BLOCK_UPDATE_RANDOM;
}
}else{
return BLOCK_UPDATE_RANDOM;
return Level::BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function getDrops(Item $item, Player $player){
$drops = array();
public function getDrops(Item $item){
$drops = [];
if($this->meta >= 0x07){
$drops[] = array(POTATO, 0, mt_rand(1, 4));
$drops[] = array(Item::CARROT, 0, mt_rand(1, 4));
}else{
$drops[] = array(POTATO, 0, 1);
$drops[] = array(Item::CARROT, 0, 1);
}
return $drops;
}
}

View File

@ -0,0 +1,149 @@
<?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/
*
*
*/
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\String;
use pocketmine\Player;
use pocketmine\tile\Chest as TileChest;
use pocketmine\tile\Tile;
class Chest extends Transparent{
const SLOTS = 27;
public function __construct($meta = 0){
parent::__construct(self::CHEST, $meta, "Chest");
$this->isActivable = true;
$this->hardness = 15;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$faces = array(
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
$chest = false;
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
for($side = 2; $side <= 5; ++$side){
if(($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)){
continue;
}elseif(($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)){
continue;
}
$c = $this->getSide($side);
if($c instanceof Chest and $c->getDamage() === $this->meta){
$tile = $this->getLevel()->getTile($c);
if($tile instanceof TileChest and !$tile->isPaired()){
$chest = $tile;
break;
}
}
}
$this->getLevel()->setBlock($block, $this, true, false, true);
$nbt = new Compound(false, array(
new Enum("Items", []),
new String("id", Tile::CHEST),
new Int("x", $this->x),
new Int("y", $this->y),
new Int("z", $this->z)
));
$nbt->Items->setTagType(NBT::TAG_Compound);
$tile = new TileChest($this->getLevel(), $nbt);
if($chest instanceof TileChest){
$chest->pairWith($tile);
$tile->pairWith($chest);
}
return true;
}
public function onBreak(Item $item){
$t = $this->getLevel()->getTile($this);
if($t instanceof TileChest){
$t->unpair();
}
$this->getLevel()->setBlock($this, new Air(), true, true, true);
return true;
}
public function onActivate(Item $item, Player $player = null){
if($player instanceof Player){
$top = $this->getSide(1);
if($top->isTransparent !== true){
return true;
}
$t = $this->getLevel()->getTile($this);
$chest = null;
if($t instanceof TileChest){
$chest = $t;
}else{
$nbt = new Compound(false, array(
new Enum("Items", []),
new String("id", Tile::CHEST),
new Int("x", $this->x),
new Int("y", $this->y),
new Int("z", $this->z)
));
$nbt->Items->setTagType(NBT::TAG_Compound);
$chest = new TileChest($this->getLevel(), $nbt);
}
if(($player->gamemode & 0x01) === 0x01){
return true;
}
$player->addWindow($chest->getInventory());
}
return true;
}
public function getDrops(Item $item){
$drops = array(
array($this->id, 0, 1),
);
$t = $this->getLevel()->getTile($this);
if($t instanceof TileChest){
for($s = 0; $s < $t->getRealInventory()->getSize(); ++$s){
$slot = $t->getRealInventory()->getItem($s);
if($slot->getID() > Item::AIR and $slot->getCount() > 0){
$drops[] = array($slot->getID(), $slot->getDamage(), $slot->getCount());
}
}
}
return $drops;
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,15 +19,19 @@
*
*/
class ClayBlock extends SolidBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
class Clay extends Solid{
public function __construct(){
parent::__construct(CLAY_BLOCK, 0, "Clay Block");
parent::__construct(self::CLAY_BLOCK, 0, "Clay Block");
$this->hardness = 3;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item $item){
return array(
array(CLAY, 0, 4),
array(Item::CLAY, 0, 4),
);
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,16 +19,17 @@
*
*/
class CoalBlock extends SolidBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
class Coal extends Solid{
public function __construct(){
parent::__construct(COAL_BLOCK, 0, "Coal Block");
parent::__construct(self::COAL_BLOCK, 0, "Coal Block");
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
public function getBreakTime(Item $item){
switch($item->isPickaxe()){
case 5:
return 0.95;
@ -44,14 +45,14 @@ class CoalBlock extends SolidBlock{
return 25;
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(COAL_BLOCK, 0, 1),
array(Item::COAL_BLOCK, 0, 1),
);
}else{
return array();
return [];
}
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,16 +19,17 @@
*
*/
class CoalOreBlock extends SolidBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
class CoalOre extends Solid{
public function __construct(){
parent::__construct(COAL_ORE, 0, "Coal Ore");
parent::__construct(self::COAL_ORE, 0, "Coal Ore");
$this->hardness = 15;
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
public function getBreakTime(Item $item){
switch($item->isPickaxe()){
case 5:
return 0.6;
@ -44,15 +45,15 @@ class CoalOreBlock extends SolidBlock{
return 15;
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(COAL, 0, 1),
array(Item::COAL, 0, 1),
);
}else{
return array();
return [];
}
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,16 +19,17 @@
*
*/
class CobblestoneBlock extends SolidBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
class Cobblestone extends Solid{
public function __construct(){
parent::__construct(COBBLESTONE, 0, "Cobblestone");
parent::__construct(self::COBBLESTONE, 0, "Cobblestone");
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
public function getBreakTime(Item $item){
switch($item->isPickaxe()){
case 5:
return 0.4;
@ -44,14 +45,14 @@ class CobblestoneBlock extends SolidBlock{
return 10;
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(COBBLESTONE, 0, 1),
array(Item::COBBLESTONE, 0, 1),
);
}else{
return array();
return [];
}
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,9 +19,12 @@
*
*/
class CobblestoneStairsBlock extends StairBlock{
namespace pocketmine\block;
class CobblestoneStairs extends Stair{
public function __construct($meta = 0){
parent::__construct(COBBLESTONE_STAIRS, $meta, "Cobblestone Stairs");
parent::__construct(self::COBBLESTONE_STAIRS, $meta, "Cobblestone Stairs");
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
@ -19,14 +19,19 @@
*
*/
class CobwebBlock extends FlowableBlock{
namespace pocketmine\block;
use pocketmine\item\Item;
class Cobweb extends Flowable{
public function __construct(){
parent::__construct(COBWEB, 0, "Cobweb");
parent::__construct(self::COBWEB, 0, "Cobweb");
$this->isSolid = true;
$this->isFullBlock = false;
$this->hardness = 25;
}
public function getDrops(Item $item, Player $player){
return array();
}
public function getDrops(Item $item){
return [];
}
}

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