Lots of new things added

This commit is contained in:
Shoghi Cervantes 2014-03-30 18:04:56 +02:00
parent ccec74076b
commit f789e6e6e3
48 changed files with 476 additions and 486 deletions

View File

@ -23,9 +23,7 @@ namespace PocketMine;
class ChatAPI{ class ChatAPI{
/** /** @var Server */
* @var Server
*/
private $server; private $server;
function __construct(){ function __construct(){
@ -33,12 +31,9 @@ class ChatAPI{
} }
public function init(){ public function init(){
$this->server->api->console->register("tell", "<player> <private message ...>", array($this, "commandHandler"));
$this->server->api->console->register("me", "<action ...>", array($this, "commandHandler")); $this->server->api->console->register("me", "<action ...>", array($this, "commandHandler"));
$this->server->api->console->register("say", "<message ...>", array($this, "commandHandler")); $this->server->api->console->register("say", "<message ...>", array($this, "commandHandler"));
$this->server->api->ban->cmdWhitelist("tell");
$this->server->api->ban->cmdWhitelist("me"); $this->server->api->ban->cmdWhitelist("me");
$this->server->api->console->alias("msg", "tell");
} }
/** /**
@ -61,18 +56,6 @@ class ChatAPI{
$sender = ($issuer instanceof Player) ? "Server" : ucfirst($issuer); $sender = ($issuer instanceof Player) ? "Server" : ucfirst($issuer);
Player::broadcastMessage("[$sender] " . $s); Player::broadcastMessage("[$sender] " . $s);
break; break;
case "me":
if(!($issuer instanceof Player)){
if($issuer === "rcon"){
$sender = "Rcon";
}else{
$sender = ucfirst($issuer);
}
}else{
$sender = $issuer->getDisplayName();
}
Player::broadcastMessage("* $sender " . implode(" ", $params));
break;
case "tell": case "tell":
if(!isset($params[0]) or !isset($params[1])){ if(!isset($params[0]) or !isset($params[1])){
$output .= "Usage: /$cmd <player> <message>\n"; $output .= "Usage: /$cmd <player> <message>\n";

View File

@ -31,7 +31,6 @@ class LevelAPI{
} }
public function init(){ public function init(){
$this->server->api->console->register("seed", "[world]", array($this, "commandHandler"));
$this->server->api->console->register("save-all", "", array($this, "commandHandler")); $this->server->api->console->register("save-all", "", array($this, "commandHandler"));
$this->server->api->console->register("save-on", "", array($this, "commandHandler")); $this->server->api->console->register("save-on", "", array($this, "commandHandler"));
$this->server->api->console->register("save-off", "", array($this, "commandHandler")); $this->server->api->console->register("save-off", "", array($this, "commandHandler"));
@ -52,16 +51,6 @@ class LevelAPI{
case "save-off": case "save-off":
$this->server->saveEnabled = false; $this->server->saveEnabled = false;
break; break;
case "seed":
if(!isset($params[0]) and ($issuer instanceof Player)){
$output .= "Seed: " . $issuer->level->getSeed() . "\n";
}elseif(isset($params[0])){
if(($lv = Level::get(trim(implode(" ", $params)))) !== false){
$output .= "Seed: " . $lv->getSeed() . "\n";
}
}else{
$output .= "Seed: " . Level::getDefault()->getSeed() . "\n";
}
} }
return $output; return $output;

View File

@ -63,6 +63,7 @@ use PocketMine\Network\RakNet\Info;
use PocketMine\Network\RakNet\Packet; use PocketMine\Network\RakNet\Packet;
use PocketMine\PMF\LevelFormat; use PocketMine\PMF\LevelFormat;
use PocketMine\Recipes\Crafting; use PocketMine\Recipes\Crafting;
use PocketMine\Scheduler\CallbackTask;
use PocketMine\Tile\Chest; use PocketMine\Tile\Chest;
use PocketMine\Tile\Furnace; use PocketMine\Tile\Furnace;
use PocketMine\Tile\Sign; use PocketMine\Tile\Sign;
@ -79,7 +80,7 @@ use PocketMine\Utils\Utils;
* Class Player * Class Player
* @package PocketMine * @package PocketMine
*/ */
class Player extends RealHuman /*TODO: implements CommandSender*/{ class Player extends RealHuman/* implements CommandSender*/{
const BROADCAST_CHANNEL_ADMINISTRATIVE = "pocketmine.broadcast.admin"; const BROADCAST_CHANNEL_ADMINISTRATIVE = "pocketmine.broadcast.admin";
const BROADCAST_CHANNEL_USERS = "pocketmine.broadcast.user"; const BROADCAST_CHANNEL_USERS = "pocketmine.broadcast.user";
@ -154,6 +155,11 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
private $chunkCount = array(); private $chunkCount = array();
private $received = array(); private $received = array();
/**
* @var \PocketMine\Scheduler\TaskHandler[]
*/
private $tasks = array();
/** /**
* @param integer $clientID * @param integer $clientID
* @param string $ip * @param string $ip
@ -166,7 +172,6 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$this->server = Server::getInstance(); $this->server = Server::getInstance();
$this->lastBreak = microtime(true); $this->lastBreak = microtime(true);
$this->clientID = $clientID; $this->clientID = $clientID;
$this->CID = Server::clientID($ip, $port);
Player::$list[$this->CID] = $this; Player::$list[$this->CID] = $this;
$this->ip = $ip; $this->ip = $ip;
$this->port = $port; $this->port = $port;
@ -180,9 +185,9 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$this->packetStats = array(0, 0); $this->packetStats = array(0, 0);
$this->buffer = new Packet(Info::DATA_PACKET_0); $this->buffer = new Packet(Info::DATA_PACKET_0);
$this->buffer->data = array(); $this->buffer->data = array();
$this->server->schedule(2, array($this, "handlePacketQueues"), array(), true); $this->tasks[] = $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "handlePacketQueues")), 1);
$this->server->schedule(20 * 60, array($this, "clearQueue"), array(), true); $this->tasks[] = $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "clearQueue")), 20 * 60);
$this->evid[] = $this->server->event("server.close", array($this, "close"));
console("[DEBUG] New Session started with " . $ip . ":" . $port . ". MTU " . $this->MTU . ", Client ID " . $this->clientID, true, true, 2); console("[DEBUG] New Session started with " . $ip . ":" . $port . ". MTU " . $this->MTU . ", Client ID " . $this->clientID, true, true, 2);
} }
@ -244,16 +249,16 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
* Sends, if available, the next ordered chunk to the client * Sends, if available, the next ordered chunk to the client
* *
* @param bool $force * @param bool $force
* @param null $ev * @param bool $ev
* *
* @return bool|void * @return bool|void
*/ */
public function getNextChunk($force = false, $ev = null){ public function getNextChunk($force = false, $ev = null){
if($this->connected === false){ if($this->connected === false){
return false; return;
} }
if($ev === "server.schedule"){ if($ev === true){
--$this->chunkScheduled; --$this->chunkScheduled;
if($this->chunkScheduled < 0){ if($this->chunkScheduled < 0){
$this->chunkScheduled = 0; $this->chunkScheduled = 0;
@ -263,10 +268,9 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
foreach($this->chunkCount as $count => $t){ foreach($this->chunkCount as $count => $t){
if(isset($this->recoveryQueue[$count]) or isset($this->resendQueue[$count])){ if(isset($this->recoveryQueue[$count]) or isset($this->resendQueue[$count])){
if($this->chunkScheduled === 0){ if($this->chunkScheduled === 0){
$this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk")); $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "getNextChunk"), array(false, true)), MAX_CHUNK_RATE);
++$this->chunkScheduled; ++$this->chunkScheduled;
} }
return; return;
}else{ }else{
unset($this->chunkCount[$count]); unset($this->chunkCount[$count]);
@ -291,7 +295,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$distance = @$this->chunksOrder[$index]; $distance = @$this->chunksOrder[$index];
if($index === null or $distance === null){ if($index === null or $distance === null){
if($this->chunkScheduled === 0){ if($this->chunkScheduled === 0){
$this->server->schedule(40, array($this, "getNextChunk")); $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "getNextChunk")), 60);
} }
return false; return false;
@ -302,7 +306,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
if(!$this->level->isChunkPopulated($X, $Z)){ if(!$this->level->isChunkPopulated($X, $Z)){
$this->orderChunks(); $this->orderChunks();
if($this->chunkScheduled === 0 or $force === true){ if($this->chunkScheduled === 0 or $force === true){
$this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk")); $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "getNextChunk")), MAX_CHUNK_RATE);
++$this->chunkScheduled; ++$this->chunkScheduled;
} }
@ -331,7 +335,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$this->lastChunk = array($X, $Z); $this->lastChunk = array($X, $Z);
if($this->chunkScheduled === 0 or $force === true){ if($this->chunkScheduled === 0 or $force === true){
$this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk")); $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "getNextChunk")), MAX_CHUNK_RATE);
++$this->chunkScheduled; ++$this->chunkScheduled;
} }
} }
@ -501,7 +505,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$this->updateMetadata(); $this->updateMetadata();
}*/ }*/
$this->setSpawn($pos); $this->setSpawn($pos);
$this->server->schedule(60, array($this, "checkSleep")); $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "checkSleep")), 60);
return true; return true;
} }
@ -534,6 +538,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
public function checkSleep(){ public function checkSleep(){
if($this->sleeping !== false){ if($this->sleeping !== false){
//TODO
if($this->server->api->time->getPhase($this->level) === "night"){ if($this->server->api->time->getPhase($this->level) === "night"){
foreach($this->level->getPlayers() as $p){ foreach($this->level->getPlayers() as $p){
if($p->sleeping === false){ if($p->sleeping === false){
@ -554,6 +559,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
*/ */
public function eventHandler($data, $event){ public function eventHandler($data, $event){
switch($event){ switch($event){
//TODO, obsolete
case "tile.update": case "tile.update":
if($data->level === $this->level){ if($data->level === $this->level){
if($data instanceof Furnace){ if($data instanceof Furnace){
@ -688,12 +694,13 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
if(($this->gamemode & 0x01) === ($gm & 0x01)){ if(($this->gamemode & 0x01) === ($gm & 0x01)){
$this->gamemode = $gm; $this->gamemode = $gm;
$this->sendMessage("Your gamemode has been changed to " . $this->getGamemode() . ".\n"); $this->sendMessage("Your gamemode has been changed to " . Server::getGamemodeString($this->getGamemode()) . ".\n");
}else{ }else{
$this->blocked = true; $this->blocked = true;
$this->gamemode = $gm; $this->gamemode = $gm;
$this->sendMessage("Your gamemode has been changed to " . $this->getGamemode() . ", you've to do a forced reconnect.\n"); $this->sendMessage("Your gamemode has been changed to " . Server::getGamemodeString($this->getGamemode()) . ", you've to do a forced reconnect.\n");
$this->server->schedule(30, array($this, "close"), "gamemode change"); //Forces a kick $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "close"), array($this->username . " has left the game", "gamemode change")), 30);
} }
$this->sendSettings(); $this->sendSettings();
@ -750,19 +757,6 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$this->dataPacket($pk); $this->dataPacket($pk);
} }
public function getGamemodeString(){
switch($this->gamemode){
case 0:
return "survival";
case 1:
return "creative";
case 2:
return "adventure";
case 3:
return "view";
}
}
public function measureLag(){ public function measureLag(){
if($this->connected === false){ if($this->connected === false){
return false; return false;
@ -949,7 +943,9 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$this->username = $packet->username; $this->username = $packet->username;
$this->iusername = strtolower($this->username); $this->iusername = strtolower($this->username);
$this->loginData = array("clientId" => $packet->clientId, "loginData" => $packet->loginData); $this->loginData = array("clientId" => $packet->clientId, "loginData" => $packet->loginData);
if(count(Player::$list) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)){
//TODO: op things
if(count(Player::$list) > $this->server->getMaxPlayers() and !$this->server->api->ban->isOp($this->iusername)){
$this->kick("server full"); $this->kick("server full");
return; return;
@ -981,10 +977,12 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
return; return;
} }
//TODO: whitelist things
if($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)){ if($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)){
$this->close($this->username . " has left the game", "Server is white-listed"); $this->close($this->username . " has left the game", "Server is white-listed");
return; return;
//TODO: ban things
}elseif($this->server->api->ban->isBanned($this->iusername) or $this->server->api->ban->isIPBanned($this->ip)){ }elseif($this->server->api->ban->isBanned($this->iusername) or $this->server->api->ban->isIPBanned($this->ip)){
$this->close($this->username . " has left the game", "You are banned"); $this->close($this->username . " has left the game", "You are banned");
@ -1071,14 +1069,16 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$this->dataPacket($pk); $this->dataPacket($pk);
} }
$this->evid[] = $this->server->event("entity.animate", array($this, "eventHandler")); //TODO: new events, or remove them!
$this->evid[] = $this->server->event("entity.event", array($this, "eventHandler")); //$this->evid[] = $this->server->event("entity.animate", array($this, "eventHandler"));
$this->evid[] = $this->server->event("entity.metadata", array($this, "eventHandler")); //$this->evid[] = $this->server->event("entity.event", array($this, "eventHandler"));
$this->evid[] = $this->server->event("player.pickup", array($this, "eventHandler")); //$this->evid[] = $this->server->event("entity.metadata", array($this, "eventHandler"));
$this->evid[] = $this->server->event("tile.container.slot", array($this, "eventHandler")); //$this->evid[] = $this->server->event("player.pickup", array($this, "eventHandler"));
$this->evid[] = $this->server->event("tile.update", array($this, "eventHandler")); //$this->evid[] = $this->server->event("tile.container.slot", array($this, "eventHandler"));
//$this->evid[] = $this->server->event("tile.update", array($this, "eventHandler"));
$this->lastMeasure = microtime(true); $this->lastMeasure = microtime(true);
$this->server->schedule(50, array($this, "measureLag"), array(), true); $this->tasks[] = $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "measureLag")), 50);
console("[INFO] " . TextFormat::AQUA . $this->username . TextFormat::RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->id . " at (" . $this->level->getName() . ", " . round($this->x, 4) . ", " . round($this->y, 4) . ", " . round($this->z, 4) . ")"); console("[INFO] " . TextFormat::AQUA . $this->username . TextFormat::RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->id . " at (" . $this->level->getName() . ", " . round($this->x, 4) . ", " . round($this->y, 4) . ", " . round($this->z, 4) . ")");
$this->server->getPluginManager()->callEvent(new Event\Player\PlayerJoinEvent($this, $this->username . " joined the game")); $this->server->getPluginManager()->callEvent(new Event\Player\PlayerJoinEvent($this, $this->username . " joined the game"));
@ -1096,12 +1096,13 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
//$this->heal($this->data->get("health"), "spawn", true); //$this->heal($this->data->get("health"), "spawn", true);
$this->spawned = true; $this->spawned = true;
$this->spawnToAll(); $this->spawnToAll();
$this->sendMessage($this->server->motd . "\n"); $this->sendMessage($this->server->getMotd() . "\n");
$this->sendInventory(); $this->sendInventory();
$this->sendSettings(); $this->sendSettings();
$this->sendArmor(); $this->sendArmor();
$this->server->schedule(30, array($this, "orderChunks"), array(), true); $this->tasks[] = $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "orderChunks")), 30);
$this->blocked = false; $this->blocked = false;
$pk = new SetTimePacket; $pk = new SetTimePacket;
@ -1111,9 +1112,11 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$pos = new Position($this->x, $this->y, $this->z, $this->level); $pos = new Position($this->x, $this->y, $this->z, $this->level);
$pos = $this->level->getSafeSpawn($pos); $pos = $this->level->getSafeSpawn($pos);
$this->teleport($pos); $this->server->getPluginManager()->callEvent($ev = new Event\Player\PlayerRespawnEvent($this, $pos));
$this->teleport($ev->getRespawnPosition());
$this->sendBuffer(); $this->sendBuffer();
$this->server->handle("player.spawn", $this);
break; break;
case 2: //Chunk loaded? case 2: //Chunk loaded?
break; break;
@ -1273,7 +1276,8 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$pk->meta = $block->getMetadata(); $pk->meta = $block->getMetadata();
$this->dataPacket($pk); $this->dataPacket($pk);
break; break;
}elseif($packet->face === 0xff and $this->server->handle("player.action", $data) !== false){ }elseif($packet->face === 0xff){
//TODO: add event
$this->inAction = true; $this->inAction = true;
$this->startAction = microtime(true); $this->startAction = microtime(true);
//$this->updateMetadata(); //$this->updateMetadata();
@ -1532,15 +1536,15 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$this->server->api->dhandle("entity.animate", array("eid" => $packet->eid, "entity" => $this->entity, "action" => $packet->action)); $this->server->api->dhandle("entity.animate", array("eid" => $packet->eid, "entity" => $this->entity, "action" => $packet->action));
break;*/ break;*/
case ProtocolInfo::RESPAWN_PACKET: case ProtocolInfo::RESPAWN_PACKET:
if($this->spawned === false){ if($this->spawned === false or $this->dead === false){
break;
}
if(@$this->entity->dead === false){
break; break;
} }
$this->craftingItems = array(); $this->craftingItems = array();
$this->toCraft = array(); $this->toCraft = array();
$this->teleport($this->spawnPosition);
$this->server->getPluginManager()->callEvent($ev = new Event\Player\PlayerRespawnEvent($this, $this->spawnPosition));
$this->teleport($ev->getRespawnPosition());
//$this->entity->fire = 0; //$this->entity->fire = 0;
//$this->entity->air = 300; //$this->entity->air = 300;
//$this->entity->setHealth(20, "respawn", true); //$this->entity->setHealth(20, "respawn", true);
@ -1548,7 +1552,6 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$this->sendInventory(); $this->sendInventory();
$this->blocked = false; $this->blocked = false;
$this->server->handle("player.respawn", $this);
break; break;
case ProtocolInfo::SET_HEALTH_PACKET: //Not used case ProtocolInfo::SET_HEALTH_PACKET: //Not used
break; break;
@ -1637,10 +1640,14 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$packet->message = TextFormat::clean($packet->message); $packet->message = TextFormat::clean($packet->message);
if(trim($packet->message) != "" and strlen($packet->message) <= 255){ if(trim($packet->message) != "" and strlen($packet->message) <= 255){
$message = $packet->message; $message = $packet->message;
if($message{0} === "/"){ //Command $this->server->getPluginManager()->callEvent($ev = new Event\Player\PlayerCommandPreprocessEvent($this, $message));
$this->server->api->console->run(substr($message, 1), $this); if($ev->isCancelled()){
break;
}
if(substr($ev->getMessage(), 0, 1) === "/"){ //Command
$this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1));
}else{ }else{
$this->server->getPluginManager()->callEvent($ev = new Event\Player\PlayerChatEvent($this, $message)); $this->server->getPluginManager()->callEvent($ev = new Event\Player\PlayerChatEvent($this, $ev->getMessage()));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
Player::groupChat(sprintf($ev->getFormat(), $ev->getPlayer()->getDisplayName(), $ev->getMessage()), $ev->getRecipients()); Player::groupChat(sprintf($ev->getFormat(), $ev->getPlayer()->getDisplayName(), $ev->getMessage()), $ev->getRecipients());
} }
@ -1757,7 +1764,8 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$item = Item::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount()); $item = Item::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
$slot = $tile->getSlot($slotn); $slot = $tile->getSlot($slotn);
if($this->server->api->dhandle("player.container.slot", array( //TODO: container access events?
/*if($this->server->api->dhandle("player.container.slot", array(
"tile" => $tile, "tile" => $tile,
"slot" => $packet->slot, "slot" => $packet->slot,
"offset" => $offset, "offset" => $offset,
@ -1772,7 +1780,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$pk->item = $slot; $pk->item = $slot;
$this->dataPacket($pk); $this->dataPacket($pk);
break; break;
} }*/
if($item->getID() !== Item::AIR and $slot->getID() == $item->getID()){ if($item->getID() !== Item::AIR and $slot->getID() == $item->getID()){
if($slot->getCount() < $item->getCount()){ if($slot->getCount() < $item->getCount()){
$it = clone $item; $it = clone $item;
@ -1811,7 +1819,8 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$item = Item::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount()); $item = Item::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
$slot = $tile->getSlot($packet->slot); $slot = $tile->getSlot($packet->slot);
if($this->server->api->dhandle("player.container.slot", array( //TODO: container access events?
/*if($this->server->api->dhandle("player.container.slot", array(
"tile" => $tile, "tile" => $tile,
"slot" => $packet->slot, "slot" => $packet->slot,
"slotdata" => $slot, "slotdata" => $slot,
@ -1825,7 +1834,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$pk->item = $slot; $pk->item = $slot;
$this->dataPacket($pk); $this->dataPacket($pk);
break; break;
} }*/
if($tile instanceof Furnace and $packet->slot == 2){ if($tile instanceof Furnace and $packet->slot == 2){
switch($slot->getID()){ switch($slot->getID()){
@ -1885,7 +1894,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
} }
break; break;
default: default:
console("[DEBUG] Unhandled 0x" . dechex($packet->pid()) . " data packet for " . $this->username . " (" . $this->clientID . "): " . print_r($packet, true), true, true, 2); console("[DEBUG] Unhandled " . $packet->pid() . " data packet for " . $this->username . " (" . $this->clientID . "): " . print_r($packet, true), true, true, 2);
break; break;
} }
} }
@ -2098,7 +2107,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
public static function getOffline($name){ public static function getOffline($name){
$server = Server::getInstance(); $server = Server::getInstance();
$iname = strtolower($name); $iname = strtolower($name);
if(!file_exists(\PocketMine\DATA . "players/" . $iname . ".dat")){ if(!file_exists(Server::getInstance()->getDataPath() . "players/" . $iname . ".dat")){
$spawn = Level::getDefault()->getSafeSpawn(); $spawn = Level::getDefault()->getSafeSpawn();
$nbt = new Compound(false, array( $nbt = new Compound(false, array(
new Enum("Pos", array( new Enum("Pos", array(
@ -2114,7 +2123,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
new Byte("SpawnForced", 1), //TODO new Byte("SpawnForced", 1), //TODO
new Enum("Inventory", array()), new Enum("Inventory", array()),
new Compound("Achievements", array()), new Compound("Achievements", array()),
new Int("playerGameType", $server->gamemode), new Int("playerGameType", $server->getGamemode()),
new Enum("Motion", array( new Enum("Motion", array(
new Double(0, 0.0), new Double(0, 0.0),
new Double(1, 0.0), new Double(1, 0.0),
@ -2135,8 +2144,8 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
$nbt->Inventory->setTagType(NBT::TAG_Compound); $nbt->Inventory->setTagType(NBT::TAG_Compound);
$nbt->Motion->setTagType(NBT::TAG_Double); $nbt->Motion->setTagType(NBT::TAG_Double);
$nbt->Rotation->setTagType(NBT::TAG_Float); $nbt->Rotation->setTagType(NBT::TAG_Float);
if(file_exists(\PocketMine\DATA . "players/" . $iname . ".yml")){ if(file_exists(Server::getInstance()->getDataPath() . "players/" . $iname . ".yml")){
$data = new Config(\PocketMine\DATA . "players/" . $iname . ".yml", Config::YAML, array()); $data = new Config(Server::getInstance()->getDataPath() . "players/" . $iname . ".yml", Config::YAML, array());
$nbt["playerGameType"] = (int) $data->get("gamemode"); $nbt["playerGameType"] = (int) $data->get("gamemode");
$nbt["Level"] = $data->get("position")["level"]; $nbt["Level"] = $data->get("position")["level"];
$nbt["Pos"][0] = $data->get("position")["x"]; $nbt["Pos"][0] = $data->get("position")["x"];
@ -2183,7 +2192,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
foreach($data->get("achievements") as $achievement => $status){ foreach($data->get("achievements") as $achievement => $status){
$nbt->Achievements[$achievement] = new Byte($achievement, $status == true ? 1 : 0); $nbt->Achievements[$achievement] = new Byte($achievement, $status == true ? 1 : 0);
} }
unlink(\PocketMine\DATA . "players/" . $iname . ".yml"); unlink(Server::getInstance()->getDataPath() . "players/" . $iname . ".yml");
}else{ }else{
console("[NOTICE] Player data not found for \"" . $iname . "\", creating new profile"); console("[NOTICE] Player data not found for \"" . $iname . "\", creating new profile");
Player::saveOffline($name, $nbt); Player::saveOffline($name, $nbt);
@ -2191,7 +2200,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
}else{ }else{
$nbt = new NBT(NBT::BIG_ENDIAN); $nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->readCompressed(file_get_contents(\PocketMine\DATA . "players/" . $iname . ".dat")); $nbt->readCompressed(file_get_contents(Server::getInstance()->getDataPath() . "players/" . $iname . ".dat"));
$nbt = $nbt->getData(); $nbt = $nbt->getData();
} }
@ -2207,7 +2216,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
public static function saveOffline($name, Compound $nbtTag){ public static function saveOffline($name, Compound $nbtTag){
$nbt = new NBT(NBT::BIG_ENDIAN); $nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->setData($nbtTag); $nbt->setData($nbtTag);
file_put_contents(\PocketMine\DATA . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed()); file_put_contents(Server::getInstance()->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
} }
/** /**
@ -2234,7 +2243,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
/** /**
* Broadcasts a Minecraft packet to a list of players * Broadcasts a Minecraft packet to a list of players
* *
* @param array $players * @param Player[] $players
* @param DataPacket $packet * @param DataPacket $packet
*/ */
public static function broadcastPacket(array $players, DataPacket $packet){ public static function broadcastPacket(array $players, DataPacket $packet){
@ -2244,16 +2253,16 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
} }
/** /**
* @param array $craft * @param Item[] $craft
* @param array $recipe * @param Item[] $recipe
* @param $type * @param int $type
* *
* @return array|bool * @return array|bool
*/ */
public function craftItems(array $craft, array $recipe, $type){ public function craftItems(array $craft, array $recipe, $type){
$craftItem = array(0, true, 0); $craftItem = array(0, true, 0);
unset($craft[-1]); unset($craft[-1]);
foreach($craft as $slot => $item){ foreach($craft as $item){
if($item instanceof Item){ if($item instanceof Item){
$craftItem[0] = $item->getID(); $craftItem[0] = $item->getID();
if($item->getMetadata() !== $craftItem[1] and $craftItem[1] !== true){ if($item->getMetadata() !== $craftItem[1] and $craftItem[1] !== true){
@ -2267,7 +2276,7 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
} }
$recipeItems = array(); $recipeItems = array();
foreach($recipe as $slot => $item){ foreach($recipe as $item){
if(!isset($recipeItems[$item->getID()])){ if(!isset($recipeItems[$item->getID()])){
$recipeItems[$item->getID()] = array($item->getID(), $item->getMetadata(), $item->getCount()); $recipeItems[$item->getID()] = array($item->getID(), $item->getMetadata(), $item->getCount());
}else{ }else{
@ -2288,10 +2297,12 @@ class Player extends RealHuman /*TODO: implements CommandSender*/{
} }
if(is_array($res)){ if(is_array($res)){
//TODO: CraftItemEvent
//$this->server->getPluginManager($ev = new CraftItemEvent($this, $recipe, $craft, $type));
//if($ev->isCancelled()){
// return false;
//}
if($this->server->api->dhandle("player.craft", array("player" => $this, "recipe" => $recipe, "craft" => $craft, "type" => $type)) === false){
return false;
}
foreach($recipe as $slot => $item){ foreach($recipe as $slot => $item){
$s = $this->getSlot($slot); $s = $this->getSlot($slot);
$s->setCount($s->getCount() - $item->getCount()); $s->setCount($s->getCount() - $item->getCount());

View File

@ -35,6 +35,7 @@ use PocketMine\Entity\Entity;
use PocketMine\Event\HandlerList; use PocketMine\Event\HandlerList;
use PocketMine\Event\Server\PacketReceiveEvent; use PocketMine\Event\Server\PacketReceiveEvent;
use PocketMine\Event\Server\PacketSendEvent; use PocketMine\Event\Server\PacketSendEvent;
use PocketMine\Event\Server\ServerCommandEvent;
use PocketMine\Item\Item; use PocketMine\Item\Item;
use PocketMine\Level\Generator\Generator; use PocketMine\Level\Generator\Generator;
use PocketMine\Level\Level; use PocketMine\Level\Level;
@ -57,49 +58,31 @@ use PocketMine\Utils\Utils;
use PocketMine\Utils\VersionString; use PocketMine\Utils\VersionString;
class Server{ class Server{
/** /** @var Server */
* @var Server
*/
private static $instance = null; private static $instance = null;
/** /** @var bool */
* @var bool
*/
private $isRunning = true; private $isRunning = true;
/** /** @var PluginManager */
* @var PluginManager
*/
private $pluginManager = null; private $pluginManager = null;
/** /** @var ServerScheduler */
* @var ServerScheduler
*/
private $scheduler = null; private $scheduler = null;
/** /** @var TickScheduler */
* @var TickScheduler
*/
private $tickScheduler = null; private $tickScheduler = null;
/** /** @var CommandReader */
* @var CommandReader
*/
private $console = null; private $console = null;
/** /** @var SimpleCommandMap */
* @var SimpleCommandMap
*/
private $commandMap = null; private $commandMap = null;
/** /** @var ConsoleCommandSender */
* @var ConsoleCommandSender
*/
private $consoleSender; private $consoleSender;
/** /** @var int */
* @var int
*/
private $maxPlayers; private $maxPlayers;
/** /**
@ -110,9 +93,7 @@ class Server{
private $tickCounter; private $tickCounter;
private $inTick = false; private $inTick = false;
/** /** @var ThreadedHandler */
* @var ThreadedHandler
*/
private $interface; private $interface;
private $serverID; private $serverID;
@ -122,14 +103,10 @@ class Server{
private $dataPath; private $dataPath;
private $pluginPath; private $pluginPath;
/** /** @var QueryHandler */
* @var QueryHandler
*/
private $queryHandler; private $queryHandler;
/** /** @var Config */
* @var Config
*/
private $properties; private $properties;
/** /**
@ -251,6 +228,61 @@ class Server{
return $this->getConfigInt("gamemode", 0) & 0b11; return $this->getConfigInt("gamemode", 0) & 0b11;
} }
/**
* Returns the gamemode text name
*
* @param int $mode
*
* @return string
*/
public static function getGamemodeString($mode){
switch((int) $mode){
case Player::SURVIVAL:
return "SURVIVAL";
case Player::CREATIVE:
return "CREATIVE";
case Player::ADVENTURE:
return "ADVENTURE";
case Player::SPECTATOR:
return "SPECTATOR";
}
return "UNKNOWN";
}
/**
* Parses a string and returns a gamemode integer, -1 if not found
*
* @param string $str
*
* @return int
*/
public static function getGamemodeFromString($str){
switch(strtolower(trim($str))){
case (string) Player::SURVIVAL:
case "survival":
case "s":
return Player::SURVIVAL;
case (string) Player::CREATIVE:
case "creative":
case "c":
return Player::CREATIVE;
case (string) Player::ADVENTURE:
case "adventure":
case "a":
return Player::ADVENTURE;
case (string) Player::SPECTATOR:
case "spectator":
case "view":
case "v":
return Player::SPECTATOR;
}
return -1;
}
/** /**
* @return int * @return int
*/ */
@ -614,7 +646,8 @@ class Server{
public function checkConsole(){ public function checkConsole(){
if(($line = $this->console->getLine()) !== null){ if(($line = $this->console->getLine()) !== null){
$this->dispatchCommand($this->consoleSender, $line); $this->pluginManager->callEvent($ev = new ServerCommandEvent($this->consoleSender, $line));
$this->dispatchCommand($this->consoleSender, $ev->getCommand());
} }
} }
@ -668,7 +701,7 @@ class Server{
pcntl_signal(SIGHUP, array($this, "close")); pcntl_signal(SIGHUP, array($this, "close"));
} }
*/ */
console("[INFO] Default game type: " . strtoupper($this->getGamemode())); //TODO: string name console("[INFO] Default game type: " . self::getGamemodeString($this->getGamemode())); //TODO: string name
//$this->trigger("server.start", microtime(true)); //$this->trigger("server.start", microtime(true));
console('[INFO] Done (' . round(microtime(true) - \PocketMine\START_TIME, 3) . 's)! For help, type "help" or "?"'); console('[INFO] Done (' . round(microtime(true) - \PocketMine\START_TIME, 3) . 's)! For help, type "help" or "?"');
if(Utils::getOS() === "win"){ //Workaround less usleep() waste if(Utils::getOS() === "win"){ //Workaround less usleep() waste
@ -691,6 +724,8 @@ class Server{
$this->scheduler->cancelAllTasks(); $this->scheduler->cancelAllTasks();
$this->scheduler->mainThreadHeartbeat(PHP_INT_MAX); $this->scheduler->mainThreadHeartbeat(PHP_INT_MAX);
$this->properties->save();
$this->tickScheduler->kill(); $this->tickScheduler->kill();
$this->console->kill(); $this->console->kill();

View File

@ -44,39 +44,25 @@ class ServerAPI{
//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 */
* @var ConsoleAPI
*/
public $console; public $console;
/** /** @var LevelAPI */
* @var LevelAPI
*/
public $level; public $level;
/** /** @var BlockAPI */
* @var BlockAPI
*/
public $block; public $block;
/** /** @var ChatAPI */
* @var ChatAPI
*/
public $chat; public $chat;
/** /** @var BanAPI */
* @var BanAPI
*/
public $ban; public $ban;
/** /** @var TimeAPI */
* @var TimeAPI
*/
public $time; public $time;
/** /** @var PlayerAPI */
* @var PlayerAPI
*/
public $player; public $player;
/** /**

View File

@ -35,9 +35,7 @@ use PocketMine\Utils\Utils;
use PocketMine\Utils\VersionString; use PocketMine\Utils\VersionString;
class ServerOld{ class ServerOld{
/** /** @var Server */
* @var Server
*/
private static $instance; private static $instance;
public $tCnt; public $tCnt;

View File

@ -29,19 +29,13 @@ use PocketMine\Server;
use PocketMine\Utils\TextFormat; use PocketMine\Utils\TextFormat;
abstract class Command{ abstract class Command{
/** /** @var string */
* @var string
*/
private $name; private $name;
/** /** @var string */
* @var string
*/
private $nextLabel; private $nextLabel;
/** /** @var string */
* @var string
*/
private $label; private $label;
/** /**
@ -54,29 +48,19 @@ abstract class Command{
*/ */
private $activeAliases = array(); private $activeAliases = array();
/** /** @var CommandMap */
* @var CommandMap
*/
private $commandMap = null; private $commandMap = null;
/** /** @var string */
* @var string
*/
protected $description = ""; protected $description = "";
/** /** @var string */
* @var string
*/
protected $usageMessage; protected $usageMessage;
/** /** @var string */
* @var string
*/
private $permission = null; private $permission = null;
/** /** @var string */
* @var string
*/
private $permissionMessage = null; private $permissionMessage = null;
/** /**

View File

@ -24,15 +24,11 @@ namespace PocketMine\Command;
class CommandReader extends \Thread{ class CommandReader extends \Thread{
private $stream; private $stream;
/** /** @var resource */
* @var resource
*/
private $fp; private $fp;
private $readline; private $readline;
/** /** @var \Threaded */
* @var \Threaded
*/
private $buffer; private $buffer;
/** /**

View File

@ -25,14 +25,10 @@ use PocketMine\Plugin\Plugin;
class PluginCommand extends Command{ class PluginCommand extends Command{
/** /** @var Plugin */
* @var Plugin
*/
private $owningPlugin; private $owningPlugin;
/** /** @var CommandExecutor */
* @var CommandExecutor
*/
private $executor; private $executor;
/** /**

View File

@ -21,6 +21,7 @@
namespace PocketMine\Command; namespace PocketMine\Command;
use PocketMine\Command\Defaults\DefaultGamemodeCommand;
use PocketMine\Command\Defaults\HelpCommand; use PocketMine\Command\Defaults\HelpCommand;
use PocketMine\Command\Defaults\PluginsCommand; use PocketMine\Command\Defaults\PluginsCommand;
use PocketMine\Command\Defaults\SeedCommand; use PocketMine\Command\Defaults\SeedCommand;
@ -37,9 +38,7 @@ class SimpleCommandMap implements CommandMap{
*/ */
protected $knownCommands = array(); protected $knownCommands = array();
/** /** @var Server */
* @var Server
*/
private $server; private $server;
public function __construct(Server $server){ public function __construct(Server $server){
@ -55,6 +54,7 @@ class SimpleCommandMap implements CommandMap{
$this->register("pocketmine", new HelpCommand("help")); $this->register("pocketmine", new HelpCommand("help"));
$this->register("pocketmine", new StopCommand("stop")); $this->register("pocketmine", new StopCommand("stop"));
$this->register("pocketmine", new TellCommand("tell")); $this->register("pocketmine", new TellCommand("tell"));
$this->register("pocketmine", new DefaultGamemodeCommand("defaultgamemode"));
} }

View File

@ -22,21 +22,19 @@
namespace PocketMine\Command\Defaults; namespace PocketMine\Command\Defaults;
use PocketMine\Command\CommandSender; use PocketMine\Command\CommandSender;
use PocketMine\Network\Protocol\Info; use PocketMine\Player;
use PocketMine\Plugin\Plugin;
use PocketMine\Server; use PocketMine\Server;
use PocketMine\Utils\TextFormat; use PocketMine\Utils\TextFormat;
class VersionCommand extends VanillaCommand{ class DefaultGamemodeCommand extends VanillaCommand{
public function __construct($name){ public function __construct($name){
parent::__construct( parent::__construct(
$name, $name,
"Gets the version of this server including any plugins in use", "Set the default gamemode",
"/version [plugin name]", "/defaultgamemode <mode>"
["ver", "about"]
); );
$this->setPermission("pocketmine.command.version"); $this->setPermission("pocketmine.command.defaultgamemode");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, $currentAlias, array $args){
@ -45,56 +43,18 @@ class VersionCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$output = "This server is running PocketMine-MP version " . Server::getInstance()->getPocketMineVersion() . "" . Server::getInstance()->getCodename() . "」 (Implementing API version " . Server::getInstance()->getApiVersion() . " for Minecraft: PE " . Server::getInstance()->getVersion() . " protocol version " . Info::CURRENT_PROTOCOL . ")"; $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
if(\PocketMine\GIT_COMMIT !== str_repeat("00", 20)){ return false;
$output .= " [git " . \PocketMine\GIT_COMMIT . "]";
}
$sender->sendMessage($output);
}else{
$pluginName = implode(" ", $args);
$exactPlugin = Server::getInstance()->getPluginManager()->getPlugin($pluginName);
if($exactPlugin instanceof Plugin){
$this->describeToSender($exactPlugin, $sender);
return true;
}
$found = false;
$pluginName = strtolower($pluginName);
foreach(Server::getInstance()->getPluginManager()->getPlugins() as $plugin){
if(stripos($plugin->getName(), $pluginName) !== false){
$this->describeToSender($plugin, $sender);
$found = true;
}
}
if(!$found){
$sender->sendMessage("This server is not running any plugin by that name.\nUse /plugins to get a list of plugins.");
}
} }
$gameMode = Server::getGamemodeFromString($args[0]);
if($gameMode !== -1){
Server::getInstance()->setConfigInt("gamemode", $gameMode);
$sender->sendMessage("Default game mode set to ". strtolower(Server::getGamemodeString($gameMode)));
}else{
$sender->sendMessage("Unknown game mode");
}
return true; return true;
} }
private function describeToSender(Plugin $plugin, CommandSender $sender){
$desc = $plugin->getDescription();
$sender->sendMessage(TextFormat::DARK_GREEN . $desc->getName() . TextFormat::WHITE . " version " . TextFormat::DARK_GREEN . $desc->getVersion());
if($desc->getDescription() != null){
$sender->sendMessage($desc->getDescription());
}
if($desc->getWebsite() != null){
$sender->sendMessage("Website: " . $desc->getWebsite());
}
if(count($authors = $desc->getAuthors()) > 0){
if(count($authors) === 1){
$sender->sendMessage("Author: " . implode(", ", $authors));
}else{
$sender->sendMessage("Authors: " . implode(", ", $authors));
}
}
}
} }

View File

@ -29,19 +29,13 @@ use PocketMine\Player;
class BlockBreakEvent extends BlockEvent implements Cancellable{ class BlockBreakEvent extends BlockEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
/** /** @var \PocketMine\Player */
* @var \PocketMine\Player
*/
protected $player; protected $player;
/** /** @var \PocketMine\Item\Item */
* @var \PocketMine\Item\Item
*/
protected $item; protected $item;
/** /** @var bool */
* @var bool
*/
protected $instaBreak = false; protected $instaBreak = false;
public function __construct(Player $player, Block $block, Item $item, $instaBreak = false){ public function __construct(Player $player, Block $block, Item $item, $instaBreak = false){

View File

@ -27,9 +27,7 @@ namespace PocketMine\Event\Block;
use PocketMine\Event\Event; use PocketMine\Event\Event;
abstract class BlockEvent extends Event{ abstract class BlockEvent extends Event{
/** /** @var \PocketMine\Block\Block */
* @var \PocketMine\Block\Block
*/
protected $block; protected $block;
public function getBlock(){ public function getBlock(){

View File

@ -32,14 +32,10 @@ use PocketMine\Player;
class BlockPlaceEvent extends BlockEvent implements Cancellable{ class BlockPlaceEvent extends BlockEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
/** /** @var \PocketMine\Player */
* @var \PocketMine\Player
*/
protected $player; protected $player;
/** /** @var \PocketMine\Item\Item */
* @var \PocketMine\Item\Item
*/
protected $item; protected $item;

View File

@ -27,9 +27,7 @@ namespace PocketMine\Event\Entity;
use PocketMine\Event\Event; use PocketMine\Event\Event;
abstract class EntityEvent extends Event{ abstract class EntityEvent extends Event{
/** /** @var \PocketMine\Entity\Entity */
* @var \PocketMine\Entity\Entity
*/
protected $entity; protected $entity;
public function getEntity(){ public function getEntity(){

View File

@ -32,9 +32,7 @@ use PocketMine\Level\Position;
class EntityExplodeEvent extends EntityEvent implements Cancellable{ class EntityExplodeEvent extends EntityEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
/** /** @var Position */
* @var Position
*/
protected $position; protected $position;
/** /**
@ -42,9 +40,7 @@ class EntityExplodeEvent extends EntityEvent implements Cancellable{
*/ */
protected $blocks; protected $blocks;
/** /** @var float */
* @var float
*/
protected $yield; protected $yield;
/** /**

View File

@ -29,9 +29,7 @@ use PocketMine\Math\Vector3 as Vector3;
class EntityMoveEvent extends EntityEvent implements Cancellable{ class EntityMoveEvent extends EntityEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
/** /** @var \PocketMine\Math\Vector3 */
* @var \PocketMine\Math\Vector3
*/
private $pos; private $pos;
public function __construct(Entity $entity, Vector3 $pos){ public function __construct(Entity $entity, Vector3 $pos){

View File

@ -0,0 +1,47 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/**
* Inventory related events
*/
namespace PocketMine\Event\Player;
use PocketMine\Event\Event;
abstract class InventoryEvent extends Event{
/** @var Inventory */
protected $inventory;
/**
* @return Inventory
*/
public function getInventory(){
return $this->inventory;
}
/**
* @return \PocketMine\Entity\Human[]
*/
public function getViewers(){
return $this->inventory->getViewers();
}
}

View File

@ -30,9 +30,7 @@ use PocketMine\Player;
class PlayerAchievementAwardedEvent extends PlayerEvent implements Cancellable{ class PlayerAchievementAwardedEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
/** /** @var string */
* @var string
*/
protected $achievement; protected $achievement;
/** /**

View File

@ -30,14 +30,10 @@ use PocketMine\Player;
class PlayerChatEvent extends PlayerEvent implements Cancellable{ class PlayerChatEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
/** /** @var string */
* @var string
*/
protected $message; protected $message;
/** /** @var string */
* @var string
*/
protected $format; protected $format;
/** /**

View File

@ -0,0 +1,73 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace PocketMine\Event\Player;
use PocketMine\Event\Cancellable;
use PocketMine\Player;
use PocketMine\Server;
/**
* Called when a player runs a command or chats, early in the process
*
* You don't want to use this except for a few cases like logging commands,
* blocking commands on certain places, or applying modifiers.
*
* The message contains a slash at the start
*/
class PlayerCommandPreprocessEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var string */
protected $message;
/**
* @param Player $player
* @param string $message
*/
public function __construct(Player $player, $message){
$this->player = $player;
$this->message = $message;
}
/**
* @return string
*/
public function getMessage(){
return $this->message;
}
/**
* @param string $message
*/
public function setMessage($message){
$this->message = $message;
}
/**
* @param Player $player
*/
public function setPlayer(Player $player){
$this->player = $player;
}
}

View File

@ -27,9 +27,7 @@ namespace PocketMine\Event\Player;
use PocketMine\Event\Event; use PocketMine\Event\Event;
abstract class PlayerEvent extends Event{ abstract class PlayerEvent extends Event{
/** /** @var \PocketMine\Player */
* @var \PocketMine\Player
*/
protected $player; protected $player;
public function getPlayer(){ public function getPlayer(){

View File

@ -30,9 +30,7 @@ use PocketMine\Player;
class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellable{ class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
/** /** @var int */
* @var int
*/
protected $gamemode; protected $gamemode;
public function __construct(Player $player, $newGamemode){ public function __construct(Player $player, $newGamemode){

View File

@ -37,14 +37,10 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{
*/ */
protected $blockTouched; protected $blockTouched;
/** /** @var int */
* @var int
*/
protected $blockFace; protected $blockFace;
/** /** @var \PocketMine\Item\Item */
* @var \PocketMine\Item\Item
*/
protected $item; protected $item;
public function __construct(Player $player, Item $item, Block $block, $face){ public function __construct(Player $player, Item $item, Block $block, $face){

View File

@ -29,9 +29,7 @@ use PocketMine\Player;
class PlayerJoinEvent extends PlayerEvent{ class PlayerJoinEvent extends PlayerEvent{
public static $handlerList = null; public static $handlerList = null;
/** /** @var string */
* @var string
*/
protected $joinMessage; protected $joinMessage;
public function __construct(Player $player, $joinMessage){ public function __construct(Player $player, $joinMessage){

View File

@ -30,14 +30,10 @@ use PocketMine\Player;
class PlayerKickEvent extends PlayerEvent implements Cancellable{ class PlayerKickEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
/** /** @var string */
* @var string
*/
protected $quitMessage; protected $quitMessage;
/** /** @var string */
* @var string
*/
protected $reason; protected $reason;
public function __construct(Player $player, $reason, $quitMessage){ public function __construct(Player $player, $reason, $quitMessage){

View File

@ -30,9 +30,7 @@ use PocketMine\Player;
class PlayerLoginEvent extends PlayerEvent implements Cancellable{ class PlayerLoginEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
/** /** @var string */
* @var string
*/
protected $kickMessage; protected $kickMessage;
public function __construct(Player $player, $kickMessage){ public function __construct(Player $player, $kickMessage){

View File

@ -30,9 +30,7 @@ use PocketMine\Player;
class PlayerPreLoginEvent extends PlayerEvent implements Cancellable{ class PlayerPreLoginEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
/** /** @var string */
* @var string
*/
protected $kickMessage; protected $kickMessage;
public function __construct(Player $player, $kickMessage){ public function __construct(Player $player, $kickMessage){

View File

@ -29,9 +29,7 @@ use PocketMine\Player;
class PlayerQuitEvent extends PlayerEvent{ class PlayerQuitEvent extends PlayerEvent{
public static $handlerList = null; public static $handlerList = null;
/** /** @var string */
* @var string
*/
protected $quitMessage; protected $quitMessage;
public function __construct(Player $player, $quitMessage){ public function __construct(Player $player, $quitMessage){

View File

@ -24,45 +24,38 @@ namespace PocketMine\Event\Player;
use PocketMine\Block\Block; use PocketMine\Block\Block;
use PocketMine\Event\Cancellable; use PocketMine\Event\Cancellable;
use PocketMine\Item\Item; use PocketMine\Item\Item;
use PocketMine\Level\Position;
use PocketMine\Player; use PocketMine\Player;
/** /**
* Called when a player interacts or touches a block (including air?) * Called when a player is respawned (or first time spawned)
*/ */
class PlayerInteractEvent extends PlayerEvent implements Cancellable{ class PlayerRespawnEvent extends PlayerEvent{
public static $handlerList = null; public static $handlerList = null;
/** /** @var Position */
* @var \PocketMine\Block\Block; protected $position;
*/
protected $blockTouched;
/** /**
* @var int * @param Player $player
* @param Position $position
*/ */
protected $blockFace; public function __construct(Player $player, Position $position){
/**
* @var \PocketMine\Item\Item
*/
protected $item;
public function __construct(Player $player, Item $item, Block $block, $face){
$this->blockTouched = $block;
$this->player = $player; $this->player = $player;
$this->item = $item; $this->position = $position;
$this->blockFace = (int) $face;
} }
public function getItem(){ /**
return $this->item; * @return Position
*/
public function getRespawnPosition(){
return $this->position;
} }
public function getBlock(){ /**
return $this->blockTouched; * @param Position $position
} */
public function setRespawnPosition(Position $position){
public function getFace(){ $this->position = $position;
return $this->blockFace;
} }
} }

View File

@ -30,9 +30,7 @@ use PocketMine\Plugin\Plugin;
abstract class PluginEvent extends Event{ abstract class PluginEvent extends Event{
/** /** @var Plugin */
* @var Plugin
*/
private $plugin; private $plugin;
/** /**

View File

@ -0,0 +1,69 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace PocketMine\Event\Server;
use PocketMine\Command\CommandSender;
use PocketMine\Event\Cancellable;
use PocketMine\Player;
use PocketMine\Server;
/**
* Called when the console runs a command, early in the process
*
* You don't want to use this except for a few cases like logging commands,
* blocking commands on certain places, or applying modifiers.
*
* The message contains a slash at the start
*/
class ServerCommandEvent extends ServerEvent implements Cancellable{
public static $handlerList = null;
/** @var string */
protected $command;
/** @var CommandSender */
protected $sender;
/**
* @param CommandSender $sender
* @param string $command
*/
public function __construct(CommandSender $sender, $command){
$this->sender = $sender;
$this->command = $command;
}
/**
* @return string
*/
public function getCommand(){
return $this->command;
}
/**
* @param string $command
*/
public function setCommand($command){
$this->command = $command;
}
}

View File

@ -74,9 +74,7 @@ class Level{
*/ */
public static $list = array(); public static $list = array();
/** /** @var Level */
* @var Level
*/
public static $default = null; public static $default = null;
/** /**
@ -106,15 +104,11 @@ class Level{
public $nextSave; public $nextSave;
/** /** @var LevelFormat */
* @var LevelFormat
*/
public $level; public $level;
public $stopTime; public $stopTime;
private $time, $startCheck, $startTime; private $time, $startCheck, $startTime;
/** /** @var Server */
* @var Server
*/
private $server; private $server;
private $name, $usedChunks, $changedBlocks, $changedCount, $generator; private $name, $usedChunks, $changedBlocks, $changedCount, $generator;
@ -976,7 +970,7 @@ class Level{
* @param int $X * @param int $X
* @param int $Z * @param int $Z
* *
* @return array * @return Entity[]
*/ */
public function getChunkEntities($X, $Z){ public function getChunkEntities($X, $Z){
$index = LevelFormat::getIndex($X, $Z); $index = LevelFormat::getIndex($X, $Z);
@ -993,7 +987,7 @@ class Level{
* @param int $X * @param int $X
* @param int $Z * @param int $Z
* *
* @return array * @return Tile[]
*/ */
public function getChunkTiles($X, $Z){ public function getChunkTiles($X, $Z){
$index = LevelFormat::getIndex($X, $Z); $index = LevelFormat::getIndex($X, $Z);

View File

@ -25,9 +25,7 @@ use PocketMine\Math\Vector3 as Vector3;
class Position extends Vector3{ class Position extends Vector3{
/** /** @var Level */
* @var Level
*/
public $level = null; public $level = null;
/** /**

View File

@ -28,9 +28,7 @@ use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Utils\Random; use PocketMine\Utils\Random;
class TallGrass extends Populator{ class TallGrass extends Populator{
/** /** @var Level */
* @var Level
*/
private $level; private $level;
private $randomAmount; private $randomAmount;
private $baseAmount; private $baseAmount;

View File

@ -25,14 +25,10 @@ use PocketMine\Plugin\Plugin;
use PocketMine\Server; use PocketMine\Server;
class PermissibleBase implements Permissible{ class PermissibleBase implements Permissible{
/** /** @var ServerOperator */
* @var ServerOperator
*/
private $opable = null; private $opable = null;
/** /** @var Permissible */
* @var Permissible
*/
private $parent; private $parent;
/** /**

View File

@ -63,14 +63,10 @@ class Permission{
} }
} }
/** /** @var string */
* @var string
*/
private $name; private $name;
/** /** @var string */
* @var string
*/
private $description; private $description;
/** /**
@ -78,9 +74,7 @@ class Permission{
*/ */
private $children = array(); private $children = array();
/** /** @var string */
* @var string
*/
private $defaultValue; private $defaultValue;
/** /**

View File

@ -24,9 +24,7 @@ namespace PocketMine\Permission;
use PocketMine\Plugin\Plugin; use PocketMine\Plugin\Plugin;
class PermissionAttachment{ class PermissionAttachment{
/** /** @var PermissionRemovedExecutor */
* @var PermissionRemovedExecutor
*/
private $removed = null; private $removed = null;
/** /**
@ -34,14 +32,10 @@ class PermissionAttachment{
*/ */
private $permissions = array(); private $permissions = array();
/** /** @var Permissible */
* @var Permissible
*/
private $permissible; private $permissible;
/** /** @var Plugin */
* @var Plugin
*/
private $plugin; private $plugin;
/** /**

View File

@ -23,24 +23,16 @@ namespace PocketMine\Permission;
class PermissionAttachmentInfo{ class PermissionAttachmentInfo{
/** /** @var Permissible */
* @var Permissible
*/
private $permissible; private $permissible;
/** /** @var string */
* @var string
*/
private $permission; private $permission;
/** /** @var PermissionAttachment */
* @var PermissionAttachment
*/
private $attachment; private $attachment;
/** /** @var bool */
* @var bool
*/
private $value; private $value;
/** /**

View File

@ -30,9 +30,7 @@ use PocketMine\Server;
*/ */
class FolderPluginLoader implements PluginLoader{ class FolderPluginLoader implements PluginLoader{
/** /** @var Server */
* @var Server
*/
private $server; private $server;
/** /**

View File

@ -35,19 +35,13 @@ use PocketMine\Server;
*/ */
class PluginManager{ class PluginManager{
/** /** @var PluginManager */
* @var PluginManager
*/
private static $instance = null; private static $instance = null;
/** /** @var Server */
* @var Server
*/
private $server; private $server;
/** /** @var SimpleCommandMap */
* @var SimpleCommandMap
*/
private $commandMap; private $commandMap;
/** /**

View File

@ -27,29 +27,19 @@ use PocketMine\Event\Listener;
class RegisteredListener{ class RegisteredListener{
/** /** @var Listener */
* @var Listener
*/
private $listener; private $listener;
/** /** @var int */
* @var int
*/
private $priority; private $priority;
/** /** @var Plugin */
* @var Plugin
*/
private $plugin; private $plugin;
/** /** @var EventExecutor */
* @var EventExecutor
*/
private $executor; private $executor;
/** /** @var bool */
* @var bool
*/
private $ignoreCancelled; private $ignoreCancelled;
/** /**

View File

@ -29,21 +29,17 @@ namespace PocketMine\Scheduler;
*/ */
class CallbackTask extends Task{ class CallbackTask extends Task{
/** /** @var callable */
* @var callable
*/
protected $callable; protected $callable;
/** /** @var array */
* @var array
*/
protected $args; protected $args;
/** /**
* @param callable $callable * @param callable $callable
* @param array $args * @param array $args
*/ */
public function __construct(callable $callable, array $args){ public function __construct(callable $callable, array $args = array()){
$this->callable = $callable; $this->callable = $callable;
$this->args = $args; $this->args = $args;
$this->args[] = $this; $this->args[] = $this;

View File

@ -28,9 +28,7 @@ use PocketMine\Plugin\Plugin;
*/ */
abstract class PluginTask extends Task{ abstract class PluginTask extends Task{
/** /** @var Plugin */
* @var Plugin
*/
protected $owner; protected $owner;
/** /**

View File

@ -38,14 +38,10 @@ class ServerScheduler{
*/ */
protected $tasks = array(); protected $tasks = array();
/** /** @var int */
* @var int
*/
private $ids = 1; private $ids = 1;
/** /** @var int */
* @var int
*/
protected $currentTick = 0; protected $currentTick = 0;
public function __construct(){ public function __construct(){

View File

@ -23,9 +23,7 @@ namespace PocketMine\Scheduler;
abstract class Task{ abstract class Task{
/** /** @var TaskHandler */
* @var TaskHandler
*/
private $taskHandler = null; private $taskHandler = null;
/** /**

View File

@ -23,34 +23,22 @@ namespace PocketMine\Scheduler;
class TaskHandler{ class TaskHandler{
/** /** @var Task */
* @var Task
*/
protected $task; protected $task;
/** /** @var int */
* @var int
*/
protected $taskId; protected $taskId;
/** /** @var int */
* @var int
*/
protected $delay; protected $delay;
/** /** @var int */
* @var int
*/
protected $period; protected $period;
/** /** @var int */
* @var int
*/
protected $nextRun; protected $nextRun;
/** /** @var bool */
* @var bool
*/
protected $cancelled = false; protected $cancelled = false;
/** /**
@ -130,7 +118,9 @@ class TaskHandler{
} }
public function cancel(){ public function cancel(){
$this->task->onCancel(); if(!$this->isCancelled()){
$this->task->onCancel();
}
$this->remove(); $this->remove();
} }

View File

@ -38,21 +38,13 @@ class Config{
const ENUM = 5; // .txt, .list, .enum const ENUM = 5; // .txt, .list, .enum
const ENUMERATION = Config::ENUM; const ENUMERATION = Config::ENUM;
/** /** @var array */
* @var array
*/
private $config; private $config;
/** /** @var string */
* @var string
*/
private $file; private $file;
/** /** @var boolean */
* @var boolean
*/
private $correct; private $correct;
/** /** @var integer */
* @var integer
*/
private $type = Config::DETECT; private $type = Config::DETECT;
public static $formats = array( public static $formats = array(