Merge branch 'moar-typehints'

This commit is contained in:
Dylan K. Taylor 2017-07-15 09:43:43 +01:00
commit 24bdf330d5
176 changed files with 879 additions and 741 deletions

View File

@ -38,7 +38,9 @@ class CrashDump{
private $fp; private $fp;
private $time; private $time;
private $data = []; private $data = [];
private $encodedData = null; /** @var string */
private $encodedData = "";
/** @var string */
private $path; private $path;
public function __construct(Server $server){ public function __construct(Server $server){
@ -64,7 +66,7 @@ class CrashDump{
$this->encodeData(); $this->encodeData();
} }
public function getPath(){ public function getPath() : string{
return $this->path; return $this->path;
} }
@ -72,7 +74,7 @@ class CrashDump{
return $this->encodedData; return $this->encodedData;
} }
public function getData(){ public function getData() : array{
return $this->data; return $this->data;
} }

View File

@ -30,7 +30,7 @@ interface IPlayer extends ServerOperator{
/** /**
* @return bool * @return bool
*/ */
public function isOnline(); public function isOnline() : bool;
/** /**
* @return string * @return string
@ -40,22 +40,22 @@ interface IPlayer extends ServerOperator{
/** /**
* @return bool * @return bool
*/ */
public function isBanned(); public function isBanned() : bool;
/** /**
* @param bool $banned * @param bool $banned
*/ */
public function setBanned($banned); public function setBanned(bool $banned);
/** /**
* @return bool * @return bool
*/ */
public function isWhitelisted(); public function isWhitelisted() : bool;
/** /**
* @param bool $value * @param bool $value
*/ */
public function setWhitelisted($value); public function setWhitelisted(bool $value);
/** /**
* @return Player|null * @return Player|null
@ -73,8 +73,8 @@ interface IPlayer extends ServerOperator{
public function getLastPlayed(); public function getLastPlayed();
/** /**
* @return mixed * @return bool
*/ */
public function hasPlayedBefore(); public function hasPlayedBefore() : bool;
} }

View File

@ -116,11 +116,11 @@ class MemoryManager{
gc_enable(); gc_enable();
} }
public function isLowMemory(){ public function isLowMemory() : bool{
return $this->lowMemory; return $this->lowMemory;
} }
public function canUseChunkCache(){ public function canUseChunkCache() : bool{
return !($this->lowMemory and $this->chunkTrigger); return !($this->lowMemory and $this->chunkTrigger);
} }

View File

