mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
Removed code remove comments
This commit is contained in:
parent
bbd66e6ad1
commit
c08bf3ef86
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine\ServerAPI as ServerAPI;
|
||||
|
||||
abstract class Achievement{
|
||||
@ -30,8 +31,7 @@ abstract class Achievement{
|
||||
),*/
|
||||
"mineWood" => array(
|
||||
"name" => "Getting Wood",
|
||||
"requires" => array(
|
||||
//"openInventory",
|
||||
"requires" => array(//"openInventory",
|
||||
),
|
||||
),
|
||||
"buildWorkBench" => array(
|
||||
@ -94,35 +94,39 @@ abstract class Achievement{
|
||||
"acquireIron",
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
||||
public static function broadcast(Player $player, $achievementId){
|
||||
if(isset(Achievement::$list[$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->getUsername()." has just earned the achievement ".Achievement::$list[$achievementId]["name"]);
|
||||
}else{
|
||||
$player->sendChat("You have just earned the achievement ".Achievement::$list[$achievementId]["name"]);
|
||||
}
|
||||
ServerAPI::request()->api->chat->broadcast($player->getUsername() . " has just earned the achievement " . Achievement::$list[$achievementId]["name"]);
|
||||
} else{
|
||||
$player->sendChat("You have just earned the achievement " . Achievement::$list[$achievementId]["name"]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static function add($achievementId, $achievementName, array $requires = array()){
|
||||
if(!isset(Achievement::$list[$achievementId])){
|
||||
Achievement::$list[$achievementId] = array(
|
||||
"name" => $achievementName,
|
||||
"requires" => $requires,
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
252
src/BanAPI.php
252
src/BanAPI.php
@ -20,33 +20,34 @@
|
||||
*/
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine\ServerAPI as ServerAPI;
|
||||
use PocketMine\Utils\Config as Config;
|
||||
use PocketMine\Player as Player;
|
||||
|
||||
class BanAPI{
|
||||
private $server;
|
||||
/*
|
||||
* I would use PHPDoc Template here but PHPStorm does not recognise it. - @sekjun9878
|
||||
*/
|
||||
/** @var Config */
|
||||
/*
|
||||
* I would use PHPDoc Template here but PHPStorm does not recognise it. - @sekjun9878
|
||||
*/
|
||||
/** @var Config */
|
||||
private $whitelist;
|
||||
/** @var Config */
|
||||
/** @var Config */
|
||||
private $banned;
|
||||
/** @var Config */
|
||||
/** @var Config */
|
||||
private $ops;
|
||||
/** @var Config */
|
||||
/** @var Config */
|
||||
private $bannedIPs;
|
||||
private $cmdWhitelist = array();//Command WhiteList
|
||||
private $cmdWhitelist = array(); //Command WhiteList
|
||||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
$this->whitelist = new Config(\PocketMine\DATA."white-list.txt", Config::ENUM);//Open whitelist list file
|
||||
$this->bannedIPs = new Config(\PocketMine\DATA."banned-ips.txt", Config::ENUM);//Open Banned IPs list file
|
||||
$this->banned = new Config(\PocketMine\DATA."banned.txt", Config::ENUM);//Open Banned Usernames list file
|
||||
$this->ops = new Config(\PocketMine\DATA."ops.txt", Config::ENUM);//Open list of OPs
|
||||
$this->whitelist = new Config(\PocketMine\DATA . "white-list.txt", Config::ENUM); //Open whitelist list file
|
||||
$this->bannedIPs = new Config(\PocketMine\DATA . "banned-ips.txt", Config::ENUM); //Open Banned IPs list file
|
||||
$this->banned = new Config(\PocketMine\DATA . "banned.txt", Config::ENUM); //Open Banned Usernames list file
|
||||
$this->ops = new Config(\PocketMine\DATA . "ops.txt", Config::ENUM); //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"));
|
||||
@ -58,82 +59,85 @@ class BanAPI{
|
||||
$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
|
||||
$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.
|
||||
/**
|
||||
* @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?
|
||||
/**
|
||||
* @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)){
|
||||
} elseif($this->ops->exists($username)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
* @param string $event
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function permissionsCheck($data, $event){
|
||||
/**
|
||||
* @param mixed $data
|
||||
* @param string $event
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function permissionsCheck($data, $event){
|
||||
switch($event){
|
||||
case "player.flying"://OPs can fly around the server.
|
||||
case "player.flying": //OPs can fly around the server.
|
||||
if($this->isOp($data->getUsername())){
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case "player.block.break":
|
||||
case "player.block.place"://Spawn protection detection. Allows OPs to place/break blocks in the spawn area.
|
||||
case "player.block.place": //Spawn protection detection. Allows OPs to place/break blocks in the spawn area.
|
||||
if(!$this->isOp($data["player"]->getUsername())){
|
||||
$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){
|
||||
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.
|
||||
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"]->getUsername())){
|
||||
return;
|
||||
}
|
||||
}elseif($data["issuer"] === "console" or $data["issuer"] === "rcon"){
|
||||
} 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){
|
||||
/**
|
||||
* @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":
|
||||
@ -144,24 +148,24 @@ class BanAPI{
|
||||
break;
|
||||
}
|
||||
$this->server->api->console->run(implode(" ", $params), $player);
|
||||
$output .= "Command ran as ".$player->getUsername().".\n";
|
||||
$output .= "Command ran as " . $player->getUsername() . ".\n";
|
||||
break;
|
||||
case "op":
|
||||
$user = strtolower($params[0]);
|
||||
if($user == NULL){
|
||||
$output .= "Usage: /op <player>\n";
|
||||
break;
|
||||
if($user == null){
|
||||
$output .= "Usage: /op <player>\n";
|
||||
break;
|
||||
}
|
||||
$player = Player::get($user);
|
||||
if(!($player instanceof Player)){
|
||||
$this->ops->set($user);
|
||||
$this->ops->save();
|
||||
$output .= $user." is now op\n";
|
||||
$output .= $user . " is now op\n";
|
||||
break;
|
||||
}
|
||||
$this->ops->set(strtolower($player->getUsername()));
|
||||
$this->ops->save();
|
||||
$output .= $player->getUsername()." is now op\n";
|
||||
$output .= $player->getUsername() . " is now op\n";
|
||||
$this->server->api->chat->sendTo(false, "You are now op.", $player->getUsername());
|
||||
break;
|
||||
case "deop":
|
||||
@ -170,32 +174,32 @@ class BanAPI{
|
||||
if(!($player instanceof Player)){
|
||||
$this->ops->remove($user);
|
||||
$this->ops->save();
|
||||
$output .= $user." is no longer op\n";
|
||||
$output .= $user . " is no longer op\n";
|
||||
break;
|
||||
}
|
||||
$this->ops->remove(strtolower($player->getUsername()));
|
||||
$this->ops->save();
|
||||
$output .= $player->getUsername()." is no longer op\n";
|
||||
$output .= $player->getUsername() . " is no longer op\n";
|
||||
$this->server->api->chat->sendTo(false, "You are no longer op.", $player->getUsername());
|
||||
break;
|
||||
case "kick":
|
||||
if(!isset($params[0])){
|
||||
$output .= "Usage: /kick <player> [reason ...]\n";
|
||||
}else{
|
||||
} else{
|
||||
$name = strtolower(array_shift($params));
|
||||
$player = Player::get($name);
|
||||
if($player === false){
|
||||
$output .= "Player \"".$name."\" does not exist\n";
|
||||
}else{
|
||||
$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
|
||||
$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->getUsername()." has been kicked by ".$issuer->getUsername().": $reason\n");
|
||||
}else{
|
||||
$this->server->api->chat->broadcast($player->getUsername()." has been kicked: $reason\n");
|
||||
$this->server->api->chat->broadcast($player->getUsername() . " has been kicked by " . $issuer->getUsername() . ": $reason\n");
|
||||
} else{
|
||||
$this->server->api->chat->broadcast($player->getUsername() . " has been kicked: $reason\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -216,10 +220,10 @@ class BanAPI{
|
||||
$output .= "Player \"$user\" added to white-list\n";
|
||||
break;
|
||||
case "reload":
|
||||
$this->whitelist = new Config(\PocketMine\DATA."white-list.txt", Config::ENUM);
|
||||
$this->whitelist = new Config(\PocketMine\DATA . "white-list.txt", Config::ENUM);
|
||||
break;
|
||||
case "list":
|
||||
$output .= "White-list: ".implode(", ", $this->whitelist->getAll(true))."\n";
|
||||
$output .= "White-list: " . implode(", ", $this->whitelist->getAll(true)) . "\n";
|
||||
break;
|
||||
case "on":
|
||||
case "true":
|
||||
@ -261,10 +265,10 @@ class BanAPI{
|
||||
$output .= "IP \"$ip\" added to ban list\n";
|
||||
break;
|
||||
case "reload":
|
||||
$this->bannedIPs = new Config(\PocketMine\DATA."banned-ips.txt", Config::ENUM);
|
||||
$this->bannedIPs = new Config(\PocketMine\DATA . "banned-ips.txt", Config::ENUM);
|
||||
break;
|
||||
case "list":
|
||||
$output .= "IP ban list: ".implode(", ", $this->bannedIPs->getAll(true))."\n";
|
||||
$output .= "IP ban list: " . implode(", ", $this->bannedIPs->getAll(true)) . "\n";
|
||||
break;
|
||||
default:
|
||||
$output .= "Usage: /banip <add|remove|list|reload> [IP|player]\n";
|
||||
@ -291,18 +295,18 @@ class BanAPI{
|
||||
$player->close("You have been banned");
|
||||
}
|
||||
if($issuer instanceof Player){
|
||||
$this->server->api->chat->broadcast($user." has been banned by ".$issuer->getUsername()."\n");
|
||||
}else{
|
||||
$this->server->api->chat->broadcast($user." has been banned\n");
|
||||
$this->server->api->chat->broadcast($user . " has been banned by " . $issuer->getUsername() . "\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(\PocketMine\DATA."banned.txt", Config::ENUM);
|
||||
$this->banned = new Config(\PocketMine\DATA . "banned.txt", Config::ENUM);
|
||||
break;
|
||||
case "list":
|
||||
$output .= "Ban list: ".implode(", ", $this->banned->getAll(true))."\n";
|
||||
$output .= "Ban list: " . implode(", ", $this->banned->getAll(true)) . "\n";
|
||||
break;
|
||||
default:
|
||||
$output .= "Usage: /ban <add|remove|list|reload> [username]\n";
|
||||
@ -310,96 +314,98 @@ class BanAPI{
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
*/
|
||||
public function ban($username){
|
||||
/**
|
||||
* @param string $username
|
||||
*/
|
||||
public function ban($username){
|
||||
$this->commandHandler("ban", array("add", $username), "console", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
*/
|
||||
/**
|
||||
* @param string $username
|
||||
*/
|
||||
public function pardon($username){
|
||||
$this->commandHandler("ban", array("pardon", $username), "console", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $ip
|
||||
*/
|
||||
/**
|
||||
* @param string $ip
|
||||
*/
|
||||
public function banIP($ip){
|
||||
$this->commandHandler("banip", array("add", $ip), "console", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $ip
|
||||
*/
|
||||
/**
|
||||
* @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"){
|
||||
/**
|
||||
* @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){
|
||||
/**
|
||||
* @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)){
|
||||
} elseif($this->bannedIPs->exists($ip, true)){
|
||||
return true;
|
||||
}else{
|
||||
} else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isBanned($username){
|
||||
/**
|
||||
* @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)){
|
||||
} elseif($this->banned->exists($username, true)){
|
||||
return true;
|
||||
}else{
|
||||
} else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function inWhitelist($username){
|
||||
/**
|
||||
* @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){
|
||||
} elseif($this->server->api->dhandle("api.ban.whitelist.check", $username) === false){
|
||||
return true;
|
||||
}elseif($this->whitelist->exists($username, true)){
|
||||
} elseif($this->whitelist->exists($username, true)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
126
src/BlockAPI.php
126
src/BlockAPI.php
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine\Level\Position as Position;
|
||||
use PocketMine\Block\GenericBlock as GenericBlock;
|
||||
use PocketMine\Item\Item as Item;
|
||||
@ -36,7 +37,7 @@ class BlockAPI{
|
||||
private $scheduledUpdates = array();
|
||||
private $randomUpdates = array();
|
||||
public static $creative = array(
|
||||
|
||||
|
||||
//Building
|
||||
array(STONE, 0),
|
||||
array(COBBLESTONE, 0),
|
||||
@ -49,7 +50,7 @@ class BlockAPI{
|
||||
array(WOODEN_PLANKS, 2),
|
||||
array(WOODEN_PLANKS, 3),
|
||||
array(BRICKS, 0),
|
||||
|
||||
|
||||
array(DIRT, 0),
|
||||
array(GRASS, 0),
|
||||
array(CLAY_BLOCK, 0),
|
||||
@ -97,7 +98,7 @@ class BlockAPI{
|
||||
array(OBSIDIAN, 0),
|
||||
array(ICE, 0),
|
||||
array(SNOW_BLOCK, 0),
|
||||
|
||||
|
||||
//Decoration
|
||||
array(COBBLESTONE_WALL, 0),
|
||||
array(COBBLESTONE_WALL, 1),
|
||||
@ -180,11 +181,11 @@ class BlockAPI{
|
||||
array(CARPET, 10),
|
||||
array(CARPET, 9),
|
||||
array(CARPET, 8),
|
||||
|
||||
|
||||
//Tools
|
||||
//array(RAILS, 0),
|
||||
//array(POWERED_RAILS, 0),
|
||||
array(TORCH, 0),
|
||||
array(TORCH, 0),
|
||||
array(BUCKET, 0),
|
||||
array(BUCKET, 8),
|
||||
array(BUCKET, 10),
|
||||
@ -201,7 +202,7 @@ class BlockAPI{
|
||||
array(SPAWN_EGG, MOB_COW),
|
||||
array(SPAWN_EGG, MOB_PIG),
|
||||
array(SPAWN_EGG, MOB_SHEEP),
|
||||
|
||||
|
||||
//Seeds
|
||||
array(SUGARCANE, 0),
|
||||
array(WHEAT, 0),
|
||||
@ -228,32 +229,34 @@ class BlockAPI{
|
||||
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){
|
||||
foreach(explode(",", $str) as $b){
|
||||
$blocks[] = BlockAPI::fromString($b, false);
|
||||
}
|
||||
|
||||
return $blocks;
|
||||
}else{
|
||||
} else{
|
||||
$b = explode(":", str_replace(" ", "_", trim($str)));
|
||||
if(!isset($b[1])){
|
||||
$meta = 0;
|
||||
}else{
|
||||
} 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{
|
||||
} else{
|
||||
$item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
@ -262,26 +265,28 @@ class BlockAPI{
|
||||
if(isset(Block::$class[$id])){
|
||||
$classname = Block::$class[$id];
|
||||
$b = new $classname($meta);
|
||||
}else{
|
||||
} 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{
|
||||
} else{
|
||||
$i = new Item($id, $meta, $count);
|
||||
}
|
||||
|
||||
return $i;
|
||||
}
|
||||
|
||||
|
||||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
@ -301,10 +306,10 @@ class BlockAPI{
|
||||
}
|
||||
$player = Player::get($params[0]);
|
||||
$item = BlockAPI::fromString($params[1]);
|
||||
|
||||
|
||||
if(!isset($params[2])){
|
||||
$item->setCount($item->getMaxStackSize());
|
||||
}else{
|
||||
} else{
|
||||
$item->setCount((int) $params[2]);
|
||||
}
|
||||
|
||||
@ -313,18 +318,19 @@ class BlockAPI{
|
||||
$output .= "Player is in creative mode.\n";
|
||||
break;
|
||||
}
|
||||
if($item->getID() == 0) {
|
||||
if($item->getID() == 0){
|
||||
$output .= "You cannot give an air block to a player.\n";
|
||||
break;
|
||||
}
|
||||
$player->addItem($item);
|
||||
$output .= "Giving ".$item->getCount()." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->getUsername()."\n";
|
||||
}else{
|
||||
$output .= "Giving " . $item->getCount() . " of " . $item->getName() . " (" . $item->getID() . ":" . $item->getMetadata() . ") to " . $player->getUsername() . "\n";
|
||||
} else{
|
||||
$output .= "Unknown player.\n";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
@ -339,6 +345,7 @@ class BlockAPI{
|
||||
if($send === true){
|
||||
$player->sendInventorySlot($player->slot);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -346,20 +353,20 @@ class BlockAPI{
|
||||
|
||||
$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);
|
||||
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){
|
||||
@ -368,17 +375,18 @@ class BlockAPI{
|
||||
if(($player->gamemode & 0x01) === 0 and $item->useOn($target) and $item->getMetadata() >= $item->getMaxDurability()){
|
||||
$player->setSlot($player->slot, new Item(AIR, 0, 0));
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
return $this->cancelAction($target, $player, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(($player->gamemode & 0x01) === 0x00 and count($drops) > 0){
|
||||
foreach($drops as $drop){
|
||||
echo "I dropped something\n";
|
||||
//$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;
|
||||
}
|
||||
|
||||
@ -387,21 +395,22 @@ class BlockAPI{
|
||||
return false;
|
||||
}
|
||||
|
||||
$target = $player->level->getBlock($vector);
|
||||
$target = $player->level->getBlock($vector);
|
||||
$block = $target->getSide($face);
|
||||
if(($player->getGamemode() & 0x01) === 0){
|
||||
$item = $player->getSlot($player->slot);
|
||||
}else{
|
||||
} else{
|
||||
$item = BlockAPI::getItem(BlockAPI::$creative[$player->slot][0], BlockAPI::$creative[$player->slot][1], 1);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@ -414,7 +423,7 @@ class BlockAPI{
|
||||
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);
|
||||
@ -424,42 +433,44 @@ class BlockAPI{
|
||||
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->getCount() <= 0){
|
||||
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if($item->isPlaceable()){
|
||||
$hand = $item->getBlock();
|
||||
$hand->position($block);
|
||||
}elseif($block->getID() === FIRE){
|
||||
} elseif($block->getID() === FIRE){
|
||||
$player->level->setBlock($block, new Block\AirBlock(), true, false, true);
|
||||
|
||||
return false;
|
||||
}else{
|
||||
} 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);
|
||||
$hand->position($block);
|
||||
//$face = -1;
|
||||
}
|
||||
|
||||
|
||||
//Implement using Bounding Boxes
|
||||
/*if($hand->isSolid === true and $player->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){
|
||||
} 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){
|
||||
@ -486,7 +497,7 @@ class BlockAPI{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = 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);
|
||||
@ -494,7 +505,7 @@ class BlockAPI{
|
||||
$this->scheduleBlockUpdate($pos->getSide(3), $delay, $type);
|
||||
$this->scheduleBlockUpdate($pos->getSide(4), $delay, $type);
|
||||
$this->scheduleBlockUpdate($pos->getSide(5), $delay, $type);
|
||||
}else{
|
||||
} else{
|
||||
$this->blockUpdate($pos->getSide(0), $type);
|
||||
$this->blockUpdate($pos->getSide(1), $type);
|
||||
$this->blockUpdate($pos->getSide(2), $type);
|
||||
@ -503,55 +514,58 @@ class BlockAPI{
|
||||
$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{
|
||||
} 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);
|
||||
}
|
||||
|
||||
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;
|
||||
$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.");");
|
||||
$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 blockUpdateTick(){
|
||||
$time = microtime(true);
|
||||
if(count($this->scheduledUpdates) > 0){
|
||||
$update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE delay <= ".$time.";");
|
||||
$update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE delay <= " . $time . ";");
|
||||
if($update instanceof \SQLite3Result){
|
||||
$upp = array();
|
||||
while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$index = $up["x"].".".$up["y"].".".$up["z"].".".$up["level"].".".$up["type"];
|
||||
$index = $up["x"] . "." . $up["y"] . "." . $up["z"] . "." . $up["level"] . "." . $up["type"];
|
||||
if(isset($this->scheduledUpdates[$index])){
|
||||
$upp[] = array((int) $up["type"], $this->scheduledUpdates[$index]);
|
||||
unset($this->scheduledUpdates[$index]);
|
||||
}
|
||||
}
|
||||
$this->server->query("DELETE FROM blockUpdates WHERE delay <= ".$time.";");
|
||||
$this->server->query("DELETE FROM blockUpdates WHERE delay <= " . $time . ";");
|
||||
foreach($upp as $b){
|
||||
$this->blockUpdate($b[1], $b[0]);
|
||||
}
|
||||
|
@ -20,15 +20,17 @@
|
||||
*/
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine\ServerAPI as ServerAPI;
|
||||
use PocketMine\Player as Player;
|
||||
|
||||
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"));
|
||||
@ -38,15 +40,15 @@ class ChatAPI{
|
||||
$this->server->api->console->alias("msg", "tell");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cmd
|
||||
* @param array $params
|
||||
* @param string $issuer
|
||||
* @param string $alias
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||
/**
|
||||
* @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":
|
||||
@ -55,20 +57,20 @@ class ChatAPI{
|
||||
$output .= "Usage: /say <message>\n";
|
||||
break;
|
||||
}
|
||||
$sender = ($issuer instanceof Player) ? "Server":ucfirst($issuer);
|
||||
$this->server->api->chat->broadcast("[$sender] ".$s);
|
||||
$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{
|
||||
} else{
|
||||
$sender = ucfirst($issuer);
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
$sender = $issuer->getUsername();
|
||||
}
|
||||
$this->broadcast("* $sender ".implode(" ", $params));
|
||||
$this->broadcast("* $sender " . implode(" ", $params));
|
||||
break;
|
||||
case "tell":
|
||||
if(!isset($params[0]) or !isset($params[1])){
|
||||
@ -77,55 +79,56 @@ class ChatAPI{
|
||||
}
|
||||
if(!($issuer instanceof Player)){
|
||||
$sender = ucfirst($issuer);
|
||||
}else{
|
||||
} else{
|
||||
$sender = $issuer->getUsername();
|
||||
}
|
||||
$n = array_shift($params);
|
||||
$target = Player::get($n);
|
||||
if($target instanceof Player){
|
||||
$target = $target->getUsername();
|
||||
}else{
|
||||
} else{
|
||||
$target = strtolower($n);
|
||||
if($target === "server" or $target === "console" or $target === "rcon"){
|
||||
$target = "Console";
|
||||
}
|
||||
}
|
||||
$mes = implode(" ", $params);
|
||||
$output .= "[me -> ".$target."] ".$mes."\n";
|
||||
$output .= "[me -> " . $target . "] " . $mes . "\n";
|
||||
if($target !== "Console" and $target !== "Rcon"){
|
||||
$this->sendTo(false, "[".$sender." -> me] ".$mes, $target);
|
||||
$this->sendTo(false, "[" . $sender . " -> me] " . $mes, $target);
|
||||
}
|
||||
if($target === "Console" or $sender === "Console"){
|
||||
console("[INFO] [".$sender." -> ".$target."] ".$mes);
|
||||
console("[INFO] [" . $sender . " -> " . $target . "] " . $mes);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*/
|
||||
public function broadcast($message){
|
||||
/**
|
||||
* @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){
|
||||
/**
|
||||
* @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){
|
||||
/**
|
||||
* @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,
|
||||
@ -133,14 +136,14 @@ class ChatAPI{
|
||||
if($owner !== false){
|
||||
if($owner instanceof Player){
|
||||
if($whitelist === false){
|
||||
console("[INFO] <".$owner->getUsername()."> ".$text);
|
||||
console("[INFO] <" . $owner->getUsername() . "> " . $text);
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
if($whitelist === false){
|
||||
console("[INFO] <".$owner."> ".$text);
|
||||
console("[INFO] <" . $owner . "> " . $text);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
if($whitelist === false){
|
||||
console("[INFO] $text");
|
||||
}
|
||||
|
@ -20,12 +20,14 @@
|
||||
*/
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine\ServerAPI as ServerAPI;
|
||||
use PocketMine\Utils\TextFormat as TextFormat;
|
||||
use PocketMine\Player as Player;
|
||||
|
||||
class ConsoleAPI{
|
||||
private $loop, $server, $event, $help, $cmds, $alias;
|
||||
|
||||
function __construct(){
|
||||
$this->help = array();
|
||||
$this->cmds = array();
|
||||
@ -59,103 +61,105 @@ class ConsoleAPI{
|
||||
}
|
||||
|
||||
public function defaultCommands($cmd, $params, $issuer, $alias){
|
||||
$output = "";
|
||||
switch($cmd){
|
||||
case "defaultgamemode":
|
||||
$gms = array(
|
||||
"0" => SURVIVAL,
|
||||
"survival" => SURVIVAL,
|
||||
"s" => SURVIVAL,
|
||||
"1" => CREATIVE,
|
||||
"creative" => CREATIVE,
|
||||
"c" => CREATIVE,
|
||||
"2" => ADVENTURE,
|
||||
"adventure" => ADVENTURE,
|
||||
"a" => ADVENTURE,
|
||||
"3" => VIEW,
|
||||
"view" => VIEW,
|
||||
"viewer" => VIEW,
|
||||
"spectator" => VIEW,
|
||||
"v" => VIEW,
|
||||
);
|
||||
if(!isset($gms[strtolower($params[0])])){
|
||||
$output .= "Usage: /$cmd <mode>\n";
|
||||
break;
|
||||
}
|
||||
$this->server->api->setProperty("gamemode", $gms[strtolower($params[0])]);
|
||||
$output .= "Default Gamemode is now ".strtoupper($this->server->getGamemode()).".\n";
|
||||
break;
|
||||
case "status":
|
||||
if(!($issuer instanceof Player) and $issuer === "console"){
|
||||
$this->server->debugInfo(true);
|
||||
}
|
||||
$info = $this->server->debugInfo();
|
||||
$output .= "TPS: ".$info["tps"].", Memory usage: ".$info["memory_usage"]." (Peak ".$info["memory_peak_usage"].")\n";
|
||||
break;
|
||||
case "update-done":
|
||||
$this->server->api->setProperty("last-update", time());
|
||||
break;
|
||||
case "stop":
|
||||
$this->loop->stop = true;
|
||||
$output .= "Stopping the server\n";
|
||||
$this->server->close();
|
||||
break;
|
||||
case "difficulty":
|
||||
$s = trim(array_shift($params));
|
||||
if($s === "" or (((int) $s) > 3 and ((int) $s) < 0)){
|
||||
$output .= "Usage: /difficulty <0|1|2|3>\n";
|
||||
break;
|
||||
}
|
||||
$this->server->api->setProperty("difficulty", (int) $s);
|
||||
$output .= "Difficulty changed to ".$this->server->difficulty."\n";
|
||||
break;
|
||||
case "?":
|
||||
if($issuer !== "console" and $issuer !== "rcon"){
|
||||
break;
|
||||
}
|
||||
case "help":
|
||||
if(isset($params[0]) and !is_numeric($params[0])){
|
||||
$c = trim(strtolower($params[0]));
|
||||
if(isset($this->help[$c]) or isset($this->alias[$c])){
|
||||
$c = isset($this->help[$c]) ? $c : $this->alias[$c];
|
||||
if($this->server->api->dhandle("console.command.".$c, array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false or $this->server->api->dhandle("console.command", array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false){
|
||||
break;
|
||||
}
|
||||
$output .= "Usage: /$c ".$this->help[$c]."\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
$cmds = array();
|
||||
foreach($this->help as $c => $h){
|
||||
if($this->server->api->dhandle("console.command.".$c, array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false or $this->server->api->dhandle("console.command", array("cmd" => $c, "parameters" => array(), "issuer" => $issuer, "alias" => false)) === false){
|
||||
continue;
|
||||
}
|
||||
$cmds[$c] = $h;
|
||||
}
|
||||
|
||||
$max = ceil(count($cmds) / 5);
|
||||
$page = (int) (isset($params[0]) ? min($max, max(1, intval($params[0]))):1);
|
||||
$output .= TextFormat::RED."-".TextFormat::RESET." Showing help page $page of $max (/help <page>) ".TextFormat::RED."-".TextFormat::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;
|
||||
$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 .= TextFormat::RED . "-" . TextFormat::RESET . " Showing help page $page of $max (/help <page>) " . TextFormat::RED . "-" . TextFormat::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;
|
||||
}
|
||||
|
||||
@ -168,7 +172,7 @@ class ConsoleAPI{
|
||||
$this->help[$cmd] = $help;
|
||||
ksort($this->help, SORT_NATURAL | SORT_FLAG_CASE);
|
||||
}
|
||||
|
||||
|
||||
public function run($line = "", $issuer = "console", $alias = false){
|
||||
if($line != ""){
|
||||
$output = "";
|
||||
@ -179,14 +183,14 @@ class ConsoleAPI{
|
||||
$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);
|
||||
return $this->run($this->alias[$cmd] . ($params !== "" ? " " . $params : ""), $issuer, $cmd);
|
||||
}
|
||||
if($issuer instanceof Player){
|
||||
console("[DEBUG] ".TextFormat::AQUA.$issuer->getUsername().TextFormat::RESET." issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2);
|
||||
}else{
|
||||
console("[DEBUG] ".TextFormat::YELLOW."*".$issuer.TextFormat::RESET." issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2);
|
||||
console("[DEBUG] " . TextFormat::AQUA . $issuer->getUsername() . TextFormat::RESET . " issued server command: " . ltrim("$alias ") . "/$cmd " . $params, true, true, 2);
|
||||
} else{
|
||||
console("[DEBUG] " . TextFormat::YELLOW . "*" . $issuer . TextFormat::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){
|
||||
@ -199,13 +203,13 @@ class ConsoleAPI{
|
||||
case "u":
|
||||
case "player":
|
||||
case "username":
|
||||
$p = ($issuer instanceof Player) ? $issuer->getUsername():$issuer;
|
||||
$p = ($issuer instanceof Player) ? $issuer->getUsername() : $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();
|
||||
$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;
|
||||
@ -215,17 +219,18 @@ class ConsoleAPI{
|
||||
if($this->server->api->ban->isOp($issuer->getUsername())){
|
||||
$output = "";
|
||||
foreach(Player::getAll() as $p){
|
||||
$output .= $this->run($cmd . " ". substr_replace($params, $p->getUsername(), $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias);
|
||||
$output .= $this->run($cmd . " " . substr_replace($params, $p->getUsername(), $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias);
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
$issuer->sendChat("You don't have permissions to use this command.\n");
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
$output = "";
|
||||
foreach(Player::getAll() as $p){
|
||||
$output .= $this->run($cmd . " ". substr_replace($params, $p->getUsername(), $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias);
|
||||
$output .= $this->run($cmd . " " . substr_replace($params, $p->getUsername(), $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias);
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
case "r":
|
||||
case "random":
|
||||
@ -238,7 +243,7 @@ class ConsoleAPI{
|
||||
if(count($l) === 0){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$p = $l[mt_rand(0, count($l) - 1)]->getUsername();
|
||||
$params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1);
|
||||
$offsetshift -= strlen($selector[0]) - strlen($p) + 1;
|
||||
@ -250,21 +255,23 @@ class ConsoleAPI{
|
||||
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){
|
||||
|
||||
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)){
|
||||
} 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){
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
@ -280,10 +287,10 @@ class ConsoleAPI{
|
||||
if($output != ""){
|
||||
$mes = explode("\n", trim($output));
|
||||
foreach($mes as $m){
|
||||
console("[CMD] ".$m);
|
||||
console("[CMD] " . $m);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
$this->loop->notify();
|
||||
}
|
||||
}
|
||||
@ -296,6 +303,7 @@ class ConsoleLoop extends \Thread{
|
||||
public $base;
|
||||
public $ev;
|
||||
public $fp;
|
||||
|
||||
public function __construct(){
|
||||
$this->line = false;
|
||||
$this->stop = false;
|
||||
@ -309,12 +317,13 @@ class ConsoleLoop extends \Thread{
|
||||
private function readLine(){
|
||||
if($this->fp){
|
||||
$line = trim(fgets($this->fp));
|
||||
}else{
|
||||
} else{
|
||||
$line = trim(readline(""));
|
||||
if($line != ""){
|
||||
readline_add_history( $line );
|
||||
readline_add_history($line);
|
||||
}
|
||||
}
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
||||
|
@ -20,10 +20,12 @@
|
||||
*/
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine;
|
||||
|
||||
class Container{
|
||||
private $payload = "", $whitelist = false, $blacklist = false;
|
||||
|
||||
public function __construct($payload = "", $whitelist = false, $blacklist = false){
|
||||
$this->payload = $payload;
|
||||
if(is_array($whitelist)){
|
||||
@ -33,11 +35,11 @@ class Container{
|
||||
$this->blacklist = $blacklist;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get(){
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
|
||||
public function check($target){
|
||||
$w = true;
|
||||
$b = false;
|
||||
@ -46,7 +48,7 @@ class Container{
|
||||
if(in_array($target, $this->whitelist, true)){
|
||||
$w = true;
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
$w = true;
|
||||
}
|
||||
if($this->blacklist !== false){
|
||||
@ -54,16 +56,17 @@ class Container{
|
||||
if(in_array($target, $this->blacklist, true)){
|
||||
$b = true;
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
$b = false;
|
||||
}
|
||||
if($w === false or $b === true){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function __toString(){
|
||||
return $this->payload;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
//TODO: REMOVE
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine\ServerAPI as ServerAPI;
|
||||
|
||||
class Deprecation{
|
||||
|
2038
src/EntityOLD.php
2038
src/EntityOLD.php
File diff suppressed because it is too large
Load Diff
@ -14,12 +14,13 @@
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine\ServerAPI as ServerAPI;
|
||||
use PocketMine\Level\Generator\Flat as Flat;
|
||||
use PocketMine\Level\Generator\Normal as Normal;
|
||||
@ -44,18 +45,20 @@ use PocketMine\Level\Position as Position;
|
||||
|
||||
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];
|
||||
}
|
||||
@ -72,7 +75,7 @@ class LevelAPI{
|
||||
}
|
||||
$this->server->spawn = $this->getDefault()->getSafeSpawn();
|
||||
}
|
||||
|
||||
|
||||
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||
$output = "";
|
||||
switch($cmd){
|
||||
@ -90,18 +93,19 @@ class LevelAPI{
|
||||
break;
|
||||
case "seed":
|
||||
if(!isset($params[0]) and ($issuer instanceof Player)){
|
||||
$output .= "Seed: ".$issuer->level->getSeed()."\n";
|
||||
}elseif(isset($params[0])){
|
||||
$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";
|
||||
$output .= "Seed: " . $lv->getSeed() . "\n";
|
||||
}
|
||||
}else{
|
||||
$output .= "Seed: ".$this->server->api->level->getDefault()->getSeed()."\n";
|
||||
} else{
|
||||
$output .= "Seed: " . $this->server->api->level->getDefault()->getSeed() . "\n";
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
public function generateLevel($name, $seed = false, $generator = false){
|
||||
if($name == "" or $this->levelExists($name)){
|
||||
return false;
|
||||
@ -113,39 +117,41 @@ class LevelAPI{
|
||||
|
||||
if($generator !== false and class_exists($generator)){
|
||||
$generator = new $generator($options);
|
||||
}else{
|
||||
} else{
|
||||
if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){
|
||||
$generator = new Flat($options);
|
||||
}else{
|
||||
} else{
|
||||
$generator = new Normal($options);
|
||||
}
|
||||
}
|
||||
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):(int) $seed);
|
||||
$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 = \PocketMine\DATA."worlds/".$name."/";
|
||||
if($this->get($name) === false and !file_exists($path."level.pmf")){
|
||||
$path = \PocketMine\DATA . "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."\"");
|
||||
console("[INFO] Unloading level \"" . $name . "\"");
|
||||
$level->nextSave = PHP_INT_MAX;
|
||||
$level->save();
|
||||
foreach($level->getPlayers() as $player){
|
||||
@ -153,28 +159,31 @@ class LevelAPI{
|
||||
}
|
||||
$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");
|
||||
} elseif($this->levelExists($name) === false){
|
||||
console("[NOTICE] Level \"" . $name . "\" not found");
|
||||
|
||||
return false;
|
||||
}
|
||||
$path = \PocketMine\DATA."worlds/".$name."/";
|
||||
console("[INFO] Preparing level \"".$name."\"");
|
||||
$level = new LevelFormat($path."level.pmf");
|
||||
$path = \PocketMine\DATA . "worlds/" . $name . "/";
|
||||
console("[INFO] Preparing level \"" . $name . "\"");
|
||||
$level = new LevelFormat($path . "level.pmf");
|
||||
if(!$level->isLoaded){
|
||||
console("[ERROR] Could not load level \"".$name."\"");
|
||||
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");
|
||||
if(file_exists($path . "tileEntities.yml")){
|
||||
@rename($path . "tileEntities.yml", $path . "tiles.yml");
|
||||
}
|
||||
$blockUpdates = new Config($path."bupdates.yml", Config::YAML);
|
||||
$blockUpdates = new Config($path . "bupdates.yml", Config::YAML);
|
||||
$this->levels[$name] = new Level($level, $name);
|
||||
/*foreach($entities->getAll() as $entity){
|
||||
if(!isset($entity["id"])){
|
||||
@ -204,22 +213,22 @@ class LevelAPI{
|
||||
$e->setHealth($entity["Health"]);
|
||||
}
|
||||
}*/
|
||||
|
||||
if(file_exists($path ."tiles.yml")){
|
||||
$tiles = new Config($path."tiles.yml", Config::YAML);
|
||||
|
||||
if(file_exists($path . "tiles.yml")){
|
||||
$tiles = new Config($path . "tiles.yml", Config::YAML);
|
||||
foreach($tiles->getAll() as $tile){
|
||||
if(!isset($tile["id"])){
|
||||
continue;
|
||||
}
|
||||
$this->levels[$name]->loadChunk($tile["x"] >> 4, $tile["z"] >> 4);
|
||||
|
||||
|
||||
$nbt = new Compound(false, array());
|
||||
foreach($tile as $index => $data){
|
||||
switch($index){
|
||||
case "Items":
|
||||
$tag = new Enum("Items", array());
|
||||
$tag->setTagType(NBT\TAG_Compound);
|
||||
foreach($data as $slot => $fields){
|
||||
foreach($data as $slot => $fields){
|
||||
$tag[(int) $slot] = new Compound(false, array(
|
||||
"Count" => new Byte("Count", $fields["Count"]),
|
||||
"Slot" => new Short("Slot", $fields["Slot"]),
|
||||
@ -229,7 +238,7 @@ class LevelAPI{
|
||||
}
|
||||
$nbt["Items"] = $tag;
|
||||
break;
|
||||
|
||||
|
||||
case "id":
|
||||
case "Text1":
|
||||
case "Text2":
|
||||
@ -237,7 +246,7 @@ class LevelAPI{
|
||||
case "Text4":
|
||||
$nbt[$index] = new String($index, $data);
|
||||
break;
|
||||
|
||||
|
||||
case "x":
|
||||
case "y":
|
||||
case "z":
|
||||
@ -245,7 +254,7 @@ class LevelAPI{
|
||||
case "pairz":
|
||||
$nbt[$index] = new Int($index, $data);
|
||||
break;
|
||||
|
||||
|
||||
case "BurnTime":
|
||||
case "CookTime":
|
||||
case "MaxTime":
|
||||
@ -265,13 +274,14 @@ class LevelAPI{
|
||||
break;
|
||||
}
|
||||
}
|
||||
unlink($path ."tiles.yml");
|
||||
unlink($path . "tiles.yml");
|
||||
$this->levels[$name]->save(true, true);
|
||||
}
|
||||
|
||||
|
||||
foreach($blockUpdates->getAll() as $bupdate){
|
||||
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
|
||||
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"], (int) $bupdate["y"], (int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -279,13 +289,13 @@ class LevelAPI{
|
||||
switch($event){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function saveAll(){
|
||||
foreach($this->levels as $level){
|
||||
$level->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function __destruct(){
|
||||
$this->saveAll();
|
||||
foreach($this->levels as $level){
|
||||
@ -296,9 +306,9 @@ class LevelAPI{
|
||||
public function getSpawn(){
|
||||
return $this->server->spawn;
|
||||
}
|
||||
|
||||
|
||||
public function getAll(){
|
||||
return $this->levels;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
555
src/Player.php
555
src/Player.php
File diff suppressed because it is too large
Load Diff
@ -14,12 +14,13 @@
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine\ServerAPI as ServerAPI;
|
||||
use PocketMine\Entity\Entity as Entity;
|
||||
use PocketMine\Player as Player;
|
||||
@ -29,6 +30,7 @@ use PocketMine\Level\Position as Position;
|
||||
|
||||
class PlayerAPI{
|
||||
private $server;
|
||||
|
||||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
@ -75,14 +77,14 @@ class PlayerAPI{
|
||||
if($e instanceof Entity){
|
||||
switch($e->class){
|
||||
case ENTITY_PLAYER:
|
||||
$message = " was killed by ".$e->name;
|
||||
$message = " was killed by " . $e->name;
|
||||
break;
|
||||
default:
|
||||
$message = " was killed";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
switch($data["cause"]){
|
||||
case "cactus":
|
||||
$message = " was pricked to death";
|
||||
@ -117,8 +119,10 @@ class PlayerAPI{
|
||||
}
|
||||
}
|
||||
$this->server->api->chat->broadcast($data["player"]->getUsername() . $message);
|
||||
|
||||
return true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||
@ -138,10 +142,10 @@ class PlayerAPI{
|
||||
$tg = array_shift($params);
|
||||
if(count($params) === 3 and substr($tg, 0, 2) === "w:"){
|
||||
$target = $this->server->api->level->get(substr($tg, 2));
|
||||
}else{
|
||||
} else{
|
||||
$target = Player::get($tg);
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
$target = $issuer;
|
||||
}
|
||||
|
||||
@ -153,20 +157,20 @@ class PlayerAPI{
|
||||
if(count($params) === 3){
|
||||
if($target instanceof Level){
|
||||
$spawn = new Vector3(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)));
|
||||
}else{
|
||||
} else{
|
||||
$spawn = new Position(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)), $issuer->level);
|
||||
}
|
||||
}else{
|
||||
} 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->getUsername()." set correctly!\n";
|
||||
}else{
|
||||
$output .= "Spawnpoint set correctly!\n";
|
||||
$output .= "Spawnpoint of world " . $target->getName() . " set correctly!\n";
|
||||
} elseif($target !== $issuer){
|
||||
$output .= "Spawnpoint of " . $target->getUsername() . " set correctly!\n";
|
||||
} else{
|
||||
$output .= "Spawnpoint set correctly!\n";
|
||||
}
|
||||
break;
|
||||
case "spawn":
|
||||
@ -181,7 +185,7 @@ class PlayerAPI{
|
||||
$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";
|
||||
$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;
|
||||
@ -206,14 +210,14 @@ class PlayerAPI{
|
||||
if(Player::get($params[1]) instanceof Player){
|
||||
$player = Player::get($params[1]);
|
||||
$setgm = $params[0];
|
||||
}elseif(Player::get($params[0]) instanceof Player){
|
||||
} elseif(Player::get($params[0]) instanceof Player){
|
||||
$player = Player::get($params[0]);
|
||||
$setgm = $params[1];
|
||||
}else{
|
||||
} else{
|
||||
$output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n";
|
||||
break;
|
||||
}
|
||||
}elseif(isset($params[0])){
|
||||
} elseif(isset($params[0])){
|
||||
if(!(Player::get($params[0]) instanceof Player)){
|
||||
if($issuer instanceof Player){
|
||||
$setgm = $params[0];
|
||||
@ -227,7 +231,7 @@ class PlayerAPI{
|
||||
break;
|
||||
}
|
||||
if($player->setGamemode($gms[strtolower($setgm)])){
|
||||
$output .= "Gamemode of ".$player->getUsername()." changed to ".$player->getGamemode()."\n";
|
||||
$output .= "Gamemode of " . $player->getUsername() . " changed to " . $player->getGamemode() . "\n";
|
||||
}
|
||||
break;
|
||||
case "tp":
|
||||
@ -235,36 +239,36 @@ class PlayerAPI{
|
||||
if((!isset($params[1]) or substr($params[0], 0, 2) === "w:") and isset($params[0]) and ($issuer instanceof Player)){
|
||||
$name = $issuer->getUsername();
|
||||
$target = implode(" ", $params);
|
||||
}elseif(isset($params[1]) and isset($params[0])){
|
||||
} elseif(isset($params[1]) and isset($params[0])){
|
||||
$name = array_shift($params);
|
||||
$target = implode(" ", $params);
|
||||
}else{
|
||||
} 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{
|
||||
} else{
|
||||
$output .= "Couldn't teleport.\n";
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
if(!isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0]) and ($issuer instanceof Player)){
|
||||
$name = $issuer->getUsername();
|
||||
$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])){
|
||||
} 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{
|
||||
} 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{
|
||||
} else{
|
||||
$output .= "Couldn't teleport.\n";
|
||||
}
|
||||
}
|
||||
@ -273,27 +277,28 @@ class PlayerAPI{
|
||||
case "suicide":
|
||||
if(!isset($params[0]) and ($issuer instanceof Player)){
|
||||
$player = $issuer;
|
||||
}else{
|
||||
} else{
|
||||
$player = Player::get($params[0]);
|
||||
}
|
||||
if($player instanceof Player){
|
||||
$player->entity->harm(1000, "console", true);
|
||||
$player->sendChat("Ouch. That looks like it hurt.\n");
|
||||
}else{
|
||||
} else{
|
||||
$output .= "Usage: /$cmd [player]\n";
|
||||
}
|
||||
break;
|
||||
case "list":
|
||||
$output .= "There are ".count(Player::$list)."/".$this->server->maxClients." players online:\n";
|
||||
$output .= "There are " . count(Player::$list) . "/" . $this->server->maxClients . " players online:\n";
|
||||
if(count(Player::$list) == 0){
|
||||
break;
|
||||
}
|
||||
foreach(Player::$list as $c){
|
||||
$output .= $c->getUsername().", ";
|
||||
$output .= $c->getUsername() . ", ";
|
||||
}
|
||||
$output = substr($output, 0, -2)."\n";
|
||||
$output = substr($output, 0, -2) . "\n";
|
||||
break;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
@ -304,9 +309,10 @@ class PlayerAPI{
|
||||
$origin = Player::get($name);
|
||||
if($origin instanceof Player){
|
||||
$name = $origin->getUsername();
|
||||
|
||||
return $origin->teleport($lv->getSafeSpawn());
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -316,9 +322,11 @@ class PlayerAPI{
|
||||
$origin = Player::get($name);
|
||||
if($origin instanceof Player){
|
||||
$name = $origin->getUsername();
|
||||
|
||||
return $origin->teleport($player->entity);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -326,12 +334,14 @@ class PlayerAPI{
|
||||
$player = Player::get($name);
|
||||
if($player instanceof Player and $player->spawned === true){
|
||||
$name = $player->getUsername();
|
||||
$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);
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine\ServerAPI as ServerAPI;
|
||||
use PocketMine\Utils\Utils as Utils;
|
||||
use PocketMine\Network\Protocol\Info as Info;
|
||||
@ -31,6 +32,7 @@ class PluginAPI extends \stdClass{
|
||||
private $server;
|
||||
private $plugins = array();
|
||||
private $randomNonce;
|
||||
|
||||
public function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
$this->randomNonce = Utils::getRandomBytes(16, false);
|
||||
@ -38,28 +40,29 @@ class PluginAPI extends \stdClass{
|
||||
$this->server->api->console->register("version", "", array($this, "commandHandler"));
|
||||
$this->server->api->ban->cmdWhitelist("version");
|
||||
}
|
||||
|
||||
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||
|
||||
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 .= $plugin["name"] . ": " . $plugin["version"] . ", ";
|
||||
}
|
||||
$output = $output === "Plugins: " ? "No plugins installed.\n" : substr($output, 0, -2)."\n";
|
||||
$output = $output === "Plugins: " ? "No plugins installed.\n" : substr($output, 0, -2) . "\n";
|
||||
break;
|
||||
case "version":
|
||||
$output = "PocketMine-MP ".VERSION." 「".CODENAME."」 API #".API_VERSION." for Minecraft: PE ".MINECRAFT_VERSION." protocol #".Info::CURRENT_PROTOCOL;
|
||||
$output = "PocketMine-MP " . VERSION . " 「" . CODENAME . "」 API #" . API_VERSION . " for Minecraft: PE " . MINECRAFT_VERSION . " protocol #" . Info::CURRENT_PROTOCOL;
|
||||
if(GIT_COMMIT !== str_repeat("00", 20)){
|
||||
$output .= " (git ".GIT_COMMIT.")";
|
||||
$output .= " (git " . GIT_COMMIT . ")";
|
||||
}
|
||||
$output .= "\n";
|
||||
break;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
public function __destruct(){
|
||||
foreach($this->plugins as $p){
|
||||
$p[0]->__destruct();
|
||||
@ -72,27 +75,30 @@ class PluginAPI extends \stdClass{
|
||||
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");
|
||||
console("[ERROR] " . basename($file) . " is not a file");
|
||||
|
||||
return false;
|
||||
}
|
||||
if(strtolower(substr($file, -3)) === "pmf"){
|
||||
$pmf = new PMFPlugin($file);
|
||||
$info = $pmf->getPluginInfo();
|
||||
}else{
|
||||
} else{
|
||||
$content = file_get_contents($file);
|
||||
$info = strstr($content, "*/", true);
|
||||
$content = str_repeat(PHP_EOL, substr_count($info, "\n")).substr(strstr($content, "*/"),2);
|
||||
$content = str_repeat(PHP_EOL, substr_count($info, "\n")) . substr(strstr($content, "*/"), 2);
|
||||
if(preg_match_all('#([a-zA-Z0-9\-_]*)=([^\r\n]*)#u', $info, $matches) == 0){ //false or 0 matches
|
||||
console("[ERROR] Failed parsing of ".basename($file));
|
||||
console("[ERROR] Failed parsing of " . basename($file));
|
||||
|
||||
return false;
|
||||
}
|
||||
$info = array();
|
||||
@ -116,42 +122,46 @@ class PluginAPI extends \stdClass{
|
||||
$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));
|
||||
console("[ERROR] Failed parsing of " . basename($file));
|
||||
|
||||
return false;
|
||||
}
|
||||
console("[INFO] Loading plugin \"".TextFormat::GREEN.$info["name"].TextFormat::RESET."\" ".TextFormat::AQUA.$info["version"].TextFormat::RESET." by ".TextFormat::AQUA.$info["author"].TextFormat::RESET);
|
||||
console("[INFO] Loading plugin \"" . TextFormat::GREEN . $info["name"] . TextFormat::RESET . "\" " . TextFormat::AQUA . $info["version"] . TextFormat::RESET . " by " . TextFormat::AQUA . $info["author"] . TextFormat::RESET);
|
||||
if($info["class"] !== "none" and class_exists($info["class"])){
|
||||
console("[ERROR] Failed loading plugin: class already exists");
|
||||
|
||||
return false;
|
||||
}
|
||||
if(((!isset($pmf) and (include $file) === false) or (isset($pmf) and eval($info["code"]) === false)) and $info["class"] !== "none" and !class_exists($info["class"])){
|
||||
console("[ERROR] Failed loading {$info['name']}: evaluation error");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$className = $info["class"];
|
||||
$apiversion = array_map("intval", explode(",", (string) $info["apiversion"]));
|
||||
if(!in_array(API_VERSION, $apiversion)){
|
||||
console("[WARNING] Plugin \"".$info["name"]."\" may not be compatible with the API (".$info["apiversion"]." != ".API_VERSION.")! It can crash or corrupt the server!");
|
||||
console("[WARNING] Plugin \"" . $info["name"] . "\" may not be compatible with the API (" . $info["apiversion"] . " != " . API_VERSION . ")! It can crash or corrupt the server!");
|
||||
}
|
||||
|
||||
|
||||
$identifier = $this->getIdentifier($info["name"], $info["author"]);
|
||||
|
||||
if($info["class"] !== "none"){
|
||||
|
||||
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");
|
||||
console("[ERROR] Plugin \"" . $info["name"] . "\" doesn't use the Plugin Interface");
|
||||
if(method_exists($object, "__destruct")){
|
||||
$object->__destruct();
|
||||
}
|
||||
$object = null;
|
||||
unset($object);
|
||||
}else{
|
||||
} else{
|
||||
$this->plugins[$identifier] = array($object, $info);
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
$this->plugins[$identifier] = array(new DummyPlugin($this->server->api, false), $info);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -166,21 +176,24 @@ class PluginAPI extends \stdClass{
|
||||
return $p;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
if(isset($this->plugins[$identifier])){
|
||||
return $this->plugins[$identifier];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function pluginsPath(){
|
||||
$path = join(DIRECTORY_SEPARATOR, array(\PocketMine\DATA."plugins", ""));
|
||||
$path = join(DIRECTORY_SEPARATOR, array(\PocketMine\DATA . "plugins", ""));
|
||||
@mkdir($path);
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function configPath(Plugin $plugin){
|
||||
$p = $this->get($plugin);
|
||||
$identifier = $this->getIdentifier($p[1]["name"], $p[1]["author"]);
|
||||
@ -190,6 +203,7 @@ class PluginAPI extends \stdClass{
|
||||
$path = $this->pluginsPath() . $p[1]["name"] . DIRECTORY_SEPARATOR;
|
||||
$this->plugins[$identifier][1]["path"] = $path;
|
||||
@mkdir($path);
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
@ -199,8 +213,9 @@ class PluginAPI extends \stdClass{
|
||||
return false;
|
||||
}
|
||||
$path = $this->configPath($plugin);
|
||||
$cnf = new Config($path."config.yml", Config::YAML, $default);
|
||||
$cnf = new Config($path . "config.yml", Config::YAML, $default);
|
||||
$cnf->save();
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
@ -228,7 +243,7 @@ class PluginAPI extends \stdClass{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function initAll(){
|
||||
console("[INFO] Starting plugins...");
|
||||
foreach($this->plugins as $p){
|
||||
@ -240,17 +255,19 @@ class PluginAPI extends \stdClass{
|
||||
|
||||
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 __construct(ServerAPI $api, $server = false){
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
}
|
||||
|
||||
|
||||
public function __destruct(){
|
||||
}
|
||||
}
|
||||
|
221
src/Server.php
221
src/Server.php
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine\Utils\VersionString as VersionString;
|
||||
use PocketMine\Utils\Utils as Utils;
|
||||
use PocketMine\Network\Handler as Handler;
|
||||
@ -40,16 +41,16 @@ class Server{
|
||||
* @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);
|
||||
@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);
|
||||
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->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;
|
||||
@ -85,26 +86,27 @@ class Server{
|
||||
$this->doTick = true;
|
||||
$this->gamemode = (int) $gamemode;
|
||||
$this->name = $name;
|
||||
$this->motd = "Welcome to ".$name;
|
||||
$this->motd = "Welcome to " . $name;
|
||||
$this->serverID = false;
|
||||
$this->seed = $seed;
|
||||
$this->serverip = $serverip;
|
||||
$this->load();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getTPS(){
|
||||
/**
|
||||
* @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 ANSI === true){
|
||||
echo "\x1b]0;PocketMine-MP ".VERSION." | Online ". count(Player::$list)."/".$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";
|
||||
echo "\x1b]0;PocketMine-MP " . VERSION . " | Online " . count(Player::$list) . "/" . $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);
|
||||
}
|
||||
@ -118,16 +120,16 @@ class Server{
|
||||
$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"];
|
||||
$data = $info["memory_usage"] . "," . $info["players"] . "," . $info["entities"];
|
||||
$i = count($this->memoryStats) - 1;
|
||||
if($i < 0 or $this->memoryStats[$i] !== $data){
|
||||
$this->memoryStats[] = $data;
|
||||
@ -152,18 +154,19 @@ class Server{
|
||||
}
|
||||
|
||||
public function query($sql, $fetch = false){
|
||||
$result = $this->database->query($sql) or console("[ERROR] [SQL Error] ".$this->database->lastErrorMsg().". Query: ".$sql, true, true, 0);
|
||||
$result = $this->database->query($sql) or console("[ERROR] [SQL Error] " . $this->database->lastErrorMsg() . ". Query: " . $sql, true, true, 0);
|
||||
if($fetch === true and ($result instanceof \SQLite3Result)){
|
||||
$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["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"] = count(Entity::$list);
|
||||
$info["players"] = count(Player::$list);
|
||||
$info["events"] = count($this->eventsID);
|
||||
@ -174,15 +177,16 @@ class Server{
|
||||
$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);
|
||||
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"){
|
||||
/**
|
||||
* @param string $reason
|
||||
*/
|
||||
public function close($reason = "server stop"){
|
||||
if($this->stop !== true){
|
||||
if(is_int($reason)){
|
||||
$reason = "signal stop";
|
||||
@ -195,7 +199,7 @@ class Server{
|
||||
$this->stop = true;
|
||||
$this->trigger("server.close", $reason);
|
||||
$this->interface->close();
|
||||
|
||||
|
||||
if(!defined("NO_THREADS")){
|
||||
@$this->asyncThread->stop = true;
|
||||
}
|
||||
@ -214,7 +218,7 @@ class Server{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function asyncOperation($type, array $data, callable $callable = null){
|
||||
if(defined("NO_THREADS")){
|
||||
return false;
|
||||
@ -223,28 +227,29 @@ class Server{
|
||||
$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));
|
||||
$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(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;
|
||||
$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;
|
||||
$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;
|
||||
$this->asyncThread->input .= Utils::writeInt($ID) . Utils::writeShort($type) . $d;
|
||||
|
||||
return $ID;
|
||||
}
|
||||
|
||||
|
||||
public function asyncOperationChecker(){
|
||||
if(defined("NO_THREADS")){
|
||||
return false;
|
||||
@ -276,7 +281,7 @@ class Server{
|
||||
if(is_array($this->async[$ID])){
|
||||
$method = $this->async[$ID][1];
|
||||
$result = $this->async[$ID][0]->$method($data, $type, $ID);
|
||||
}else{
|
||||
} else{
|
||||
$result = $this->async[$ID]($data, $type, $ID);
|
||||
}
|
||||
}
|
||||
@ -284,31 +289,32 @@ class Server{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $event
|
||||
* @param callable $callable
|
||||
* @param integer $priority
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function addHandler($event,callable $callable, $priority = 5){
|
||||
/**
|
||||
* @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])){
|
||||
} elseif(isset(Deprecation::$events[$event])){
|
||||
$sub = "";
|
||||
if(Deprecation::$events[$event] !== false){
|
||||
$sub = " Substitute \"".Deprecation::$events[$event]."\" found.";
|
||||
$sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
|
||||
}
|
||||
console("[ERROR] Event \"$event\" has been deprecated.$sub [Adding handle to ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)."]");
|
||||
console("[ERROR] Event \"$event\" has been deprecated.$sub [Adding handle to " . (is_array($callable) ? get_class($callable[0]) . "::" . $callable[1] : $callable) . "]");
|
||||
}
|
||||
$priority = (int) $priority;
|
||||
$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);
|
||||
$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);
|
||||
}
|
||||
@ -331,17 +337,17 @@ class Server{
|
||||
if(is_array($handler)){
|
||||
$method = $handler[1];
|
||||
$result = $handler[0]->$method($data, $event);
|
||||
}else{
|
||||
} else{
|
||||
$result = $handler($data, $event);
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}elseif(isset(Deprecation::$events[$event])){
|
||||
} elseif(isset(Deprecation::$events[$event])){
|
||||
$sub = "";
|
||||
if(Deprecation::$events[$event] !== false){
|
||||
$sub = " Substitute \"".Deprecation::$events[$event]."\" found.";
|
||||
$sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
|
||||
}
|
||||
console("[ERROR] Event \"$event\" has been deprecated.$sub [Handler]");
|
||||
}
|
||||
@ -349,6 +355,7 @@ class Server{
|
||||
if($result !== false){
|
||||
$this->trigger($event, $data);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -358,10 +365,10 @@ class Server{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getGamemode(){
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getGamemode(){
|
||||
switch($this->gamemode){
|
||||
case SURVIVAL:
|
||||
return "survival";
|
||||
@ -375,10 +382,9 @@ class Server{
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function init(){
|
||||
public function init(){
|
||||
register_tick_function(array($this, "tick"));
|
||||
declare(ticks=5000); //Minimum TPS for main thread locks
|
||||
declare(ticks = 5000); //Minimum TPS for main thread locks
|
||||
|
||||
$this->loadEvents();
|
||||
register_shutdown_function(array($this, "dumpError"));
|
||||
@ -388,9 +394,9 @@ class Server{
|
||||
pcntl_signal(SIGINT, array($this, "close"));
|
||||
pcntl_signal(SIGHUP, array($this, "close"));
|
||||
}
|
||||
console("[INFO] Default game type: ".strtoupper($this->getGamemode()));
|
||||
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 "?"');
|
||||
console('[INFO] Done (' . round(microtime(true) - START_TIME, 3) . 's)! For help, type "help" or "?"');
|
||||
$this->process();
|
||||
}
|
||||
|
||||
@ -400,7 +406,7 @@ class Server{
|
||||
}
|
||||
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";
|
||||
$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",
|
||||
@ -419,16 +425,16 @@ class Server{
|
||||
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";
|
||||
$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 .= "[" . ($l + 1) . "] " . @$file[$l] . "\r\n";
|
||||
}
|
||||
$dump .= "\r\n\r\n";
|
||||
$dump .= "Backtrace: \r\n";
|
||||
@ -437,43 +443,43 @@ class Server{
|
||||
}
|
||||
$dump .= "\r\n\r\n";
|
||||
$version = new VersionString();
|
||||
$dump .= "PocketMine-MP version: ".$version." #".$version->getNumber()." [Protocol ".Info::CURRENT_PROTOCOL."; API ".API_VERSION."]\r\n";
|
||||
$dump .= "Git commit: ".GIT_COMMIT."\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";
|
||||
$dump .= "PocketMine-MP version: " . $version . " #" . $version->getNumber() . " [Protocol " . Info::CURRENT_PROTOCOL . "; API " . API_VERSION . "]\r\n";
|
||||
$dump .= "Git commit: " . GIT_COMMIT . "\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";
|
||||
$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";
|
||||
$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 .= $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";
|
||||
|
||||
$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";
|
||||
$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";
|
||||
$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");
|
||||
$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);
|
||||
}
|
||||
@ -484,8 +490,10 @@ class Server{
|
||||
$this->tickMeasure[] = $this->lastTick = $time;
|
||||
unset($this->tickMeasure[key($this->tickMeasure)]);
|
||||
++$this->ticks;
|
||||
|
||||
return $this->tickerFunction($time);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -499,7 +507,7 @@ class Server{
|
||||
$CID = Server::clientID($packet->ip, $packet->port);
|
||||
if(isset(Player::$list[$CID])){
|
||||
Player::$list[$CID]->handlePacket($packet);
|
||||
}else{
|
||||
} else{
|
||||
switch($packet->pid()){
|
||||
case RakNetInfo::UNCONNECTED_PING:
|
||||
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
|
||||
@ -513,33 +521,33 @@ class Server{
|
||||
$this->send($pk);
|
||||
break;
|
||||
}
|
||||
if(!isset($this->custom["times_".$CID])){
|
||||
$this->custom["times_".$CID] = 0;
|
||||
if(!isset($this->custom["times_" . $CID])){
|
||||
$this->custom["times_" . $CID] = 0;
|
||||
}
|
||||
$ln = 15;
|
||||
if($this->description == "" or substr($this->description, -1) != " "){
|
||||
if($this->description == "" or substr($this->description, -1) != " "){
|
||||
$this->description .= " ";
|
||||
}
|
||||
$txt = substr($this->description, $this->custom["times_".$CID], $ln);
|
||||
$txt = substr($this->description, $this->custom["times_" . $CID], $ln);
|
||||
$txt .= substr($this->description, 0, $ln - strlen($txt));
|
||||
$pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
|
||||
$pk->pingID = $packet->pingID;
|
||||
$pk->serverID = $this->serverID;
|
||||
$pk->serverType = $this->serverType . $this->name . " [".count(Player::$list)."/".$this->maxClients."] ".$txt;
|
||||
$pk->serverType = $this->serverType . $this->name . " [" . count(Player::$list) . "/" . $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);
|
||||
$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);
|
||||
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{
|
||||
} else{
|
||||
$pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1);
|
||||
$pk->serverID = $this->serverID;
|
||||
$pk->mtuSize = strlen($packet->buffer);
|
||||
@ -552,7 +560,7 @@ class Server{
|
||||
if($this->invisible === true){
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
new Player($packet->clientID, $packet->ip, $packet->port, $packet->mtuSize); //New Session!
|
||||
$pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_2);
|
||||
$pk->serverID = $this->serverID;
|
||||
@ -580,15 +588,15 @@ class Server{
|
||||
}
|
||||
if($this->tick() > 0){
|
||||
$lastLoop = 0;
|
||||
}else{
|
||||
} else{
|
||||
++$lastLoop;
|
||||
if($lastLoop < 64){
|
||||
|
||||
}elseif($lastLoop < 256){
|
||||
} elseif($lastLoop < 256){
|
||||
usleep(100);
|
||||
}elseif($lastLoop < 512){
|
||||
} elseif($lastLoop < 512){
|
||||
usleep(512);
|
||||
}else{
|
||||
} else{
|
||||
usleep(5000);
|
||||
}
|
||||
}
|
||||
@ -605,14 +613,14 @@ class Server{
|
||||
if(is_array($ev)){
|
||||
$method = $ev[1];
|
||||
$ev[0]->$method($data, $event);
|
||||
}else{
|
||||
} else{
|
||||
$ev($data, $event);
|
||||
}
|
||||
}
|
||||
}elseif(isset(Deprecation::$events[$event])){
|
||||
} elseif(isset(Deprecation::$events[$event])){
|
||||
$sub = "";
|
||||
if(Deprecation::$events[$event] !== false){
|
||||
$sub = " Substitute \"".Deprecation::$events[$event]."\" found.";
|
||||
$sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
|
||||
}
|
||||
console("[ERROR] Event \"$event\" has been deprecated.$sub [Trigger]");
|
||||
}
|
||||
@ -624,7 +632,8 @@ class Server{
|
||||
}
|
||||
$chcnt = $this->scheduleCnt++;
|
||||
$this->schedule[$chcnt] = array($callback, $data, $eventName);
|
||||
$this->query("INSERT INTO actions (ID, interval, last, repeat) VALUES(".$chcnt.", ".($ticks / 20).", ".microtime(true).", ".(((bool) $repeat) === true ? 1:0).");");
|
||||
$this->query("INSERT INTO actions (ID, interval, last, repeat) VALUES(" . $chcnt . ", " . ($ticks / 20) . ", " . microtime(true) . ", " . (((bool) $repeat) === true ? 1 : 0) . ");");
|
||||
|
||||
return $chcnt;
|
||||
}
|
||||
|
||||
@ -644,31 +653,32 @@ class Server{
|
||||
$this->preparedSQL->updateAction->execute();
|
||||
if(!@is_callable($this->schedule[$cid][0])){
|
||||
$return = false;
|
||||
}else{
|
||||
} else{
|
||||
++$actionCount;
|
||||
$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->query("DELETE FROM actions WHERE ID = " . $action["ID"] . ";");
|
||||
$this->schedule[$cid] = null;
|
||||
unset($this->schedule[$cid]);
|
||||
}
|
||||
}
|
||||
$actions->finalize();
|
||||
}
|
||||
|
||||
return $actionCount;
|
||||
}
|
||||
|
||||
public function event($event,callable $func){
|
||||
public function event($event, callable $func){
|
||||
if(!is_callable($func)){
|
||||
return false;
|
||||
}elseif(isset(Deprecation::$events[$event])){
|
||||
} elseif(isset(Deprecation::$events[$event])){
|
||||
$sub = "";
|
||||
if(Deprecation::$events[$event] !== false){
|
||||
$sub = " Substitute \"".Deprecation::$events[$event]."\" found.";
|
||||
$sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
|
||||
}
|
||||
console("[ERROR] Event \"$event\" has been deprecated.$sub [Attach to ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)."]");
|
||||
console("[ERROR] Event \"$event\" has been deprecated.$sub [Attach to " . (is_array($func) ? get_class($func[0]) . "::" . $func[1] : $func) . "]");
|
||||
}
|
||||
$evid = $this->evCnt++;
|
||||
if(!isset($this->events[$event])){
|
||||
@ -676,7 +686,8 @@ class Server{
|
||||
}
|
||||
$this->events[$event][$evid] = $func;
|
||||
$this->eventsID[$evid] = $event;
|
||||
console("[INTERNAL] Attached ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)." to event ".$event." (ID ".$evid.")", true, true, 3);
|
||||
console("[INTERNAL] Attached " . (is_array($func) ? get_class($func[0]) . "::" . $func[1] : $func) . " to event " . $event . " (ID " . $evid . ")", true, true, 3);
|
||||
|
||||
return $evid;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine\Utils\VersionString as VersionString;
|
||||
use PocketMine\Utils\TextFormat as TextFormat;
|
||||
use PocketMine\Utils\Config as Config;
|
||||
@ -43,10 +44,10 @@ class ServerAPI{
|
||||
private $apiList = array();
|
||||
private $asyncCnt = 0;
|
||||
private $rcon;
|
||||
|
||||
|
||||
public $query;
|
||||
|
||||
//TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs.
|
||||
//TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs.
|
||||
|
||||
/**
|
||||
* @var ConsoleAPI
|
||||
@ -94,31 +95,32 @@ class ServerAPI{
|
||||
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(\PocketMine\DATA."players/", 0755);
|
||||
@mkdir(\PocketMine\DATA."worlds/", 0755);
|
||||
@mkdir(\PocketMine\DATA."plugins/", 0755);
|
||||
|
||||
@mkdir(\PocketMine\DATA . "players/", 0755);
|
||||
@mkdir(\PocketMine\DATA . "worlds/", 0755);
|
||||
@mkdir(\PocketMine\DATA . "plugins/", 0755);
|
||||
|
||||
//Init all the events
|
||||
foreach(get_declared_classes() as $class){
|
||||
if(is_subclass_of($class, "Event") and property_exists($class, "handlers") and property_exists($class, "handlerPriority")){
|
||||
$class::unregisterAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$version = new VersionString();
|
||||
console("[INFO] Starting Minecraft PE server version ".TextFormat::AQUA.MINECRAFT_VERSION);
|
||||
|
||||
console("[INFO] Starting Minecraft PE server version " . TextFormat::AQUA . MINECRAFT_VERSION);
|
||||
|
||||
console("[INFO] Loading properties...");
|
||||
$this->config = new Config(\PocketMine\DATA . "server.properties", Config::PROPERTIES, array(
|
||||
"server-name" => "Minecraft: PE Server",
|
||||
@ -150,9 +152,9 @@ class ServerAPI{
|
||||
"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));
|
||||
@ -165,56 +167,56 @@ class ServerAPI{
|
||||
PortForward($this->getProperty("server-port"));
|
||||
}
|
||||
|
||||
$this->server = new Server($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed:false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0");
|
||||
$this->server = new Server($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() ? TextFormat::YELLOW:"").VERSION.TextFormat::RESET." \"".CODENAME."\" (MCPE: ".MINECRAFT_VERSION.") (API ".API_VERSION.")", true, true, 0);
|
||||
console("[INFO] This server is running PocketMine-MP version " . ($version->isDev() ? TextFormat::YELLOW : "") . VERSION . TextFormat::RESET . " \"" . CODENAME . "\" (MCPE: " . MINECRAFT_VERSION . ") (API " . 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: ".TextFormat::AQUA.date("Y-m-d H:i:s", $this->getProperty("last-update"))."\x1b[0m");
|
||||
console("[INFO] Last check: " . TextFormat::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{
|
||||
} 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] ".TextFormat::YELLOW."A new DEVELOPMENT version of PocketMine-MP has been released!");
|
||||
console("[NOTICE] ".TextFormat::YELLOW."Commit \"".$info[0]["commit"]["message"]."\" [".substr($info[0]["sha"], 0, 10)."] by ".$info[0]["commit"]["committer"]["name"]);
|
||||
console("[NOTICE] ".TextFormat::YELLOW."Get it at PocketMine.net or at https://github.com/PocketMine/PocketMine-MP/archive/".$info[0]["sha"].".zip");
|
||||
console("[NOTICE] " . TextFormat::YELLOW . "A new DEVELOPMENT version of PocketMine-MP has been released!");
|
||||
console("[NOTICE] " . TextFormat::YELLOW . "Commit \"" . $info[0]["commit"]["message"] . "\" [" . substr($info[0]["sha"], 0, 10) . "] by " . $info[0]["commit"]["committer"]["name"]);
|
||||
console("[NOTICE] " . TextFormat::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{
|
||||
} else{
|
||||
$this->setProperty("last-update", time());
|
||||
console("[INFO] ".TextFormat::AQUA."This is the latest DEVELOPMENT version");
|
||||
console("[INFO] " . TextFormat::AQUA . "This is the latest DEVELOPMENT version");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} 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{
|
||||
} else{
|
||||
$newest = new VersionString(VERSION);
|
||||
$newestN = $newest->getNumber();
|
||||
$update = new VersionString($info[0]["name"]);
|
||||
$updateN = $update->getNumber();
|
||||
if($updateN > $newestN){
|
||||
console("[NOTICE] ".TextFormat::GREEN."A new STABLE version of PocketMine-MP has been released!");
|
||||
console("[NOTICE] ".TextFormat::GREEN."Version \"".$info[0]["name"]."\" #".$updateN);
|
||||
console("[NOTICE] Get it at PocketMine.net or at ".$info[0]["zipball_url"]);
|
||||
console("[NOTICE] " . TextFormat::GREEN . "A new STABLE version of PocketMine-MP has been released!");
|
||||
console("[NOTICE] " . TextFormat::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{
|
||||
} else{
|
||||
$this->setProperty("last-update", time());
|
||||
console("[INFO] ".TextFormat::AQUA."This is the latest STABLE version");
|
||||
console("[INFO] " . TextFormat::AQUA . "This is the latest STABLE version");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->loadProperties();
|
||||
|
||||
|
||||
$this->apiList[] = $this->console = new ConsoleAPI();
|
||||
$this->apiList[] = $this->level = new LevelAPI();
|
||||
$this->apiList[] = $this->block = new BlockAPI();
|
||||
@ -222,17 +224,17 @@ class ServerAPI{
|
||||
$this->apiList[] = $this->ban = new BanAPI();
|
||||
$this->apiList[] = $this->player = new PlayerAPI();
|
||||
$this->apiList[] = $this->time = new TimeAPI();
|
||||
|
||||
|
||||
foreach($this->apiList as $ob){
|
||||
if(is_callable(array($ob, "init"))){
|
||||
$ob->init(); //Fails sometimes!!!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->apiList[] = $this->plugin = new PluginAPI();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function checkTickUpdates(){
|
||||
//Update entities that need update
|
||||
if(count(Entity::$needUpdate) > 0){
|
||||
@ -242,7 +244,7 @@ class ServerAPI{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Update tiles that need update
|
||||
if(count(Tile::$needUpdate) > 0){
|
||||
foreach(Tile::$needUpdate as $id => $tile){
|
||||
@ -251,35 +253,38 @@ class ServerAPI{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function async(callable $callable, $params = array(), $remove = false){
|
||||
$cnt = $this->asyncCnt++;
|
||||
$this->asyncCalls[$cnt] = new \Async($callable, $params);
|
||||
return $remove === true ? $this->getAsync($cnt):$cnt;
|
||||
|
||||
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"]).";";
|
||||
$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(
|
||||
@ -296,7 +301,7 @@ class ServerAPI{
|
||||
"max" => $this->server->maxClients,
|
||||
"plugins" => $plist,
|
||||
),
|
||||
), NULL);
|
||||
), null);
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
@ -317,7 +322,7 @@ class ServerAPI{
|
||||
console("[WARNING] PocketMine-MP may not work right with less than 128MB of RAM", true, true, 0);
|
||||
}
|
||||
@ini_set("memory_limit", $memory);
|
||||
}else{
|
||||
} else{
|
||||
$this->setProperty("memory-limit", "128M");
|
||||
}
|
||||
|
||||
@ -342,7 +347,7 @@ class ServerAPI{
|
||||
case "last-update":
|
||||
if($v === false){
|
||||
$v = time();
|
||||
}else{
|
||||
} else{
|
||||
$v = (int) $v;
|
||||
}
|
||||
break;
|
||||
@ -355,7 +360,7 @@ class ServerAPI{
|
||||
break;
|
||||
case "server-id":
|
||||
if($v !== false){
|
||||
$v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)):$v;
|
||||
$v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)) : $v;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -376,10 +381,10 @@ class ServerAPI{
|
||||
$this->sendUsage();
|
||||
}
|
||||
if($this->getProperty("auto-save") === true){
|
||||
$this->server->schedule(18000, array($this, "autoSave"), array(), 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));
|
||||
$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){
|
||||
@ -394,10 +399,11 @@ class ServerAPI{
|
||||
$this->rcon->stop();
|
||||
}
|
||||
$this->__destruct();
|
||||
if($this->getProperty("upnp-forwarding") === true ){
|
||||
if($this->getProperty("upnp-forwarding") === true){
|
||||
console("[INFO] [UPnP] Removing port forward...");
|
||||
RemovePortForward($this->getProperty("server-port"));
|
||||
}
|
||||
|
||||
return $this->restart;
|
||||
}
|
||||
|
||||
@ -406,7 +412,7 @@ class ServerAPI{
|
||||
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);
|
||||
}
|
||||
@ -434,7 +440,7 @@ class ServerAPI{
|
||||
public function deleteEvent($id){
|
||||
return $this->server->deleteEvent($id);
|
||||
}
|
||||
|
||||
|
||||
public function getProperties(){
|
||||
return $this->config->getAll();
|
||||
}
|
||||
@ -460,7 +466,7 @@ class ServerAPI{
|
||||
case "last-update":
|
||||
if($v === false){
|
||||
$v = time();
|
||||
}else{
|
||||
} else{
|
||||
$v = (int) $v;
|
||||
}
|
||||
break;
|
||||
@ -472,9 +478,11 @@ class ServerAPI{
|
||||
$v = (int) $v;
|
||||
break;
|
||||
}
|
||||
|
||||
return $v;
|
||||
}
|
||||
return ($this->config->exists($name) ? $this->config->get($name):$default);
|
||||
|
||||
return ($this->config->exists($name) ? $this->config->get($name) : $default);
|
||||
}
|
||||
|
||||
public function setProperty($name, $value, $save = true){
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine\ServerAPI as ServerAPI;
|
||||
|
||||
class TimeAPI{
|
||||
@ -30,6 +31,7 @@ class TimeAPI{
|
||||
"sunrise" => 17800,
|
||||
);
|
||||
private $server;
|
||||
|
||||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
@ -49,19 +51,19 @@ class TimeAPI{
|
||||
$p = strtolower(array_shift($params));
|
||||
switch($p){
|
||||
case "check":
|
||||
$output .= "Time: ".$this->getDate($level).", ".$this->getPhase($level)." (".$this->get(true, $level).")\n";
|
||||
$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";
|
||||
$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";
|
||||
$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";
|
||||
$output .= "Set the time to " . $this->set($p, $level) . "\n";
|
||||
break;
|
||||
default:
|
||||
$output .= "Usage: /time <check|set|add> [time]\n";
|
||||
@ -69,18 +71,22 @@ class TimeAPI{
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function night(){
|
||||
return $this->set("night");
|
||||
}
|
||||
|
||||
public function day(){
|
||||
return $this->set("day");
|
||||
}
|
||||
|
||||
public function sunrise(){
|
||||
return $this->set("sunrise");
|
||||
}
|
||||
|
||||
public function sunset(){
|
||||
return $this->set("sunset");
|
||||
}
|
||||
@ -89,7 +95,8 @@ class TimeAPI{
|
||||
if(!($level instanceof Level)){
|
||||
$level = $this->server->api->level->getDefault();
|
||||
}
|
||||
return $raw === true ? $level->getTime():abs($level->getTime()) % 19200;
|
||||
|
||||
return $raw === true ? $level->getTime() : abs($level->getTime()) % 19200;
|
||||
}
|
||||
|
||||
public function add($time, $level = false){
|
||||
@ -100,21 +107,23 @@ class TimeAPI{
|
||||
}
|
||||
|
||||
public function getDate($time = false){
|
||||
$time = !is_integer($time) ? $this->get(false, $time):$time;
|
||||
return str_pad(strval((floor($time /800) + 6) % 24), 2, "0", STR_PAD_LEFT).":".str_pad(strval(floor(($time % 800) / 13.33)), 2, "0", STR_PAD_LEFT);
|
||||
$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;
|
||||
$time = !is_integer($time) ? $this->get(false, $time) : $time;
|
||||
if($time < TimeAPI::$phases["sunset"]){
|
||||
$time = "day";
|
||||
}elseif($time < TimeAPI::$phases["night"]){
|
||||
} elseif($time < TimeAPI::$phases["night"]){
|
||||
$time = "sunset";
|
||||
}elseif($time < TimeAPI::$phases["sunrise"]){
|
||||
} elseif($time < TimeAPI::$phases["sunrise"]){
|
||||
$time = "night";
|
||||
}else{
|
||||
} else{
|
||||
$time = "sunrise";
|
||||
}
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
@ -124,9 +133,10 @@ class TimeAPI{
|
||||
}
|
||||
if(is_string($time) and isset(TimeAPI::$phases[$time])){
|
||||
$level->setTime(TimeAPI::$phases[$time]);
|
||||
}else{
|
||||
} else{
|
||||
$level->setTime((int) $time);
|
||||
}
|
||||
|
||||
return $level->getTime();
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ class AirBlock extends TransparentBlock{
|
||||
$this->isSolid = false;
|
||||
$this->isFullBlock = true;
|
||||
$this->hardness = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -26,103 +26,109 @@ class BedBlock extends TransparentBlock{
|
||||
$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;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
$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 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),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -25,12 +25,13 @@ class BedrockBlock extends SolidBlock{
|
||||
$this->breakable = false;
|
||||
$this->hardness = 18000000;
|
||||
}
|
||||
|
||||
|
||||
public function isBreakable(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -31,11 +31,13 @@ class BeetrootBlock extends FlowableBlock{
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||
$this->meta = 0x07;
|
||||
@ -43,8 +45,10 @@ class BeetrootBlock extends FlowableBlock{
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->count--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -53,30 +57,34 @@ class BeetrootBlock extends FlowableBlock{
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(BEETROOT_SEEDS, 0, 1));
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
} 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{
|
||||
} 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{
|
||||
} else{
|
||||
$drops[] = array(BEETROOT_SEEDS, 0, 1);
|
||||
}
|
||||
|
||||
return $drops;
|
||||
}
|
||||
}
|
@ -21,130 +21,130 @@
|
||||
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
COBBLESTONE_STAIRS => "CobblestoneStairsBlock",
|
||||
WALL_SIGN => "WallSignBlock",
|
||||
|
||||
IRON_DOOR_BLOCK => "IronDoorBlock",
|
||||
REDSTONE_ORE => "RedstoneOreBlock",
|
||||
GLOWING_REDSTONE_ORE => "GlowingRedstoneOreBlock",
|
||||
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",
|
||||
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",
|
||||
FENCE => "FenceBlock",
|
||||
PUMPKIN => "PumpkinBlock",
|
||||
NETHERRACK => "NetherrackBlock",
|
||||
SOUL_SAND => "SoulSandBlock",
|
||||
GLOWSTONE_BLOCK => "GlowstoneBlock",
|
||||
|
||||
LIT_PUMPKIN => "LitPumpkinBlock",
|
||||
CAKE_BLOCK => "CakeBlock",
|
||||
|
||||
TRAPDOOR => "TrapdoorBlock",
|
||||
LIT_PUMPKIN => "LitPumpkinBlock",
|
||||
CAKE_BLOCK => "CakeBlock",
|
||||
|
||||
STONE_BRICKS => "StoneBricksBlock",
|
||||
TRAPDOOR => "TrapdoorBlock",
|
||||
|
||||
IRON_BARS => "IronBarsBlock",
|
||||
GLASS_PANE => "GlassPaneBlock",
|
||||
MELON_BLOCK => "MelonBlock",
|
||||
PUMPKIN_STEM => "PumpkinStemBlock",
|
||||
MELON_STEM => "MelonStemBlock",
|
||||
STONE_BRICKS => "StoneBricksBlock",
|
||||
|
||||
FENCE_GATE => "FenceGateBlock",
|
||||
BRICK_STAIRS => "BrickStairsBlock",
|
||||
STONE_BRICK_STAIRS => "StoneBrickStairsBlock",
|
||||
IRON_BARS => "IronBarsBlock",
|
||||
GLASS_PANE => "GlassPaneBlock",
|
||||
MELON_BLOCK => "MelonBlock",
|
||||
PUMPKIN_STEM => "PumpkinStemBlock",
|
||||
MELON_STEM => "MelonStemBlock",
|
||||
|
||||
NETHER_BRICKS => "NetherBricksBlock",
|
||||
FENCE_GATE => "FenceGateBlock",
|
||||
BRICK_STAIRS => "BrickStairsBlock",
|
||||
STONE_BRICK_STAIRS => "StoneBrickStairsBlock",
|
||||
|
||||
NETHER_BRICKS_STAIRS => "NetherBricksStairsBlock",
|
||||
NETHER_BRICKS => "NetherBricksBlock",
|
||||
|
||||
SANDSTONE_STAIRS => "SandstoneStairsBlock",
|
||||
|
||||
SPRUCE_WOOD_STAIRS => "SpruceWoodStairsBlock",
|
||||
BIRCH_WOOD_STAIRS => "BirchWoodStairsBlock",
|
||||
JUNGLE_WOOD_STAIRS => "JungleWoodStairsBlock",
|
||||
STONE_WALL => "StoneWallBlock",
|
||||
|
||||
CARROT_BLOCK => "CarrotBlock",
|
||||
POTATO_BLOCK => "PotatoBlock",
|
||||
NETHER_BRICKS_STAIRS => "NetherBricksStairsBlock",
|
||||
|
||||
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",
|
||||
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;
|
||||
@ -165,7 +165,7 @@ abstract class Block extends Position{
|
||||
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;
|
||||
@ -173,66 +173,68 @@ abstract class Block extends Position{
|
||||
$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{
|
||||
} 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.")";
|
||||
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);
|
||||
}
|
||||
|
@ -24,5 +24,5 @@ class BookshelfBlock extends SolidBlock{
|
||||
parent::__construct(BOOKSHELF, 0, "Bookshelf");
|
||||
$this->hardness = 7.5;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -23,5 +23,5 @@ class BrickStairsBlock extends StairBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(BRICK_STAIRS, $meta, "Brick Stairs");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -28,7 +28,7 @@ class BricksBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.4;
|
||||
@ -44,13 +44,13 @@ class BricksBlock extends SolidBlock{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return array(
|
||||
array(BRICKS_BLOCK, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -30,18 +30,22 @@ class BrownMushroomBlock extends FlowableBlock{
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down->isTransparent === false){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
return true;
|
||||
}
|
||||
$down = $this->getSide(0);
|
||||
if($down->isTransparent === false){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -40,15 +40,17 @@ class BurningFurnaceBlock extends SolidBlock{
|
||||
"id" => new NBT\Tag\String("id", Tile::FURNACE),
|
||||
"x" => new NBT\Tag\Int("x", $this->x),
|
||||
"y" => new NBT\Tag\Int("y", $this->y),
|
||||
"z" =>new NBT\Tag\Int("z", $this->z)
|
||||
"z" => new NBT\Tag\Int("z", $this->z)
|
||||
));
|
||||
$nbt->Items->setTagType(NBT\Tag_Compound);
|
||||
$furnace = new Furnace($this->level, $nbt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function onBreak(Item $item, Player $player){
|
||||
$this->level->setBlock($this, new AirBlock(), true, true, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -58,30 +60,31 @@ class BurningFurnaceBlock extends SolidBlock{
|
||||
$furnace = false;
|
||||
if($t instanceof Furnace){
|
||||
$furnace = $t;
|
||||
}else{
|
||||
} else{
|
||||
$nbt = new NBT\Tag\Compound(false, array(
|
||||
"Items" => new NBT\Tag\Enum("Items", array()),
|
||||
"id" => new NBT\Tag\String("id", Tile::FURNACE),
|
||||
"x" => new NBT\Tag\Int("x", $this->x),
|
||||
"y" => new NBT\Tag\Int("y", $this->y),
|
||||
"z" =>new NBT\Tag\Int("z", $this->z)
|
||||
"z" => new NBT\Tag\Int("z", $this->z)
|
||||
));
|
||||
$nbt->Items->setTagType(NBT\Tag_Compound);
|
||||
$furnace = new Furnace($this->level, $nbt);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
@ -97,7 +100,7 @@ class BurningFurnaceBlock extends SolidBlock{
|
||||
return 17.5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
$drops = array();
|
||||
if($item->isPickaxe() >= 1){
|
||||
@ -112,6 +115,7 @@ class BurningFurnaceBlock extends SolidBlock{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $drops;
|
||||
}
|
||||
}
|
@ -32,30 +32,33 @@ class CactusBlock extends TransparentBlock{
|
||||
if($down->getID() !== SAND and $down->getID() !== CACTUS){ //Replace with common break method
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
} elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if($this->getSide(0)->getID() !== CACTUS){
|
||||
if($this->meta == 0x0F){
|
||||
for($y = 1; $y < 3; ++$y){
|
||||
$b = $this->level->getBlock(new Math\Vector3($this->x, $this->y + $y, $this->z));
|
||||
if($b->getID() === AIR){
|
||||
$this->level->setBlock($b, new CactusBlock(), true, false, true);
|
||||
$this->level->setBlock($b, new CactusBlock(), true, false, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->meta = 0;
|
||||
$this->level->setBlock($this, $this, false);
|
||||
}else{
|
||||
} else{
|
||||
++$this->meta;
|
||||
$this->level->setBlock($this, $this, false);
|
||||
}
|
||||
|
||||
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() === SAND or $down->getID() === CACTUS){
|
||||
@ -66,12 +69,14 @@ class CactusBlock extends TransparentBlock{
|
||||
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array($this->id, 0, 1),
|
||||
|
@ -27,42 +27,48 @@ class CakeBlock extends TransparentBlock{
|
||||
$this->meta = $meta & 0x07;
|
||||
$this->hardness = 2.5;
|
||||
}
|
||||
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() !== AIR){
|
||||
$this->level->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;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($player->entity->getHealth() < 20){
|
||||
++$this->meta;
|
||||
$player->entity->heal(3, "cake");
|
||||
if($this->meta >= 0x06){
|
||||
$this->level->setBlock($this, new AirBlock(), true, false, true);
|
||||
}else{
|
||||
} else{
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -42,28 +42,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){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() !== AIR){
|
||||
$this->level->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;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -31,11 +31,13 @@ class CarrotBlock extends FlowableBlock{
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||
$this->meta = 0x07;
|
||||
@ -43,8 +45,10 @@ class CarrotBlock extends FlowableBlock{
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->count--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -53,29 +57,33 @@ class CarrotBlock extends FlowableBlock{
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(CARROT, 0, 1));
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
} 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{
|
||||
} else{
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
$drops = array();
|
||||
if($this->meta >= 0x07){
|
||||
$drops[] = array(CARROT, 0, mt_rand(1, 4));
|
||||
}else{
|
||||
} else{
|
||||
$drops[] = array(CARROT, 0, 1);
|
||||
}
|
||||
|
||||
return $drops;
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ class ChestBlock extends TransparentBlock{
|
||||
$this->isActivable = true;
|
||||
$this->hardness = 15;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$faces = array(
|
||||
0 => 4,
|
||||
@ -35,11 +36,11 @@ class ChestBlock extends TransparentBlock{
|
||||
|
||||
$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)){
|
||||
} elseif(($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)){
|
||||
continue;
|
||||
}
|
||||
$c = $this->getSide($side);
|
||||
@ -57,7 +58,7 @@ class ChestBlock extends TransparentBlock{
|
||||
"id" => new NBT\Tag\String("id", Tile::CHEST),
|
||||
"x" => new NBT\Tag\Int("x", $this->x),
|
||||
"y" => new NBT\Tag\Int("y", $this->y),
|
||||
"z" =>new NBT\Tag\Int("z", $this->z)
|
||||
"z" => new NBT\Tag\Int("z", $this->z)
|
||||
));
|
||||
$nbt->Items->setTagType(NBT\Tag_Compound);
|
||||
$tile = new Chest($this->level, $nbt);
|
||||
@ -66,47 +67,49 @@ class ChestBlock extends TransparentBlock{
|
||||
$chest->pairWith($tile);
|
||||
$tile->pairWith($chest);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function onBreak(Item $item, Player $player){
|
||||
$t = $this->level->getTile($this);
|
||||
if($t instanceof Chest){
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
$t = $this->level->getTile($this);
|
||||
$chest = false;
|
||||
if($t instanceof Chest){
|
||||
$chest = $t;
|
||||
}else{
|
||||
} else{
|
||||
$nbt = new NBT\Tag\Compound(false, array(
|
||||
"Items" => new NBT\Tag\Enum("Items", array()),
|
||||
"id" => new NBT\Tag\String("id", Tile::CHEST),
|
||||
"x" => new NBT\Tag\Int("x", $this->x),
|
||||
"y" => new NBT\Tag\Int("y", $this->y),
|
||||
"z" =>new NBT\Tag\Int("z", $this->z)
|
||||
"z" => new NBT\Tag\Int("z", $this->z)
|
||||
));
|
||||
$nbt->Items->setTagType(NBT\Tag_Compound);
|
||||
$chest = new Chest($this->level, $nbt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return true;
|
||||
}
|
||||
|
||||
$chest->openInventory($player);
|
||||
|
||||
$chest->openInventory($player);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -123,6 +126,7 @@ class ChestBlock extends TransparentBlock{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $drops;
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ class CoalBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.95;
|
||||
@ -44,13 +44,13 @@ class CoalBlock extends SolidBlock{
|
||||
return 25;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return array(
|
||||
array(COAL_BLOCK, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,11 @@ class CoalOreBlock extends SolidBlock{
|
||||
parent::__construct(COAL_ORE, 0, "Coal Ore");
|
||||
$this->hardness = 15;
|
||||
}
|
||||
|
||||
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.6;
|
||||
@ -44,15 +44,15 @@ class CoalOreBlock extends SolidBlock{
|
||||
return 15;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return array(
|
||||
array(COAL, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -28,7 +28,7 @@ class CobblestoneBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.4;
|
||||
@ -44,13 +44,13 @@ class CobblestoneBlock extends SolidBlock{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return array(
|
||||
array(COBBLESTONE, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,5 @@ class CobblestoneStairsBlock extends StairBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(COBBLESTONE_STAIRS, $meta, "Cobblestone Stairs");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -21,12 +21,13 @@
|
||||
|
||||
class CobwebBlock extends FlowableBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(COBWEB, 0, "Cobweb");
|
||||
parent::__construct(COBWEB, 0, "Cobweb");
|
||||
$this->isSolid = true;
|
||||
$this->isFullBlock = false;
|
||||
$this->hardness = 25;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
@ -26,11 +26,13 @@ class CyanFlowerBlock extends FlowableBlock{
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
return true;
|
||||
}
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -39,9 +41,11 @@ class CyanFlowerBlock extends FlowableBlock{
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -26,11 +26,13 @@ class DandelionBlock extends FlowableBlock{
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
return true;
|
||||
}
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -39,9 +41,11 @@ class DandelionBlock extends FlowableBlock{
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -30,10 +30,12 @@ class DeadBushBlock extends FlowableBlock{
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -24,11 +24,11 @@ class DiamondBlock extends SolidBlock{
|
||||
parent::__construct(DIAMOND_BLOCK, 0, "Diamond Block");
|
||||
$this->hardness = 30;
|
||||
}
|
||||
|
||||
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.95;
|
||||
@ -38,13 +38,13 @@ class DiamondBlock extends SolidBlock{
|
||||
return 25;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 4){
|
||||
return array(
|
||||
array(DIAMOND_BLOCK, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,11 @@ class DiamondOreBlock extends SolidBlock{
|
||||
parent::__construct(DIAMOND_ORE, 0, "Diamond Ore");
|
||||
$this->hardness = 15;
|
||||
}
|
||||
|
||||
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.6;
|
||||
@ -38,13 +38,13 @@ class DiamondOreBlock extends SolidBlock{
|
||||
return 15;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 4){
|
||||
return array(
|
||||
array(DIAMOND, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,10 @@ class DirtBlock extends SolidBlock{
|
||||
$item->useOn($this);
|
||||
}
|
||||
$this->level->setBlock($this, BlockAPI::get(FARMLAND, 0), true, false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -20,47 +20,49 @@
|
||||
*/
|
||||
|
||||
class DoorBlock extends TransparentBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @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){
|
||||
/**
|
||||
* @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){
|
||||
/**
|
||||
* @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);
|
||||
@ -81,43 +83,45 @@ class DoorBlock extends TransparentBlock{
|
||||
$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 true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function onBreak(Item $item, Player $player){
|
||||
/**
|
||||
* @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{
|
||||
} 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){
|
||||
/**
|
||||
* @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){
|
||||
@ -132,10 +136,12 @@ class DoorBlock extends TransparentBlock{
|
||||
$pk->evid = 1003;
|
||||
$pk->data = 0;
|
||||
ServerAPI::request()->api->player->broadcastPacket($players, $pk);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}else{
|
||||
} else{
|
||||
$this->meta ^= 0x04;
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
$players = ServerAPI::request()->api->player->getAll($this->level);
|
||||
@ -148,6 +154,7 @@ class DoorBlock extends TransparentBlock{
|
||||
$pk->data = 0;
|
||||
ServerAPI::request()->api->player->broadcastPacket($players, $pk);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@ class DoubleSlabBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.4;
|
||||
@ -54,15 +54,15 @@ class DoubleSlabBlock extends SolidBlock{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return array(
|
||||
array(SLAB, $this->meta & 0x07, 2),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -35,7 +35,7 @@ class DoubleWoodSlabBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isAxe()){
|
||||
case 5:
|
||||
return 0.4;
|
||||
@ -51,11 +51,11 @@ class DoubleWoodSlabBlock extends SolidBlock{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array(WOOD_SLAB, $this->meta & 0x07, 2),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -20,31 +20,32 @@
|
||||
*/
|
||||
|
||||
class FallableBlock extends SolidBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @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){
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
@ -24,9 +24,10 @@ class FarmlandBlock extends SolidBlock{
|
||||
parent::__construct(FARMLAND, $meta, "Farmland");
|
||||
$this->hardness = 3;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array(DIRT, 0, 1),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -25,5 +25,5 @@ class FenceBlock extends TransparentBlock{
|
||||
$this->isFullBlock = false;
|
||||
$this->hardness = 15;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -25,11 +25,12 @@ class FenceGateBlock extends TransparentBlock{
|
||||
$this->isActivable = true;
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
} else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
$this->hardness = 15;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$faces = array(
|
||||
0 => 3,
|
||||
@ -39,13 +40,16 @@ class FenceGateBlock extends TransparentBlock{
|
||||
);
|
||||
$this->meta = $faces[$player->entity->getDirection()] & 0x03;
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array($this->id, 0, 1),
|
||||
);
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
$faces = array(
|
||||
0 => 3,
|
||||
@ -56,10 +60,11 @@ class FenceGateBlock extends TransparentBlock{
|
||||
$this->meta = ($faces[$player->entity->getDirection()] & 0x03) | ((~$this->meta) & 0x04);
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
} else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -27,11 +27,11 @@ class FireBlock extends FlowableBlock{
|
||||
$this->isFullBlock = true;
|
||||
$this->hardness = 0;
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
for($s = 0; $s <= 5; ++$s){
|
||||
@ -41,14 +41,17 @@ class FireBlock extends FlowableBlock{
|
||||
}
|
||||
}
|
||||
$this->level->setBlock($this, new AirBlock(), true, false, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
} elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if($this->getSide(0)->getID() !== NETHERRACK){
|
||||
$this->level->setBlock($this, new AirBlock(), true, false, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -20,12 +20,12 @@
|
||||
*/
|
||||
|
||||
class FlowableBlock extends TransparentBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->isFlowable = true;
|
||||
$this->isFullBlock = false;
|
||||
|
@ -21,57 +21,57 @@
|
||||
|
||||
|
||||
class GenericBlock extends Block{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @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){
|
||||
/**
|
||||
* @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){
|
||||
/**
|
||||
* @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){
|
||||
/**
|
||||
* @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){
|
||||
/**
|
||||
* @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)){
|
||||
@ -88,18 +88,20 @@ class GenericBlock extends Block{
|
||||
$e->spawnToAll();
|
||||
$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){
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function onActivate(Item $item, Player $player){
|
||||
return $this->isActivable;
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ class GlassBlock extends TransparentBlock{
|
||||
parent::__construct(GLASS, 0, "Glass");
|
||||
$this->hardness = 1.5;
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array();
|
||||
}
|
||||
|
@ -25,5 +25,5 @@ class GlassPaneBlock extends TransparentBlock{
|
||||
$this->isFullBlock = false;
|
||||
$this->isSolid = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -23,5 +23,5 @@ class GlowingObsidianBlock extends SolidBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(GLOWING_OBSIDIAN, $meta, "Glowing Obsidian");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -27,19 +27,21 @@ class GlowingRedstoneOreBlock extends SolidBlock{
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){
|
||||
$this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false, false, true);
|
||||
$this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false, false, true);
|
||||
|
||||
return BLOCK_UPDATE_WEAK;
|
||||
}else{
|
||||
} else{
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.6;
|
||||
@ -49,15 +51,15 @@ class GlowingRedstoneOreBlock extends SolidBlock{
|
||||
return 15;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 4){
|
||||
return array(
|
||||
array(REDSTONE_DUST, 0, mt_rand(4, 5)),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -28,7 +28,7 @@ class GoldBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.6;
|
||||
@ -38,13 +38,13 @@ class GoldBlock extends SolidBlock{
|
||||
return 15;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 4){
|
||||
return array(
|
||||
array(GOLD_BLOCK, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class GoldOreBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.6;
|
||||
@ -38,13 +38,13 @@ class GoldOreBlock extends SolidBlock{
|
||||
return 15;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 4){
|
||||
return array(
|
||||
array(GOLD_ORE, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ class GrassBlock extends SolidBlock{
|
||||
$this->isActivable = true;
|
||||
$this->hardness = 3;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array(DIRT, 0, 1),
|
||||
@ -37,14 +38,17 @@ class GrassBlock extends SolidBlock{
|
||||
$item->count--;
|
||||
}
|
||||
TallGrassObject::growGrass($this->level, $this, new Random(), 8, 2);
|
||||
|
||||
return true;
|
||||
}elseif($item->isHoe()){
|
||||
} elseif($item->isHoe()){
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->useOn($this);
|
||||
}
|
||||
$this->level->setBlock($this, new FarmlandBlock());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -24,16 +24,17 @@ class GravelBlock extends FallableBlock{
|
||||
parent::__construct(GRAVEL, 0, "Gravel");
|
||||
$this->hardness = 3;
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if(mt_rand(1,10) === 1){
|
||||
if(mt_rand(1, 10) === 1){
|
||||
return array(
|
||||
array(FLINT, 0, 1),
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
array(GRAVEL, 0, 1),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -24,7 +24,7 @@ class HayBaleBlock extends SolidBlock{
|
||||
parent::__construct(HAY_BALE, $meta, "Hay Bale");
|
||||
$this->hardness = 10;
|
||||
}
|
||||
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$faces = array(
|
||||
0 => 0,
|
||||
@ -37,6 +37,7 @@ class HayBaleBlock extends SolidBlock{
|
||||
|
||||
$this->meta = ($this->meta & 0x03) | $faces[$face];
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -45,5 +46,5 @@ class HayBaleBlock extends SolidBlock{
|
||||
array($this->id, 0, 1),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -24,20 +24,21 @@ class IceBlock extends TransparentBlock{
|
||||
parent::__construct(ICE, 0, "Ice");
|
||||
$this->hardness = 2.5;
|
||||
}
|
||||
|
||||
|
||||
public function onBreak(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$this->level->setBlock($this, new WaterBlock(), true, false, true);
|
||||
}else{
|
||||
} else{
|
||||
$this->level->setBlock($this, new AirBlock(), 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.1;
|
||||
|
@ -28,7 +28,7 @@ class IronBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.95;
|
||||
@ -40,13 +40,13 @@ class IronBlock extends SolidBlock{
|
||||
return 25;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 3){
|
||||
return array(
|
||||
array(IRON_BLOCK, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -25,5 +25,5 @@ class IronBarsBlock extends TransparentBlock{
|
||||
$this->isFullBlock = false;
|
||||
$this->isSolid = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -29,7 +29,7 @@ class IronDoorBlock extends DoorBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.95;
|
||||
@ -45,13 +45,13 @@ class IronDoorBlock extends DoorBlock{
|
||||
return 25;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return array(
|
||||
array(IRON_DOOR, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class IronOreBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.6;
|
||||
@ -40,13 +40,13 @@ class IronOreBlock extends SolidBlock{
|
||||
return 15;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 3){
|
||||
return array(
|
||||
array(IRON_ORE, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -26,20 +26,23 @@ class LadderBlock extends TransparentBlock{
|
||||
$this->isFullBlock = false;
|
||||
$this->hardness = 2;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($target->isTransparent === false){
|
||||
$faces = array(
|
||||
2 => 2,
|
||||
3 => 3,
|
||||
4 => 4,
|
||||
5 => 5,
|
||||
);
|
||||
$faces = array(
|
||||
2 => 2,
|
||||
3 => 3,
|
||||
4 => 4,
|
||||
5 => 5,
|
||||
);
|
||||
if(isset($faces[$face])){
|
||||
$this->meta = $faces[$face];
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -51,6 +54,7 @@ class LadderBlock extends TransparentBlock{
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}*/
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -58,5 +62,5 @@ class LadderBlock extends TransparentBlock{
|
||||
return array(
|
||||
array($this->id, 0, 1),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ class LapisBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.6;
|
||||
@ -40,13 +40,13 @@ class LapisBlock extends SolidBlock{
|
||||
return 15;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 3){
|
||||
return array(
|
||||
array(LAPIS_BLOCK, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,11 @@ class LapisOreBlock extends SolidBlock{
|
||||
parent::__construct(LAPIS_ORE, 0, "Lapis Ore");
|
||||
$this->hardness = 15;
|
||||
}
|
||||
|
||||
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.6;
|
||||
@ -46,9 +46,9 @@ class LapisOreBlock extends SolidBlock{
|
||||
return array(
|
||||
array(DYE, 4, mt_rand(4, 8)),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -24,17 +24,18 @@ class LavaBlock extends LiquidBlock{
|
||||
parent::__construct(LAVA, $meta, "Lava");
|
||||
$this->hardness = 0;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 40, BLOCK_UPDATE_NORMAL);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
public function getSourceCount(){
|
||||
$count = 0;
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
if($this->getSide($side) instanceof LavaBlock ){
|
||||
if($this->getSide($side) instanceof LavaBlock){
|
||||
$b = $this->getSide($side);
|
||||
$level = $b->meta & 0x07;
|
||||
if($level == 0x00){
|
||||
@ -42,9 +43,10 @@ class LavaBlock extends LiquidBlock{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
||||
public function checkWater(){
|
||||
for($side = 1; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
@ -52,27 +54,28 @@ class LavaBlock extends LiquidBlock{
|
||||
$level = $this->meta & 0x07;
|
||||
if($level == 0x00){
|
||||
$this->level->setBlock($this, new ObsidianBlock(), false, false, true);
|
||||
}else{
|
||||
} else{
|
||||
$this->level->setBlock($this, new CobblestoneBlock(), false, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getFrom(){
|
||||
for($side = 0; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
if($b instanceof LavaBlock){
|
||||
$tlevel = $b->meta & 0x07;
|
||||
$level = $this->meta & 0x07;
|
||||
if( ($tlevel + 2) == $level || ($side == 0x01 && $level == 0x01 ) || ($tlevel == 6 && $level == 7 )){
|
||||
if(($tlevel + 2) == $level || ($side == 0x01 && $level == 0x01) || ($tlevel == 6 && $level == 7)){
|
||||
return $b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function onUpdate($type){
|
||||
//return false;
|
||||
$newId = $this->id;
|
||||
@ -80,42 +83,42 @@ class LavaBlock extends LiquidBlock{
|
||||
if($type !== BLOCK_UPDATE_NORMAL){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if($this->checkWater()){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$falling = $this->meta >> 3;
|
||||
$down = $this->getSide(0);
|
||||
|
||||
|
||||
$from = $this->getFrom();
|
||||
if($from !== null || $level == 0x00){
|
||||
if($level !== 0x07){
|
||||
if($down instanceof AirBlock || $down instanceof LavaBlock){
|
||||
$this->level->setBlock($down, new LavaBlock(0x01), false, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
|
||||
}else{
|
||||
} else{
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
if($b instanceof LavaBlock){
|
||||
|
||||
}elseif($b->isFlowable === true){
|
||||
$this->level->setBlock($b, new LavaBlock( min($level + 2,7) ), false, false, true);
|
||||
|
||||
} elseif($b->isFlowable === true){
|
||||
$this->level->setBlock($b, new LavaBlock(min($level + 2, 7)), false, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
//Extend Remove for Left Lavas
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$sb = $this->getSide($side);
|
||||
if($sb instanceof LavaBlock){
|
||||
$tlevel = $sb->meta & 0x07;
|
||||
if($tlevel != 0x00){
|
||||
for ($s = 0; $s <= 5; $s++) {
|
||||
$ssb = $sb->getSide($s);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
|
||||
for($s = 0; $s <= 5; $s++){
|
||||
$ssb = $sb->getSide($s);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
$this->level->setBlock($sb, new AirBlock(), false, false, true);
|
||||
}
|
||||
@ -124,10 +127,10 @@ class LavaBlock extends LiquidBlock{
|
||||
if($b instanceof LavaBlock){
|
||||
$tlevel = $b->meta & 0x07;
|
||||
if($tlevel != 0x00){
|
||||
for ($s = 0; $s <= 5; $s++) {
|
||||
$ssb = $sb->getSide($s);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
for($s = 0; $s <= 5; $s++){
|
||||
$ssb = $sb->getSide($s);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
$this->level->setBlock($b, new AirBlock(), false, false, true);
|
||||
}
|
||||
}
|
||||
@ -136,7 +139,8 @@ class LavaBlock extends LiquidBlock{
|
||||
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ class LeavesBlock extends TransparentBlock{
|
||||
const OAK = 0;
|
||||
const SPRUCE = 1;
|
||||
const BIRCH = 2;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(LEAVES, $meta, "Leaves");
|
||||
$names = array(
|
||||
@ -34,16 +35,16 @@ class LeavesBlock extends TransparentBlock{
|
||||
$this->name = $names[$this->meta & 0x03];
|
||||
$this->hardness = 1;
|
||||
}
|
||||
|
||||
|
||||
private function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null){
|
||||
++$check;
|
||||
$index = $pos->x.".".$pos->y.".".$pos->z;
|
||||
$index = $pos->x . "." . $pos->y . "." . $pos->z;
|
||||
if(isset($visited[$index])){
|
||||
return false;
|
||||
}
|
||||
if($pos->getID() === WOOD){
|
||||
return true;
|
||||
}elseif($pos->getID() === LEAVES and $distance < 3){
|
||||
} elseif($pos->getID() === LEAVES and $distance < 3){
|
||||
$visited[$index] = true;
|
||||
$down = $pos->getSide(0)->getID();
|
||||
if($down === WOOD){
|
||||
@ -55,41 +56,41 @@ class LeavesBlock extends TransparentBlock{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}else{ //No more loops
|
||||
} else{ //No more loops
|
||||
switch($fromSide){
|
||||
case 2:
|
||||
if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
} elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
} elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
} elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
} elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
} elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
} elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
} elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
} elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@ -99,54 +100,57 @@ class LeavesBlock extends TransparentBlock{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if(($this->meta & 0b00001100) === 0){
|
||||
$this->meta |= 0x08;
|
||||
$this->level->setBlock($this, $this, false, false, true);
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
} elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if(($this->meta & 0b00001100) === 0x08){
|
||||
$this->meta &= 0x03;
|
||||
$visited = array();
|
||||
$check = 0;
|
||||
if($this->findLog($this, $visited, 0, $check) === true){
|
||||
$this->level->setBlock($this, $this, false, false, true);
|
||||
}else{
|
||||
} else{
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
if(mt_rand(1,20) === 1){ //Saplings
|
||||
if(mt_rand(1, 20) === 1){ //Saplings
|
||||
//TODO
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x03, 1));
|
||||
}
|
||||
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
|
||||
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1, 200) === 1){ //Apples
|
||||
//TODO
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1));
|
||||
}
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$this->meta |= 0x04;
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
$drops = array();
|
||||
if($item->isShears()){
|
||||
$drops[] = array(LEAVES, $this->meta & 0x03, 1);
|
||||
}else{
|
||||
if(mt_rand(1,20) === 1){ //Saplings
|
||||
} else{
|
||||
if(mt_rand(1, 20) === 1){ //Saplings
|
||||
$drops[] = array(SAPLING, $this->meta & 0x03, 1);
|
||||
}
|
||||
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
|
||||
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1, 200) === 1){ //Apples
|
||||
$drops[] = array(APPLE, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return $drops;
|
||||
}
|
||||
}
|
@ -20,12 +20,12 @@
|
||||
*/
|
||||
|
||||
class LiquidBlock extends TransparentBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->isLiquid = true;
|
||||
$this->breakable = false;
|
||||
|
@ -25,15 +25,16 @@ class LitPumpkinBlock extends SolidBlock{
|
||||
$this->hardness = 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 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;
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ class MelonBlock extends TransparentBlock{
|
||||
parent::__construct(MELON_BLOCK, 0, "Melon Block");
|
||||
$this->hardness = 5;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array(MELON_SLICE, 0, mt_rand(3, 7)),
|
||||
|
@ -25,13 +25,16 @@ class MelonStemBlock extends FlowableBlock{
|
||||
$this->isActivable = true;
|
||||
$this->hardness = 0;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -40,33 +43,37 @@ class MelonStemBlock extends FlowableBlock{
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
} 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{
|
||||
} 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));
|
||||
$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;
|
||||
@ -74,11 +81,13 @@ class MelonStemBlock extends FlowableBlock{
|
||||
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)),
|
||||
|
@ -28,7 +28,7 @@ class MossStoneBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.4;
|
||||
@ -44,13 +44,13 @@ class MossStoneBlock extends SolidBlock{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return array(
|
||||
array(MOSS_STONE, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class NetherBricksBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.4;
|
||||
@ -44,13 +44,13 @@ class NetherBricksBlock extends SolidBlock{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return array(
|
||||
array(NETHER_BRICKS, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,5 @@ class NetherBricksStairsBlock extends StairBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(NETHER_BRICKS_STAIRS, $meta, "Nether Bricks Stairs");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -24,5 +24,5 @@ class NetherReactorBlock extends SolidBlock{
|
||||
parent::__construct(NETHER_REACTOR, $meta, "Nether Reactor");
|
||||
$this->isActivable = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -24,11 +24,11 @@ class NetherrackBlock extends SolidBlock{
|
||||
parent::__construct(NETHERRACK, 0, "Netherrack");
|
||||
$this->hardness = 2;
|
||||
}
|
||||
|
||||
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.1;
|
||||
@ -50,7 +50,7 @@ class NetherrackBlock extends SolidBlock{
|
||||
return array(
|
||||
array(NETHERRACK, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -22,26 +22,26 @@
|
||||
class ObsidianBlock extends SolidBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(OBSIDIAN, 0, "Obsidian");
|
||||
$this->hardness = 6000;
|
||||
$this->hardness = 6000;
|
||||
}
|
||||
|
||||
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
if($item->isPickaxe() >= 5){
|
||||
return 9.4;
|
||||
}else{
|
||||
} else{
|
||||
return 250;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 5){
|
||||
return array(
|
||||
array(OBSIDIAN, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -31,5 +31,5 @@ class PlanksBlock extends SolidBlock{
|
||||
$this->name = $names[$this->meta & 0x03];
|
||||
$this->hardness = 15;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -31,11 +31,13 @@ class PotatoBlock extends FlowableBlock{
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||
$this->meta = 0x07;
|
||||
@ -43,8 +45,10 @@ class PotatoBlock extends FlowableBlock{
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->count--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -53,29 +57,33 @@ class PotatoBlock extends FlowableBlock{
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(POTATO, 0, 1));
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
} 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{
|
||||
} else{
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
$drops = array();
|
||||
if($this->meta >= 0x07){
|
||||
$drops[] = array(POTATO, 0, mt_rand(1, 4));
|
||||
}else{
|
||||
} else{
|
||||
$drops[] = array(POTATO, 0, 1);
|
||||
}
|
||||
|
||||
return $drops;
|
||||
}
|
||||
}
|
@ -24,5 +24,5 @@ class PumpkinBlock extends SolidBlock{
|
||||
parent::__construct(PUMPKIN, "Pumpkin");
|
||||
$this->hardness = 5;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -25,13 +25,16 @@ class PumpkinStemBlock extends FlowableBlock{
|
||||
$this->isActivable = true;
|
||||
$this->hardness = 0;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -40,33 +43,37 @@ class PumpkinStemBlock extends FlowableBlock{
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
} 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{
|
||||
} 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));
|
||||
$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;
|
||||
@ -74,11 +81,13 @@ class PumpkinStemBlock extends FlowableBlock{
|
||||
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)),
|
||||
|
@ -34,7 +34,7 @@ class QuartzBlock extends SolidBlock{
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.15;
|
||||
@ -50,13 +50,13 @@ class QuartzBlock extends SolidBlock{
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return array(
|
||||
array(QUARTZ_BLOCK, $this->meta & 0x03, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,5 @@ class QuartzStairsBlock extends StairBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(QUARTZ_STAIRS, $meta, "Quartz Stairs");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -31,9 +31,11 @@ class RedMushroomBlock extends FlowableBlock{
|
||||
//TODO
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -41,8 +43,10 @@ class RedMushroomBlock extends FlowableBlock{
|
||||
$down = $this->getSide(0);
|
||||
if($down->isTransparent === false){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -24,13 +24,15 @@ class RedstoneOreBlock extends SolidBlock{
|
||||
parent::__construct(REDSTONE_ORE, 0, "Redstone Ore");
|
||||
$this->hardness = 15;
|
||||
}
|
||||
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){
|
||||
$this->level->setBlock($this, BlockAPI::get(GLOWING_REDSTONE_ORE, $this->meta), false, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
|
||||
return BLOCK_UPDATE_WEAK;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -39,7 +41,7 @@ class RedstoneOreBlock extends SolidBlock{
|
||||
return array(
|
||||
array(REDSTONE_DUST, 0, mt_rand(4, 5)),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -24,5 +24,5 @@ class SandBlock extends FallableBlock{
|
||||
parent::__construct(SAND, 0, "Sand");
|
||||
$this->hardness = 2.5;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -27,14 +27,14 @@ class SandstoneBlock extends SolidBlock{
|
||||
1 => "Chiseled Sandstone",
|
||||
2 => "Smooth Sandstone",
|
||||
);
|
||||
$this->name = $names[$this->meta & 0x03];
|
||||
$this->name = $names[$this->meta & 0x03];
|
||||
$this->hardness = 4;
|
||||
}
|
||||
|
||||
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
return 0.20;
|
||||
}
|
||||
}
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.15;
|
||||
@ -56,9 +56,9 @@ class SandstoneBlock extends SolidBlock{
|
||||
return array(
|
||||
array(SANDSTONE, $this->meta & 0x03, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -23,5 +23,5 @@ class SandstoneStairsBlock extends StairBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(SANDSTONE_STAIRS, $meta, "Sandstone Stairs");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -25,7 +25,7 @@ class SaplingBlock extends FlowableBlock{
|
||||
const BIRCH = 2;
|
||||
const JUNGLE = 3;
|
||||
const BURN_TIME = 5;
|
||||
|
||||
|
||||
public function __construct($meta = Sapling::OAK){
|
||||
parent::__construct(SAPLING, $meta, "Sapling");
|
||||
$this->isActivable = true;
|
||||
@ -38,51 +38,59 @@ class SaplingBlock extends FlowableBlock{
|
||||
$this->name = $names[$this->meta & 0x03];
|
||||
$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() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->count--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
//TODO
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){ //Growth
|
||||
if(mt_rand(1,7) === 1){
|
||||
} elseif($type === BLOCK_UPDATE_RANDOM){ //Growth
|
||||
if(mt_rand(1, 7) === 1){
|
||||
if(($this->meta & 0x08) === 0x08){
|
||||
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
|
||||
}else{
|
||||
} else{
|
||||
$this->meta |= 0x08;
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}else{
|
||||
} else{
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array($this->id, $this->meta & 0x03, 1),
|
||||
|
@ -26,7 +26,7 @@ class SignPostBlock extends TransparentBlock{
|
||||
$this->isFullBlock = false;
|
||||
$this->hardness = 5;
|
||||
}
|
||||
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($face !== 0){
|
||||
$faces = array(
|
||||
@ -38,29 +38,35 @@ class SignPostBlock extends TransparentBlock{
|
||||
if(!isset($faces[$face])){
|
||||
$this->meta = floor((($player->entity->yaw + 180) * 16 / 360) + 0.5) & 0x0F;
|
||||
$this->level->setBlock($block, BlockAPI::get(SIGN_POST, $this->meta), true, false, true);
|
||||
|
||||
return true;
|
||||
}else{
|
||||
} else{
|
||||
$this->meta = $faces[$face];
|
||||
$this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta), 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(SIGN, 0, 1));
|
||||
$this->level->setBlock($this, new AirBlock(), true, true, true);
|
||||
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function onBreak(Item $item, Player $player){
|
||||
$this->level->setBlock($this, new AirBlock(), true, true, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -68,5 +74,5 @@ class SignPostBlock extends TransparentBlock{
|
||||
return array(
|
||||
array(SIGN, 0, 1),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -32,61 +32,68 @@ class SlabBlock extends TransparentBlock{
|
||||
6 => "Quartz",
|
||||
7 => "",
|
||||
);
|
||||
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab";
|
||||
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab";
|
||||
if(($this->meta & 0x08) === 0x08){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
} 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->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;
|
||||
}else{
|
||||
}
|
||||
|
||||
return false;
|
||||
} else{
|
||||
if($fy > 0.5){
|
||||
$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;
|
||||
} 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;
|
||||
@ -102,13 +109,13 @@ class SlabBlock extends TransparentBlock{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return array(
|
||||
array($this->id, $this->meta & 0x07, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -24,5 +24,5 @@ class SnowBlock extends SolidBlock{
|
||||
parent::__construct(SNOW_BLOCK, 0, "Snow Block");
|
||||
$this->hardness = 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -27,32 +27,37 @@ class SnowLayerBlock extends FlowableBlock{
|
||||
$this->isFullBlock = false;
|
||||
$this->hardness = 0.5;
|
||||
}
|
||||
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down instanceof SolidBlock){
|
||||
$this->level->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;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isShovel() !== false){
|
||||
return array(
|
||||
array(SNOWBALL, 0, 1),
|
||||
);
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
}
|
@ -20,12 +20,12 @@
|
||||
*/
|
||||
|
||||
class SolidBlock extends GenericBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->isSolid = true;
|
||||
$this->isFullBlock = true;
|
||||
|
@ -24,5 +24,5 @@ class SoulSandBlock extends SolidBlock{
|
||||
parent::__construct(SOUL_SAND, 0, "Soul Sand");
|
||||
$this->hardness = 2.5;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -24,5 +24,5 @@ class SpongeBlock extends SolidBlock{
|
||||
parent::__construct(SPONGE, "Sponge");
|
||||
$this->hardness = 3;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -20,34 +20,34 @@
|
||||
*/
|
||||
|
||||
class StairBlock extends TransparentBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
} else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
$this->hardness = 30;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 bool|mixed
|
||||
*/
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
/**
|
||||
* @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 bool|mixed
|
||||
*/
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$faces = array(
|
||||
0 => 0,
|
||||
1 => 2,
|
||||
@ -59,21 +59,22 @@ class StairBlock extends TransparentBlock{
|
||||
$this->meta |= 0x04; //Upside-down stairs
|
||||
}
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDrops(Item $item, Player $player){
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return array(
|
||||
array($this->id, 0, 1),
|
||||
);
|
||||
}else{
|
||||
} else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user