Fixed lots of errors, added auto-save

This commit is contained in:
Shoghi Cervantes 2014-03-31 20:42:58 +02:00
parent 8571796611
commit 5dafe8e7f0
11 changed files with 308 additions and 86 deletions

View File

@ -104,8 +104,8 @@ abstract class Achievement{
public static function broadcast(Player $player, $achievementId){
if(isset(Achievement::$list[$achievementId])){
if(Server::getInstance()->api->getProperty("announce-player-achievements") == true){
Player::broadcastMessage($player->getDisplayName() . " has just earned the achievement " . Achievement::$list[$achievementId]["name"]);
if(Server::getInstance()->getConfigString("announce-player-achievements", true) === true){
Server::getInstance()->broadcastMessage($player->getDisplayName() . " has just earned the achievement " . Achievement::$list[$achievementId]["name"]);
}else{
$player->sendMessage("You have just earned the achievement " . Achievement::$list[$achievementId]["name"]);
}

View File

@ -38,25 +38,20 @@ use PocketMine\NBT\Tag\Int;
use PocketMine\NBT\Tag\Short;
use PocketMine\NBT\Tag\String;
use PocketMine\Network\Protocol\AdventureSettingsPacket;
use PocketMine\Network\Protocol\AnimatePacket;
use PocketMine\Network\Protocol\ChunkDataPacket;
use PocketMine\Network\Protocol\ContainerClosePacket;
use PocketMine\Network\Protocol\ContainerSetContentPacket;
use PocketMine\Network\Protocol\ContainerSetDataPacket;
use PocketMine\Network\Protocol\ContainerSetSlotPacket;
use PocketMine\Network\Protocol\DataPacket;
use PocketMine\Network\Protocol\DisconnectPacket;
use PocketMine\Network\Protocol\EntityEventPacket;
use PocketMine\Network\Protocol\Info as ProtocolInfo;
use PocketMine\Network\Protocol\LoginStatusPacket;
use PocketMine\Network\Protocol\MessagePacket;
use PocketMine\Network\Protocol\PongPacket;
use PocketMine\Network\Protocol\ServerHandshakePacket;
use PocketMine\Network\Protocol\SetEntityDataPacket;
use PocketMine\Network\Protocol\SetSpawnPositionPacket;
use PocketMine\Network\Protocol\SetTimePacket;
use PocketMine\Network\Protocol\StartGamePacket;
use PocketMine\Network\Protocol\TakeItemEntityPacket;
use PocketMine\Network\Protocol\TileEventPacket;
use PocketMine\Network\Protocol\UnknownPacket;
use PocketMine\Network\Protocol\UpdateBlockPacket;
@ -85,8 +80,6 @@ use PocketMine\Utils\Utils;
* @package PocketMine
*/
class Player extends Human implements CommandSender{
const BROADCAST_CHANNEL_ADMINISTRATIVE = "pocketmine.broadcast.admin";
const BROADCAST_CHANNEL_USERS = "pocketmine.broadcast.user";
const SURVIVAL = 0;
const CREATIVE = 1;
@ -103,7 +96,6 @@ class Player extends Human implements CommandSender{
*/
public static $list = array();
public $auth = false;
public $CID;
public $MTU;
public $spawned = false;
@ -139,10 +131,10 @@ class Player extends Human implements CommandSender{
private $resendQueue = array();
private $ackQueue = array();
private $receiveCount = -1;
/** @var \PocketMine\Network\RakNet\Packet */
private $buffer;
private $bufferLen = 0;
private $nextBuffer = 0;
private $evid = array();
private $timeout;
private $counter = array(0, 0, 0, 0);
private $viewDistance;
@ -166,6 +158,7 @@ class Player extends Human implements CommandSender{
*/
private $tasks = array();
/** @var PermissibleBase */
private $perm = null;
@ -342,12 +335,20 @@ class Player extends Human implements CommandSender{
console("[DEBUG] New Session started with " . $ip . ":" . $port . ". MTU " . $this->MTU . ", Client ID " . $this->clientID, true, true, 2);
}
/**
* @param string $achievementId
*/
public function removeAchievement($achievementId){
if($this->hasAchievement($achievementId)){
$this->achievements[$achievementId] = false;
}
}
/**
* @param string $achievementId
*
* @return bool
*/
public function hasAchievement($achievementId){
if(!isset(Achievement::$list[$achievementId]) or !isset($this->achievements)){
$this->achievements = array();
@ -362,36 +363,70 @@ class Player extends Human implements CommandSender{
return true;
}
/**
* @return bool
*/
public function isConnected(){
return $this->connected === true;
}
/**
* Gets the "friendly" name to display of this player to use in the chat.
*
* @return string
*/
public function getDisplayName(){
return $this->displayName;
}
/**
* @param string $name
*/
public function setDisplayName($name){
$this->displayName = $name;
}
public function getIP(){
/**
* Gets the player IP address
*
* @return string
*/
public function getAddress(){
return $this->ip;
}
/**
* @return int
*/
public function getPort(){
return $this->port;
}
/**
* @return bool
*/
public function isSleeping(){
return $this->sleeping instanceof Vector3;
}
/**
* Sets the chunk send flags for a specific index
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param int $index
* @param int $flags
*/
public function setChunkIndex($index, $flags){
if(isset($this->chunksLoaded[$index])){
$this->chunksLoaded[$index] |= $flags;
}
}
/**
* @return Position
*/
public function getSpawn(){
return $this->spawnPosition;
}
@ -399,6 +434,9 @@ class Player extends Human implements CommandSender{
/**
* Sends, if available, the next ordered chunk to the client
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param bool $force
* @param bool $ev
*
@ -492,6 +530,13 @@ class Player extends Human implements CommandSender{
}
}
/**
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @return bool
*/
public function orderChunks(){
if($this->connected === false){
return false;
@ -548,6 +593,8 @@ class Player extends Human implements CommandSender{
}
/**
* Sends an ordered DataPacket to the send buffer
*
* @param DataPacket $packet
*
* @return array|bool
@ -617,6 +664,14 @@ class Player extends Human implements CommandSender{
return $cnts;
}
/**
* Sends a raw Packet to the conection
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param Packet $packet
*/
public function send(Packet $packet){
if($this->connected === true){
$packet->ip = $this->ip;
@ -625,6 +680,12 @@ class Player extends Human implements CommandSender{
}
}
/**
* Forces sending the buffer
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*/
public function sendBuffer(){
if($this->connected === true){
if($this->bufferLen > 0 and $this->buffer instanceof Packet){
@ -688,13 +749,17 @@ class Player extends Human implements CommandSender{
//}
}
/**
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*/
public function checkSleep(){
if($this->sleeping !== false){
//TODO
if($this->server->api->time->getPhase($this->level) === "night"){
foreach($this->level->getPlayers() as $p){
if($p->sleeping === false){
return false;
return;
}
}
$this->server->api->time->set("day", $this->level);
@ -703,13 +768,11 @@ class Player extends Human implements CommandSender{
}
}
}
return;
}
/**
* @param mixed $data
* @param string $event
*/
public function eventHandler($data, $event){
/*public function eventHandler($data, $event){
switch($event){
//TODO, obsolete
case "tile.update":
@ -807,8 +870,13 @@ class Player extends Human implements CommandSender{
}
break;
}
}
}*/
/**
* @param string $achievementId
*
* @return bool
*/
public function awardAchievement($achievementId){
if(isset(Achievement::$list[$achievementId]) and !$this->hasAchievement($achievementId)){
foreach(Achievement::$list[$achievementId]["requires"] as $requerimentId){
@ -830,10 +898,21 @@ class Player extends Human implements CommandSender{
return false;
}
/**
* @return int
*/
public function getGamemode(){
return $this->gamemode;
}
/**
* Sets the gamemode, and if needed, kicks the player
* TODO: Check if Mojang adds the ability to change gamemode without kicking players
*
* @param int $gm
*
* @return bool
*/
public function setGamemode($gm){
if($gm < 0 or $gm > 3 or $this->gamemode === $gm){
return false;
@ -859,6 +938,14 @@ class Player extends Human implements CommandSender{
return true;
}
/**
* Sends all the option flags
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param bool $nametags
*/
public function sendSettings($nametags = true){
/*
bit mask | flag name
@ -909,6 +996,12 @@ class Player extends Human implements CommandSender{
$this->dataPacket($pk);
}
/**
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @return bool
*/
public function measureLag(){
if($this->connected === false){
return false;
@ -928,18 +1021,39 @@ class Player extends Human implements CommandSender{
$this->lastMeasure = microtime(true);
}
/**
* WARNING: Experimental method
*
* @return int
*/
public function getLag(){
return $this->lagStat * 1000;
}
/**
* WARNING: Experimental method
*
* @return int
*/
public function getPacketLoss(){
return $this->packetLoss;
}
/**
* WARNING: Experimental method
*
* @return float
*/
public function getBandwidth(){
return array_sum($this->bandwidthStats) / max(1, count($this->bandwidthStats));
}
/**
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @return bool
*/
public function clearQueue(){
if($this->connected === false){
return false;
@ -956,6 +1070,12 @@ class Player extends Human implements CommandSender{
}
}
/**
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @return bool
*/
public function handlePacketQueues(){
if($this->connected === false){
return false;
@ -1047,6 +1167,9 @@ class Player extends Human implements CommandSender{
* Handles a Minecraft packet
* TODO: Separate all of this in handlers
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param DataPacket $packet
*/
public function handleDataPacket(DataPacket $packet){
@ -1098,10 +1221,10 @@ class Player extends Human implements CommandSender{
$this->loginData = array("clientId" => $packet->clientId, "loginData" => $packet->loginData);
//TODO: op things
if(count(Player::$list) > $this->server->getMaxPlayers() and !$this->server->api->ban->isOp($this->iusername)){
$this->kick("server full");
return;
if(count(Player::$list) > $this->server->getMaxPlayers()){
if($this->kick("server full") === true){
return;
}
}
if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){
if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){
@ -1134,14 +1257,13 @@ class Player extends Human implements CommandSender{
$this->close($this->username . " has left the game", "Server is white-listed");
return;
}elseif($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getIP())){
}elseif($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress())){
$this->close($this->username . " has left the game", "You are banned");
return;
}
$this->server->getPluginManager()->subscribeToPermission(Player::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
$this->server->getPluginManager()->subscribeToPermission(Player::BROADCAST_CHANNEL_USERS, $this);
$this->loggedIn = true;
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this);
$u = Player::get($this->iusername, false, true);
if(count($u) > 0){
@ -1179,9 +1301,8 @@ class Player extends Human implements CommandSender{
}
Player::saveOffline($this->username, $nbt);
$this->auth = true;
parent::__construct($this->level, $nbt);
$this->loggedIn = true;
if(($this->gamemode & 0x01) === 0x01){
$this->slot = 0;
@ -1246,6 +1367,7 @@ class Player extends Human implements CommandSender{
if($this->spawned !== false){
break;
}
//TODO
//$this->heal($this->data->get("health"), "spawn", true);
$this->spawned = true;
$this->spawnToAll();
@ -2138,10 +2260,10 @@ class Player extends Human implements CommandSender{
Player::saveOffline($this->username, $this->namedtag);
}
if(isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != ""){
Player::broadcastMessage($ev->getQuitMessage());
$this->server->broadcastMessage($ev->getQuitMessage());
}
$this->server->getPluginManager()->unsubscribeFromPermission(Player::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
$this->server->getPluginManager()->unsubscribeFromPermission(Player::BROADCAST_CHANNEL_USERS, $this);
$this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
$this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this);
$this->spawned = false;
console("[INFO] " . TextFormat::AQUA . $this->username . TextFormat::RESET . "[/" . $this->ip . ":" . $this->port . "] logged out due to " . $reason);
$this->windows = array();
@ -2208,15 +2330,6 @@ class Player extends Human implements CommandSender{
return array($pk->seqNumber);
}
/**
* Broadcasts a message to all the players
*
* @param string $message
*/
public static function broadcastMessage($message){
self::groupChat($message, Server::getInstance()->getPluginManager()->getPermissionSubscriptions(Player::BROADCAST_CHANNEL_USERS));
}
/**
* @return Player[]
*/
@ -2380,20 +2493,6 @@ class Player extends Human implements CommandSender{
file_put_contents(Server::getInstance()->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
}
/**
* Sends a message to a group of players
*
* @param string $message
* @param Player[] $players
*/
public static function groupChat($message, array $players){
foreach($players as $p){
if($p instanceof CommandSender){
$p->sendMessage($message);
}
}
}
/**
* Gets the username
*

View File

@ -52,6 +52,7 @@ use PocketMine\Plugin\Plugin;
use PocketMine\Plugin\PluginLoadOrder;
use PocketMine\Plugin\PluginManager;
use PocketMine\Recipes\Crafting;
use PocketMine\Scheduler\CallbackTask;
use PocketMine\Scheduler\ServerScheduler;
use PocketMine\Scheduler\TickScheduler;
use PocketMine\Tile\Tile;
@ -61,6 +62,9 @@ use PocketMine\Utils\Utils;
use PocketMine\Utils\VersionString;
class Server{
const BROADCAST_CHANNEL_ADMINISTRATIVE = "pocketmine.broadcast.admin";
const BROADCAST_CHANNEL_USERS = "pocketmine.broadcast.user";
/** @var Server */
private static $instance = null;
@ -688,7 +692,7 @@ class Server{
$this->consoleSender = new ConsoleCommandSender();
$this->commandMap = new SimpleCommandMap($this);
$this->pluginManager = new PluginManager($this, $this->commandMap);
$this->pluginManager->subscribeToPermission(Player::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender);
$this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender);
$this->pluginManager->registerInterface("PocketMine\\Plugin\\FolderPluginLoader");
$this->pluginManager->loadPlugins($this->pluginPath);
@ -710,18 +714,45 @@ class Server{
$this->server->schedule(6000, array($this, "sendUsage"), array(), true); //Send the info after 5 minutes have passed
$this->sendUsage();
}
if($this->getProperty("auto-save") === true){
$this->server->schedule(18000, array($this, "autoSave"), array(), true);
}
if(!defined("NO_THREADS") and $this->getProperty("enable-rcon") === true){
$this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip : "0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50));
}*/
//$this->schedule(2, array($this, "checkTickUpdates"), array(), true);
$this->scheduler->scheduleRepeatingTask(new CallbackTask("PocketMine\\Utils\\Cache::cleanup"), 20 * 45);
if($this->getConfigBoolean("auto-save", true) === true){
$this->scheduler->scheduleRepeatingTask(new CallbackTask(array($this, "doAutoSave")), 18000);
}
$this->enablePlugins(PluginLoadOrder::POSTWORLD);
}
/**
* @param $message
*
* @return int
*/
public function broadcastMessage($message){
return $this->broadcast($message, self::BROADCAST_CHANNEL_USERS);
}
/**
* @param string $message
* @param string $permission
*
* @return int
*/
public function broadcast($message, $permission){
$count = 0;
foreach($this->pluginManager->getPermissionSubscriptions($permission) as $permissible){
if($permissible instanceof CommandSender and $permissible->hasPermission($permission)){
$permissible->sendMessage($message);
++$count;
}
}
return $count;
}
/**
* @param int $type
*/
@ -747,10 +778,6 @@ class Server{
*/
public function loadPlugin(Plugin $plugin){
$this->pluginManager->enablePlugin($plugin);
foreach($plugin->getDescription()->getPermisions() as $perm){
$this->pluginManager->addPermission($perm);
}
}
public function disablePlugins(){
@ -979,13 +1006,13 @@ class Server{
//TODO: Add level blocks
//Do level ticks
foreach(Level::$list as $level){
foreach(Level::getAll() as $level){
$level->doTick();
}
}
public function autoSave(){
console("[DEBUG] Saving....", true, true, 2);
public function doAutoSave(){
$this->broadcast(TextFormat::GRAY . "Saving...", self::BROADCAST_CHANNEL_ADMINISTRATIVE);
Level::saveAll();
}

View File

@ -24,7 +24,6 @@
*/
namespace PocketMine\Command;
use PocketMine\Player;
use PocketMine\Server;
use PocketMine\Utils\TextFormat;
@ -286,7 +285,7 @@ abstract class Command{
//Command minecarts or command blocks are not implemented
$users = Server::getInstance()->getPluginManager()->getPermissionSubscriptions(Player::BROADCAST_CHANNEL_ADMINISTRATIVE);
$users = Server::getInstance()->getPluginManager()->getPermissionSubscriptions(Server::BROADCAST_CHANNEL_ADMINISTRATIVE);
$colored = TextFormat::GRAY . TextFormat::ITALIC . "[$result" . TextFormat::GRAY . TextFormat::ITALIC . "]";
if($sendToSource === true and !($source instanceof ConsoleCommandSender)){
$source->sendMessage($message);

View File

@ -56,7 +56,7 @@ class BanIpCommand extends VanillaCommand{
$this->processIPBan($value, $sender, $reason);
}else{
if(($player = Player::get($value, true)) instanceof Player){
$this->processIPBan($player->getIP(), $sender, $reason);
$this->processIPBan($player->getAddress(), $sender, $reason);
}else{
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
@ -71,7 +71,7 @@ class BanIpCommand extends VanillaCommand{
Server::getInstance()->getIPBans()->addBan($ip, $reason, null, $sender->getName());
foreach(Player::getAll() as $player){
if($player->getIP() === $ip){
if($player->getAddress() === $ip){
$player->kick("You have been IP banned.");
}
}

View File

@ -23,6 +23,7 @@ namespace PocketMine\Command\Defaults;
use PocketMine\Command\CommandSender;
use PocketMine\Player;
use PocketMine\Server;
use PocketMine\Utils\TextFormat;
class MeCommand extends VanillaCommand{
@ -54,7 +55,7 @@ class MeCommand extends VanillaCommand{
$message .= $sender->getName();
}
Player::broadcastMessage($message . " " . implode(" ", $args));
Server::getInstance()->broadcastMessage($message . " " . implode(" ", $args));
return true;
}

View File

@ -24,6 +24,7 @@ namespace PocketMine\Command\Defaults;
use PocketMine\Command\CommandSender;
use PocketMine\Command\ConsoleCommandSender;
use PocketMine\Player;
use PocketMine\Server;
use PocketMine\Utils\TextFormat;
class SayCommand extends VanillaCommand{
@ -57,7 +58,7 @@ class SayCommand extends VanillaCommand{
$message .= $sender->getName();
}
$message .= TextFormat::LIGHT_PURPLE . "] " . implode(" ", $args);
Player::broadcastMessage($message);
Server::getInstance()->broadcastMessage($message);
return true;
}

View File

@ -296,9 +296,10 @@ class Level{
$level->save(true, true);
}
foreach($blockUpdates->getAll() as $bupdate){
//TODO
/*foreach($blockUpdates->getAll() as $bupdate){
Server::getInstance()->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"], (int) $bupdate["y"], (int) $bupdate["z"], $level), (float) $bupdate["delay"], (int) $bupdate["type"]);
}
}*/
return true;
}
@ -306,7 +307,7 @@ class Level{
/**
* Generates a new level
*
* @param $name
* @param string $name
* @param bool $seed
* @param bool $generator
* @param bool|array $options
@ -341,7 +342,7 @@ class Level{
/**
* Searches if a level exists on file
*
* @param $name
* @param string $name
*
* @return bool
*/
@ -416,35 +417,75 @@ class Level{
return true;
}
/**
* Gets the chunks being used by players
*
* @param int $X
* @param int $Z
*
* @return Player[][]
*/
public function getUsingChunk($X, $Z){
$index = LevelFormat::getIndex($X, $Z);
return isset($this->usedChunks[$index]) ? $this->usedChunks[$index] : array();
}
/**
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param int $X
* @param int $Z
* @param Player $player
*/
public function useChunk($X, $Z, Player $player){
$index = LevelFormat::getIndex($X, $Z);
$this->loadChunk($X, $Z);
$this->usedChunks[$index][$player->CID] = $player;
}
/**
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param Player $player
*/
public function freeAllChunks(Player $player){
foreach($this->usedChunks as $i => $c){
unset($this->usedChunks[$i][$player->CID]);
}
}
/**
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param int $X
* @param int $Z
* @param Player $player
*/
public function freeChunk($X, $Z, Player $player){
unset($this->usedChunks[LevelFormat::getIndex($X, $Z)][$player->CID]);
}
/**
* @param int $X
* @param int $Z
*
* @return bool
*/
public function isChunkPopulated($X, $Z){
return $this->level->isPopulated($X, $Z);
}
/**
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*/
public function checkTime(){
if(!isset($this->level)){
return false;
return;
}
$now = microtime(true);
if($this->stopTime == true){
@ -462,6 +503,12 @@ class Level{
return;
}
/**
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @return bool
*/
public function doTick(){
if(!isset($this->level)){
return false;
@ -518,7 +565,8 @@ class Level{
$block = $this->getBlockRaw(new Vector3(($X << 4) + mt_rand(0, 15), ($Y << 4) + mt_rand(0, 15), ($Z << 4) + mt_rand(0, 15)));
if($block instanceof Block){
if($block->onUpdate(self::BLOCK_UPDATE_RANDOM) === self::BLOCK_UPDATE_NORMAL){
$this->server->api->block->blockUpdateAround($block);
//TODO
//$this->server->api->block->blockUpdateAround($block);
}
}
}
@ -543,6 +591,12 @@ class Level{
}
}
/**
* @param int $X
* @param int $Z
*
* @return bool
*/
public function generateChunk($X, $Z){
++$this->level->isGenerating;
$this->generator->generateChunk($X, $Z);
@ -551,6 +605,12 @@ class Level{
return true;
}
/**
* @param int $X
* @param int $Z
*
* @return bool
*/
public function populateChunk($X, $Z){
$this->level->setPopulated($X, $Z);
$this->generator->populateChunk($X, $Z);
@ -567,6 +627,12 @@ class Level{
}
}
/**
* @param bool $force
* @param bool $extra
*
* @return bool
*/
public function save($force = false, $extra = true){
if(!isset($this->level)){
return false;
@ -617,12 +683,22 @@ class Level{
}
}
/**
* @param Vector3 $pos
*
* @return Block
*/
public function getBlockRaw(Vector3 $pos){
$b = $this->level->getBlock($pos->x, $pos->y, $pos->z);
return Block::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this));
}
/**
* @param Vector3 $pos
*
* @return bool|Block
*/
public function getBlock(Vector3 $pos){
if($pos instanceof Position and $pos->level !== $this){
return false;
@ -632,6 +708,14 @@ class Level{
return Block::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this));
}
/**
* @param Vector3 $pos
* @param Block $block
* @param bool $direct
* @param bool $send
*
* @return bool
*/
public function setBlockRaw(Vector3 $pos, Block $block, $direct = true, $send = true){
if(($ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata())) === true and $send !== false){
if($direct === true){
@ -667,6 +751,15 @@ class Level{
return $ret;
}
/**
* @param Vector3 $pos
* @param Block $block
* @param bool $update
* @param bool $tiles
* @param bool $direct
*
* @return bool
*/
public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false){
if((($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){
return false;
@ -705,7 +798,8 @@ class Level{
}
if($update === true){
$this->server->api->block->blockUpdateAround($pos, self::BLOCK_UPDATE_NORMAL, 1);
//TODO
//$this->server->api->block->blockUpdateAround($pos, self::BLOCK_UPDATE_NORMAL, 1);
}
if($tiles === true){
if(($t = $this->getTile($pos)) instanceof Tile){
@ -1286,6 +1380,7 @@ class Level{
}
public function scheduleBlockUpdate(Position $pos, $delay, $type = self::BLOCK_UPDATE_SCHEDULED){
return $this->server->api->block->scheduleBlockUpdate($pos, $delay, $type);
//TODO
//return $this->server->api->block->scheduleBlockUpdate($pos, $delay, $type);
}
}

View File

@ -24,7 +24,7 @@ namespace PocketMine\Network\Protocol;
use PocketMine\Item\Item;
use PocketMine\Utils\Utils;
abstract class DataPacket{
abstract class DataPacket extends \stdClass{
private $offset = 0;
public $buffer = "";

View File

@ -183,7 +183,7 @@ class PluginDescription{
/**
* @return Permission[]
*/
public function getPermisions(){
public function getPermissions(){
return $this->permissions;
}

View File

@ -500,7 +500,7 @@ class PluginManager{
$this->commandMap->registerAll($plugin->getDescription()->getName(), $pluginCommands);
}
foreach($plugin->getDescription()->getPermisions() as $perm){
foreach($plugin->getDescription()->getPermissions() as $perm){
$this->addPermission($perm);
}
@ -573,7 +573,7 @@ class PluginManager{
$plugin->getPluginLoader()->disablePlugin($plugin);
$this->server->getScheduler()->cancelTasks($plugin);
HandlerList::unregisterAll($plugin);
foreach($plugin->getDescription()->getCommands() as $perm){
foreach($plugin->getDescription()->getPermissions() as $perm){
$this->removePermission($perm);
}
}