@ -48,7 +48,7 @@ class OfflinePlayer implements IPlayer, Metadatable{
} }
} }
public function isOnline(){ public function isOnline() : bool{
return $this->getPlayer() !== null; return $this->getPlayer() !== null;
} }
@ -60,11 +60,11 @@ class OfflinePlayer implements IPlayer, Metadatable{
return $this->server; return $this->server;
} }
public function isOp(){ public function isOp() : bool{
return $this->server->isOp(strtolower($this->getName())); return $this->server->isOp(strtolower($this->getName()));
} }
public function setOp($value){ public function setOp(bool $value){
if($value === $this->isOp()){ if($value === $this->isOp()){
return; return;
} }
@ -76,11 +76,11 @@ class OfflinePlayer implements IPlayer, Metadatable{
} }
} }
public function isBanned(){ public function isBanned() : bool{
return $this->server->getNameBans()->isBanned(strtolower($this->getName())); return $this->server->getNameBans()->isBanned(strtolower($this->getName()));
} }
public function setBanned($value){ public function setBanned(bool $value){
if($value === true){ if($value === true){
$this->server->getNameBans()->addBan($this->getName(), null, null, null); $this->server->getNameBans()->addBan($this->getName(), null, null, null);
}else{ }else{
@ -88,11 +88,11 @@ class OfflinePlayer implements IPlayer, Metadatable{
} }
} }
public function isWhitelisted(){ public function isWhitelisted() : bool{
return $this->server->isWhitelisted(strtolower($this->getName())); return $this->server->isWhitelisted(strtolower($this->getName()));
} }
public function setWhitelisted($value){ public function setWhitelisted(bool $value){
if($value === true){ if($value === true){
$this->server->addWhitelist(strtolower($this->getName())); $this->server->addWhitelist(strtolower($this->getName()));
}else{ }else{
@ -112,7 +112,7 @@ class OfflinePlayer implements IPlayer, Metadatable{
return $this->namedtag instanceof CompoundTag ? $this->namedtag["lastPlayed"] : null; return $this->namedtag instanceof CompoundTag ? $this->namedtag["lastPlayed"] : null;
} }
public function hasPlayedBefore(){ public function hasPlayedBefore() : bool{
return $this->namedtag instanceof CompoundTag; return $this->namedtag instanceof CompoundTag;
} }

View File

@ -76,7 +76,6 @@ use pocketmine\inventory\BigShapedRecipe;
use pocketmine\inventory\BigShapelessRecipe; use pocketmine\inventory\BigShapelessRecipe;
use pocketmine\inventory\FurnaceInventory; use pocketmine\inventory\FurnaceInventory;
use pocketmine\inventory\Inventory; use pocketmine\inventory\Inventory;
use pocketmine\inventory\InventoryHolder;
use pocketmine\inventory\PlayerInventory; use pocketmine\inventory\PlayerInventory;
use pocketmine\inventory\ShapedRecipe; use pocketmine\inventory\ShapedRecipe;
use pocketmine\inventory\ShapelessRecipe; use pocketmine\inventory\ShapelessRecipe;
@ -160,6 +159,7 @@ use pocketmine\network\mcpe\protocol\UseItemPacket;
use pocketmine\network\SourceInterface; use pocketmine\network\SourceInterface;
use pocketmine\permission\PermissibleBase; use pocketmine\permission\PermissibleBase;
use pocketmine\permission\PermissionAttachment; use pocketmine\permission\PermissionAttachment;
use pocketmine\permission\PermissionAttachmentInfo;
use pocketmine\plugin\Plugin; use pocketmine\plugin\Plugin;
use pocketmine\resourcepacks\ResourcePack; use pocketmine\resourcepacks\ResourcePack;
use pocketmine\tile\ItemFrame; use pocketmine\tile\ItemFrame;
@ -253,7 +253,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
protected $sleeping = null; protected $sleeping = null;
protected $clientID = null; protected $clientID = null;
private $loaderId = null; private $loaderId = 0;
protected $stepHeight = 0.6; protected $stepHeight = 0.6;
@ -320,11 +320,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return $this->clientSecret; return $this->clientSecret;
} }
public function isBanned(){ public function isBanned() : bool{
return $this->server->getNameBans()->isBanned($this->iusername); return $this->server->getNameBans()->isBanned($this->iusername);
} }
public function setBanned($value){ public function setBanned(bool $value){
if($value === true){ if($value === true){
$this->server->getNameBans()->addBan($this->getName(), null, null, null); $this->server->getNameBans()->addBan($this->getName(), null, null, null);
$this->kick("You have been banned"); $this->kick("You have been banned");
@ -333,11 +333,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
} }
public function isWhitelisted(){ public function isWhitelisted() : bool{
return $this->server->isWhitelisted($this->iusername); return $this->server->isWhitelisted($this->iusername);
} }
public function setWhitelisted($value){ public function setWhitelisted(bool $value){
if($value === true){ if($value === true){
$this->server->addWhitelist($this->iusername); $this->server->addWhitelist($this->iusername);
}else{ }else{
@ -357,12 +357,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return $this->namedtag instanceof CompoundTag ? $this->namedtag["lastPlayed"] : null; return $this->namedtag instanceof CompoundTag ? $this->namedtag["lastPlayed"] : null;
} }
public function hasPlayedBefore(){ public function hasPlayedBefore() : bool{
return $this->playedBefore; return $this->playedBefore;
} }
public function setAllowFlight($value){ public function setAllowFlight(bool $value){
$this->allowFlight = (bool) $value; $this->allowFlight = $value;
$this->sendSettings(); $this->sendSettings();
} }
@ -423,7 +423,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** /**
* @return bool * @return bool
*/ */
public function getRemoveFormat(){ public function getRemoveFormat() : bool{
return $this->removeFormat; return $this->removeFormat;
} }
@ -450,7 +450,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* *
* @return bool * @return bool
*/ */
public function canSee(Player $player){ public function canSee(Player $player) : bool{
return !isset($this->hiddenPlayers[$player->getRawUniqueId()]); return !isset($this->hiddenPlayers[$player->getRawUniqueId()]);
} }
@ -509,21 +509,21 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** /**
* @return bool * @return bool
*/ */
public function isOnline(){ public function isOnline() : bool{
return $this->connected === true and $this->loggedIn === true; return $this->connected === true and $this->loggedIn === true;
} }
/** /**
* @return bool * @return bool
*/ */
public function isOp(){ public function isOp() : bool{
return $this->server->isOp($this->getName()); return $this->server->isOp($this->getName());
} }
/** /**
* @param bool $value * @param bool $value
*/ */
public function setOp($value){ public function setOp(bool $value){
if($value === $this->isOp()){ if($value === $this->isOp()){
return; return;
} }
@ -542,7 +542,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* *
* @return bool * @return bool
*/ */
public function isPermissionSet($name){ public function isPermissionSet($name) : bool{
return $this->perm->isPermissionSet($name); return $this->perm->isPermissionSet($name);
} }
@ -553,7 +553,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* *
* @throws \InvalidStateException if the player is closed * @throws \InvalidStateException if the player is closed
*/ */
public function hasPermission($name){ public function hasPermission($name) : bool{
if($this->closed){ if($this->closed){
throw new \InvalidStateException("Trying to get permissions of closed player"); throw new \InvalidStateException("Trying to get permissions of closed player");
} }
@ -599,9 +599,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
/** /**
* @return permission\PermissionAttachmentInfo[] * @return PermissionAttachmentInfo[]
*/ */
public function getEffectivePermissions(){ public function getEffectivePermissions() : array{
return $this->perm->getEffectivePermissions(); return $this->perm->getEffectivePermissions();
} }
@ -670,7 +670,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* *
* @return bool * @return bool
*/ */
public function hasAchievement($achievementId){ public function hasAchievement(string $achievementId) : bool{
if(!isset(Achievement::$list[$achievementId])){ if(!isset(Achievement::$list[$achievementId])){
return false; return false;
} }
@ -681,7 +681,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** /**
* @return bool * @return bool
*/ */
public function isConnected(){ public function isConnected() : bool{
return $this->connected === true; return $this->connected === true;
} }
@ -690,7 +690,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* *
* @return string * @return string
*/ */
public function getDisplayName(){ public function getDisplayName() : string{
return $this->displayName; return $this->displayName;
} }
@ -716,14 +716,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* *
* @return string * @return string
*/ */
public function getAddress(){ public function getAddress() : string{
return $this->ip; return $this->ip;
} }
/** /**
* @return int * @return int
*/ */
public function getPort(){ public function getPort() : int{
return $this->port; return $this->port;
} }
@ -734,7 +734,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** /**
* @return bool * @return bool
*/ */
public function isSleeping(){ public function isSleeping() : bool{
return $this->sleeping !== null; return $this->sleeping !== null;
} }
@ -1007,7 +1007,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* *
* @return bool * @return bool
*/ */
public function batchDataPacket(DataPacket $packet){ public function batchDataPacket(DataPacket $packet) : bool{
if($this->connected === false){ if($this->connected === false){
return false; return false;
} }
@ -1105,9 +1105,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** /**
* @param Vector3 $pos * @param Vector3 $pos
* *
* @return boolean * @return bool
*/ */
public function sleepOn(Vector3 $pos){ public function sleepOn(Vector3 $pos) : bool{
if(!$this->isOnline()){ if(!$this->isOnline()){
return false; return false;
} }
@ -1181,7 +1181,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* *
* @return bool * @return bool
*/ */
public function awardAchievement($achievementId){ public function awardAchievement(string $achievementId) : bool{
if(isset(Achievement::$list[$achievementId]) and !$this->hasAchievement($achievementId)){ if(isset(Achievement::$list[$achievementId]) and !$this->hasAchievement($achievementId)){
foreach(Achievement::$list[$achievementId]["requires"] as $requirementId){ foreach(Achievement::$list[$achievementId]["requires"] as $requirementId){
if(!$this->hasAchievement($requirementId)){ if(!$this->hasAchievement($requirementId)){
@ -1205,7 +1205,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** /**
* @return int * @return int
*/ */
public function getGamemode(){ public function getGamemode() : int{
return $this->gamemode; return $this->gamemode;
} }
@ -1237,7 +1237,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* *
* @return bool * @return bool
*/ */
public function setGamemode(int $gm, bool $client = false){ public function setGamemode(int $gm, bool $client = false) : bool{
if($gm < 0 or $gm > 3 or $this->gamemode === $gm){ if($gm < 0 or $gm > 3 or $this->gamemode === $gm){
return false; return false;
} }
@ -1374,7 +1374,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return $this->isCreative(); return $this->isCreative();
} }
public function getDrops(){ public function getDrops() : array{
if(!$this->isCreative()){ if(!$this->isCreative()){
return parent::getDrops(); return parent::getDrops();
} }
@ -3216,7 +3216,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* *
* @return bool * @return bool
*/ */
public function kick($reason = "", $isAdmin = true){ public function kick($reason = "", bool $isAdmin = true) : bool{
$this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, $this->getLeaveMessage())); $this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, $this->getLeaveMessage()));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
if($isAdmin){ if($isAdmin){
@ -3874,11 +3874,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
public function getLoaderId(){ public function getLoaderId() : int{
return $this->loaderId; return $this->loaderId;
} }
public function isLoaderActive(){ public function isLoaderActive() : bool{
return $this->isConnected(); return $this->isConnected();
} }
} }

View File

@ -79,7 +79,7 @@ namespace pocketmine {
use raklib\RakLib; use raklib\RakLib;
const VERSION = "1.6.2dev"; const VERSION = "1.6.2dev";
const API_VERSION = "3.0.0-ALPHA6"; const API_VERSION = "3.0.0-ALPHA7";
const CODENAME = "Unleashed"; const CODENAME = "Unleashed";
/* /*

View File

@ -577,7 +577,7 @@ class Server{
} }
/** /**
* @return \AttachableThreadedLogger * @return MainLogger
*/ */
public function getLogger(){ public function getLogger(){
return $this->logger; return $this->logger;
@ -1043,12 +1043,12 @@ class Server{
* *
* @return bool * @return bool
*/ */
public function generateLevel(string $name, $seed = null, $generator = null, array $options = []){ public function generateLevel(string $name, int $seed = null, $generator = null, array $options = []) : bool{
if(trim($name) === "" or $this->isLevelGenerated($name)){ if(trim($name) === "" or $this->isLevelGenerated($name)){
return false; return false;
} }
$seed = $seed === null ? Binary::readInt(random_bytes(4)) : (int) $seed; $seed = $seed ?? Binary::readInt(random_bytes(4));
if(!isset($options["preset"])){ if(!isset($options["preset"])){
$options["preset"] = $this->getConfigString("generator-settings", ""); $options["preset"] = $this->getConfigString("generator-settings", "");
@ -1328,7 +1328,7 @@ class Server{
* *
* @return bool * @return bool
*/ */
public function isWhitelisted(string $name){ public function isWhitelisted(string $name) : bool{
return !$this->hasWhitelist() or $this->operators->exists($name, true) or $this->whitelist->exists($name, true); return !$this->hasWhitelist() or $this->operators->exists($name, true) or $this->whitelist->exists($name, true);
} }
@ -1337,7 +1337,7 @@ class Server{
* *
* @return bool * @return bool
*/ */
public function isOp(string $name){ public function isOp(string $name) : bool{
return $this->operators->exists($name, true); return $this->operators->exists($name, true);
} }
@ -1765,7 +1765,7 @@ class Server{
* *
* @return int * @return int
*/ */
public function broadcastTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1, $recipients = null){ public function broadcastTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1, array $recipients = null) : int{
if(!is_array($recipients)){ if(!is_array($recipients)){
/** @var Player[] $recipients */ /** @var Player[] $recipients */
$recipients = []; $recipients = [];
@ -1931,7 +1931,7 @@ class Server{
* *
* @return bool * @return bool
*/ */
public function dispatchCommand(CommandSender $sender, string $commandLine){ public function dispatchCommand(CommandSender $sender, string $commandLine) : bool{
if($this->commandMap->dispatch($sender, $commandLine)){ if($this->commandMap->dispatch($sender, $commandLine)){
return true; return true;
} }
@ -2054,6 +2054,9 @@ class Server{
} }
/**
* @return QueryRegenerateEvent
*/
public function getQueryInformation(){ public function getQueryInformation(){
return $this->queryRegenerateTask; return $this->queryRegenerateTask;
} }
@ -2428,7 +2431,7 @@ class Server{
/** /**
* Tries to execute a server tick * Tries to execute a server tick
*/ */
private function tick(){ private function tick() : bool{
$tickTime = microtime(true); $tickTime = microtime(true);
if(($tickTime - $this->nextTick) < -0.025){ //Allow half a tick of diff if(($tickTime - $this->nextTick) < -0.025){ //Allow half a tick of diff
return false; return false;

View File

@ -60,7 +60,7 @@ class ThreadManager extends \Volatile{
/** /**
* @return Worker[]|Thread[] * @return Worker[]|Thread[]
*/ */
public function getAll(){ public function getAll() : array{
$array = []; $array = [];
foreach($this as $key => $thread){ foreach($this as $key => $thread){
$array[$key] = $thread; $array[$key] = $thread;

View File

@ -88,7 +88,7 @@ abstract class Worker extends \Worker{
ThreadManager::getInstance()->remove($this); ThreadManager::getInstance()->remove($this);
} }
public function getThreadName(){ public function getThreadName() : string{
return (new \ReflectionClass($this))->getShortName(); return (new \ReflectionClass($this))->getShortName();
} }
} }

View File

@ -74,7 +74,7 @@ abstract class Command{
* @param string $usageMessage * @param string $usageMessage
* @param string[] $aliases * @param string[] $aliases
*/ */
public function __construct($name, $description = "", $usageMessage = null, array $aliases = []){ public function __construct(string $name, string $description = "", string $usageMessage = null, array $aliases = []){
$this->commandData = self::generateDefaultData(); $this->commandData = self::generateDefaultData();
$this->name = $name; $this->name = $name;
$this->setLabel($name); $this->setLabel($name);
@ -100,7 +100,7 @@ abstract class Command{
* *
* @return array * @return array
*/ */
public function generateCustomCommandData(Player $player){ public function generateCustomCommandData(Player $player) : array{
//TODO: fix command permission filtering on join //TODO: fix command permission filtering on join
/*if(!$this->testPermissionSilent($player)){ /*if(!$this->testPermissionSilent($player)){
return null; return null;
@ -118,7 +118,7 @@ abstract class Command{
/** /**
* @return array * @return array
*/ */
public function getOverloads(): array{ public function getOverloads() : array{
return $this->commandData["overloads"]; return $this->commandData["overloads"];
} }
@ -129,12 +129,12 @@ abstract class Command{
* *
* @return mixed * @return mixed
*/ */
abstract public function execute(CommandSender $sender, $commandLabel, array $args); abstract public function execute(CommandSender $sender, string $commandLabel, array $args);
/** /**
* @return string * @return string
*/ */
public function getName(){ public function getName() : string{
return $this->name; return $this->name;
} }
@ -149,7 +149,7 @@ abstract class Command{
/** /**
* @param string|null $permission * @param string|null $permission
*/ */
public function setPermission($permission){ public function setPermission(string $permission = null){
if($permission !== null){ if($permission !== null){
$this->commandData["pocketminePermission"] = $permission; $this->commandData["pocketminePermission"] = $permission;
}else{ }else{
@ -162,7 +162,7 @@ abstract class Command{
* *
* @return bool * @return bool
*/ */
public function testPermission(CommandSender $target){ public function testPermission(CommandSender $target) : bool{
if($this->testPermissionSilent($target)){ if($this->testPermissionSilent($target)){
return true; return true;
} }
@ -181,7 +181,7 @@ abstract class Command{
* *
* @return bool * @return bool
*/ */
public function testPermissionSilent(CommandSender $target){ public function testPermissionSilent(CommandSender $target) : bool{
if(($perm = $this->getPermission()) === null or $perm === ""){ if(($perm = $this->getPermission()) === null or $perm === ""){
return true; return true;
} }
@ -198,11 +198,11 @@ abstract class Command{
/** /**
* @return string * @return string
*/ */
public function getLabel(){ public function getLabel() : string{
return $this->label; return $this->label;
} }
public function setLabel($name){ public function setLabel(string $name) : bool{
$this->nextLabel = $name; $this->nextLabel = $name;
if(!$this->isRegistered()){ if(!$this->isRegistered()){
if($this->timings instanceof TimingsHandler){ if($this->timings instanceof TimingsHandler){
@ -224,7 +224,7 @@ abstract class Command{
* *
* @return bool * @return bool
*/ */
public function register(CommandMap $commandMap){ public function register(CommandMap $commandMap) : bool{
if($this->allowChangesFrom($commandMap)){ if($this->allowChangesFrom($commandMap)){
$this->commandMap = $commandMap; $this->commandMap = $commandMap;
@ -239,7 +239,7 @@ abstract class Command{
* *
* @return bool * @return bool
*/ */
public function unregister(CommandMap $commandMap){ public function unregister(CommandMap $commandMap) : bool{
if($this->allowChangesFrom($commandMap)){ if($this->allowChangesFrom($commandMap)){
$this->commandMap = null; $this->commandMap = null;
$this->activeAliases = $this->commandData["aliases"]; $this->activeAliases = $this->commandData["aliases"];
@ -256,42 +256,42 @@ abstract class Command{
* *
* @return bool * @return bool
*/ */
private function allowChangesFrom(CommandMap $commandMap){ private function allowChangesFrom(CommandMap $commandMap) : bool{
return $this->commandMap === null or $this->commandMap === $commandMap; return $this->commandMap === null or $this->commandMap === $commandMap;
} }
/** /**
* @return bool * @return bool
*/ */
public function isRegistered(){ public function isRegistered() : bool{
return $this->commandMap !== null; return $this->commandMap !== null;
} }
/** /**
* @return string[] * @return string[]
*/ */
public function getAliases(){ public function getAliases() : array{
return $this->activeAliases; return $this->activeAliases;
} }
/** /**
* @return string * @return string
*/ */
public function getPermissionMessage(){ public function getPermissionMessage() : string{
return $this->permissionMessage; return $this->permissionMessage;
} }
/** /**
* @return string * @return string
*/ */
public function getDescription(){ public function getDescription() : string{
return $this->commandData["description"]; return $this->commandData["description"];
} }
/** /**
* @return string * @return string
*/ */
public function getUsage(){ public function getUsage() : string{
return $this->usageMessage; return $this->usageMessage;
} }
@ -308,21 +308,21 @@ abstract class Command{
/** /**
* @param string $description * @param string $description
*/ */
public function setDescription($description){ public function setDescription(string $description){
$this->commandData["description"] = $description; $this->commandData["description"] = $description;
} }
/** /**
* @param string $permissionMessage * @param string $permissionMessage
*/ */
public function setPermissionMessage($permissionMessage){ public function setPermissionMessage(string $permissionMessage){
$this->permissionMessage = $permissionMessage; $this->permissionMessage = $permissionMessage;
} }
/** /**
* @param string $usage * @param string $usage
*/ */
public function setUsage($usage){ public function setUsage(string $usage){
$this->usageMessage = $usage; $this->usageMessage = $usage;
} }
@ -338,10 +338,10 @@ abstract class Command{
/** /**
* @param CommandSender $source * @param CommandSender $source
* @param string $message * @param TextContainer|string $message
* @param bool $sendToSource * @param bool $sendToSource
*/ */
public static function broadcastCommandMessage(CommandSender $source, $message, $sendToSource = true){ public static function broadcastCommandMessage(CommandSender $source, $message, bool $sendToSource = true){
if($message instanceof TextContainer){ if($message instanceof TextContainer){
$m = clone $message; $m = clone $message;
$result = "[" . $source->getName() . ": " . ($source->getServer()->getLanguage()->get($m->getText()) !== $m->getText() ? "%" : "") . $m->getText() . "]"; $result = "[" . $source->getName() . ": " . ($source->getServer()->getLanguage()->get($m->getText()) !== $m->getText() ? "%" : "") . $m->getText() . "]";
@ -377,7 +377,7 @@ abstract class Command{
/** /**
* @return string * @return string
*/ */
public function __toString(){ public function __toString() : string{
return $this->name; return $this->name;
} }
} }

View File

@ -34,6 +34,6 @@ interface CommandExecutor{
* *
* @return bool * @return bool
*/ */
public function onCommand(CommandSender $sender, Command $command, $label, array $args); public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool;
} }

View File

@ -30,14 +30,16 @@ interface CommandMap{
* @param string $fallbackPrefix * @param string $fallbackPrefix
* @param Command[] $commands * @param Command[] $commands
*/ */
public function registerAll($fallbackPrefix, array $commands); public function registerAll(string $fallbackPrefix, array $commands);
/** /**
* @param string $fallbackPrefix * @param string $fallbackPrefix
* @param Command $command * @param Command $command
* @param string $label * @param string|null $label
*
* @return bool
*/ */
public function register($fallbackPrefix, Command $command, $label = null); public function register(string $fallbackPrefix, Command $command, string $label = null) : bool;
/** /**
* @param CommandSender $sender * @param CommandSender $sender
@ -45,7 +47,7 @@ interface CommandMap{
* *
* @return bool * @return bool
*/ */
public function dispatch(CommandSender $sender, $cmdLine); public function dispatch(CommandSender $sender, string $cmdLine) : bool;
/** /**
* @return void * @return void
@ -55,9 +57,9 @@ interface CommandMap{
/** /**
* @param string $name * @param string $name
* *
* @return Command * @return Command|null
*/ */
public function getCommand($name); public function getCommand(string $name);
} }

View File

@ -31,7 +31,6 @@ use pocketmine\permission\PermissionAttachmentInfo;
use pocketmine\plugin\Plugin; use pocketmine\plugin\Plugin;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\MainLogger; use pocketmine\utils\MainLogger;
use pocketmine\utils\Terminal;
class ConsoleCommandSender implements CommandSender{ class ConsoleCommandSender implements CommandSender{
@ -49,7 +48,7 @@ class ConsoleCommandSender implements CommandSender{
* *
* @return bool * @return bool
*/ */
public function isPermissionSet($name){ public function isPermissionSet($name) : bool{
return $this->perm->isPermissionSet($name); return $this->perm->isPermissionSet($name);
} }
@ -58,7 +57,7 @@ class ConsoleCommandSender implements CommandSender{
* *
* @return bool * @return bool
*/ */
public function hasPermission($name){ public function hasPermission($name) : bool{
return $this->perm->hasPermission($name); return $this->perm->hasPermission($name);
} }
@ -89,14 +88,14 @@ class ConsoleCommandSender implements CommandSender{
/** /**
* @return PermissionAttachmentInfo[] * @return PermissionAttachmentInfo[]
*/ */
public function getEffectivePermissions(){ public function getEffectivePermissions() : array{
return $this->perm->getEffectivePermissions(); return $this->perm->getEffectivePermissions();
} }
/** /**
* @return bool * @return bool
*/ */
public function isPlayer(){ public function isPlayer() : bool{
return false; return false;
} }
@ -132,14 +131,14 @@ class ConsoleCommandSender implements CommandSender{
/** /**
* @return bool * @return bool
*/ */
public function isOp(){ public function isOp() : bool{
return true; return true;
} }
/** /**
* @param bool $value * @param bool $value
*/ */
public function setOp($value){ public function setOp(bool $value){
} }

View File

@ -34,12 +34,12 @@ class FormattedCommandAlias extends Command{
* @param string $alias * @param string $alias
* @param string[] $formatStrings * @param string[] $formatStrings
*/ */
public function __construct($alias, array $formatStrings){ public function __construct(string $alias, array $formatStrings){
parent::__construct($alias); parent::__construct($alias);
$this->formatStrings = $formatStrings; $this->formatStrings = $formatStrings;
} }
public function execute(CommandSender $sender, $commandLabel, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
$commands = []; $commands = [];
$result = false; $result = false;
@ -71,9 +71,8 @@ class FormattedCommandAlias extends Command{
* @param array $args * @param array $args
* *
* @return string * @return string
* @throws \InvalidArgumentException
*/ */
private function buildCommand($formatString, array $args){ private function buildCommand(string $formatString, array $args) : string{
$index = strpos($formatString, '$'); $index = strpos($formatString, '$');
while($index !== false){ while($index !== false){
$start = $index; $start = $index;
@ -153,7 +152,7 @@ class FormattedCommandAlias extends Command{
* *
* @return bool * @return bool
*/ */
private static function inRange($i, $j, $k){ private static function inRange(int $i, int $j, int $k) : bool{
return $i >= $j and $i <= $k; return $i >= $j and $i <= $k;
} }

View File

@ -45,7 +45,7 @@ class PluginCommand extends Command implements PluginIdentifiableCommand{
$this->usageMessage = ""; $this->usageMessage = "";
} }
public function execute(CommandSender $sender, $commandLabel, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->owningPlugin->isEnabled()){ if(!$this->owningPlugin->isEnabled()){
return false; return false;
@ -64,7 +64,7 @@ class PluginCommand extends Command implements PluginIdentifiableCommand{
return $success; return $success;
} }
public function getExecutor(){ public function getExecutor() : CommandExecutor{
return $this->executor; return $this->executor;
} }
@ -78,7 +78,7 @@ class PluginCommand extends Command implements PluginIdentifiableCommand{
/** /**
* @return Plugin * @return Plugin
*/ */
public function getPlugin(){ public function getPlugin() : Plugin{
return $this->owningPlugin; return $this->owningPlugin;
} }
} }

View File

@ -30,5 +30,5 @@ interface PluginIdentifiableCommand{
/** /**
* @return Plugin * @return Plugin
*/ */
public function getPlugin(); public function getPlugin() : Plugin;
} }

View File

@ -131,13 +131,20 @@ class SimpleCommandMap implements CommandMap{
} }
public function registerAll($fallbackPrefix, array $commands){ public function registerAll(string $fallbackPrefix, array $commands){
foreach($commands as $command){ foreach($commands as $command){
$this->register($fallbackPrefix, $command); $this->register($fallbackPrefix, $command);
} }
} }
public function register($fallbackPrefix, Command $command, $label = null){ /**
* @param string $fallbackPrefix
* @param Command $command
* @param string|null $label
*
* @return bool
*/
public function register(string $fallbackPrefix, Command $command, string $label = null) : bool{
if($label === null){ if($label === null){
$label = $command->getName(); $label = $command->getName();
} }
@ -163,7 +170,15 @@ class SimpleCommandMap implements CommandMap{
return $registered; return $registered;
} }
private function registerAlias(Command $command, $isAlias, $fallbackPrefix, $label){ /**
* @param Command $command
* @param bool $isAlias
* @param string $fallbackPrefix
* @param string $label
*
* @return bool
*/
private function registerAlias(Command $command, bool $isAlias, string $fallbackPrefix, string $label) : bool{
$this->knownCommands[$fallbackPrefix . ":" . $label] = $command; $this->knownCommands[$fallbackPrefix . ":" . $label] = $command;
if(($command instanceof VanillaCommand or $isAlias) and isset($this->knownCommands[$label])){ if(($command instanceof VanillaCommand or $isAlias) and isset($this->knownCommands[$label])){
return false; return false;
@ -207,7 +222,7 @@ class SimpleCommandMap implements CommandMap{
return null; return null;
} }
public function dispatch(CommandSender $sender, $commandLine){ public function dispatch(CommandSender $sender, string $commandLine) : bool{
$args = explode(" ", $commandLine); $args = explode(" ", $commandLine);
$sentCommandLabel = ""; $sentCommandLabel = "";
$target = $this->matchCommand($sentCommandLabel, $args); $target = $this->matchCommand($sentCommandLabel, $args);
@ -241,14 +256,14 @@ class SimpleCommandMap implements CommandMap{
$this->setDefaultCommands(); $this->setDefaultCommands();
} }
public function getCommand($name){ public function getCommand(string $name){
return $this->knownCommands[$name] ?? null; return $this->knownCommands[$name] ?? null;
} }
/** /**
* @return Command[] * @return Command[]
*/ */
public function getCommands(){ public function getCommands() : array{
return $this->knownCommands; return $this->knownCommands;
} }

View File

@ -40,7 +40,7 @@ class BanCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.ban.player"); $this->setPermission("pocketmine.command.ban.player");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -40,7 +40,7 @@ class BanIpCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.ban.ip"); $this->setPermission("pocketmine.command.ban.ip");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -39,7 +39,7 @@ class BanListCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.ban.list"); $this->setPermission("pocketmine.command.ban.list");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -39,7 +39,7 @@ class DefaultGamemodeCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.defaultgamemode"); $this->setPermission("pocketmine.command.defaultgamemode");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -41,7 +41,7 @@ class DeopCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.op.take"); $this->setPermission("pocketmine.command.op.take");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -41,7 +41,7 @@ class DifficultyCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.difficulty"); $this->setPermission("pocketmine.command.difficulty");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -38,7 +38,7 @@ class DumpMemoryCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.dumpmemory"); $this->setPermission("pocketmine.command.dumpmemory");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -40,7 +40,7 @@ class EffectCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.effect"); $this->setPermission("pocketmine.command.effect");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -40,7 +40,7 @@ class EnchantCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.enchant"); $this->setPermission("pocketmine.command.enchant");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -42,7 +42,7 @@ class GamemodeCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.gamemode"); $this->setPermission("pocketmine.command.gamemode");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -37,7 +37,7 @@ class GarbageCollectorCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.gc"); $this->setPermission("pocketmine.command.gc");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -44,7 +44,7 @@ class GiveCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.give"); $this->setPermission("pocketmine.command.give");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -25,7 +25,6 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\ConsoleCommandSender;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -41,7 +40,7 @@ class HelpCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.help"); $this->setPermission("pocketmine.command.help");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -41,7 +41,7 @@ class KickCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.kick"); $this->setPermission("pocketmine.command.kick");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -43,7 +43,7 @@ class KillCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.kill.self;pocketmine.command.kill.other"); $this->setPermission("pocketmine.command.kill.self;pocketmine.command.kill.other");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -38,7 +38,7 @@ class ListCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.list"); $this->setPermission("pocketmine.command.list");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -40,7 +40,7 @@ class MeCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.me"); $this->setPermission("pocketmine.command.me");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -41,7 +41,7 @@ class OpCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.op.give"); $this->setPermission("pocketmine.command.op.give");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -39,7 +39,7 @@ class PardonCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.unban.player"); $this->setPermission("pocketmine.command.unban.player");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -39,7 +39,7 @@ class PardonIpCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.unban.ip"); $this->setPermission("pocketmine.command.unban.ip");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -72,7 +72,7 @@ class ParticleCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.particle"); $this->setPermission("pocketmine.command.particle");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -39,7 +39,7 @@ class PluginsCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.plugins"); $this->setPermission("pocketmine.command.plugins");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -39,7 +39,7 @@ class ReloadCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.reload"); $this->setPermission("pocketmine.command.reload");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -38,7 +38,7 @@ class SaveCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.save.perform"); $this->setPermission("pocketmine.command.save.perform");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -38,7 +38,7 @@ class SaveOffCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.save.disable"); $this->setPermission("pocketmine.command.save.disable");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -38,7 +38,7 @@ class SaveOnCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.save.enable"); $this->setPermission("pocketmine.command.save.enable");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -41,7 +41,7 @@ class SayCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.say"); $this->setPermission("pocketmine.command.say");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -38,7 +38,7 @@ class SeedCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.seed"); $this->setPermission("pocketmine.command.seed");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -42,7 +42,7 @@ class SetWorldSpawnCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.setworldspawn"); $this->setPermission("pocketmine.command.setworldspawn");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -43,7 +43,7 @@ class SpawnpointCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.spawnpoint"); $this->setPermission("pocketmine.command.spawnpoint");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -38,7 +38,7 @@ class StatusCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.status"); $this->setPermission("pocketmine.command.status");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -38,7 +38,7 @@ class StopCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.stop"); $this->setPermission("pocketmine.command.stop");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -42,7 +42,7 @@ class TeleportCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.teleport"); $this->setPermission("pocketmine.command.teleport");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -41,7 +41,7 @@ class TellCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.tell"); $this->setPermission("pocketmine.command.tell");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -42,7 +42,7 @@ class TimeCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.time.add;pocketmine.command.time.set;pocketmine.command.time.start;pocketmine.command.time.stop"); $this->setPermission("pocketmine.command.time.add;pocketmine.command.time.set;pocketmine.command.time.start;pocketmine.command.time.stop");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(count($args) < 1){ if(count($args) < 1){
throw new InvalidCommandSyntaxException(); throw new InvalidCommandSyntaxException();
} }

View File

@ -44,7 +44,7 @@ class TimingsCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.timings"); $this->setPermission("pocketmine.command.timings");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -38,7 +38,7 @@ class TitleCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.title"); $this->setPermission("pocketmine.command.title");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -40,7 +40,7 @@ class TransferServerCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.transferserver"); $this->setPermission("pocketmine.command.transferserver");
} }
public function execute(CommandSender $sender, $commandLabel, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(count($args) < 1){ if(count($args) < 1){
throw new InvalidCommandSyntaxException(); throw new InvalidCommandSyntaxException();
}elseif(!($sender instanceof Player)){ }elseif(!($sender instanceof Player)){

View File

@ -41,7 +41,7 @@ class VersionCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.version"); $this->setPermission("pocketmine.command.version");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -40,7 +40,7 @@ class WhitelistCommand extends VanillaCommand{
$this->setPermission("pocketmine.command.whitelist.reload;pocketmine.command.whitelist.enable;pocketmine.command.whitelist.disable;pocketmine.command.whitelist.list;pocketmine.command.whitelist.add;pocketmine.command.whitelist.remove"); $this->setPermission("pocketmine.command.whitelist.reload;pocketmine.command.whitelist.enable;pocketmine.command.whitelist.disable;pocketmine.command.whitelist.list;pocketmine.command.whitelist.add;pocketmine.command.whitelist.remove");
} }
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace pocketmine\entity; namespace pocketmine\entity;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\Liquid;
use pocketmine\event\entity\EntityBlockChangeEvent; use pocketmine\event\entity\EntityBlockChangeEvent;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item as ItemItem; use pocketmine\item\Item as ItemItem;

View File

@ -99,7 +99,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
/** /**
* @return string * @return string
*/ */
public function getRawUniqueId(){ public function getRawUniqueId() : string{
return $this->rawUUID; return $this->rawUUID;
} }
@ -431,7 +431,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
return $this->getNameTag(); return $this->getNameTag();
} }
public function getDrops(){ public function getDrops() : array{
return $this->inventory !== null ? array_values($this->inventory->getContents()) : []; return $this->inventory !== null ? array_values($this->inventory->getContents()) : [];
} }

View File

@ -33,7 +33,6 @@ use pocketmine\event\Timings;
use pocketmine\item\Item as ItemItem; use pocketmine\item\Item as ItemItem;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\nbt\tag\FloatTag; use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\utils\BlockIterator; use pocketmine\utils\BlockIterator;
@ -275,7 +274,7 @@ abstract class Living extends Entity implements Damageable{
/** /**
* @return ItemItem[] * @return ItemItem[]
*/ */
public function getDrops(){ public function getDrops() : array{
return []; return [];
} }

View File

@ -164,7 +164,7 @@ class Squid extends WaterAnimal{
parent::spawnTo($player); parent::spawnTo($player);
} }
public function getDrops(){ public function getDrops() : array{
return [ return [
ItemItem::get(ItemItem::DYE, 0, mt_rand(1, 3)) ItemItem::get(ItemItem::DYE, 0, mt_rand(1, 3))
]; ];

View File

@ -57,7 +57,7 @@ class Zombie extends Monster{
parent::spawnTo($player); parent::spawnTo($player);
} }
public function getDrops(){ public function getDrops() : array{
$drops = [ $drops = [
ItemItem::get(ItemItem::FEATHER, 0, 1) ItemItem::get(ItemItem::FEATHER, 0, 1)
]; ];

View File

@ -31,7 +31,7 @@ interface Cancellable{
/** /**
* @return bool * @return bool
*/ */
public function isCancelled(); public function isCancelled() : bool;
/** /**
* @param bool $value * @param bool $value

View File

@ -176,7 +176,7 @@ abstract class Timings{
* *
* @return TimingsHandler * @return TimingsHandler
*/ */
public static function getPluginTaskTimings(TaskHandler $task, int $period){ public static function getPluginTaskTimings(TaskHandler $task, int $period) : TimingsHandler{
$ftask = $task->getTask(); $ftask = $task->getTask();
if($ftask instanceof PluginTask and $ftask->getOwner() !== null){ if($ftask instanceof PluginTask and $ftask->getOwner() !== null){
$plugin = $ftask->getOwner()->getDescription()->getFullName(); $plugin = $ftask->getOwner()->getDescription()->getFullName();
@ -208,7 +208,7 @@ abstract class Timings{
* *
* @return TimingsHandler * @return TimingsHandler
*/ */
public static function getEntityTimings(Entity $entity){ public static function getEntityTimings(Entity $entity) : TimingsHandler{
$entityType = (new \ReflectionClass($entity))->getShortName(); $entityType = (new \ReflectionClass($entity))->getShortName();
if(!isset(self::$entityTypeTimingMap[$entityType])){ if(!isset(self::$entityTypeTimingMap[$entityType])){
if($entity instanceof Player){ if($entity instanceof Player){
@ -226,7 +226,7 @@ abstract class Timings{
* *
* @return TimingsHandler * @return TimingsHandler
*/ */
public static function getTileEntityTimings(Tile $tile){ public static function getTileEntityTimings(Tile $tile) : TimingsHandler{
$tileType = (new \ReflectionClass($tile))->getShortName(); $tileType = (new \ReflectionClass($tile))->getShortName();
if(!isset(self::$tileEntityTypeTimingMap[$tileType])){ if(!isset(self::$tileEntityTypeTimingMap[$tileType])){
self::$tileEntityTypeTimingMap[$tileType] = new TimingsHandler("** tickTileEntity - " . $tileType, self::$tickTileEntityTimer); self::$tileEntityTypeTimingMap[$tileType] = new TimingsHandler("** tickTileEntity - " . $tileType, self::$tickTileEntityTimer);
@ -240,7 +240,7 @@ abstract class Timings{
* *
* @return TimingsHandler * @return TimingsHandler
*/ */
public static function getReceiveDataPacketTimings(DataPacket $pk){ public static function getReceiveDataPacketTimings(DataPacket $pk) : TimingsHandler{
if(!isset(self::$packetReceiveTimingMap[$pk::NETWORK_ID])){ if(!isset(self::$packetReceiveTimingMap[$pk::NETWORK_ID])){
$pkName = (new \ReflectionClass($pk))->getShortName(); $pkName = (new \ReflectionClass($pk))->getShortName();
self::$packetReceiveTimingMap[$pk::NETWORK_ID] = new TimingsHandler("** receivePacket - " . $pkName . " [0x" . dechex($pk::NETWORK_ID) . "]", self::$playerNetworkReceiveTimer); self::$packetReceiveTimingMap[$pk::NETWORK_ID] = new TimingsHandler("** receivePacket - " . $pkName . " [0x" . dechex($pk::NETWORK_ID) . "]", self::$playerNetworkReceiveTimer);
@ -255,7 +255,7 @@ abstract class Timings{
* *
* @return TimingsHandler * @return TimingsHandler
*/ */
public static function getSendDataPacketTimings(DataPacket $pk){ public static function getSendDataPacketTimings(DataPacket $pk) : TimingsHandler{
if(!isset(self::$packetSendTimingMap[$pk::NETWORK_ID])){ if(!isset(self::$packetSendTimingMap[$pk::NETWORK_ID])){
$pkName = (new \ReflectionClass($pk))->getShortName(); $pkName = (new \ReflectionClass($pk))->getShortName();
self::$packetSendTimingMap[$pk::NETWORK_ID] = new TimingsHandler("** sendPacket - " . $pkName . " [0x" . dechex($pk::NETWORK_ID) . "]", self::$playerNetworkTimer); self::$packetSendTimingMap[$pk::NETWORK_ID] = new TimingsHandler("** sendPacket - " . $pkName . " [0x" . dechex($pk::NETWORK_ID) . "]", self::$playerNetworkTimer);

View File

@ -23,8 +23,6 @@ declare(strict_types=1);
namespace pocketmine\event\block; namespace pocketmine\event\block;
use pocketmine\block\Block;
class BlockFormEvent extends BlockGrowEvent{ class BlockFormEvent extends BlockGrowEvent{
public static $handlerList = null; public static $handlerList = null;

View File

@ -23,10 +23,6 @@ declare(strict_types=1);
namespace pocketmine\event\player; namespace pocketmine\event\player;
use pocketmine\block\Block;
use pocketmine\item\Item;
use pocketmine\Player;
class PlayerBucketFillEvent extends PlayerBucketEvent{ class PlayerBucketFillEvent extends PlayerBucketEvent{
public static $handlerList = null; public static $handlerList = null;
} }

View File

@ -26,7 +26,6 @@ namespace pocketmine\event\player;
use pocketmine\entity\Human; use pocketmine\entity\Human;
use pocketmine\event\Cancellable; use pocketmine\event\Cancellable;
use pocketmine\event\entity\EntityEvent; use pocketmine\event\entity\EntityEvent;
use pocketmine\Player;
class PlayerExhaustEvent extends EntityEvent implements Cancellable{ class PlayerExhaustEvent extends EntityEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;

View File

@ -84,32 +84,32 @@ abstract class BaseInventory implements Inventory{
$this->slots = []; $this->slots = [];
} }
public function getSize(){ public function getSize() : int{
return $this->size; return $this->size;
} }
public function setSize($size){ public function setSize(int $size){
$this->size = (int) $size; $this->size = $size;
} }
public function getMaxStackSize(){ public function getMaxStackSize() : int{
return $this->maxStackSize; return $this->maxStackSize;
} }
public function getName(){ public function getName() : string{
return $this->name; return $this->name;
} }
public function getTitle(){ public function getTitle() : string{
return $this->title; return $this->title;
} }
public function getItem($index){ public function getItem(int $index) : Item{
assert($index >= 0, "Inventory slot should not be negative"); assert($index >= 0, "Inventory slot should not be negative");
return isset($this->slots[$index]) ? clone $this->slots[$index] : Item::get(Item::AIR, 0, 0); return isset($this->slots[$index]) ? clone $this->slots[$index] : Item::get(Item::AIR, 0, 0);
} }
public function getContents(){ public function getContents() : array{
return $this->slots; return $this->slots;
} }
@ -134,7 +134,7 @@ abstract class BaseInventory implements Inventory{
} }
} }
public function setItem($index, Item $item){ public function setItem(int $index, Item $item) : bool{
$item = clone $item; $item = clone $item;
if($index < 0 or $index >= $this->size){ if($index < 0 or $index >= $this->size){
return false; return false;
@ -159,7 +159,7 @@ abstract class BaseInventory implements Inventory{
return true; return true;
} }
public function contains(Item $item){ public function contains(Item $item) : bool{
$count = max(1, $item->getCount()); $count = max(1, $item->getCount());
$checkDamage = !$item->hasAnyDamageValue(); $checkDamage = !$item->hasAnyDamageValue();
$checkTags = $item->hasCompoundTag(); $checkTags = $item->hasCompoundTag();
@ -175,7 +175,7 @@ abstract class BaseInventory implements Inventory{
return false; return false;
} }
public function all(Item $item){ public function all(Item $item) : array{
$slots = []; $slots = [];
$checkDamage = !$item->hasAnyDamageValue(); $checkDamage = !$item->hasAnyDamageValue();
$checkTags = $item->hasCompoundTag(); $checkTags = $item->hasCompoundTag();
@ -199,7 +199,7 @@ abstract class BaseInventory implements Inventory{
} }
} }
public function first(Item $item){ public function first(Item $item) : int{
$count = max(1, $item->getCount()); $count = max(1, $item->getCount());
$checkDamage = !$item->hasAnyDamageValue(); $checkDamage = !$item->hasAnyDamageValue();
$checkTags = $item->hasCompoundTag(); $checkTags = $item->hasCompoundTag();
@ -213,7 +213,7 @@ abstract class BaseInventory implements Inventory{
return -1; return -1;
} }
public function firstEmpty(){ public function firstEmpty() : int{
for($i = 0; $i < $this->size; ++$i){ for($i = 0; $i < $this->size; ++$i){
if($this->getItem($i)->getId() === Item::AIR){ if($this->getItem($i)->getId() === Item::AIR){
return $i; return $i;
@ -223,7 +223,7 @@ abstract class BaseInventory implements Inventory{
return -1; return -1;
} }
public function canAddItem(Item $item){ public function canAddItem(Item $item) : bool{
$item = clone $item; $item = clone $item;
$checkDamage = !$item->hasAnyDamageValue(); $checkDamage = !$item->hasAnyDamageValue();
$checkTags = $item->hasCompoundTag(); $checkTags = $item->hasCompoundTag();
@ -245,7 +245,7 @@ abstract class BaseInventory implements Inventory{
return false; return false;
} }
public function addItem(Item ...$slots){ public function addItem(Item ...$slots) : array{
/** @var Item[] $itemSlots */ /** @var Item[] $itemSlots */
/** @var Item[] $slots */ /** @var Item[] $slots */
$itemSlots = []; $itemSlots = [];
@ -302,7 +302,7 @@ abstract class BaseInventory implements Inventory{
return $itemSlots; return $itemSlots;
} }
public function removeItem(Item ...$slots){ public function removeItem(Item ...$slots) : array{
/** @var Item[] $itemSlots */ /** @var Item[] $itemSlots */
/** @var Item[] $slots */ /** @var Item[] $slots */
$itemSlots = []; $itemSlots = [];
@ -338,7 +338,7 @@ abstract class BaseInventory implements Inventory{
return $itemSlots; return $itemSlots;
} }
public function clear($index){ public function clear(int $index) : bool{
if(isset($this->slots[$index])){ if(isset($this->slots[$index])){
$item = Item::get(Item::AIR, 0, 0); $item = Item::get(Item::AIR, 0, 0);
$old = $this->slots[$index]; $old = $this->slots[$index];
@ -372,7 +372,7 @@ abstract class BaseInventory implements Inventory{
/** /**
* @return Player[] * @return Player[]
*/ */
public function getViewers(){ public function getViewers() : array{
return $this->viewers; return $this->viewers;
} }
@ -380,11 +380,11 @@ abstract class BaseInventory implements Inventory{
return $this->holder; return $this->holder;
} }
public function setMaxStackSize($size){ public function setMaxStackSize(int $size){
$this->maxStackSize = (int) $size; $this->maxStackSize = $size;
} }
public function open(Player $who){ public function open(Player $who) : bool{
$who->getServer()->getPluginManager()->callEvent($ev = new InventoryOpenEvent($this, $who)); $who->getServer()->getPluginManager()->callEvent($ev = new InventoryOpenEvent($this, $who));
if($ev->isCancelled()){ if($ev->isCancelled()){
return false; return false;
@ -459,7 +459,7 @@ abstract class BaseInventory implements Inventory{
} }
} }
public function getType(){ public function getType() : InventoryType{
return $this->type; return $this->type;
} }

View File

@ -43,31 +43,31 @@ class BaseTransaction implements Transaction{
* @param Item $sourceItem * @param Item $sourceItem
* @param Item $targetItem * @param Item $targetItem
*/ */
public function __construct(Inventory $inventory, $slot, Item $sourceItem, Item $targetItem){ public function __construct(Inventory $inventory, int $slot, Item $sourceItem, Item $targetItem){
$this->inventory = $inventory; $this->inventory = $inventory;
$this->slot = (int) $slot; $this->slot = $slot;
$this->sourceItem = clone $sourceItem; $this->sourceItem = clone $sourceItem;
$this->targetItem = clone $targetItem; $this->targetItem = clone $targetItem;
$this->creationTime = microtime(true); $this->creationTime = microtime(true);
} }
public function getCreationTime(){ public function getCreationTime() : float{
return $this->creationTime; return $this->creationTime;
} }
public function getInventory(){ public function getInventory() : Inventory{
return $this->inventory; return $this->inventory;
} }
public function getSlot(){ public function getSlot() : int{
return $this->slot; return $this->slot;
} }
public function getSourceItem(){ public function getSourceItem() : Item{
return clone $this->sourceItem; return clone $this->sourceItem;
} }
public function getTargetItem(){ public function getTargetItem() : Item{
return clone $this->targetItem; return clone $this->targetItem;
} }
} }

View File

@ -56,7 +56,7 @@ class CraftingInventory extends BaseInventory{
return $this->resultInventory; return $this->resultInventory;
} }
public function getSize(){ public function getSize() : int{
return $this->getResultInventory()->getSize() + parent::getSize(); return $this->getResultInventory()->getSize() + parent::getSize();
} }
} }

View File

@ -160,14 +160,14 @@ class CraftingManager{
/** /**
* @return Recipe[] * @return Recipe[]
*/ */
public function getRecipes(){ public function getRecipes() : array{
return $this->recipes; return $this->recipes;
} }
/** /**
* @return FurnaceRecipe[] * @return FurnaceRecipe[]
*/ */
public function getFurnaceRecipes(){ public function getFurnaceRecipes() : array{
return $this->furnaceRecipes; return $this->furnaceRecipes;
} }
@ -238,7 +238,7 @@ class CraftingManager{
* @param ShapelessRecipe $recipe * @param ShapelessRecipe $recipe
* @return bool * @return bool
*/ */
public function matchRecipe(ShapelessRecipe $recipe){ public function matchRecipe(ShapelessRecipe $recipe) : bool{
if(!isset($this->recipeLookup[$idx = $recipe->getResult()->getId() . ":" . $recipe->getResult()->getDamage()])){ if(!isset($this->recipeLookup[$idx = $recipe->getResult()->getId() . ":" . $recipe->getResult()->getDamage()])){
return false; return false;
} }

View File

@ -50,19 +50,19 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
return $this->left->getHolder(); return $this->left->getHolder();
} }
public function getItem($index){ public function getItem(int $index) : Item{
return $index < $this->left->getSize() ? $this->left->getItem($index) : $this->right->getItem($index - $this->right->getSize()); return $index < $this->left->getSize() ? $this->left->getItem($index) : $this->right->getItem($index - $this->right->getSize());
} }
public function setItem($index, Item $item){ public function setItem(int $index, Item $item) : bool{
return $index < $this->left->getSize() ? $this->left->setItem($index, $item) : $this->right->setItem($index - $this->right->getSize(), $item); return $index < $this->left->getSize() ? $this->left->setItem($index, $item) : $this->right->setItem($index - $this->right->getSize(), $item);
} }
public function clear($index){ public function clear(int $index) : bool{
return $index < $this->left->getSize() ? $this->left->clear($index) : $this->right->clear($index - $this->right->getSize()); return $index < $this->left->getSize() ? $this->left->clear($index) : $this->right->clear($index - $this->right->getSize());
} }
public function getContents(){ public function getContents() : array{
$contents = []; $contents = [];
for($i = 0; $i < $this->getSize(); ++$i){ for($i = 0; $i < $this->getSize(); ++$i){
$contents[$i] = $this->getItem($i); $contents[$i] = $this->getItem($i);
@ -129,14 +129,14 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
/** /**
* @return ChestInventory * @return ChestInventory
*/ */
public function getLeftSide(){ public function getLeftSide() : ChestInventory{
return $this->left; return $this->left;
} }
/** /**
* @return ChestInventory * @return ChestInventory
*/ */
public function getRightSide(){ public function getRightSide() : ChestInventory{
return $this->right; return $this->right;
} }
} }

View File

@ -41,21 +41,21 @@ class FurnaceInventory extends ContainerInventory{
/** /**
* @return Item * @return Item
*/ */
public function getResult(){ public function getResult() : Item{
return $this->getItem(2); return $this->getItem(2);
} }
/** /**
* @return Item * @return Item
*/ */
public function getFuel(){ public function getFuel() : Item{
return $this->getItem(1); return $this->getItem(1);
} }
/** /**
* @return Item * @return Item
*/ */
public function getSmelting(){ public function getSmelting() : Item{
return $this->getItem(0); return $this->getItem(0);
} }
@ -64,7 +64,7 @@ class FurnaceInventory extends ContainerInventory{
* *
* @return bool * @return bool
*/ */
public function setResult(Item $item){ public function setResult(Item $item) : bool{
return $this->setItem(2, $item); return $this->setItem(2, $item);
} }
@ -73,7 +73,7 @@ class FurnaceInventory extends ContainerInventory{
* *
* @return bool * @return bool
*/ */
public function setFuel(Item $item){ public function setFuel(Item $item) : bool{
return $this->setItem(1, $item); return $this->setItem(1, $item);
} }
@ -82,7 +82,7 @@ class FurnaceInventory extends ContainerInventory{
* *
* @return bool * @return bool
*/ */
public function setSmelting(Item $item){ public function setSmelting(Item $item) : bool{
return $this->setItem(0, $item); return $this->setItem(0, $item);
} }

View File

@ -29,6 +29,7 @@ use pocketmine\utils\UUID;
class FurnaceRecipe implements Recipe{ class FurnaceRecipe implements Recipe{
/** @var UUID|null */
private $id = null; private $id = null;
/** @var Item */ /** @var Item */
@ -46,10 +47,16 @@ class FurnaceRecipe implements Recipe{
$this->ingredient = clone $ingredient; $this->ingredient = clone $ingredient;
} }
/**
* @return UUID|null
*/
public function getId(){ public function getId(){
return $this->id; return $this->id;
} }
/**
* @param UUID $id
*/
public function setId(UUID $id){ public function setId(UUID $id){
if($this->id !== null){ if($this->id !== null){
throw new \InvalidStateException("Id is already set"); throw new \InvalidStateException("Id is already set");
@ -68,14 +75,14 @@ class FurnaceRecipe implements Recipe{
/** /**
* @return Item * @return Item
*/ */
public function getInput(){ public function getInput() : Item{
return clone $this->ingredient; return clone $this->ingredient;
} }
/** /**
* @return Item * @return Item
*/ */
public function getResult(){ public function getResult() : Item{
return clone $this->output; return clone $this->output;
} }

View File

@ -32,37 +32,48 @@ use pocketmine\Player;
interface Inventory{ interface Inventory{
const MAX_STACK = 64; const MAX_STACK = 64;
public function getSize(); /**
* @return int
*/
public function getSize() : int;
public function getMaxStackSize(); /**
* @return int
*/
public function getMaxStackSize() : int;
/** /**
* @param int $size * @param int $size
*/ */
public function setMaxStackSize($size); public function setMaxStackSize(int $size);
public function getName(); /**
* @return string
*/
public function getName() : string;
public function getTitle(); /**
* @return string
*/
public function getTitle() : string;
/** /**
* @param int $index * @param int $index
* *
* @return Item * @return Item
*/ */
public function getItem($index); public function getItem(int $index) : Item;
/** /**
* Puts an Item in a slot. * Puts an Item in a slot.
* If a plugin refuses the update or $index is invalid, it'll return false * If a plugin refuses the update or $index is invalid, it'll return false
* If a source Player is specified, it won't send a Inventory update to it
* *
* @param int $index * @param int $index
* @param Item $item * @param Item $item
* *
* @return bool * @return bool
*/ */
public function setItem($index, Item $item); public function setItem(int $index, Item $item) : bool;
/** /**
* Stores the given Items in the inventory. This will try to fill * Stores the given Items in the inventory. This will try to fill
@ -74,7 +85,7 @@ interface Inventory{
* *
* @return Item[] * @return Item[]
*/ */
public function addItem(Item ...$slots); public function addItem(Item ...$slots) : array;
/** /**
* Checks if a given Item can be added to the inventory * Checks if a given Item can be added to the inventory
@ -83,7 +94,7 @@ interface Inventory{
* *
* @return bool * @return bool
*/ */
public function canAddItem(Item $item); public function canAddItem(Item $item) : bool;
/** /**
* Removes the given Item from the inventory. * Removes the given Item from the inventory.
@ -93,12 +104,12 @@ interface Inventory{
* *
* @return Item[] * @return Item[]
*/ */
public function removeItem(Item ...$slots); public function removeItem(Item ...$slots) : array;
/** /**
* @return Item[] * @return Item[]
*/ */
public function getContents(); public function getContents() : array;
/** /**
* @param Item[] $items * @param Item[] $items
@ -124,7 +135,7 @@ interface Inventory{
* *
* @return bool * @return bool
*/ */
public function contains(Item $item); public function contains(Item $item) : bool;
/** /**
* Will return all the Items that has the same id and metadata (if not null). * Will return all the Items that has the same id and metadata (if not null).
@ -134,7 +145,7 @@ interface Inventory{
* *
* @return Item[] * @return Item[]
*/ */
public function all(Item $item); public function all(Item $item) : array;
/** /**
* Will return the first slot has the same id and metadata (if not null) as the Item. * Will return the first slot has the same id and metadata (if not null) as the Item.
@ -144,14 +155,14 @@ interface Inventory{
* *
* @return int * @return int
*/ */
public function first(Item $item); public function first(Item $item) : int;
/** /**
* Returns the first empty slot, or -1 if not found * Returns the first empty slot, or -1 if not found
* *
* @return int * @return int
*/ */
public function firstEmpty(); public function firstEmpty() : int;
/** /**
* Will remove all the Items that has the same id and metadata (if not null) * Will remove all the Items that has the same id and metadata (if not null)
@ -167,7 +178,7 @@ interface Inventory{
* *
* @return bool * @return bool
*/ */
public function clear($index); public function clear(int $index) : bool;
/** /**
* Clears all the slots * Clears all the slots
@ -180,12 +191,12 @@ interface Inventory{
* *
* @return Player[] * @return Player[]
*/ */
public function getViewers(); public function getViewers() : array;
/** /**
* @return InventoryType * @return InventoryType
*/ */
public function getType(); public function getType() : InventoryType;
/** /**
* @return InventoryHolder * @return InventoryHolder
@ -204,7 +215,7 @@ interface Inventory{
* *
* @return bool * @return bool
*/ */
public function open(Player $who); public function open(Player $who) : bool;
public function close(Player $who); public function close(Player $who);

View File

@ -91,21 +91,21 @@ class InventoryType{
/** /**
* @return int * @return int
*/ */
public function getDefaultSize(){ public function getDefaultSize() : int{
return $this->size; return $this->size;
} }
/** /**
* @return string * @return string
*/ */
public function getDefaultTitle(){ public function getDefaultTitle() : string{
return $this->title; return $this->title;
} }
/** /**
* @return int * @return int
*/ */
public function getNetworkType(){ public function getNetworkType() : int{
return $this->typeId; return $this->typeId;
} }
} }

View File

@ -47,11 +47,11 @@ class PlayerInventory extends BaseInventory{
parent::__construct($player, InventoryType::get(InventoryType::PLAYER)); parent::__construct($player, InventoryType::get(InventoryType::PLAYER));
} }
public function getSize(){ public function getSize() : int{
return parent::getSize() - 4; //Remove armor slots return parent::getSize() - 4; //Remove armor slots
} }
public function setSize($size){ public function setSize(int $size){
parent::setSize($size + 4); parent::setSize($size + 4);
$this->sendContents($this->getViewers()); $this->sendContents($this->getViewers());
} }
@ -316,7 +316,7 @@ class PlayerInventory extends BaseInventory{
return $this->setItem($this->getSize() + 3, $boots); return $this->setItem($this->getSize() + 3, $boots);
} }
public function setItem($index, Item $item){ public function setItem(int $index, Item $item) : bool{
if($index < 0 or $index >= $this->size){ if($index < 0 or $index >= $this->size){
return false; return false;
}elseif($item->getId() === 0 or $item->getCount() <= 0){ }elseif($item->getId() === 0 or $item->getCount() <= 0){
@ -347,7 +347,7 @@ class PlayerInventory extends BaseInventory{
return true; return true;
} }
public function clear($index){ public function clear(int $index) : bool{
if(isset($this->slots[$index])){ if(isset($this->slots[$index])){
$item = Item::get(Item::AIR, 0, 0); $item = Item::get(Item::AIR, 0, 0);
$old = $this->slots[$index]; $old = $this->slots[$index];

View File

@ -31,14 +31,17 @@ interface Recipe{
/** /**
* @return Item * @return Item
*/ */
public function getResult(); public function getResult() : Item;
public function registerToCraftingManager(); public function registerToCraftingManager();
/** /**
* @return UUID * @return UUID|null
*/ */
public function getId(); public function getId();
/**
* @param UUID $id
*/
public function setId(UUID $id); public function setId(UUID $id);
} }

View File

@ -32,6 +32,7 @@ class ShapedRecipe implements Recipe{
/** @var Item */ /** @var Item */
private $output; private $output;
/** @var UUID|null */
private $id = null; private $id = null;
/** @var string[] */ /** @var string[] */
@ -49,7 +50,7 @@ class ShapedRecipe implements Recipe{
* *
* @throws \Exception * @throws \Exception
*/ */
public function __construct(Item $result, $height, $width){ public function __construct(Item $result, int $height, int $width){
for($h = 0; $h < $height; $h++){ for($h = 0; $h < $height; $h++){
if($width === 0 or $width > 3){ if($width === 0 or $width > 3){
throw new \InvalidStateException("Crafting rows should be 1, 2, 3 wide, not $width"); throw new \InvalidStateException("Crafting rows should be 1, 2, 3 wide, not $width");
@ -60,18 +61,24 @@ class ShapedRecipe implements Recipe{
$this->output = clone $result; $this->output = clone $result;
} }
public function getWidth(){ public function getWidth() : int{
return count($this->ingredients[0]); return count($this->ingredients[0]);
} }
public function getHeight(){ public function getHeight() : int{
return count($this->ingredients); return count($this->ingredients);
} }
public function getResult(){ /**
* @return Item
*/
public function getResult() : Item{
return $this->output; return $this->output;
} }
/**
* @return UUID|null
*/
public function getId(){ public function getId(){
return $this->id; return $this->id;
} }
@ -84,7 +91,14 @@ class ShapedRecipe implements Recipe{
$this->id = $id; $this->id = $id;
} }
public function addIngredient($x, $y, Item $item){ /**
* @param int $x
* @param int $y
* @param Item $item
*
* @return $this
*/
public function addIngredient(int $x, int $y, Item $item){
$this->ingredients[$y][$x] = clone $item; $this->ingredients[$y][$x] = clone $item;
return $this; return $this;
} }
@ -96,7 +110,7 @@ class ShapedRecipe implements Recipe{
* @return $this * @return $this
* @throws \Exception * @throws \Exception
*/ */
public function setIngredient($key, Item $item){ public function setIngredient(string $key, Item $item){
if(!array_key_exists($key, $this->shape)){ if(!array_key_exists($key, $this->shape)){
throw new \Exception("Symbol does not appear in the shape: " . $key); throw new \Exception("Symbol does not appear in the shape: " . $key);
} }
@ -106,7 +120,11 @@ class ShapedRecipe implements Recipe{
return $this; return $this;
} }
protected function fixRecipe($key, $item){ /**
* @param string $key
* @param Item $item
*/
protected function fixRecipe(string $key, Item $item){
foreach($this->shapeItems[$key] as $entry){ foreach($this->shapeItems[$key] as $entry){
$this->ingredients[$entry->y][$entry->x] = clone $item; $this->ingredients[$entry->y][$entry->x] = clone $item;
} }
@ -115,7 +133,7 @@ class ShapedRecipe implements Recipe{
/** /**
* @return Item[][] * @return Item[][]
*/ */
public function getIngredientMap(){ public function getIngredientMap() : array{
$ingredients = []; $ingredients = [];
foreach($this->ingredients as $y => $row){ foreach($this->ingredients as $y => $row){
$ingredients[$y] = []; $ingredients[$y] = [];
@ -132,18 +150,19 @@ class ShapedRecipe implements Recipe{
} }
/** /**
* @param $x * @param int $x
* @param $y * @param int $y
* @return null|Item *
* @return Item
*/ */
public function getIngredient($x, $y){ public function getIngredient(int $x, int $y) : Item{
return $this->ingredients[$y][$x] ?? Item::get(Item::AIR); return $this->ingredients[$y][$x] ?? Item::get(Item::AIR);
} }
/** /**
* @return string[] * @return string[]
*/ */
public function getShape(){ public function getShape() : array{
return $this->shape; return $this->shape;
} }

View File

@ -31,6 +31,7 @@ class ShapelessRecipe implements Recipe{
/** @var Item */ /** @var Item */
private $output; private $output;
/** @var UUID|null */
private $id = null; private $id = null;
/** @var Item[] */ /** @var Item[] */
@ -40,10 +41,16 @@ class ShapelessRecipe implements Recipe{
$this->output = clone $result; $this->output = clone $result;
} }
/**
* @return UUID|null
*/
public function getId(){ public function getId(){
return $this->id; return $this->id;
} }
/**
* @param UUID $id
*/
public function setId(UUID $id){ public function setId(UUID $id){
if($this->id !== null){ if($this->id !== null){
throw new \InvalidStateException("Id is already set"); throw new \InvalidStateException("Id is already set");
@ -52,18 +59,18 @@ class ShapelessRecipe implements Recipe{
$this->id = $id; $this->id = $id;
} }
public function getResult(){ public function getResult() : Item{
return clone $this->output; return clone $this->output;
} }
/** /**
* @param Item $item * @param Item $item
* *
* @returns ShapelessRecipe * @return ShapelessRecipe
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function addIngredient(Item $item){ public function addIngredient(Item $item) : ShapelessRecipe{
if(count($this->ingredients) >= 9){ if(count($this->ingredients) >= 9){
throw new \InvalidArgumentException("Shapeless recipes cannot have more than 9 ingredients"); throw new \InvalidArgumentException("Shapeless recipes cannot have more than 9 ingredients");
} }
@ -101,7 +108,7 @@ class ShapelessRecipe implements Recipe{
/** /**
* @return Item[] * @return Item[]
*/ */
public function getIngredientList(){ public function getIngredientList() : array{
$ingredients = []; $ingredients = [];
foreach($this->ingredients as $ingredient){ foreach($this->ingredients as $ingredient){
$ingredients[] = clone $ingredient; $ingredients[] = clone $ingredient;
@ -113,7 +120,7 @@ class ShapelessRecipe implements Recipe{
/** /**
* @return int * @return int
*/ */
public function getIngredientCount(){ public function getIngredientCount() : int{
$count = 0; $count = 0;
foreach($this->ingredients as $ingredient){ foreach($this->ingredients as $ingredient){
$count += $ingredient->getCount(); $count += $ingredient->getCount();

View File

@ -54,19 +54,25 @@ class SimpleTransactionGroup implements TransactionGroup{
/** /**
* @return Player * @return Player
*/ */
public function getSource(){ public function getSource() : Player{
return $this->source; return $this->source;
} }
public function getCreationTime(){ public function getCreationTime() : float{
return $this->creationTime; return $this->creationTime;
} }
public function getInventories(){ /**
* @return Inventory[]
*/
public function getInventories() : array{
return $this->inventories; return $this->inventories;
} }
public function getTransactions(){ /**
* @return Transaction[]
*/
public function getTransactions() : array{
return $this->transactions; return $this->transactions;
} }
@ -93,7 +99,7 @@ class SimpleTransactionGroup implements TransactionGroup{
* *
* @return bool * @return bool
*/ */
protected function matchItems(array &$needItems, array &$haveItems){ protected function matchItems(array &$needItems, array &$haveItems) : bool{
foreach($this->transactions as $key => $ts){ foreach($this->transactions as $key => $ts){
if($ts->getTargetItem()->getId() !== Item::AIR){ if($ts->getTargetItem()->getId() !== Item::AIR){
$needItems[] = $ts->getTargetItem(); $needItems[] = $ts->getTargetItem();
@ -128,7 +134,7 @@ class SimpleTransactionGroup implements TransactionGroup{
return true; return true;
} }
public function canExecute(){ public function canExecute() : bool{
$haveItems = []; $haveItems = [];
$needItems = []; $needItems = [];
@ -149,7 +155,10 @@ class SimpleTransactionGroup implements TransactionGroup{
return false; return false;
} }
public function execute(){ /**
* @return bool
*/
public function execute() : bool{
if($this->hasExecuted() or !$this->canExecute()){ if($this->hasExecuted() or !$this->canExecute()){
return false; return false;
} }
@ -175,7 +184,7 @@ class SimpleTransactionGroup implements TransactionGroup{
return true; return true;
} }
public function hasExecuted(){ public function hasExecuted() : bool{
return $this->hasExecuted; return $this->hasExecuted;
} }
} }

View File

@ -30,25 +30,25 @@ interface Transaction{
/** /**
* @return Inventory * @return Inventory
*/ */
public function getInventory(); public function getInventory() : Inventory;
/** /**
* @return int * @return int
*/ */
public function getSlot(); public function getSlot() : int;
/** /**
* @return Item * @return Item
*/ */
public function getSourceItem(); public function getSourceItem() : Item;
/** /**
* @return Item * @return Item
*/ */
public function getTargetItem(); public function getTargetItem() : Item;
/** /**
* @return float * @return float
*/ */
public function getCreationTime(); public function getCreationTime() : float;
} }

View File

@ -28,17 +28,17 @@ interface TransactionGroup{
/** /**
* @return float * @return float
*/ */
public function getCreationTime(); public function getCreationTime() : float;
/** /**
* @return Transaction[] * @return Transaction[]
*/ */
public function getTransactions(); public function getTransactions() : array;
/** /**
* @return Inventory[] * @return Inventory[]
*/ */
public function getInventories(); public function getInventories() : array;
/** /**
* @param Transaction $transaction * @param Transaction $transaction
@ -48,16 +48,16 @@ interface TransactionGroup{
/** /**
* @return bool * @return bool
*/ */
public function canExecute(); public function canExecute() : bool;
/** /**
* @return bool * @return bool
*/ */
public function execute(); public function execute() : bool;
/** /**
* @return bool * @return bool
*/ */
public function hasExecuted(); public function hasExecuted() : bool;
} }

View File

@ -106,7 +106,7 @@ class BaseLang{
* *
* @return string * @return string
*/ */
public function translateString($str, array $params = [], $onlyPrefix = null){ public function translateString(string $str, array $params = [], string $onlyPrefix = null) : string{
$baseText = $this->get($str); $baseText = $this->get($str);
$baseText = $this->parseTranslation(($baseText !== null and ($onlyPrefix === null or strpos($str, $onlyPrefix) === 0)) ? $baseText : $str, $onlyPrefix); $baseText = $this->parseTranslation(($baseText !== null and ($onlyPrefix === null or strpos($str, $onlyPrefix) === 0)) ? $baseText : $str, $onlyPrefix);
@ -152,7 +152,13 @@ class BaseLang{
return $id; return $id;
} }
protected function parseTranslation($text, $onlyPrefix = null){ /**
* @param string $text
* @param string|null $onlyPrefix
*
* @return string
*/
protected function parseTranslation(string $text, string $onlyPrefix = null) : string{
$newString = ""; $newString = "";
$replaceString = null; $replaceString = null;

View File

@ -45,14 +45,14 @@ interface ChunkLoader{
* *
* @return int * @return int
*/ */
public function getLoaderId(); public function getLoaderId() : int;
/** /**
* Returns if the chunk loader is currently active * Returns if the chunk loader is currently active
* *
* @return bool * @return bool
*/ */
public function isLoaderActive(); public function isLoaderActive() : bool;
/** /**
* @return Position * @return Position

View File

@ -130,7 +130,7 @@ interface ChunkManager{
* *
* @return int * @return int
*/ */
public function getSeed(); public function getSeed() : int;
/** /**
* Returns the height of the world * Returns the height of the world

View File

@ -63,7 +63,7 @@ class Explosion{
/** /**
* @return bool * @return bool
*/ */
public function explodeA(){ public function explodeA() : bool{
if($this->size < 0.1){ if($this->size < 0.1){
return false; return false;
} }
@ -114,7 +114,7 @@ class Explosion{
return true; return true;
} }
public function explodeB(){ public function explodeB() : bool{
$send = []; $send = [];
$updateBlocks = []; $updateBlocks = [];

View File

@ -173,7 +173,7 @@ class Level implements ChunkManager, Metadatable{
/** @var Player[][] */ /** @var Player[][] */
private $playerLoaders = []; private $playerLoaders = [];
/** @var DataPacket[] */ /** @var DataPacket[][] */
private $chunkPackets = []; private $chunkPackets = [];
/** @var float[] */ /** @var float[] */
@ -292,7 +292,7 @@ class Level implements ChunkManager, Metadatable{
} }
public static function generateChunkLoaderId(ChunkLoader $loader) : int{ public static function generateChunkLoaderId(ChunkLoader $loader) : int{
if($loader->getLoaderId() === 0 or $loader->getLoaderId() === null){ if($loader->getLoaderId() === 0){
return self::$chunkLoaderCounter++; return self::$chunkLoaderCounter++;
}else{ }else{
throw new \InvalidStateException("ChunkLoader has a loader id already assigned: " . $loader->getLoaderId()); throw new \InvalidStateException("ChunkLoader has a loader id already assigned: " . $loader->getLoaderId());
@ -2774,9 +2774,9 @@ class Level implements ChunkManager, Metadatable{
/** /**
* Gets the level seed * Gets the level seed
* *
* @return int|string int value of seed, or the string numeric representation of a long in 32-bit systems * @return int
*/ */
public function getSeed(){ public function getSeed() : int{
return $this->provider->getSeed(); return $this->provider->getSeed();
} }

View File

@ -55,7 +55,7 @@ class Location extends Position{
* *
* @return Location * @return Location
*/ */
public static function fromObject(Vector3 $pos, Level $level = null, $yaw = 0.0, $pitch = 0.0){ public static function fromObject(Vector3 $pos, Level $level = null, $yaw = 0.0, $pitch = 0.0) : Location{
return new Location($pos->x, $pos->y, $pos->z, $yaw, $pitch, $level ?? (($pos instanceof Position) ? $pos->level : null)); return new Location($pos->x, $pos->y, $pos->z, $yaw, $pitch, $level ?? (($pos instanceof Position) ? $pos->level : null));
} }
@ -80,7 +80,7 @@ class Location extends Position{
return "Location (level=" . ($this->isValid() ? $this->getLevel()->getName() : "null") . ", x=$this->x, y=$this->y, z=$this->z, yaw=$this->yaw, pitch=$this->pitch)"; return "Location (level=" . ($this->isValid() ? $this->getLevel()->getName() : "null") . ", x=$this->x, y=$this->y, z=$this->z, yaw=$this->yaw, pitch=$this->pitch)";
} }
public function equals(Vector3 $v){ public function equals(Vector3 $v) : bool{
if($v instanceof Location){ if($v instanceof Location){
return parent::equals($v) and $v->yaw == $this->yaw and $v->pitch == $this->pitch; return parent::equals($v) and $v->yaw == $this->yaw and $v->pitch == $this->pitch;
} }

View File

@ -60,7 +60,7 @@ class MovingObjectPosition{
* *
* @return MovingObjectPosition * @return MovingObjectPosition
*/ */
public static function fromBlock($x, $y, $z, $side, Vector3 $hitVector){ public static function fromBlock(int $x, int $y, int $z, int $side, Vector3 $hitVector) : MovingObjectPosition{
$ob = new MovingObjectPosition; $ob = new MovingObjectPosition;
$ob->typeOfHit = 0; $ob->typeOfHit = 0;
$ob->blockX = $x; $ob->blockX = $x;
@ -75,7 +75,7 @@ class MovingObjectPosition{
* *
* @return MovingObjectPosition * @return MovingObjectPosition
*/ */
public static function fromEntity(Entity $entity){ public static function fromEntity(Entity $entity) : MovingObjectPosition{
$ob = new MovingObjectPosition; $ob = new MovingObjectPosition;
$ob->typeOfHit = 1; $ob->typeOfHit = 1;
$ob->entityHit = $entity; $ob->entityHit = $entity;

View File

@ -95,7 +95,7 @@ class Position extends Vector3{
* *
* @return bool * @return bool
*/ */
public function isValid(){ public function isValid() : bool{
return $this->getLevel() instanceof Level; return $this->getLevel() instanceof Level;
} }
@ -133,7 +133,7 @@ class Position extends Vector3{
return $this; return $this;
} }
public function equals(Vector3 $v){ public function equals(Vector3 $v) : bool{
if($v instanceof Position){ if($v instanceof Position){
return parent::equals($v) and $v->getLevel() === $this->getLevel(); return parent::equals($v) and $v->getLevel() === $this->getLevel();
} }

View File

@ -164,7 +164,7 @@ class SimpleChunkManager implements ChunkManager{
* *
* @return int * @return int
*/ */
public function getSeed(){ public function getSeed() : int{
return $this->seed; return $this->seed;
} }

View File

@ -28,7 +28,6 @@ namespace pocketmine\level\format;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\level\format\ChunkException;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
@ -989,7 +988,7 @@ class Chunk{
* *
* @return Chunk * @return Chunk
*/ */
public static function fastDeserialize(string $data){ public static function fastDeserialize(string $data) : Chunk{
$stream = new BinaryStream(); $stream = new BinaryStream();
$stream->setBuffer($data); $stream->setBuffer($data);
$data = null; $data = null;

View File

@ -76,7 +76,7 @@ abstract class BaseLevelProvider implements LevelProvider{
return $this->level->getServer(); return $this->level->getServer();
} }
public function getLevel(){ public function getLevel() : Level{
return $this->level; return $this->level;
} }

View File

@ -174,7 +174,7 @@ interface LevelProvider{
/** /**
* @return string * @return string
*/ */
public function getName(); public function getName() : string;
/** /**
* @return int|string int, or the string numeric representation of a long in 32-bit systems * @return int|string int, or the string numeric representation of a long in 32-bit systems
@ -216,7 +216,7 @@ interface LevelProvider{
/** /**
* @return Level * @return Level
*/ */
public function getLevel(); public function getLevel() : Level;
public function close(); public function close();

View File

@ -25,7 +25,6 @@ namespace pocketmine\level\format\io\leveldb;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\level\format\Chunk; use pocketmine\level\format\Chunk;
use pocketmine\level\format\ChunkException;
use pocketmine\level\format\io\BaseLevelProvider; use pocketmine\level\format\io\BaseLevelProvider;
use pocketmine\level\format\io\ChunkUtils; use pocketmine\level\format\io\ChunkUtils;
use pocketmine\level\format\io\exception\UnsupportedChunkFormatException; use pocketmine\level\format\io\exception\UnsupportedChunkFormatException;
@ -576,7 +575,7 @@ class LevelDB extends BaseLevelProvider{
/** /**
* @return \LevelDB * @return \LevelDB
*/ */
public function getDatabase(){ public function getDatabase() : \LevelDB{
return $this->db; return $this->db;
} }

View File

@ -422,7 +422,7 @@ class McRegion extends BaseLevelProvider{
* *
* @return Chunk * @return Chunk
*/ */
public function getEmptyChunk(int $chunkX, int $chunkZ){ public function getEmptyChunk(int $chunkX, int $chunkZ) : Chunk{
return Chunk::getEmptyChunk($chunkX, $chunkZ); return Chunk::getEmptyChunk($chunkX, $chunkZ);
} }

View File

@ -50,11 +50,11 @@ class Flat extends Generator{
private $populators = []; private $populators = [];
private $structure, $chunks, $options, $floorLevel, $preset; private $structure, $chunks, $options, $floorLevel, $preset;
public function getSettings(){ public function getSettings() : array{
return $this->options; return $this->options;
} }
public function getName(){ public function getName() : string{
return "flat"; return "flat";
} }
@ -155,7 +155,7 @@ class Flat extends Generator{
*/ */
} }
public function generateChunk($chunkX, $chunkZ){ public function generateChunk(int $chunkX, int $chunkZ){
if($this->chunk === null){ if($this->chunk === null){
if(isset($this->options["preset"]) and $this->options["preset"] != ""){ if(isset($this->options["preset"]) and $this->options["preset"] != ""){
$this->parsePreset($this->options["preset"], $chunkX, $chunkZ); $this->parsePreset($this->options["preset"], $chunkX, $chunkZ);
@ -169,7 +169,7 @@ class Flat extends Generator{
$this->level->setChunk($chunkX, $chunkZ, $chunk); $this->level->setChunk($chunkX, $chunkZ, $chunk);
} }
public function populateChunk($chunkX, $chunkZ){ public function populateChunk(int $chunkX, int $chunkZ){
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
foreach($this->populators as $populator){ foreach($this->populators as $populator){
$populator->populate($this->level, $chunkX, $chunkZ, $this->random); $populator->populate($this->level, $chunkX, $chunkZ, $this->random);
@ -177,7 +177,7 @@ class Flat extends Generator{
} }
public function getSpawn(){ public function getSpawn() : Vector3{
return new Vector3(128, $this->floorLevel, 128); return new Vector3(128, $this->floorLevel, 128);
} }
} }

View File

@ -29,12 +29,13 @@ namespace pocketmine\level\generator;
use pocketmine\level\ChunkManager; use pocketmine\level\ChunkManager;
use pocketmine\level\generator\noise\Noise; use pocketmine\level\generator\noise\Noise;
use pocketmine\level\generator\normal\Normal; use pocketmine\level\generator\normal\Normal;
use pocketmine\math\Vector3;
use pocketmine\utils\Random; use pocketmine\utils\Random;
abstract class Generator{ abstract class Generator{
private static $list = []; private static $list = [];
public static function addGenerator($object, $name){ public static function addGenerator($object, $name) : bool{
if(is_subclass_of($object, Generator::class) and !isset(Generator::$list[$name = strtolower($name)])){ if(is_subclass_of($object, Generator::class) and !isset(Generator::$list[$name = strtolower($name)])){
Generator::$list[$name] = $object; Generator::$list[$name] = $object;
@ -47,7 +48,7 @@ abstract class Generator{
/** /**
* @return string[] * @return string[]
*/ */
public static function getGeneratorList(){ public static function getGeneratorList() : array{
return array_keys(Generator::$list); return array_keys(Generator::$list);
} }
@ -83,10 +84,8 @@ abstract class Generator{
* @param int $z * @param int $z
* *
* @return \SplFixedArray * @return \SplFixedArray
*
* @throws \InvalidArgumentCountException
*/ */
public static function getFastNoise1D(Noise $noise, $xSize, $samplingRate, $x, $y, $z){ public static function getFastNoise1D(Noise $noise, int $xSize, int $samplingRate, int $x, int $y, int $z) : \SplFixedArray{
if($samplingRate === 0){ if($samplingRate === 0){
throw new \InvalidArgumentException("samplingRate cannot be 0"); throw new \InvalidArgumentException("samplingRate cannot be 0");
} }
@ -120,11 +119,8 @@ abstract class Generator{
* @param int $z * @param int $z
* *
* @return \SplFixedArray * @return \SplFixedArray
*
* @throws \InvalidArgumentException
* @throws \InvalidArgumentCountException
*/ */
public static function getFastNoise2D(Noise $noise, $xSize, $zSize, $samplingRate, $x, $y, $z){ public static function getFastNoise2D(Noise $noise, int $xSize, int $zSize, int $samplingRate, int $x, int $y, int $z) : \SplFixedArray{
assert($samplingRate !== 0, new \InvalidArgumentException("samplingRate cannot be 0")); assert($samplingRate !== 0, new \InvalidArgumentException("samplingRate cannot be 0"));
assert($xSize % $samplingRate === 0, new \InvalidArgumentCountException("xSize % samplingRate must return 0")); assert($xSize % $samplingRate === 0, new \InvalidArgumentCountException("xSize % samplingRate must return 0"));
@ -172,12 +168,9 @@ abstract class Generator{
* @param int $y * @param int $y
* @param int $z * @param int $z
* *
* @return \SplFixedArray * @return array
*
* @throws \InvalidArgumentException
* @throws \InvalidArgumentCountException
*/ */
public static function getFastNoise3D(Noise $noise, $xSize, $ySize, $zSize, $xSamplingRate, $ySamplingRate, $zSamplingRate, $x, $y, $z){ public static function getFastNoise3D(Noise $noise, int $xSize, int $ySize, int $zSize, int $xSamplingRate, int $ySamplingRate, int $zSamplingRate, int $x, int $y, int $z) : array{
assert($xSamplingRate !== 0, new \InvalidArgumentException("xSamplingRate cannot be 0")); assert($xSamplingRate !== 0, new \InvalidArgumentException("xSamplingRate cannot be 0"));
assert($zSamplingRate !== 0, new \InvalidArgumentException("zSamplingRate cannot be 0")); assert($zSamplingRate !== 0, new \InvalidArgumentException("zSamplingRate cannot be 0"));
@ -239,13 +232,13 @@ abstract class Generator{
abstract public function init(ChunkManager $level, Random $random); abstract public function init(ChunkManager $level, Random $random);
abstract public function generateChunk($chunkX, $chunkZ); abstract public function generateChunk(int $chunkX, int $chunkZ);
abstract public function populateChunk($chunkX, $chunkZ); abstract public function populateChunk(int $chunkX, int $chunkZ);
abstract public function getSettings(); abstract public function getSettings() : array;
abstract public function getName(); abstract public function getName() : string;
abstract public function getSpawn(); abstract public function getSpawn() : Vector3;
} }

View File

@ -70,7 +70,9 @@ abstract class Biome{
/** @var Populator[] */ /** @var Populator[] */
private $populators = []; private $populators = [];
/** @var int */
private $minElevation; private $minElevation;
/** @var int */
private $maxElevation; private $maxElevation;
private $groundCover = []; private $groundCover = [];
@ -78,9 +80,9 @@ abstract class Biome{
protected $rainfall = 0.5; protected $rainfall = 0.5;
protected $temperature = 0.5; protected $temperature = 0.5;
protected static function register($id, Biome $biome){ protected static function register(int $id, Biome $biome){
self::$biomes[(int) $id] = $biome; self::$biomes[$id] = $biome;
$biome->setId((int) $id); $biome->setId($id);
} }
public static function init(){ public static function init(){
@ -102,11 +104,11 @@ abstract class Biome{
} }
/** /**
* @param $id * @param int $id
* *
* @return Biome * @return Biome
*/ */
public static function getBiome($id){ public static function getBiome(int $id) : Biome{
return self::$biomes[$id] ?? self::$biomes[self::OCEAN]; return self::$biomes[$id] ?? self::$biomes[self::OCEAN];
} }
@ -118,38 +120,47 @@ abstract class Biome{
$this->populators[] = $populator; $this->populators[] = $populator;
} }
public function populateChunk(ChunkManager $level, $chunkX, $chunkZ, Random $random){ /**
* @param ChunkManager $level
* @param int $chunkX
* @param int $chunkZ
* @param Random $random
*/
public function populateChunk(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){
foreach($this->populators as $populator){ foreach($this->populators as $populator){
$populator->populate($level, $chunkX, $chunkZ, $random); $populator->populate($level, $chunkX, $chunkZ, $random);
} }
} }
public function getPopulators(){ /**
* @return Populator[]
*/
public function getPopulators() : array{
return $this->populators; return $this->populators;
} }
public function setId($id){ public function setId(int $id){
if(!$this->registered){ if(!$this->registered){
$this->registered = true; $this->registered = true;
$this->id = $id; $this->id = $id;
} }
} }
public function getId(){ public function getId() : int{
return $this->id; return $this->id;
} }
abstract public function getName(); abstract public function getName() : string;
public function getMinElevation(){ public function getMinElevation() : int{
return $this->minElevation; return $this->minElevation;
} }
public function getMaxElevation(){ public function getMaxElevation() : int{
return $this->maxElevation; return $this->maxElevation;
} }
public function setElevation($min, $max){ public function setElevation(int $min, int $max){
$this->minElevation = $min; $this->minElevation = $min;
$this->maxElevation = $max; $this->maxElevation = $max;
} }
@ -157,7 +168,7 @@ abstract class Biome{
/** /**
* @return Block[] * @return Block[]
*/ */
public function getGroundCover(){ public function getGroundCover() : array{
return $this->groundCover; return $this->groundCover;
} }
@ -168,11 +179,11 @@ abstract class Biome{
$this->groundCover = $covers; $this->groundCover = $covers;
} }
public function getTemperature(){ public function getTemperature() : float{
return $this->temperature; return $this->temperature;
} }
public function getRainfall(){ public function getRainfall() : float{
return $this->rainfall; return $this->rainfall;
} }
} }

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