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){ public static function broadcast(Player $player, $achievementId){
if(isset(Achievement::$list[$achievementId])){ if(isset(Achievement::$list[$achievementId])){
if(Server::getInstance()->api->getProperty("announce-player-achievements") == true){ if(Server::getInstance()->getConfigString("announce-player-achievements", true) === true){
Player::broadcastMessage($player->getDisplayName() . " has just earned the achievement " . Achievement::$list[$achievementId]["name"]); Server::getInstance()->broadcastMessage($player->getDisplayName() . " has just earned the achievement " . Achievement::$list[$achievementId]["name"]);
}else{ }else{
$player->sendMessage("You have just earned the achievement " . Achievement::$list[$achievementId]["name"]); $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\Short;
use PocketMine\NBT\Tag\String; use PocketMine\NBT\Tag\String;
use PocketMine\Network\Protocol\AdventureSettingsPacket; use PocketMine\Network\Protocol\AdventureSettingsPacket;
use PocketMine\Network\Protocol\AnimatePacket;
use PocketMine\Network\Protocol\ChunkDataPacket; use PocketMine\Network\Protocol\ChunkDataPacket;
use PocketMine\Network\Protocol\ContainerClosePacket; use PocketMine\Network\Protocol\ContainerClosePacket;
use PocketMine\Network\Protocol\ContainerSetContentPacket; use PocketMine\Network\Protocol\ContainerSetContentPacket;
use PocketMine\Network\Protocol\ContainerSetDataPacket;
use PocketMine\Network\Protocol\ContainerSetSlotPacket; use PocketMine\Network\Protocol\ContainerSetSlotPacket;
use PocketMine\Network\Protocol\DataPacket; use PocketMine\Network\Protocol\DataPacket;
use PocketMine\Network\Protocol\DisconnectPacket; use PocketMine\Network\Protocol\DisconnectPacket;
use PocketMine\Network\Protocol\EntityEventPacket;
use PocketMine\Network\Protocol\Info as ProtocolInfo; use PocketMine\Network\Protocol\Info as ProtocolInfo;
use PocketMine\Network\Protocol\LoginStatusPacket; use PocketMine\Network\Protocol\LoginStatusPacket;
use PocketMine\Network\Protocol\MessagePacket; use PocketMine\Network\Protocol\MessagePacket;
use PocketMine\Network\Protocol\PongPacket; use PocketMine\Network\Protocol\PongPacket;
use PocketMine\Network\Protocol\ServerHandshakePacket; use PocketMine\Network\Protocol\ServerHandshakePacket;
use PocketMine\Network\Protocol\SetEntityDataPacket;
use PocketMine\Network\Protocol\SetSpawnPositionPacket; use PocketMine\Network\Protocol\SetSpawnPositionPacket;
use PocketMine\Network\Protocol\SetTimePacket; use PocketMine\Network\Protocol\SetTimePacket;
use PocketMine\Network\Protocol\StartGamePacket; use PocketMine\Network\Protocol\StartGamePacket;
use PocketMine\Network\Protocol\TakeItemEntityPacket;
use PocketMine\Network\Protocol\TileEventPacket; use PocketMine\Network\Protocol\TileEventPacket;
use PocketMine\Network\Protocol\UnknownPacket; use PocketMine\Network\Protocol\UnknownPacket;
use PocketMine\Network\Protocol\UpdateBlockPacket; use PocketMine\Network\Protocol\UpdateBlockPacket;
@ -85,8 +80,6 @@ use PocketMine\Utils\Utils;
* @package PocketMine * @package PocketMine
*/ */
class Player extends Human implements CommandSender{ class Player extends Human implements CommandSender{
const BROADCAST_CHANNEL_ADMINISTRATIVE = "pocketmine.broadcast.admin";
const BROADCAST_CHANNEL_USERS = "pocketmine.broadcast.user";
const SURVIVAL = 0; const SURVIVAL = 0;
const CREATIVE = 1; const CREATIVE = 1;
@ -103,7 +96,6 @@ class Player extends Human implements CommandSender{
*/ */
public static $list = array(); public static $list = array();
public $auth = false;
public $CID; public $CID;
public $MTU; public $MTU;
public $spawned = false; public $spawned = false;
@ -139,10 +131,10 @@ class Player extends Human implements CommandSender{
private $resendQueue = array(); private $resendQueue = array();
private $ackQueue = array(); private $ackQueue = array();
private $receiveCount = -1; private $receiveCount = -1;
/** @var \PocketMine\Network\RakNet\Packet */
private $buffer; private $buffer;
private $bufferLen = 0; private $bufferLen = 0;
private $nextBuffer = 0; private $nextBuffer = 0;
private $evid = array();
private $timeout; private $timeout;
private $counter = array(0, 0, 0, 0); private $counter = array(0, 0, 0, 0);
private $viewDistance; private $viewDistance;
@ -166,6 +158,7 @@ class Player extends Human implements CommandSender{
*/ */
private $tasks = array(); private $tasks = array();
/** @var PermissibleBase */
private $perm = null; 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); 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){ public function removeAchievement($achievementId){
if($this->hasAchievement($achievementId)){ if($this->hasAchievement($achievementId)){
$this->achievements[$achievementId] = false; $this->achievements[$achievementId] = false;
} }
} }
/**
* @param string $achievementId
*
* @return bool
*/
public function hasAchievement($achievementId){ public function hasAchievement($achievementId){
if(!isset(Achievement::$list[$achievementId]) or !isset($this->achievements)){ if(!isset(Achievement::$list[$achievementId]) or !isset($this->achievements)){
$this->achievements = array(); $this->achievements = array();
@ -362,36 +363,70 @@ class Player extends Human implements CommandSender{
return true; return true;
} }
/**
* @return bool
*/
public function isConnected(){ public function isConnected(){
return $this->connected === true; return $this->connected === true;
} }
/**
* Gets the "friendly" name to display of this player to use in the chat.
*
* @return string
*/
public function getDisplayName(){ public function getDisplayName(){
return $this->displayName; return $this->displayName;
} }
/**
* @param string $name
*/
public function setDisplayName($name){ public function setDisplayName($name){
$this->displayName = $name; $this->displayName = $name;
} }
public function getIP(){ /**
* Gets the player IP address
*
* @return string
*/
public function getAddress(){
return $this->ip; return $this->ip;
} }
/**
* @return int
*/
public function getPort(){ public function getPort(){
return $this->port; return $this->port;
} }
/**
* @return bool
*/
public function isSleeping(){ public function isSleeping(){
return $this->sleeping instanceof Vector3; 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){ public function setChunkIndex($index, $flags){
if(isset($this->chunksLoaded[$index])){ if(isset($this->chunksLoaded[$index])){
$this->chunksLoaded[$index] |= $flags; $this->chunksLoaded[$index] |= $flags;
} }
} }
/**
* @return Position
*/
public function getSpawn(){ public function getSpawn(){
return $this->spawnPosition; return $this->spawnPosition;
} }
@ -399,6 +434,9 @@ class Player extends Human implements CommandSender{
/** /**
* Sends, if available, the next ordered chunk to the client * 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 $force
* @param bool $ev * @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(){ public function orderChunks(){
if($this->connected === false){ if($this->connected === false){
return false; return false;
@ -548,6 +593,8 @@ class Player extends Human implements CommandSender{
} }
/** /**
* Sends an ordered DataPacket to the send buffer
*
* @param DataPacket $packet * @param DataPacket $packet
* *
* @return array|bool * @return array|bool
@ -617,6 +664,14 @@ class Player extends Human implements CommandSender{
return $cnts; 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){ public function send(Packet $packet){
if($this->connected === true){ if($this->connected === true){
$packet->ip = $this->ip; $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(){ public function sendBuffer(){
if($this->connected === true){ if($this->connected === true){
if($this->bufferLen > 0 and $this->buffer instanceof Packet){ 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(){ public function checkSleep(){
if($this->sleeping !== false){ if($this->sleeping !== false){
//TODO //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){
return false; return;
} }
} }
$this->server->api->time->set("day", $this->level); $this->server->api->time->set("day", $this->level);
@ -703,13 +768,11 @@ class Player extends Human implements CommandSender{
} }
} }
} }
return;
} }
/** /*public function eventHandler($data, $event){
* @param mixed $data
* @param string $event
*/
public function eventHandler($data, $event){
switch($event){ switch($event){
//TODO, obsolete //TODO, obsolete
case "tile.update": case "tile.update":
@ -807,8 +870,13 @@ class Player extends Human implements CommandSender{
} }
break; break;
} }
} }*/
/**
* @param string $achievementId
*
* @return bool
*/
public function awardAchievement($achievementId){ public function awardAchievement($achievementId){
if(isset(Achievement::$list[$achievementId]) and !$this->hasAchievement($achievementId)){ if(isset(Achievement::$list[$achievementId]) and !$this->hasAchievement($achievementId)){
foreach(Achievement::$list[$achievementId]["requires"] as $requerimentId){ foreach(Achievement::$list[$achievementId]["requires"] as $requerimentId){
@ -830,10 +898,21 @@ class Player extends Human implements CommandSender{
return false; return false;
} }
/**
* @return int
*/
public function getGamemode(){ public function getGamemode(){
return $this->gamemode; 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){ public function setGamemode($gm){
if($gm < 0 or $gm > 3 or $this->gamemode === $gm){ if($gm < 0 or $gm > 3 or $this->gamemode === $gm){
return false; return false;
@ -859,6 +938,14 @@ class Player extends Human implements CommandSender{
return true; 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){ public function sendSettings($nametags = true){
/* /*
bit mask | flag name bit mask | flag name
@ -909,6 +996,12 @@ class Player extends Human implements CommandSender{
$this->dataPacket($pk); $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(){ public function measureLag(){
if($this->connected === false){ if($this->connected === false){
return false; return false;
@ -928,18 +1021,39 @@ class Player extends Human implements CommandSender{
$this->lastMeasure = microtime(true); $this->lastMeasure = microtime(true);
} }
/**
* WARNING: Experimental method
*
* @return int
*/
public function getLag(){ public function getLag(){
return $this->lagStat * 1000; return $this->lagStat * 1000;
} }
/**
* WARNING: Experimental method
*
* @return int
*/
public function getPacketLoss(){ public function getPacketLoss(){
return $this->packetLoss; return $this->packetLoss;
} }
/**
* WARNING: Experimental method
*
* @return float
*/
public function getBandwidth(){ public function getBandwidth(){
return array_sum($this->bandwidthStats) / max(1, count($this->bandwidthStats)); 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(){ public function clearQueue(){
if($this->connected === false){ if($this->connected === false){
return 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(){ public function handlePacketQueues(){
if($this->connected === false){ if($this->connected === false){
return false; return false;
@ -1047,6 +1167,9 @@ class Player extends Human implements CommandSender{
* Handles a Minecraft packet * Handles a Minecraft packet
* TODO: Separate all of this in handlers * 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 * @param DataPacket $packet
*/ */
public function handleDataPacket(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); $this->loginData = array("clientId" => $packet->clientId, "loginData" => $packet->loginData);
//TODO: op things //TODO: op things
if(count(Player::$list) > $this->server->getMaxPlayers() and !$this->server->api->ban->isOp($this->iusername)){ if(count(Player::$list) > $this->server->getMaxPlayers()){
$this->kick("server full"); if($this->kick("server full") === true){
return;
return; }
} }
if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){
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"); $this->close($this->username . " has left the game", "Server is white-listed");
return; 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"); $this->close($this->username . " has left the game", "You are banned");
return; return;
} }
$this->server->getPluginManager()->subscribeToPermission(Player::BROADCAST_CHANNEL_ADMINISTRATIVE, $this); $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
$this->server->getPluginManager()->subscribeToPermission(Player::BROADCAST_CHANNEL_USERS, $this); $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this);
$this->loggedIn = true;
$u = Player::get($this->iusername, false, true); $u = Player::get($this->iusername, false, true);
if(count($u) > 0){ if(count($u) > 0){
@ -1179,9 +1301,8 @@ class Player extends Human implements CommandSender{
} }
Player::saveOffline($this->username, $nbt); Player::saveOffline($this->username, $nbt);
$this->auth = true;
parent::__construct($this->level, $nbt); parent::__construct($this->level, $nbt);
$this->loggedIn = true;
if(($this->gamemode & 0x01) === 0x01){ if(($this->gamemode & 0x01) === 0x01){
$this->slot = 0; $this->slot = 0;
@ -1246,6 +1367,7 @@ class Player extends Human implements CommandSender{
if($this->spawned !== false){ if($this->spawned !== false){
break; break;
} }
//TODO
//$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();
@ -2138,10 +2260,10 @@ class Player extends Human implements CommandSender{
Player::saveOffline($this->username, $this->namedtag); Player::saveOffline($this->username, $this->namedtag);
} }
if(isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != ""){ 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(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
$this->server->getPluginManager()->unsubscribeFromPermission(Player::BROADCAST_CHANNEL_USERS, $this); $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this);
$this->spawned = false; $this->spawned = false;
console("[INFO] " . TextFormat::AQUA . $this->username . TextFormat::RESET . "[/" . $this->ip . ":" . $this->port . "] logged out due to " . $reason); console("[INFO] " . TextFormat::AQUA . $this->username . TextFormat::RESET . "[/" . $this->ip . ":" . $this->port . "] logged out due to " . $reason);
$this->windows = array(); $this->windows = array();
@ -2208,15 +2330,6 @@ class Player extends Human implements CommandSender{
return array($pk->seqNumber); 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[] * @return Player[]
*/ */
@ -2380,20 +2493,6 @@ class Player extends Human implements CommandSender{
file_put_contents(Server::getInstance()->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed()); 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 * Gets the username
* *

View File

@ -52,6 +52,7 @@ use PocketMine\Plugin\Plugin;
use PocketMine\Plugin\PluginLoadOrder; use PocketMine\Plugin\PluginLoadOrder;
use PocketMine\Plugin\PluginManager; use PocketMine\Plugin\PluginManager;
use PocketMine\Recipes\Crafting; use PocketMine\Recipes\Crafting;
use PocketMine\Scheduler\CallbackTask;
use PocketMine\Scheduler\ServerScheduler; use PocketMine\Scheduler\ServerScheduler;
use PocketMine\Scheduler\TickScheduler; use PocketMine\Scheduler\TickScheduler;
use PocketMine\Tile\Tile; use PocketMine\Tile\Tile;
@ -61,6 +62,9 @@ use PocketMine\Utils\Utils;
use PocketMine\Utils\VersionString; use PocketMine\Utils\VersionString;
class Server{ class Server{
const BROADCAST_CHANNEL_ADMINISTRATIVE = "pocketmine.broadcast.admin";
const BROADCAST_CHANNEL_USERS = "pocketmine.broadcast.user";
/** @var Server */ /** @var Server */
private static $instance = null; private static $instance = null;
@ -688,7 +692,7 @@ class Server{
$this->consoleSender = new ConsoleCommandSender(); $this->consoleSender = new ConsoleCommandSender();
$this->commandMap = new SimpleCommandMap($this); $this->commandMap = new SimpleCommandMap($this);
$this->pluginManager = new PluginManager($this, $this->commandMap); $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->registerInterface("PocketMine\\Plugin\\FolderPluginLoader");
$this->pluginManager->loadPlugins($this->pluginPath); $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->server->schedule(6000, array($this, "sendUsage"), array(), true); //Send the info after 5 minutes have passed
$this->sendUsage(); $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){ 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));
}*/ }*/
$this->scheduler->scheduleRepeatingTask(new CallbackTask("PocketMine\\Utils\\Cache::cleanup"), 20 * 45);
//$this->schedule(2, array($this, "checkTickUpdates"), array(), true); if($this->getConfigBoolean("auto-save", true) === true){
$this->scheduler->scheduleRepeatingTask(new CallbackTask(array($this, "doAutoSave")), 18000);
}
$this->enablePlugins(PluginLoadOrder::POSTWORLD); $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 * @param int $type
*/ */
@ -747,10 +778,6 @@ class Server{
*/ */
public function loadPlugin(Plugin $plugin){ public function loadPlugin(Plugin $plugin){
$this->pluginManager->enablePlugin($plugin); $this->pluginManager->enablePlugin($plugin);
foreach($plugin->getDescription()->getPermisions() as $perm){
$this->pluginManager->addPermission($perm);
}
} }
public function disablePlugins(){ public function disablePlugins(){
@ -979,13 +1006,13 @@ class Server{
//TODO: Add level blocks //TODO: Add level blocks
//Do level ticks //Do level ticks
foreach(Level::$list as $level){ foreach(Level::getAll() as $level){
$level->doTick(); $level->doTick();
} }
} }
public function autoSave(){ public function doAutoSave(){
console("[DEBUG] Saving....", true, true, 2); $this->broadcast(TextFormat::GRAY . "Saving...", self::BROADCAST_CHANNEL_ADMINISTRATIVE);
Level::saveAll(); Level::saveAll();
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -296,9 +296,10 @@ class Level{
$level->save(true, true); $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"]); 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; return true;
} }
@ -306,7 +307,7 @@ class Level{
/** /**
* Generates a new level * Generates a new level
* *
* @param $name * @param string $name
* @param bool $seed * @param bool $seed
* @param bool $generator * @param bool $generator
* @param bool|array $options * @param bool|array $options
@ -341,7 +342,7 @@ class Level{
/** /**
* Searches if a level exists on file * Searches if a level exists on file
* *
* @param $name * @param string $name
* *
* @return bool * @return bool
*/ */
@ -416,35 +417,75 @@ class Level{
return true; return true;
} }
/**
* Gets the chunks being used by players
*
* @param int $X
* @param int $Z
*
* @return Player[][]
*/
public function getUsingChunk($X, $Z){ public function getUsingChunk($X, $Z){
$index = LevelFormat::getIndex($X, $Z); $index = LevelFormat::getIndex($X, $Z);
return isset($this->usedChunks[$index]) ? $this->usedChunks[$index] : array(); 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){ public function useChunk($X, $Z, Player $player){
$index = LevelFormat::getIndex($X, $Z); $index = LevelFormat::getIndex($X, $Z);
$this->loadChunk($X, $Z); $this->loadChunk($X, $Z);
$this->usedChunks[$index][$player->CID] = $player; $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){ public function freeAllChunks(Player $player){
foreach($this->usedChunks as $i => $c){ foreach($this->usedChunks as $i => $c){
unset($this->usedChunks[$i][$player->CID]); 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){ public function freeChunk($X, $Z, Player $player){
unset($this->usedChunks[LevelFormat::getIndex($X, $Z)][$player->CID]); unset($this->usedChunks[LevelFormat::getIndex($X, $Z)][$player->CID]);
} }
/**
* @param int $X
* @param int $Z
*
* @return bool
*/
public function isChunkPopulated($X, $Z){ public function isChunkPopulated($X, $Z){
return $this->level->isPopulated($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(){ public function checkTime(){
if(!isset($this->level)){ if(!isset($this->level)){
return false; return;
} }
$now = microtime(true); $now = microtime(true);
if($this->stopTime == true){ if($this->stopTime == true){
@ -462,6 +503,12 @@ class Level{
return; 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(){ public function doTick(){
if(!isset($this->level)){ if(!isset($this->level)){
return false; 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))); $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 instanceof Block){
if($block->onUpdate(self::BLOCK_UPDATE_RANDOM) === self::BLOCK_UPDATE_NORMAL){ 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){ public function generateChunk($X, $Z){
++$this->level->isGenerating; ++$this->level->isGenerating;
$this->generator->generateChunk($X, $Z); $this->generator->generateChunk($X, $Z);
@ -551,6 +605,12 @@ class Level{
return true; return true;
} }
/**
* @param int $X
* @param int $Z
*
* @return bool
*/
public function populateChunk($X, $Z){ public function populateChunk($X, $Z){
$this->level->setPopulated($X, $Z); $this->level->setPopulated($X, $Z);
$this->generator->populateChunk($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){ public function save($force = false, $extra = true){
if(!isset($this->level)){ if(!isset($this->level)){
return false; return false;
@ -617,12 +683,22 @@ class Level{
} }
} }
/**
* @param Vector3 $pos
*
* @return Block
*/
public function getBlockRaw(Vector3 $pos){ public function getBlockRaw(Vector3 $pos){
$b = $this->level->getBlock($pos->x, $pos->y, $pos->z); $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)); 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){ public function getBlock(Vector3 $pos){
if($pos instanceof Position and $pos->level !== $this){ if($pos instanceof Position and $pos->level !== $this){
return false; return false;
@ -632,6 +708,14 @@ class Level{
return Block::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this)); 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){ 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(($ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata())) === true and $send !== false){
if($direct === true){ if($direct === true){
@ -667,6 +751,15 @@ class Level{
return $ret; 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){ 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){ if((($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){
return false; return false;
@ -705,7 +798,8 @@ class Level{
} }
if($update === true){ 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($tiles === true){
if(($t = $this->getTile($pos)) instanceof Tile){ if(($t = $this->getTile($pos)) instanceof Tile){
@ -1286,6 +1380,7 @@ class Level{
} }
public function scheduleBlockUpdate(Position $pos, $delay, $type = self::BLOCK_UPDATE_SCHEDULED){ 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\Item\Item;
use PocketMine\Utils\Utils; use PocketMine\Utils\Utils;
abstract class DataPacket{ abstract class DataPacket extends \stdClass{
private $offset = 0; private $offset = 0;
public $buffer = ""; public $buffer = "";

View File

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

View File

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