diff --git a/src/pocketmine/MemoryManager.php b/src/pocketmine/MemoryManager.php index 0cb9268cec..355bcf38f6 100644 --- a/src/pocketmine/MemoryManager.php +++ b/src/pocketmine/MemoryManager.php @@ -33,27 +33,45 @@ class MemoryManager{ /** @var Server */ private $server; + /** @var int */ private $memoryLimit; + /** @var int */ private $globalMemoryLimit; + /** @var int */ private $checkRate; + /** @var int */ private $checkTicker = 0; + /** @var bool */ private $lowMemory = false; + /** @var bool */ private $continuousTrigger = true; + /** @var int */ private $continuousTriggerRate; + /** @var int */ private $continuousTriggerCount = 0; + /** @var int */ private $continuousTriggerTicker = 0; + /** @var int */ private $garbageCollectionPeriod; + /** @var int */ private $garbageCollectionTicker = 0; + /** @var bool */ private $garbageCollectionTrigger; + /** @var bool */ private $garbageCollectionAsync; + /** @var int */ private $chunkRadiusOverride; + /** @var bool */ private $chunkCollect; + /** @var bool */ private $chunkTrigger; + /** @var bool */ private $chunkCache; + /** @var bool */ private $cacheTrigger; public function __construct(Server $server){ @@ -116,10 +134,16 @@ class MemoryManager{ gc_enable(); } + /** + * @return bool + */ public function isLowMemory() : bool{ return $this->lowMemory; } + /** + * @return bool + */ public function canUseChunkCache() : bool{ return !($this->lowMemory and $this->chunkTrigger); } @@ -132,10 +156,18 @@ class MemoryManager{ * @return int */ public function getViewDistance(int $distance) : int{ - return $this->lowMemory ? min($this->chunkRadiusOverride, $distance) : $distance; + return $this->lowMemory ? (int) min($this->chunkRadiusOverride, $distance) : $distance; } - public function trigger($memory, $limit, $global = false, $triggerCount = 0){ + /** + * Triggers garbage collection and cache cleanup to try and free memory. + * + * @param int $memory + * @param int $limit + * @param bool $global + * @param int $triggerCount + */ + public function trigger(int $memory, int $limit, bool $global = false, int $triggerCount = 0){ $this->server->getLogger()->debug(sprintf("[Memory Manager] %sLow memory triggered, limit %gMB, using %gMB", $global ? "Global " : "", round(($limit / 1024) / 1024, 2), round(($memory / 1024) / 1024, 2))); if($this->cacheTrigger){ @@ -161,6 +193,9 @@ class MemoryManager{ $this->server->getLogger()->debug(sprintf("[Memory Manager] Freed %gMB, $cycles cycles", round(($ev->getMemoryFreed() / 1024) / 1024, 2))); } + /** + * Called every tick to update the memory manager state. + */ public function check(){ Timings::$memoryManagerTimer->startTiming(); @@ -198,7 +233,10 @@ class MemoryManager{ Timings::$memoryManagerTimer->stopTiming(); } - public function triggerGarbageCollector(){ + /** + * @return int + */ + public function triggerGarbageCollector() : int{ Timings::$garbageCollectorTimer->startTiming(); if($this->garbageCollectionAsync){ @@ -215,7 +253,14 @@ class MemoryManager{ return $cycles; } - public function dumpServerMemory($outputFolder, $maxNesting, $maxStringSize){ + /** + * Dumps the server memory into the specified output folder. + * + * @param string $outputFolder + * @param int $maxNesting + * @param int $maxStringSize + */ + public function dumpServerMemory(string $outputFolder, int $maxNesting, int $maxStringSize){ $hardLimit = ini_get('memory_limit'); ini_set('memory_limit', '-1'); gc_disable(); @@ -328,7 +373,16 @@ class MemoryManager{ gc_enable(); } - private function continueDump($from, &$data, &$objects, &$refCounts, $recursion, $maxNesting, $maxStringSize){ + /** + * @param mixed $from + * @param mixed &$data + * @param object[] &$objects + * @param int[] &$refCounts + * @param int $recursion + * @param int $maxNesting + * @param int $maxStringSize + */ + private function continueDump($from, &$data, array &$objects, array &$refCounts, int $recursion, int $maxNesting, int $maxStringSize){ if($maxNesting <= 0){ $data = "(error) NESTING LIMIT REACHED"; return; diff --git a/src/pocketmine/OfflinePlayer.php b/src/pocketmine/OfflinePlayer.php index 4f7b4105e6..09d76dd405 100644 --- a/src/pocketmine/OfflinePlayer.php +++ b/src/pocketmine/OfflinePlayer.php @@ -119,20 +119,20 @@ class OfflinePlayer implements IPlayer, Metadatable{ return $this->namedtag instanceof CompoundTag; } - public function setMetadata($metadataKey, MetadataValue $metadataValue){ - $this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue); + public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){ + $this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); } - public function getMetadata($metadataKey){ + public function getMetadata(string $metadataKey){ return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey); } - public function hasMetadata($metadataKey){ + public function hasMetadata(string $metadataKey) : bool{ return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey); } - public function removeMetadata($metadataKey, Plugin $plugin){ - $this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin); + public function removeMetadata(string $metadataKey, Plugin $owningPlugin){ + $this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); } diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b2a0d52b3f..794c920d19 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3878,20 +3878,20 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - public function setMetadata($metadataKey, MetadataValue $metadataValue){ - $this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue); + public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){ + $this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); } - public function getMetadata($metadataKey){ + public function getMetadata(string $metadataKey){ return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey); } - public function hasMetadata($metadataKey){ + public function hasMetadata(string $metadataKey) : bool{ return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey); } - public function removeMetadata($metadataKey, Plugin $plugin){ - $this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin); + public function removeMetadata(string $metadataKey, Plugin $owningPlugin){ + $this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); } public function onChunkChanged(Chunk $chunk){ diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 9c7cb65937..da971e24d4 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -436,7 +436,7 @@ class Block extends Position implements BlockIds, Metadatable{ } /** - * Returns if the item can be broken with an specific Item + * Returns if the block can be broken with an specific Item * * @param Item $item * @@ -830,13 +830,13 @@ class Block extends Position implements BlockIds, Metadatable{ return MovingObjectPosition::fromBlock($this->x, $this->y, $this->z, $f, $vector->add($this->x, $this->y, $this->z)); } - public function setMetadata($metadataKey, MetadataValue $metadataValue){ + public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){ if($this->getLevel() instanceof Level){ - $this->getLevel()->getBlockMetadata()->setMetadata($this, $metadataKey, $metadataValue); + $this->getLevel()->getBlockMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); } } - public function getMetadata($metadataKey){ + public function getMetadata(string $metadataKey){ if($this->getLevel() instanceof Level){ return $this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey); } @@ -844,15 +844,17 @@ class Block extends Position implements BlockIds, Metadatable{ return null; } - public function hasMetadata($metadataKey){ + public function hasMetadata(string $metadataKey) : bool{ if($this->getLevel() instanceof Level){ - $this->getLevel()->getBlockMetadata()->hasMetadata($this, $metadataKey); + return $this->getLevel()->getBlockMetadata()->hasMetadata($this, $metadataKey); } + + return false; } - public function removeMetadata($metadataKey, Plugin $plugin){ + public function removeMetadata(string $metadataKey, Plugin $owningPlugin){ if($this->getLevel() instanceof Level){ - $this->getLevel()->getBlockMetadata()->removeMetadata($this, $metadataKey, $plugin); + $this->getLevel()->getBlockMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); } } } diff --git a/src/pocketmine/command/defaults/PardonIpCommand.php b/src/pocketmine/command/defaults/PardonIpCommand.php index 76cc5544f5..cfe7571edb 100644 --- a/src/pocketmine/command/defaults/PardonIpCommand.php +++ b/src/pocketmine/command/defaults/PardonIpCommand.php @@ -50,6 +50,7 @@ class PardonIpCommand extends VanillaCommand{ if(preg_match("/^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$/", $args[0])){ $sender->getServer()->getIPBans()->remove($args[0]); + $sender->getServer()->getNetwork()->unblockAddress($args[0]); Command::broadcastCommandMessage($sender, new TranslationContainer("commands.unbanip.success", [$args[0]])); }else{ $sender->sendMessage(new TranslationContainer("commands.unbanip.invalid")); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 56140222fd..ef570e42bc 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1902,20 +1902,21 @@ abstract class Entity extends Location implements Metadatable{ $this->close(); } - public function setMetadata($metadataKey, MetadataValue $metadataValue){ - $this->server->getEntityMetadata()->setMetadata($this, $metadataKey, $metadataValue); + + public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){ + $this->server->getEntityMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); } - public function getMetadata($metadataKey){ + public function getMetadata(string $metadataKey){ return $this->server->getEntityMetadata()->getMetadata($this, $metadataKey); } - public function hasMetadata($metadataKey){ + public function hasMetadata(string $metadataKey) : bool{ return $this->server->getEntityMetadata()->hasMetadata($this, $metadataKey); } - public function removeMetadata($metadataKey, Plugin $plugin){ - $this->server->getEntityMetadata()->removeMetadata($this, $metadataKey, $plugin); + public function removeMetadata(string $metadataKey, Plugin $owningPlugin){ + $this->server->getEntityMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); } public function __toString(){ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 7c36e4acdc..b438ed2037 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -2905,19 +2905,19 @@ class Level implements ChunkManager, Metadatable{ } } - public function setMetadata($metadataKey, MetadataValue $metadataValue){ - $this->server->getLevelMetadata()->setMetadata($this, $metadataKey, $metadataValue); + public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){ + $this->server->getLevelMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); } - public function getMetadata($metadataKey){ + public function getMetadata(string $metadataKey){ return $this->server->getLevelMetadata()->getMetadata($this, $metadataKey); } - public function hasMetadata($metadataKey){ + public function hasMetadata(string $metadataKey) : bool{ return $this->server->getLevelMetadata()->hasMetadata($this, $metadataKey); } - public function removeMetadata($metadataKey, Plugin $plugin){ - $this->server->getLevelMetadata()->removeMetadata($this, $metadataKey, $plugin); + public function removeMetadata(string $metadataKey, Plugin $owningPlugin){ + $this->server->getLevelMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); } } diff --git a/src/pocketmine/metadata/Metadatable.php b/src/pocketmine/metadata/Metadatable.php index b3e1c6c41a..c43b9ce8e6 100644 --- a/src/pocketmine/metadata/Metadatable.php +++ b/src/pocketmine/metadata/Metadatable.php @@ -32,10 +32,8 @@ interface Metadatable{ * * @param string $metadataKey * @param MetadataValue $newMetadataValue - * - * @return void */ - public function setMetadata($metadataKey, MetadataValue $newMetadataValue); + public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue); /** * Returns a list of previously set metadata values from the implementing @@ -45,7 +43,7 @@ interface Metadatable{ * * @return MetadataValue[] */ - public function getMetadata($metadataKey); + public function getMetadata(string $metadataKey); /** * Tests to see whether the implementing object contains the given @@ -55,7 +53,7 @@ interface Metadatable{ * * @return bool */ - public function hasMetadata($metadataKey); + public function hasMetadata(string $metadataKey) : bool; /** * Removes the given metadata value from the implementing object's @@ -63,9 +61,7 @@ interface Metadatable{ * * @param string $metadataKey * @param Plugin $owningPlugin - * - * @return void */ - public function removeMetadata($metadataKey, Plugin $owningPlugin); + public function removeMetadata(string $metadataKey, Plugin $owningPlugin); } \ No newline at end of file diff --git a/src/pocketmine/network/AdvancedSourceInterface.php b/src/pocketmine/network/AdvancedSourceInterface.php index b85ff8b993..cf553081ec 100644 --- a/src/pocketmine/network/AdvancedSourceInterface.php +++ b/src/pocketmine/network/AdvancedSourceInterface.php @@ -34,6 +34,11 @@ interface AdvancedSourceInterface extends SourceInterface{ */ public function blockAddress(string $address, int $timeout = 300); + /** + * @param string $address + */ + public function unblockAddress(string $address); + /** * @param Network $network */ diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 6b60ddd80f..4f1ce278e8 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -171,4 +171,10 @@ class Network{ $interface->blockAddress($address, $timeout); } } + + public function unblockAddress(string $address){ + foreach($this->advancedInterfaces as $interface){ + $interface->unblockAddress($address); + } + } } diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index 863caaf147..2e57a27cdd 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -152,6 +152,10 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ $this->interface->blockAddress($address, $timeout); } + public function unblockAddress(string $address){ + $this->interface->unblockAddress($address); + } + public function handleRaw($address, $port, $payload){ $this->server->handlePacket($address, $port, $payload); } diff --git a/src/raklib b/src/raklib index ddd953f0e2..5d1c052cc6 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit ddd953f0e2a6577dd39f0a450546dad12a472b01 +Subproject commit 5d1c052cc6668576d116a7ab246820d75c885382