diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml
index 5ad6e4778..c8cc68bf7 100644
--- a/.github/workflows/draft-release.yml
+++ b/.github/workflows/draft-release.yml
@@ -69,7 +69,7 @@ jobs:
${{ github.workspace }}/build_info.json
- name: Create draft release
- uses: ncipollo/release-action@v1.11.2
+ uses: ncipollo/release-action@v1.12.0
with:
artifacts: ${{ github.workspace }}/PocketMine-MP.phar,${{ github.workspace }}/start.*,${{ github.workspace }}/build_info.json
commit: ${{ github.sha }}
diff --git a/.github/workflows/support.yml b/.github/workflows/support.yml
index 44487684b..fe726dfef 100644
--- a/.github/workflows/support.yml
+++ b/.github/workflows/support.yml
@@ -8,7 +8,7 @@ jobs:
support:
runs-on: ubuntu-latest
steps:
- - uses: dessant/support-requests@v2
+ - uses: dessant/support-requests@v3
with:
github-token: ${{ github.token }}
support-label: "Support request"
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 1df291e8e..c3fac9558 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -62,6 +62,11 @@
+
+
+
+
+
diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php
index 70801c065..32af1ef48 100644
--- a/.php-cs-fixer.php
+++ b/.php-cs-fixer.php
@@ -66,6 +66,9 @@ BODY,
],
'indentation_type' => true,
'logical_operators' => true,
+ 'native_constant_invocation' => [
+ 'scope' => 'namespaced'
+ ],
'native_function_invocation' => [
'scope' => 'namespaced',
'include' => ['@all'],
@@ -92,6 +95,12 @@ BODY,
],
'sort_algorithm' => 'alpha'
],
+ 'phpdoc_align' => [
+ 'align' => 'vertical',
+ 'tags' => [
+ 'param',
+ ]
+ ],
'phpdoc_line_span' => [
'property' => 'single',
'method' => null,
diff --git a/build/generate-block-serializer-consts.php b/build/generate-block-serializer-consts.php
index 5f82b8e58..279ffc788 100644
--- a/build/generate-block-serializer-consts.php
+++ b/build/generate-block-serializer-consts.php
@@ -48,6 +48,8 @@ use function sort;
use function strrpos;
use function strtoupper;
use function substr;
+use const SORT_STRING;
+use const STDERR;
require dirname(__DIR__) . '/vendor/autoload.php';
diff --git a/build/generate-item-type-names.php b/build/generate-item-type-names.php
index 2da9b263e..2cbc07c2d 100644
--- a/build/generate-item-type-names.php
+++ b/build/generate-item-type-names.php
@@ -36,6 +36,8 @@ use function file_get_contents;
use function fopen;
use function fwrite;
use function strtoupper;
+use const SORT_STRING;
+use const STDERR;
require dirname(__DIR__) . '/vendor/autoload.php';
diff --git a/build/generate-registry-annotations.php b/build/generate-registry-annotations.php
index 1198db207..f17e39170 100644
--- a/build/generate-registry-annotations.php
+++ b/build/generate-registry-annotations.php
@@ -39,6 +39,7 @@ use function sprintf;
use function str_replace;
use function substr;
use const SORT_STRING;
+use const STDERR;
if(count($argv) !== 2){
fwrite(STDERR, "Provide a path to process\n");
diff --git a/build/generate-runtime-enum-serializers.php b/build/generate-runtime-enum-serializers.php
index e3cfc2abe..5907628f0 100644
--- a/build/generate-runtime-enum-serializers.php
+++ b/build/generate-runtime-enum-serializers.php
@@ -48,6 +48,7 @@ use function lcfirst;
use function log;
use function ob_get_clean;
use function ob_start;
+use const SORT_STRING;
require dirname(__DIR__) . '/vendor/autoload.php';
diff --git a/build/server-phar.php b/build/server-phar.php
index f3d26a2c4..0665c89d5 100644
--- a/build/server-phar.php
+++ b/build/server-phar.php
@@ -40,12 +40,13 @@ use function rtrim;
use function sprintf;
use function str_replace;
use function unlink;
+use const DIRECTORY_SEPARATOR;
use const PHP_EOL;
require dirname(__DIR__) . '/vendor/autoload.php';
/**
- * @param string[] $strings
+ * @param string[] $strings
*
* @return string[]
*/
diff --git a/composer.lock b/composer.lock
index fe5a5bf6b..70ee2bb68 100644
--- a/composer.lock
+++ b/composer.lock
@@ -198,16 +198,16 @@
},
{
"name": "netresearch/jsonmapper",
- "version": "v4.0.0",
+ "version": "v4.1.0",
"source": {
"type": "git",
"url": "https://github.com/cweiske/jsonmapper.git",
- "reference": "8bbc021a8edb2e4a7ea2f8ad4fa9ec9dce2fcb8d"
+ "reference": "cfa81ea1d35294d64adb9c68aa4cb9e92400e53f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/cweiske/jsonmapper/zipball/8bbc021a8edb2e4a7ea2f8ad4fa9ec9dce2fcb8d",
- "reference": "8bbc021a8edb2e4a7ea2f8ad4fa9ec9dce2fcb8d",
+ "url": "https://api.github.com/repos/cweiske/jsonmapper/zipball/cfa81ea1d35294d64adb9c68aa4cb9e92400e53f",
+ "reference": "cfa81ea1d35294d64adb9c68aa4cb9e92400e53f",
"shasum": ""
},
"require": {
@@ -243,9 +243,9 @@
"support": {
"email": "cweiske@cweiske.de",
"issues": "https://github.com/cweiske/jsonmapper/issues",
- "source": "https://github.com/cweiske/jsonmapper/tree/v4.0.0"
+ "source": "https://github.com/cweiske/jsonmapper/tree/v4.1.0"
},
- "time": "2020-12-01T19:48:11+00:00"
+ "time": "2022-12-08T20:46:14+00:00"
},
{
"name": "pocketmine/bedrock-block-upgrade-schema",
@@ -1824,21 +1824,21 @@
},
{
"name": "phpstan/phpstan-phpunit",
- "version": "1.2.2",
+ "version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-phpunit.git",
- "reference": "dea1f87344c6964c607d9076dee42d891f3923f0"
+ "reference": "4c06b7e3f2c40081334d86975350dda814bd064a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/dea1f87344c6964c607d9076dee42d891f3923f0",
- "reference": "dea1f87344c6964c607d9076dee42d891f3923f0",
+ "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/4c06b7e3f2c40081334d86975350dda814bd064a",
+ "reference": "4c06b7e3f2c40081334d86975350dda814bd064a",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0",
- "phpstan/phpstan": "^1.8.11"
+ "phpstan/phpstan": "^1.9.0"
},
"conflict": {
"phpunit/phpunit": "<7.0"
@@ -1870,9 +1870,9 @@
"description": "PHPUnit extensions and rules for PHPStan",
"support": {
"issues": "https://github.com/phpstan/phpstan-phpunit/issues",
- "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.2.2"
+ "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.3.0"
},
- "time": "2022-10-28T10:23:07+00:00"
+ "time": "2022-12-07T15:46:24+00:00"
},
{
"name": "phpstan/phpstan-strict-rules",
@@ -2242,16 +2242,16 @@
},
{
"name": "phpunit/phpunit",
- "version": "9.5.26",
+ "version": "9.5.27",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "851867efcbb6a1b992ec515c71cdcf20d895e9d2"
+ "reference": "a2bc7ffdca99f92d959b3f2270529334030bba38"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/851867efcbb6a1b992ec515c71cdcf20d895e9d2",
- "reference": "851867efcbb6a1b992ec515c71cdcf20d895e9d2",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a2bc7ffdca99f92d959b3f2270529334030bba38",
+ "reference": "a2bc7ffdca99f92d959b3f2270529334030bba38",
"shasum": ""
},
"require": {
@@ -2324,7 +2324,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
- "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.26"
+ "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.27"
},
"funding": [
{
@@ -2340,7 +2340,7 @@
"type": "tidelift"
}
],
- "time": "2022-10-28T06:00:21+00:00"
+ "time": "2022-12-09T07:31:23+00:00"
},
{
"name": "sebastian/cli-parser",
diff --git a/src/MemoryManager.php b/src/MemoryManager.php
index 9b35c952f..710f6acd2 100644
--- a/src/MemoryManager.php
+++ b/src/MemoryManager.php
@@ -477,7 +477,7 @@ class MemoryManager{
}
/**
- * @param object[] $objects reference parameter
+ * @param object[] $objects reference parameter
* @param int[] $refCounts reference parameter
*
* @phpstan-param array $objects
diff --git a/src/PocketMine.php b/src/PocketMine.php
index d84cf50a2..f49115826 100644
--- a/src/PocketMine.php
+++ b/src/PocketMine.php
@@ -39,11 +39,14 @@ namespace pocketmine {
use function extension_loaded;
use function function_exists;
use function getcwd;
+ use function is_dir;
+ use function mkdir;
use function phpversion;
use function preg_match;
use function preg_quote;
use function realpath;
use function version_compare;
+ use const DIRECTORY_SEPARATOR;
require_once __DIR__ . '/VersionInfo.php';
@@ -273,25 +276,33 @@ JIT_WARNING
$pluginPath = getopt_string("plugins") ?? $cwd . DIRECTORY_SEPARATOR . "plugins";
Filesystem::addCleanedPath($pluginPath, Filesystem::CLEAN_PATH_PLUGINS_PREFIX);
- if(!@mkdir($dataPath, 0777, true) && (!is_dir($dataPath) || !is_writable($dataPath))){
+ if(!@mkdir($dataPath, 0777, true) && !is_dir($dataPath)){
critical_error("Unable to create/access data directory at $dataPath. Check that the target location is accessible by the current user.");
exit(1);
}
//this has to be done after we're sure the data path exists
$dataPath = realpath($dataPath) . DIRECTORY_SEPARATOR;
- if(!@mkdir($pluginPath, 0777, true) && (!is_dir($pluginPath) || !is_writable($pluginPath))){
- critical_error("Unable to create plugin directory at $pluginPath. Check that the target location is accessible by the current user.");
- exit(1);
- }
- $pluginPath = realpath($pluginPath) . DIRECTORY_SEPARATOR;
$lockFilePath = Path::join($dataPath, 'server.lock');
- if(($pid = Filesystem::createLockFile($lockFilePath)) !== null){
+ try{
+ $pid = Filesystem::createLockFile($lockFilePath);
+ }catch(\InvalidArgumentException $e){
+ critical_error($e->getMessage());
+ critical_error("Please ensure that there is enough space on the disk and that the current user has read/write permissions to the selected data directory $dataPath.");
+ exit(1);
+ }
+ if($pid !== null){
critical_error("Another " . VersionInfo::NAME . " instance (PID $pid) is already using this folder (" . realpath($dataPath) . ").");
critical_error("Please stop the other server first before running a new one.");
exit(1);
}
+ if(!@mkdir($pluginPath, 0777, true) && !is_dir($pluginPath)){
+ critical_error("Unable to create plugin directory at $pluginPath. Check that the target location is accessible by the current user.");
+ exit(1);
+ }
+ $pluginPath = realpath($pluginPath) . DIRECTORY_SEPARATOR;
+
//Logger has a dependency on timezone
Timezone::init();
diff --git a/src/Server.php b/src/Server.php
index 4c4f25348..546212c8a 100644
--- a/src/Server.php
+++ b/src/Server.php
@@ -1265,7 +1265,7 @@ class Server{
}
/**
- * @param CommandSender[]|null $recipients
+ * @param CommandSender[]|null $recipients
*/
public function broadcastMessage(Translatable|string $message, ?array $recipients = null) : int{
$recipients = $recipients ?? $this->getBroadcastChannelSubscribers(self::BROADCAST_CHANNEL_USERS);
@@ -1318,9 +1318,9 @@ class Server{
}
/**
- * @param int $fadeIn Duration in ticks for fade-in. If -1 is given, client-sided defaults will be used.
- * @param int $stay Duration in ticks to stay on screen for
- * @param int $fadeOut Duration in ticks for fade-out.
+ * @param int $fadeIn Duration in ticks for fade-in. If -1 is given, client-sided defaults will be used.
+ * @param int $stay Duration in ticks to stay on screen for
+ * @param int $fadeOut Duration in ticks for fade-out.
* @param Player[]|null $recipients
*/
public function broadcastTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1, ?array $recipients = null) : int{
diff --git a/src/block/BaseBanner.php b/src/block/BaseBanner.php
index 89e06d535..72318032a 100644
--- a/src/block/BaseBanner.php
+++ b/src/block/BaseBanner.php
@@ -89,7 +89,7 @@ abstract class BaseBanner extends Transparent{
}
/**
- * @param BannerPatternLayer[] $patterns
+ * @param BannerPatternLayer[] $patterns
*
* @phpstan-param list $patterns
* @return $this
diff --git a/src/block/Block.php b/src/block/Block.php
index 24a5d917f..daa2f0e30 100644
--- a/src/block/Block.php
+++ b/src/block/Block.php
@@ -63,7 +63,7 @@ class Block{
protected ?array $collisionBoxes = null;
/**
- * @param string $name English name of the block type (TODO: implement translations)
+ * @param string $name English name of the block type (TODO: implement translations)
*/
public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){
$this->idInfo = $idInfo;
diff --git a/src/block/BlockFactory.php b/src/block/BlockFactory.php
index 737747184..9c17e0c45 100644
--- a/src/block/BlockFactory.php
+++ b/src/block/BlockFactory.php
@@ -85,7 +85,7 @@ class BlockFactory{
* NOTE: If you are registering a new block type, you will need to add it to the creative inventory yourself - it
* will not automatically appear there.
*
- * @param bool $override Whether to override existing registrations
+ * @param bool $override Whether to override existing registrations
*
* @throws \InvalidArgumentException if something attempted to override an already-registered block without specifying the
* $override parameter.
diff --git a/src/block/tile/Banner.php b/src/block/tile/Banner.php
index 0af4b2e79..191d4c8a5 100644
--- a/src/block/tile/Banner.php
+++ b/src/block/tile/Banner.php
@@ -135,7 +135,7 @@ class Banner extends Spawnable{
}
/**
- * @param BannerPatternLayer[] $patterns
+ * @param BannerPatternLayer[] $patterns
*
* @phpstan-param list $patterns
*/
diff --git a/src/command/CommandExecutor.php b/src/command/CommandExecutor.php
index 138c4f22a..1356b7581 100644
--- a/src/command/CommandExecutor.php
+++ b/src/command/CommandExecutor.php
@@ -26,7 +26,7 @@ namespace pocketmine\command;
interface CommandExecutor{
/**
- * @param string[] $args
+ * @param string[] $args
*/
public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool;
diff --git a/src/crafting/CraftingManager.php b/src/crafting/CraftingManager.php
index f83901d33..fcb1de866 100644
--- a/src/crafting/CraftingManager.php
+++ b/src/crafting/CraftingManager.php
@@ -204,7 +204,7 @@ class CraftingManager{
}
/**
- * @param Item[] $outputs
+ * @param Item[] $outputs
*/
public function matchRecipe(CraftingGrid $grid, array $outputs) : ?CraftingRecipe{
//TODO: try to match special recipes before anything else (first they need to be implemented!)
diff --git a/src/crafting/ShapedRecipe.php b/src/crafting/ShapedRecipe.php
index b9a77f360..89ba57413 100644
--- a/src/crafting/ShapedRecipe.php
+++ b/src/crafting/ShapedRecipe.php
@@ -45,15 +45,15 @@ class ShapedRecipe implements CraftingRecipe{
/**
* Constructs a ShapedRecipe instance.
*
- * @param string[] $shape
- * Array of 1, 2, or 3 strings representing the rows of the recipe.
- * This accepts an array of 1, 2 or 3 strings. Each string should be of the same length and must be at most 3
- * characters long. Each character represents a unique type of ingredient. Spaces are interpreted as air.
- * @param RecipeIngredient[] $ingredients
- * Char => Item map of items to be set into the shape.
- * This accepts an array of Items, indexed by character. Every unique character (except space) in the shape
- * array MUST have a corresponding item in this list. Space character is automatically treated as air.
- * @param Item[] $results List of items that this recipe produces when crafted.
+ * @param string[] $shape
+ * Array of 1, 2, or 3 strings representing the rows of the recipe.
+ * This accepts an array of 1, 2 or 3 strings. Each string should be of the same length and must be at most 3
+ * characters long. Each character represents a unique type of ingredient. Spaces are interpreted as air.
+ * @param RecipeIngredient[] $ingredients
+ * Char => Item map of items to be set into the shape.
+ * This accepts an array of Items, indexed by character. Every unique character (except space) in the shape
+ * array MUST have a corresponding item in this list. Space character is automatically treated as air.
+ * @param Item[] $results List of items that this recipe produces when crafted.
*
* Note: Recipes **do not** need to be square. Do NOT add padding for empty rows/columns.
*/
diff --git a/src/crafting/ShapelessRecipe.php b/src/crafting/ShapelessRecipe.php
index 5c78bc21e..ce7a57c30 100644
--- a/src/crafting/ShapelessRecipe.php
+++ b/src/crafting/ShapelessRecipe.php
@@ -36,7 +36,8 @@ class ShapelessRecipe implements CraftingRecipe{
/**
* @param RecipeIngredient[] $ingredients No more than 9 total. This applies to sum of item stack counts, not count of array.
- * @param Item[] $results List of result items created by this recipe.
+ * @param Item[] $results List of result items created by this recipe.
+ *
* TODO: we'll want to make the type parameter mandatory in PM5
*/
public function __construct(array $ingredients, array $results, ?ShapelessRecipeType $type = null){
diff --git a/src/crafting/json/ShapedRecipeData.php b/src/crafting/json/ShapedRecipeData.php
index abf37098e..dd040f516 100644
--- a/src/crafting/json/ShapedRecipeData.php
+++ b/src/crafting/json/ShapedRecipeData.php
@@ -54,9 +54,9 @@ final class ShapedRecipeData{
/**
* TODO: convert this to use promoted properties - avoiding them for now since it would break JsonMapper
*
- * @param string[] $shape
+ * @param string[] $shape
* @param RecipeIngredientData[] $input
- * @param ItemStackData[] $output
+ * @param ItemStackData[] $output
*
* @phpstan-param list $shape
* @phpstan-param array $input
diff --git a/src/crafting/json/ShapelessRecipeData.php b/src/crafting/json/ShapelessRecipeData.php
index 453b349dd..d59bafbbf 100644
--- a/src/crafting/json/ShapelessRecipeData.php
+++ b/src/crafting/json/ShapelessRecipeData.php
@@ -47,7 +47,7 @@ final class ShapelessRecipeData{
/**
* @param RecipeIngredientData[] $input
- * @param ItemStackData[] $output
+ * @param ItemStackData[] $output
*
* @phpstan-param list $input
* @phpstan-param list $output
diff --git a/src/data/bedrock/ItemTagToIdMap.php b/src/data/bedrock/ItemTagToIdMap.php
index fa5b24e7a..0782ff424 100644
--- a/src/data/bedrock/ItemTagToIdMap.php
+++ b/src/data/bedrock/ItemTagToIdMap.php
@@ -34,6 +34,7 @@ use function gettype;
use function is_array;
use function is_string;
use function json_decode;
+use const JSON_THROW_ON_ERROR;
use const pocketmine\BEDROCK_DATA_PATH;
/**
diff --git a/src/data/bedrock/item/BlockItemIdMap.php b/src/data/bedrock/item/BlockItemIdMap.php
index 04c4058ff..d012fe3cb 100644
--- a/src/data/bedrock/item/BlockItemIdMap.php
+++ b/src/data/bedrock/item/BlockItemIdMap.php
@@ -31,6 +31,7 @@ use function array_flip;
use function file_get_contents;
use function is_array;
use function json_decode;
+use const JSON_THROW_ON_ERROR;
use const pocketmine\BEDROCK_DATA_PATH;
/**
diff --git a/src/data/bedrock/item/upgrade/ItemDataUpgrader.php b/src/data/bedrock/item/upgrade/ItemDataUpgrader.php
index 33d4bffc2..defaed6a3 100644
--- a/src/data/bedrock/item/upgrade/ItemDataUpgrader.php
+++ b/src/data/bedrock/item/upgrade/ItemDataUpgrader.php
@@ -37,6 +37,7 @@ use pocketmine\nbt\tag\StringTag;
use pocketmine\utils\Binary;
use function assert;
use function ksort;
+use const SORT_NUMERIC;
final class ItemDataUpgrader{
private const TAG_LEGACY_ID = "id"; //TAG_Short (or TAG_String for Java itemstacks)
diff --git a/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchema.php b/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchema.php
index a977f4ad2..e88111ef2 100644
--- a/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchema.php
+++ b/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchema.php
@@ -28,7 +28,7 @@ use function mb_strtolower;
final class ItemIdMetaUpgradeSchema{
/**
- * @param string[] $renamedIds
+ * @param string[] $renamedIds
* @param string[][] $remappedMetas
* @phpstan-param array $renamedIds
* @phpstan-param array> $remappedMetas
diff --git a/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchemaUtils.php b/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchemaUtils.php
index 0d315819c..c7d5d1577 100644
--- a/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchemaUtils.php
+++ b/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchemaUtils.php
@@ -31,6 +31,8 @@ use function gettype;
use function is_object;
use function json_decode;
use function ksort;
+use const JSON_THROW_ON_ERROR;
+use const SORT_NUMERIC;
final class ItemIdMetaUpgradeSchemaUtils{
diff --git a/src/data/bedrock/item/upgrade/R12ItemIdToBlockIdMap.php b/src/data/bedrock/item/upgrade/R12ItemIdToBlockIdMap.php
index be8a070d9..9e5c86a3d 100644
--- a/src/data/bedrock/item/upgrade/R12ItemIdToBlockIdMap.php
+++ b/src/data/bedrock/item/upgrade/R12ItemIdToBlockIdMap.php
@@ -32,6 +32,7 @@ use function is_array;
use function is_string;
use function json_decode;
use function mb_strtolower;
+use const JSON_THROW_ON_ERROR;
use const pocketmine\BEDROCK_ITEM_UPGRADE_SCHEMA_PATH;
/**
diff --git a/src/entity/Entity.php b/src/entity/Entity.php
index 520ff782b..a8c7edd02 100644
--- a/src/entity/Entity.php
+++ b/src/entity/Entity.php
@@ -1569,7 +1569,7 @@ abstract class Entity{
/**
* @param Player[]|null $targets
- * @param MetadataProperty[] $data Properly formatted entity data, defaults to everything
+ * @param MetadataProperty[] $data Properly formatted entity data, defaults to everything
*
* @phpstan-param array $data
*/
diff --git a/src/entity/Living.php b/src/entity/Living.php
index acd1753d5..711c343bf 100644
--- a/src/entity/Living.php
+++ b/src/entity/Living.php
@@ -439,7 +439,9 @@ abstract class Living extends Entity{
*/
protected function applyPostDamageEffects(EntityDamageEvent $source) : void{
$this->setAbsorption(max(0, $this->getAbsorption() + $source->getModifier(EntityDamageEvent::MODIFIER_ABSORPTION)));
- $this->damageArmor($source->getBaseDamage());
+ if($source->canBeReducedByArmor()){
+ $this->damageArmor($source->getBaseDamage());
+ }
if($source instanceof EntityDamageByEntityEvent && ($attacker = $source->getDamager()) !== null){
$damage = 0;
diff --git a/src/entity/effect/Effect.php b/src/entity/effect/Effect.php
index cce009733..6373a2281 100644
--- a/src/entity/effect/Effect.php
+++ b/src/entity/effect/Effect.php
@@ -35,9 +35,9 @@ class Effect{
use NotSerializable;
/**
- * @param Translatable|string $name Translation key used for effect name
- * @param Color $color Color of bubbles given by this effect
- * @param bool $bad Whether the effect is harmful
+ * @param Translatable|string $name Translation key used for effect name
+ * @param Color $color Color of bubbles given by this effect
+ * @param bool $bad Whether the effect is harmful
* @param bool $hasBubbles Whether the effect has potion bubbles. Some do not (e.g. Instant Damage has its own particles instead of bubbles)
*/
public function __construct(
diff --git a/src/entity/effect/EffectInstance.php b/src/entity/effect/EffectInstance.php
index f948b1f39..50d92a67b 100644
--- a/src/entity/effect/EffectInstance.php
+++ b/src/entity/effect/EffectInstance.php
@@ -36,7 +36,7 @@ class EffectInstance{
private Color $color;
/**
- * @param int|null $duration Passing null will use the effect type's default duration
+ * @param int|null $duration Passing null will use the effect type's default duration
*/
public function __construct(Effect $effectType, ?int $duration = null, int $amplifier = 0, bool $visible = true, bool $ambient = false, ?Color $overrideColor = null){
$this->effectType = $effectType;
diff --git a/src/event/entity/EntityExplodeEvent.php b/src/event/entity/EntityExplodeEvent.php
index f2463af0e..0a0e4f696 100644
--- a/src/event/entity/EntityExplodeEvent.php
+++ b/src/event/entity/EntityExplodeEvent.php
@@ -43,7 +43,7 @@ class EntityExplodeEvent extends EntityEvent implements Cancellable{
/**
* @param Block[] $blocks
- * @param float $yield 0-100
+ * @param float $yield 0-100
*/
public function __construct(
Entity $entity,
diff --git a/src/event/inventory/CraftItemEvent.php b/src/event/inventory/CraftItemEvent.php
index 2ca324d77..64f285f15 100644
--- a/src/event/inventory/CraftItemEvent.php
+++ b/src/event/inventory/CraftItemEvent.php
@@ -35,8 +35,8 @@ class CraftItemEvent extends Event implements Cancellable{
use CancellableTrait;
/**
- * @param Item[] $inputs
- * @param Item[] $outputs
+ * @param Item[] $inputs
+ * @param Item[] $outputs
*/
public function __construct(
private CraftingTransaction $transaction,
diff --git a/src/event/world/WorldParticleEvent.php b/src/event/world/WorldParticleEvent.php
new file mode 100644
index 000000000..5fe5ca76a
--- /dev/null
+++ b/src/event/world/WorldParticleEvent.php
@@ -0,0 +1,73 @@
+particle;
+ }
+
+ public function setParticle(Particle $particle) : void{
+ $this->particle = $particle;
+ }
+
+ public function getPosition() : Vector3{
+ return $this->position;
+ }
+
+ /**
+ * @return Player[]
+ */
+ public function getRecipients() : array{
+ return $this->recipients;
+ }
+
+ /**
+ * @param Player[] $recipients
+ */
+ public function setRecipients(array $recipients) : void{
+ $this->recipients = $recipients;
+ }
+}
diff --git a/src/event/world/WorldSoundEvent.php b/src/event/world/WorldSoundEvent.php
new file mode 100644
index 000000000..641214e20
--- /dev/null
+++ b/src/event/world/WorldSoundEvent.php
@@ -0,0 +1,77 @@
+sound;
+ }
+
+ public function setSound(Sound $sound) : void{
+ $this->sound = $sound;
+ }
+
+ public function getPosition() : Vector3{
+ return $this->position;
+ }
+
+ /**
+ * @return Player[]
+ */
+ public function getRecipients() : array{
+ return $this->recipients;
+ }
+
+ /**
+ * @param Player[] $recipients
+ */
+ public function setRecipients(array $recipients) : void{
+ $this->recipients = $recipients;
+ }
+}
diff --git a/src/form/Form.php b/src/form/Form.php
index f17da3e36..97f49df07 100644
--- a/src/form/Form.php
+++ b/src/form/Form.php
@@ -34,7 +34,7 @@ interface Form extends \JsonSerializable{
/**
* Handles a form response from a player.
*
- * @param mixed $data
+ * @param mixed $data
*
* @throws FormValidationException if the data could not be processed
*/
diff --git a/src/item/Banner.php b/src/item/Banner.php
index 6cb91eb6a..e86d4dbce 100644
--- a/src/item/Banner.php
+++ b/src/item/Banner.php
@@ -77,7 +77,7 @@ class Banner extends ItemBlockWallOrFloor{
}
/**
- * @param BannerPatternLayer[] $patterns
+ * @param BannerPatternLayer[] $patterns
*
* @phpstan-param list $patterns
*
diff --git a/src/item/Item.php b/src/item/Item.php
index ed516adc0..3ad52d8ad 100644
--- a/src/item/Item.php
+++ b/src/item/Item.php
@@ -568,6 +568,16 @@ class Item implements \JsonSerializable{
return false;
}
+ /**
+ * Called when a player uses the item to interact with entity, for example by using a name tag.
+ *
+ * @param Vector3 $clickVector The exact position of the click (absolute coordinates)
+ * @return bool whether some action took place
+ */
+ public function onInteractEntity(Player $player, Entity $entity, Vector3 $clickVector) : bool{
+ return false;
+ }
+
/**
* Returns the number of ticks a player must wait before activating this item again.
*/
@@ -578,7 +588,7 @@ class Item implements \JsonSerializable{
/**
* Compares an Item to this Item and check if they match.
*
- * @param bool $checkDamage @deprecated
+ * @param bool $checkDamage @deprecated
* @param bool $checkCompound Whether to verify that the items' NBT match.
*/
final public function equals(Item $item, bool $checkDamage = true, bool $checkCompound = true) : bool{
diff --git a/src/network/AdvancedNetworkInterface.php b/src/network/AdvancedNetworkInterface.php
index 1fac1311d..da1af4b28 100644
--- a/src/network/AdvancedNetworkInterface.php
+++ b/src/network/AdvancedNetworkInterface.php
@@ -35,7 +35,7 @@ interface AdvancedNetworkInterface extends NetworkInterface{
/**
* Prevents packets received from the IP address getting processed for the given timeout.
*
- * @param int $timeout Seconds
+ * @param int $timeout Seconds
*/
public function blockAddress(string $address, int $timeout = 300) : void;
diff --git a/src/network/mcpe/PacketBroadcaster.php b/src/network/mcpe/PacketBroadcaster.php
index a31393981..2a231b7f3 100644
--- a/src/network/mcpe/PacketBroadcaster.php
+++ b/src/network/mcpe/PacketBroadcaster.php
@@ -28,7 +28,7 @@ use pocketmine\network\mcpe\protocol\ClientboundPacket;
interface PacketBroadcaster{
/**
- * @param NetworkSession[] $recipients
+ * @param NetworkSession[] $recipients
* @param ClientboundPacket[] $packets
*/
public function broadcastPackets(array $recipients, array $packets) : void;
diff --git a/src/network/mcpe/convert/BlockStateDictionary.php b/src/network/mcpe/convert/BlockStateDictionary.php
index 24d49e34c..4c6e8aec0 100644
--- a/src/network/mcpe/convert/BlockStateDictionary.php
+++ b/src/network/mcpe/convert/BlockStateDictionary.php
@@ -36,6 +36,7 @@ use function get_debug_type;
use function is_array;
use function is_int;
use function json_decode;
+use const JSON_THROW_ON_ERROR;
/**
* Handles translation of network block runtime IDs into blockstate data, and vice versa
@@ -50,7 +51,7 @@ final class BlockStateDictionary{
private ?array $idMetaToStateIdLookupCache = null;
/**
- * @param BlockStateDictionaryEntry[] $states
+ * @param BlockStateDictionaryEntry[] $states
*
* @phpstan-param list $states
*/
diff --git a/src/network/mcpe/encryption/EncryptionUtils.php b/src/network/mcpe/encryption/EncryptionUtils.php
index cb56562db..920c54a7e 100644
--- a/src/network/mcpe/encryption/EncryptionUtils.php
+++ b/src/network/mcpe/encryption/EncryptionUtils.php
@@ -34,6 +34,7 @@ use function openssl_digest;
use function openssl_error_string;
use function openssl_pkey_derive;
use function str_pad;
+use const STR_PAD_LEFT;
final class EncryptionUtils{
diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php
index 8d65b0872..3d5e01d6a 100644
--- a/src/network/mcpe/handler/InGamePacketHandler.php
+++ b/src/network/mcpe/handler/InGamePacketHandler.php
@@ -306,6 +306,8 @@ class InGamePacketHandler extends PacketHandler{
public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{
$result = true;
+ $this->inventoryManager->addPredictedSlotChanges($packet->trData->getActions());
+
if($packet->trData instanceof NormalTransactionData){
$result = $this->handleNormalTransaction($packet->trData);
}elseif($packet->trData instanceof MismatchTransactionData){
@@ -355,7 +357,6 @@ class InGamePacketHandler extends PacketHandler{
return false;
}
}
- $this->inventoryManager->addPredictedSlotChanges($data->getActions());
if($isCraftingPart){
if($this->craftingTransaction === null){
diff --git a/src/network/mcpe/raklib/RakLibInterface.php b/src/network/mcpe/raklib/RakLibInterface.php
index 33a50ac56..bf1f75c26 100644
--- a/src/network/mcpe/raklib/RakLibInterface.php
+++ b/src/network/mcpe/raklib/RakLibInterface.php
@@ -52,6 +52,7 @@ use function mt_rand;
use function random_bytes;
use function rtrim;
use function substr;
+use const PHP_INT_MAX;
class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
/**
diff --git a/src/network/query/DedicatedQueryNetworkInterface.php b/src/network/query/DedicatedQueryNetworkInterface.php
index c2d27029c..2917ba0ee 100644
--- a/src/network/query/DedicatedQueryNetworkInterface.php
+++ b/src/network/query/DedicatedQueryNetworkInterface.php
@@ -40,6 +40,7 @@ use function strlen;
use function time;
use function trim;
use const AF_INET;
+use const AF_INET6;
use const IPPROTO_IPV6;
use const IPV6_V6ONLY;
use const PHP_INT_MAX;
diff --git a/src/network/upnp/UPnP.php b/src/network/upnp/UPnP.php
index e1d059339..2d48a2db8 100644
--- a/src/network/upnp/UPnP.php
+++ b/src/network/upnp/UPnP.php
@@ -73,6 +73,12 @@ use function sprintf;
use function strlen;
use function trim;
use const AF_INET;
+use const PREG_BACKTRACK_LIMIT_ERROR;
+use const PREG_BAD_UTF8_ERROR;
+use const PREG_BAD_UTF8_OFFSET_ERROR;
+use const PREG_INTERNAL_ERROR;
+use const PREG_JIT_STACKLIMIT_ERROR;
+use const PREG_RECURSION_LIMIT_ERROR;
use const SO_RCVTIMEO;
use const SOCK_DGRAM;
use const SOCKET_ETIMEDOUT;
diff --git a/src/player/Player.php b/src/player/Player.php
index 4f99c93a4..391684c76 100644
--- a/src/player/Player.php
+++ b/src/player/Player.php
@@ -1392,7 +1392,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
/**
* Returns whether the player can interact with the specified position. This checks distance and direction.
*
- * @param float $maxDiff defaults to half of the 3D diagonal width of a block
+ * @param float $maxDiff defaults to half of the 3D diagonal width of a block
*/
public function canInteract(Vector3 $pos, float $maxDistance, float $maxDiff = M_SQRT3 / 2) : bool{
$eyePos = $this->getEyePos();
@@ -1836,7 +1836,17 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$ev->call();
+ $item = $this->inventory->getItemInHand();
+ $oldItem = clone $item;
if(!$ev->isCancelled()){
+ if($item->onInteractEntity($this, $entity, $clickPos)){
+ if($this->hasFiniteResources() && !$item->equalsExact($oldItem) && $oldItem->equalsExact($this->inventory->getItemInHand())){
+ if($item instanceof Durable && $item->isBroken()){
+ $this->broadcastSound(new ItemBreakSound());
+ }
+ $this->inventory->setItemInHand($item);
+ }
+ }
return $entity->onInteract($this, $clickPos);
}
return false;
@@ -1934,9 +1944,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
/**
* Adds a title text to the user's screen, with an optional subtitle.
*
- * @param int $fadeIn Duration in ticks for fade-in. If -1 is given, client-sided defaults will be used.
- * @param int $stay Duration in ticks to stay on screen for
- * @param int $fadeOut Duration in ticks for fade-out.
+ * @param int $fadeIn Duration in ticks for fade-in. If -1 is given, client-sided defaults will be used.
+ * @param int $stay Duration in ticks to stay on screen for
+ * @param int $fadeOut Duration in ticks for fade-out.
*/
public function sendTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1) : void{
$this->setTitleDuration($fadeIn, $stay, $fadeOut);
@@ -1977,8 +1987,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
/**
* Sets the title duration.
*
- * @param int $fadeIn Title fade-in time in ticks.
- * @param int $stay Title stay time in ticks.
+ * @param int $fadeIn Title fade-in time in ticks.
+ * @param int $stay Title stay time in ticks.
* @param int $fadeOut Title fade-out time in ticks.
*/
public function setTitleDuration(int $fadeIn, int $stay, int $fadeOut) : void{
@@ -2076,7 +2086,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* Transfers a player to another server.
*
* @param string $address The IP address or hostname of the destination server
- * @param int $port The destination port, defaults to 19132
+ * @param int $port The destination port, defaults to 19132
* @param string $message Message to show in the console when closing the player
*
* @return bool if transfer was successful.
@@ -2120,7 +2130,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
*
* Note for internals developers: Do not call this from network sessions. It will cause a feedback loop.
*
- * @param string $reason Shown to the player, usually this will appear on their disconnect screen.
+ * @param string $reason Shown to the player, usually this will appear on their disconnect screen.
* @param Translatable|string|null $quitMessage Message to broadcast to online players (null will use default)
*/
public function disconnect(string $reason, Translatable|string|null $quitMessage = null) : void{
@@ -2136,7 +2146,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* @internal
* This method executes post-disconnect actions and cleanups.
*
- * @param string $reason Shown to the player, usually this will appear on their disconnect screen.
+ * @param string $reason Shown to the player, usually this will appear on their disconnect screen.
* @param Translatable|string|null $quitMessage Message to broadcast to online players (null will use default)
*/
public function onPostDisconnect(string $reason, Translatable|string|null $quitMessage) : void{
diff --git a/src/plugin/PluginBase.php b/src/plugin/PluginBase.php
index 9b0ac2399..a4c0f6ba4 100644
--- a/src/plugin/PluginBase.php
+++ b/src/plugin/PluginBase.php
@@ -45,6 +45,7 @@ use function stream_copy_to_stream;
use function strpos;
use function strtolower;
use function trim;
+use const DIRECTORY_SEPARATOR;
abstract class PluginBase implements Plugin, CommandExecutor{
private bool $isEnabled = false;
@@ -201,7 +202,7 @@ abstract class PluginBase implements Plugin, CommandExecutor{
}
/**
- * @param string[] $args
+ * @param string[] $args
*/
public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{
return false;
diff --git a/src/resourcepacks/ResourcePack.php b/src/resourcepacks/ResourcePack.php
index 93f446965..04feeeb3d 100644
--- a/src/resourcepacks/ResourcePack.php
+++ b/src/resourcepacks/ResourcePack.php
@@ -57,7 +57,7 @@ interface ResourcePack{
* Note that resource packs must **always** be in zip archive format for sending.
* A folder resource loader may need to perform on-the-fly compression for this purpose.
*
- * @param int $start Offset to start reading the chunk from
+ * @param int $start Offset to start reading the chunk from
* @param int $length Maximum length of data to return.
*
* @return string byte-array
diff --git a/src/resourcepacks/ResourcePackManager.php b/src/resourcepacks/ResourcePackManager.php
index d1482d8b6..c8b2cb389 100644
--- a/src/resourcepacks/ResourcePackManager.php
+++ b/src/resourcepacks/ResourcePackManager.php
@@ -58,7 +58,7 @@ class ResourcePackManager{
private array $encryptionKeys = [];
/**
- * @param string $path Path to resource-packs directory.
+ * @param string $path Path to resource-packs directory.
*/
public function __construct(string $path, \Logger $logger){
$this->path = $path;
diff --git a/src/scheduler/AsyncTask.php b/src/scheduler/AsyncTask.php
index 13a4f5781..9b8866f43 100644
--- a/src/scheduler/AsyncTask.php
+++ b/src/scheduler/AsyncTask.php
@@ -183,7 +183,7 @@ abstract class AsyncTask extends \Threaded{
* {@link AsyncTask::onCompletion} is called.
*
* @param mixed $progress The parameter passed to {@link AsyncTask#publishProgress}. It is serialize()'ed
- * and then unserialize()'ed, as if it has been cloned.
+ * and then unserialize()'ed, as if it has been cloned.
*/
public function onProgressUpdate($progress) : void{
diff --git a/src/scheduler/BulkCurlTaskOperation.php b/src/scheduler/BulkCurlTaskOperation.php
index cd6b478fd..3291d8718 100644
--- a/src/scheduler/BulkCurlTaskOperation.php
+++ b/src/scheduler/BulkCurlTaskOperation.php
@@ -26,7 +26,7 @@ namespace pocketmine\scheduler;
final class BulkCurlTaskOperation{
/**
* @param string[] $extraHeaders
- * @param mixed[] $extraOpts
+ * @param mixed[] $extraOpts
* @phpstan-param list $extraHeaders
* @phpstan-param array $extraOpts
*/
diff --git a/src/utils/BroadcastLoggerForwarder.php b/src/utils/BroadcastLoggerForwarder.php
index a015615b5..1900421fc 100644
--- a/src/utils/BroadcastLoggerForwarder.php
+++ b/src/utils/BroadcastLoggerForwarder.php
@@ -29,6 +29,7 @@ use pocketmine\lang\Translatable;
use pocketmine\permission\PermissibleBase;
use pocketmine\permission\PermissibleDelegateTrait;
use pocketmine\Server;
+use const PHP_INT_MAX;
/**
* Forwards any messages it receives via sendMessage() to the given logger. Used for forwarding chat messages and
diff --git a/src/utils/Config.php b/src/utils/Config.php
index cee137e32..861c8beb3 100644
--- a/src/utils/Config.php
+++ b/src/utils/Config.php
@@ -55,6 +55,7 @@ use const CASE_LOWER;
use const JSON_BIGINT_AS_STRING;
use const JSON_PRETTY_PRINT;
use const JSON_THROW_ON_ERROR;
+use const YAML_UTF8_ENCODING;
/**
* Config Class for simple config manipulation of multiple formats.
@@ -108,8 +109,8 @@ class Config{
];
/**
- * @param string $file Path of the file to be loaded
- * @param int $type Config type to load, -1 by default (detect)
+ * @param string $file Path of the file to be loaded
+ * @param int $type Config type to load, -1 by default (detect)
* @param mixed[] $default Array with the default values that will be written to the file if it did not exist
* @phpstan-param array $default
*/
@@ -469,7 +470,7 @@ class Config{
/**
* @param mixed[] $default
- * @param mixed[] $data reference parameter
+ * @param mixed[] $data reference parameter
* @phpstan-param array $default
* @phpstan-param array $data
* @phpstan-param-out array $data
diff --git a/src/utils/Filesystem.php b/src/utils/Filesystem.php
index 762d39c3b..39094c5b3 100644
--- a/src/utils/Filesystem.php
+++ b/src/utils/Filesystem.php
@@ -182,9 +182,10 @@ final class Filesystem{
* @throws \InvalidArgumentException if the lock file path is invalid (e.g. parent directory doesn't exist, permission denied)
*/
public static function createLockFile(string $lockFilePath) : ?int{
- $resource = fopen($lockFilePath, "a+b");
- if($resource === false){
- throw new \InvalidArgumentException("Invalid lock file path or read/write permissions denied");
+ try{
+ $resource = ErrorToExceptionHandler::trapAndRemoveFalse(fn() => fopen($lockFilePath, "a+b"));
+ }catch(\ErrorException $e){
+ throw new \InvalidArgumentException("Failed to open lock file: " . $e->getMessage(), 0, $e);
}
if(!flock($resource, LOCK_EX | LOCK_NB)){
//wait for a shared lock to avoid race conditions if two servers started at the same time - this makes sure the
diff --git a/src/utils/Git.php b/src/utils/Git.php
index 9d5744f06..041d795a1 100644
--- a/src/utils/Git.php
+++ b/src/utils/Git.php
@@ -36,7 +36,7 @@ final class Git{
/**
* Returns the git hash of the currently checked out head of the given repository, or null on failure.
*
- * @param bool $dirty reference parameter, set to whether the repo has local changes
+ * @param bool $dirty reference parameter, set to whether the repo has local changes
*/
public static function getRepositoryState(string $dir, bool &$dirty) : ?string{
if(Process::execute("git -C \"$dir\" rev-parse HEAD", $out) === 0 && $out !== false && strlen($out = trim($out)) === 40){
diff --git a/src/utils/Internet.php b/src/utils/Internet.php
index 87a90f488..07b3c7a33 100644
--- a/src/utils/Internet.php
+++ b/src/utils/Internet.php
@@ -137,9 +137,9 @@ class Internet{
*
* @phpstan-template TErrorVar of mixed
*
- * @param int $timeout default 10
+ * @param int $timeout default 10
* @param string[] $extraHeaders
- * @param string|null $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation.
+ * @param string|null $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation.
* @phpstan-param list $extraHeaders
* @phpstan-param TErrorVar $err
* @phpstan-param-out TErrorVar|string $err
@@ -161,7 +161,7 @@ class Internet{
*
* @param string[]|string $args
* @param string[] $extraHeaders
- * @param string|null $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occurred during the operation.
+ * @param string|null $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occurred during the operation.
* @phpstan-param string|array $args
* @phpstan-param list $extraHeaders
* @phpstan-param TErrorVar $err
@@ -183,7 +183,7 @@ class Internet{
* General cURL shorthand function.
* NOTE: This is a blocking operation and can take a significant amount of time. It is inadvisable to use this method on the main thread.
*
- * @param float $timeout The maximum connect timeout and timeout in seconds, correct to ms.
+ * @param float $timeout The maximum connect timeout and timeout in seconds, correct to ms.
* @param string[] $extraHeaders extra headers to send as a plain string array
* @param array $extraOpts extra CURLOPT_* to set as an [opt => value] map
* @param \Closure|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle.
diff --git a/src/utils/Process.php b/src/utils/Process.php
index d0d38ec00..e0265d0da 100644
--- a/src/utils/Process.php
+++ b/src/utils/Process.php
@@ -150,8 +150,8 @@ final class Process{
/**
* @param string $command Command to execute
- * @param string|null $stdout Reference parameter to write stdout to
- * @param string|null $stderr Reference parameter to write stderr to
+ * @param string|null $stdout Reference parameter to write stdout to
+ * @param string|null $stderr Reference parameter to write stderr to
* @phpstan-param-out string $stdout
* @phpstan-param-out string $stderr
*
diff --git a/src/utils/Random.php b/src/utils/Random.php
index 616a0d73d..77f655b89 100644
--- a/src/utils/Random.php
+++ b/src/utils/Random.php
@@ -114,7 +114,7 @@ class Random{
* Returns a random integer between $start and $end
*
* @param int $start default 0
- * @param int $end default 0x7fffffff
+ * @param int $end default 0x7fffffff
*/
public function nextRange(int $start = 0, int $end = 0x7fffffff) : int{
return $start + ($this->nextInt() % ($end + 1 - $start));
diff --git a/src/utils/Utils.php b/src/utils/Utils.php
index 4f3f6d577..e4abdd172 100644
--- a/src/utils/Utils.php
+++ b/src/utils/Utils.php
@@ -534,7 +534,7 @@ final class Utils{
* incompatible.
*
* @param callable|CallbackType $signature Dummy callable with the required parameters and return type
- * @param callable $subject Callable to check the signature of
+ * @param callable $subject Callable to check the signature of
* @phpstan-param anyCallable|CallbackType $signature
* @phpstan-param anyCallable $subject
*
diff --git a/src/world/World.php b/src/world/World.php
index a8b6a7c6d..5a19195ee 100644
--- a/src/world/World.php
+++ b/src/world/World.php
@@ -51,7 +51,9 @@ use pocketmine\event\world\ChunkLoadEvent;
use pocketmine\event\world\ChunkPopulateEvent;
use pocketmine\event\world\ChunkUnloadEvent;
use pocketmine\event\world\SpawnChangeEvent;
+use pocketmine\event\world\WorldParticleEvent;
use pocketmine\event\world\WorldSaveEvent;
+use pocketmine\event\world\WorldSoundEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemUseResult;
use pocketmine\item\LegacyStringToItemParser;
@@ -647,7 +649,7 @@ class World implements ChunkManager{
* Returns a list of players who are in the given filter and also using the chunk containing the target position.
* Used for broadcasting sounds and particles with specific targets.
*
- * @param Player[] $allowed
+ * @param Player[] $allowed
* @phpstan-param list $allowed
*
* @return array
@@ -669,9 +671,19 @@ class World implements ChunkManager{
* @param Player[]|null $players
*/
public function addSound(Vector3 $pos, Sound $sound, ?array $players = null) : void{
- $pk = $sound->encode($pos);
+ $players ??= $this->getViewersForPosition($pos);
+ $ev = new WorldSoundEvent($this, $sound, $pos, $players);
+
+ $ev->call();
+
+ if($ev->isCancelled()){
+ return;
+ }
+
+ $pk = $ev->getSound()->encode($pos);
+ $players = $ev->getRecipients();
if(count($pk) > 0){
- if($players === null){
+ if($players === $this->getViewersForPosition($pos)){
foreach($pk as $e){
$this->broadcastPacketToViewers($pos, $e);
}
@@ -685,14 +697,24 @@ class World implements ChunkManager{
* @param Player[]|null $players
*/
public function addParticle(Vector3 $pos, Particle $particle, ?array $players = null) : void{
- $pk = $particle->encode($pos);
+ $players ??= $this->getViewersForPosition($pos);
+ $ev = new WorldParticleEvent($this, $particle, $pos, $players);
+
+ $ev->call();
+
+ if($ev->isCancelled()){
+ return;
+ }
+
+ $pk = $ev->getParticle()->encode($pos);
+ $players = $ev->getRecipients();
if(count($pk) > 0){
- if($players === null){
+ if($players === $this->getViewersForPosition($pos)){
foreach($pk as $e){
$this->broadcastPacketToViewers($pos, $e);
}
}else{
- $this->server->broadcastPackets($this->filterViewersForPosition($pos, $players), $pk);
+ $this->server->broadcastPackets($this->filterViewersForPosition($pos, $ev->getRecipients()), $pk);
}
}
}
@@ -1657,8 +1679,8 @@ class World implements ChunkManager{
* Note: If you're using this for performance-sensitive code, and you're guaranteed to be supplying ints in the
* specified vector, consider using {@link getBlockAt} instead for better performance.
*
- * @param bool $cached Whether to use the block cache for getting the block (faster, but may be inaccurate)
- * @param bool $addToCache Whether to cache the block object created by this method call.
+ * @param bool $cached Whether to use the block cache for getting the block (faster, but may be inaccurate)
+ * @param bool $addToCache Whether to cache the block object created by this method call.
*/
public function getBlock(Vector3 $pos, bool $cached = true, bool $addToCache = true) : Block{
return $this->getBlockAt((int) floor($pos->x), (int) floor($pos->y), (int) floor($pos->z), $cached, $addToCache);
@@ -1670,7 +1692,7 @@ class World implements ChunkManager{
* Note for plugin developers: If you are using this method a lot (thousands of times for many positions for
* example), you may want to set addToCache to false to avoid using excessive amounts of memory.
*
- * @param bool $cached Whether to use the block cache for getting the block (faster, but may be inaccurate)
+ * @param bool $cached Whether to use the block cache for getting the block (faster, but may be inaccurate)
* @param bool $addToCache Whether to cache the block object created by this method call.
*/
public function getBlockAt(int $x, int $y, int $z, bool $cached = true, bool $addToCache = true) : Block{
@@ -1821,7 +1843,7 @@ class World implements ChunkManager{
* Tries to break a block using a item, including Player time checks if available
* It'll try to lower the durability if Item is a tool, and set it to Air if broken.
*
- * @param Item &$item reference parameter (if null, can break anything)
+ * @param Item &$item reference parameter (if null, can break anything)
* @param Item[] &$returnedItems Items to be added to the target's inventory (or dropped, if the inventory is full)
* @phpstan-param-out Item $item
*/
@@ -1927,8 +1949,8 @@ class World implements ChunkManager{
/**
* Uses a item on a position and face, placing it or activating the block
*
- * @param Player|null $player default null
- * @param bool $playSound Whether to play a block-place sound if the block was placed successfully.
+ * @param Player|null $player default null
+ * @param bool $playSound Whether to play a block-place sound if the block was placed successfully.
* @param Item[] &$returnedItems Items to be added to the target's inventory (or dropped if the inventory is full)
*/
public function useItemOn(Vector3 $vector, Item &$item, int $face, ?Vector3 $clickVector = null, ?Player $player = null, bool $playSound = false, array &$returnedItems = []) : bool{
@@ -2122,8 +2144,8 @@ class World implements ChunkManager{
/**
* Returns the closest Entity to the specified position, within the given radius.
*
- * @param string $entityType Class of entity to use for instanceof
- * @param bool $includeDead Whether to include entitites which are dead
+ * @param string $entityType Class of entity to use for instanceof
+ * @param bool $includeDead Whether to include entitites which are dead
* @phpstan-template TEntity of Entity
* @phpstan-param class-string $entityType
*
diff --git a/src/world/WorldManager.php b/src/world/WorldManager.php
index 1c26d494b..80561298d 100644
--- a/src/world/WorldManager.php
+++ b/src/world/WorldManager.php
@@ -166,7 +166,7 @@ class WorldManager{
/**
* Loads a world from the data directory
*
- * @param bool $autoUpgrade Converts worlds to the default format if the world's format is not writable / deprecated
+ * @param bool $autoUpgrade Converts worlds to the default format if the world's format is not writable / deprecated
*
* @throws WorldException
*/
diff --git a/src/world/format/Chunk.php b/src/world/format/Chunk.php
index 423fe0bef..e6b4780c6 100644
--- a/src/world/format/Chunk.php
+++ b/src/world/format/Chunk.php
@@ -160,8 +160,8 @@ class Chunk{
/**
* Sets the biome ID at the specified X/Z chunk block coordinates
*
- * @param int $x 0-15
- * @param int $z 0-15
+ * @param int $x 0-15
+ * @param int $z 0-15
* @param int $biomeId 0-255
*/
public function setBiomeId(int $x, int $z, int $biomeId) : void{
diff --git a/src/world/format/io/leveldb/LevelDB.php b/src/world/format/io/leveldb/LevelDB.php
index 5d8c899a0..13514261b 100644
--- a/src/world/format/io/leveldb/LevelDB.php
+++ b/src/world/format/io/leveldb/LevelDB.php
@@ -561,7 +561,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
}
/**
- * @param CompoundTag[] $targets
+ * @param CompoundTag[] $targets
*/
private function writeTags(array $targets, string $index, \LevelDBWriteBatch $write) : void{
if(count($targets) > 0){
diff --git a/src/world/generator/FlatGeneratorOptions.php b/src/world/generator/FlatGeneratorOptions.php
index 3cda876cd..ab10c8a47 100644
--- a/src/world/generator/FlatGeneratorOptions.php
+++ b/src/world/generator/FlatGeneratorOptions.php
@@ -38,7 +38,7 @@ use function preg_match_all;
final class FlatGeneratorOptions{
/**
- * @param int[] $structure
+ * @param int[] $structure
* @param mixed[] $extraOptions
* @phpstan-param array $structure
* @phpstan-param array|true> $extraOptions
diff --git a/src/world/generator/GeneratorManager.php b/src/world/generator/GeneratorManager.php
index e94d2336a..a00edd559 100644
--- a/src/world/generator/GeneratorManager.php
+++ b/src/world/generator/GeneratorManager.php
@@ -58,10 +58,10 @@ final class GeneratorManager{
}
/**
- * @param string $class Fully qualified name of class that extends \pocketmine\world\generator\Generator
- * @param string $name Alias for this generator type that can be written in configs
- * @param \Closure $presetValidator Callback to validate generator options for new worlds
- * @param bool $overwrite Whether to force overwriting any existing registered generator with the same name
+ * @param string $class Fully qualified name of class that extends \pocketmine\world\generator\Generator
+ * @param string $name Alias for this generator type that can be written in configs
+ * @param \Closure $presetValidator Callback to validate generator options for new worlds
+ * @param bool $overwrite Whether to force overwriting any existing registered generator with the same name
*
* @phpstan-param \Closure(string) : ?InvalidGeneratorOptionsException $presetValidator
*
diff --git a/src/world/light/SkyLightUpdate.php b/src/world/light/SkyLightUpdate.php
index d0a17af5f..d77f1de5b 100644
--- a/src/world/light/SkyLightUpdate.php
+++ b/src/world/light/SkyLightUpdate.php
@@ -208,8 +208,8 @@ class SkyLightUpdate extends LightUpdate{
/**
* Recalculates the heightmap for the block column at the specified X/Z chunk coordinates
*
- * @param int $x 0-15
- * @param int $z 0-15
+ * @param int $x 0-15
+ * @param int $z 0-15
* @param true[] $directSkyLightBlockers
* @phpstan-param array $directSkyLightBlockers
*
diff --git a/tests/phpunit/block/BlockTest.php b/tests/phpunit/block/BlockTest.php
index 69848492e..7404b15e3 100644
--- a/tests/phpunit/block/BlockTest.php
+++ b/tests/phpunit/block/BlockTest.php
@@ -29,6 +29,7 @@ use function file_get_contents;
use function is_array;
use function json_decode;
use function print_r;
+use const SORT_STRING;
class BlockTest extends TestCase{
diff --git a/tests/phpunit/network/mcpe/handler/StupidJsonDecodeTest.php b/tests/phpunit/network/mcpe/handler/StupidJsonDecodeTest.php
index 99890b402..6a48bd1ba 100644
--- a/tests/phpunit/network/mcpe/handler/StupidJsonDecodeTest.php
+++ b/tests/phpunit/network/mcpe/handler/StupidJsonDecodeTest.php
@@ -57,7 +57,7 @@ class StupidJsonDecodeTest extends TestCase{
/**
* @dataProvider stupidJsonDecodeProvider
*
- * @param mixed $expect
+ * @param mixed $expect
*
* @throws \ReflectionException
*/
diff --git a/tools/compact-regions.php b/tools/compact-regions.php
index beb764060..6959c82fe 100644
--- a/tools/compact-regions.php
+++ b/tools/compact-regions.php
@@ -43,6 +43,10 @@ use function rename;
use function round;
use function scandir;
use function unlink;
+use const PATHINFO_EXTENSION;
+use const PHP_BINARY;
+use const SCANDIR_SORT_NONE;
+use const SORT_NUMERIC;
require dirname(__DIR__) . '/vendor/autoload.php';
diff --git a/tools/decode-crashdump.php b/tools/decode-crashdump.php
index b73cc201f..26a5d144f 100644
--- a/tools/decode-crashdump.php
+++ b/tools/decode-crashdump.php
@@ -37,6 +37,8 @@ use function realpath;
use function trim;
use function zlib_decode;
use const FILE_IGNORE_NEW_LINES;
+use const JSON_PRETTY_PRINT;
+use const JSON_UNESCAPED_SLASHES;
use const PHP_EOL;
use const STDERR;
diff --git a/tools/generate-block-palette-spec.php b/tools/generate-block-palette-spec.php
index 2bcee5a13..bb8505b77 100644
--- a/tools/generate-block-palette-spec.php
+++ b/tools/generate-block-palette-spec.php
@@ -40,6 +40,9 @@ use function fwrite;
use function get_class;
use function json_encode;
use function ksort;
+use const JSON_PRETTY_PRINT;
+use const SORT_STRING;
+use const STDERR;
require dirname(__DIR__) . '/vendor/autoload.php';
diff --git a/tools/generate-blockstate-upgrade-schema.php b/tools/generate-blockstate-upgrade-schema.php
index db13f00e5..abf0be797 100644
--- a/tools/generate-blockstate-upgrade-schema.php
+++ b/tools/generate-blockstate-upgrade-schema.php
@@ -41,6 +41,8 @@ use function file_put_contents;
use function fwrite;
use function json_encode;
use function ksort;
+use const JSON_PRETTY_PRINT;
+use const SORT_STRING;
use const STDERR;
require_once dirname(__DIR__) . '/vendor/autoload.php';
@@ -82,7 +84,7 @@ function loadUpgradeTable(string $file, bool $reverse) : array{
}
/**
- * @param true[] $removedPropertiesCache
+ * @param true[] $removedPropertiesCache
* @param Tag[][] $remappedPropertyValuesCache
* @phpstan-param array $removedPropertiesCache
* @phpstan-param array> $remappedPropertyValuesCache
diff --git a/tools/generate-item-upgrade-schema.php b/tools/generate-item-upgrade-schema.php
index 31a7467bf..0f59bebe0 100644
--- a/tools/generate-item-upgrade-schema.php
+++ b/tools/generate-item-upgrade-schema.php
@@ -40,6 +40,11 @@ use function json_decode;
use function json_encode;
use function ksort;
use function scandir;
+use const JSON_FORCE_OBJECT;
+use const JSON_PRETTY_PRINT;
+use const JSON_THROW_ON_ERROR;
+use const SCANDIR_SORT_ASCENDING;
+use const SORT_STRING;
require dirname(__DIR__) . '/vendor/autoload.php';
diff --git a/tools/ping-server.php b/tools/ping-server.php
index 83a997bbd..1784d0988 100644
--- a/tools/ping-server.php
+++ b/tools/ping-server.php
@@ -49,9 +49,13 @@ use function socket_strerror;
use function strlen;
use function time;
use function trim;
+use const AF_INET;
use const MSG_DONTROUTE;
use const PHP_BINARY;
use const PHP_INT_MAX;
+use const SOCK_DGRAM;
+use const SOL_UDP;
+use const STDIN;
require_once 'vendor/autoload.php';