Compare commits

...

307 Commits

Author SHA1 Message Date
2fb4704269 Release 3.22.4 2021-09-05 15:47:54 +01:00
0c0eb72b1b make-release: display the current and next version numbers 2021-09-05 15:46:40 +01:00
466107d3b8 actions: fix release build shitting the bed 2021-09-05 15:45:07 +01:00
4f59d3487a 3.22.4 is next 2021-09-05 15:42:39 +01:00
65220b4f7f Release 3.22.3 2021-09-05 15:42:38 +01:00
85eb6b30a5 Player: do not allow doFirstSpawn() to be executed before the constructor is called
this problem doesn't exist on PM4.
2021-09-05 15:38:14 +01:00
1c2eb35025 actions: fixed bad git hash on published releases 2021-09-05 15:32:31 +01:00
85ed7efcb4 PHPStan 0.12.98 2021-09-03 11:50:18 +01:00
183489e863 PHPUnit 9.5.9 2021-09-03 11:47:31 +01:00
ac060f2ec6 Update build/php submodule to pmmp/php-build-scripts@e55c60f176 2021-09-03 11:45:43 +01:00
6c85d4d254 CommandReader: fixed CS with php-cs-fixer 3.1.0 2021-08-29 23:35:07 +01:00
f506c922b5 phpstan.neon.dist: fix indentation inconsistency
fuck you, phpstorm!

it doesn't have an option to use tabs for indentation in YAML, and YAML is the closest thing to NEON, so ...
2021-08-29 23:19:35 +01:00
a5b08fc8f2 Rewrite CONTRIBUTING.md to be more developer-oriented 2021-08-27 15:05:57 +01:00
c3c4c80b70 SECURITY: drop supported versions table
this isn't actively maintained, so it's misleading.
[ci skip]
2021-08-27 13:53:01 +01:00
5695fa9086 CONTRIBUTING: fixed a broken link
[ci skip]
2021-08-27 13:51:16 +01:00
f78808bad0 Bump phpstan/phpstan-strict-rules from 0.12.10 to 0.12.11 (#4401)
Bumps [phpstan/phpstan-strict-rules](https://github.com/phpstan/phpstan-strict-rules) from 0.12.10 to 0.12.11.
- [Release notes](https://github.com/phpstan/phpstan-strict-rules/releases)
- [Commits](https://github.com/phpstan/phpstan-strict-rules/compare/0.12.10...0.12.11)

---
updated-dependencies:
- dependency-name: phpstan/phpstan-strict-rules
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-25 20:41:11 +01:00
dc0082162b Bump phpstan/phpstan from 0.12.95 to 0.12.96 (#4397)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.95 to 0.12.96.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.95...0.12.96)

---
updated-dependencies:
- dependency-name: phpstan/phpstan
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-23 13:53:20 +01:00
ff4aa148ef phpstan 0.12.95 2021-08-20 22:47:29 +01:00
63e86fe806 Config: fixed incorrect fluent @return annotations 2021-08-20 14:44:59 +01:00
ab05bc7379 Replace some references to Pocket Edition with Bedrock Edition
closes #4387
2021-08-20 14:23:11 +01:00
1a395a51c9 Fixing function import inconsistencies since php-cs-fixer 3.0 migration 2021-08-19 15:26:45 +01:00
142c8f067b fix CS in php-cs-fixer config
unfortunately i can't seem to make it fix itself
2021-08-19 15:25:20 +01:00
cd3c96aad2 shivammathur/setup-php 2.12.0 2021-08-19 02:31:18 +01:00
19c47fa71f 3.22.3 is next 2021-08-18 14:14:58 +01:00
d670bc8bf8 Release 3.22.2 2021-08-18 14:14:54 +01:00
7bd8d09023 GitHub Actions: automatically build and upload release artifacts, and auto-update update.pmmp.io (#4376) 2021-08-18 14:02:52 +01:00
5a970541f9 actions: use newer pthreads version 2021-08-16 23:15:47 +01:00
e561fa6222 actions: update PHP versions 2021-08-16 23:14:17 +01:00
025dde19ce Bump phpstan/phpstan-phpunit from 0.12.21 to 0.12.22 (#4367)
Bumps [phpstan/phpstan-phpunit](https://github.com/phpstan/phpstan-phpunit) from 0.12.21 to 0.12.22.
- [Release notes](https://github.com/phpstan/phpstan-phpunit/releases)
- [Commits](https://github.com/phpstan/phpstan-phpunit/compare/0.12.21...0.12.22)

---
updated-dependencies:
- dependency-name: phpstan/phpstan-phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-13 12:51:34 +01:00
28bfe9fbb4 emit_performance_warnings(): Log a warning when using a PHP debug build 2021-08-11 20:14:03 +01:00
cd53fa162b Merge branch 'stable' of github.com:pmmp/PocketMine-MP into stable 2021-08-03 20:22:41 +01:00
748e9705ba Updated build/php submodule to pmmp/php-build-scripts@49971716b0 2021-08-03 20:20:56 +01:00
219ed81389 Player: Fixed items on the crafting grid disappearing when the player disconnects (#4344) 2021-08-02 19:48:36 +01:00
6a7196530c Bump phpunit/phpunit from 9.5.7 to 9.5.8 (#4345)
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.5.7 to 9.5.8.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-9.5.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.5.7...9.5.8)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-02 11:52:17 +01:00
01fe497c49 phpstan: use PHP 8.0 as primary version
I'm using 8.0 for local development now, so having the phpstan configs targeted at 7.4 by default makes things inconvenient.
2021-07-26 14:34:47 +01:00
3bbd088a09 Update build/php submodule to pmmp/php-build-scripts@280dd0524a 2021-07-24 22:40:28 +01:00
85effa5240 Remove junk from php8 baseline 2021-07-23 15:56:06 +01:00
81c5b83bd9 actions: test on 8.0 2021-07-23 15:55:01 +01:00
ef31a9fc66 Update bug_report.md 2021-07-23 13:32:18 +01:00
dc56a99473 3.22.2 is next 2021-07-23 13:03:27 +01:00
9477034a4a Release 3.22.1 2021-07-23 13:03:27 +01:00
5844b59b12 Fixed incorrect encoding of NpcDialoguePacket
this is in fact an ActorUniqueID, but for some reason written as a uint64 instead of a varint.
2021-07-23 12:53:30 +01:00
3af18917f0 Player: remove note about bans from getUniqueId()
while it's true that you might be able to skip the CPU waste from verifying a player's login just to find out that they are banned, this is generally a minority case anyway, so it doesn't make a lot of difference overall. This additional note is essentially a recommendation premature optimisation, which will likely lead to people making security mistakes.
2021-07-22 22:14:14 +01:00
61528393c2 Player: rewrite the confusing documentation of getUniqueId() 2021-07-22 21:14:31 +01:00
59b8453228 Player: added extra debug message for XUID mismatches 2021-07-22 21:04:40 +01:00
8cb48bfe1d Bump phpunit/phpunit from 9.5.6 to 9.5.7 (#4322)
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.5.6 to 9.5.7.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-9.5.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.5.6...9.5.7)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-19 12:48:11 +01:00
8fb4d7b982 BUILDING.md: Changed pre-requisites PHP version to 7.4 or newer (#4319)
[ci skip]
2021-07-18 00:08:14 +01:00
13f114f30e bootstrap: report loaded php.ini in error, as well as php binary path
in some cases extension loading issues are caused by incorrect php.ini path, which should be easy to spot if the path is given.
2021-07-17 21:50:30 +01:00
eccd258aeb start.cmd: fixed incorrect php.ini scan dir when using a non-local binary 2021-07-17 21:49:11 +01:00
bd5f379c4c apparently opcache_get_status() may return false? 2021-07-17 21:11:12 +01:00
2588895ab0 bootstrap: add a giant yellow warning about JIT 2021-07-17 19:00:19 +01:00
432999a7d7 Bump phpstan/phpstan-phpunit from 0.12.20 to 0.12.21 (#4313)
Bumps [phpstan/phpstan-phpunit](https://github.com/phpstan/phpstan-phpunit) from 0.12.20 to 0.12.21.
- [Release notes](https://github.com/phpstan/phpstan-phpunit/releases)
- [Commits](https://github.com/phpstan/phpstan-phpunit/compare/0.12.20...0.12.21)

---
updated-dependencies:
- dependency-name: phpstan/phpstan-phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-15 22:32:47 +01:00
68699dbff9 PlayerAuthInputFlags: Fixed a mistake in the documentation 2021-07-14 21:08:23 +01:00
bfbe3d83de 3.22.1 is next 2021-07-13 18:31:34 +01:00
c32c21464c Release 3.22.0 2021-07-13 18:31:28 +01:00
16faafa1ef Merge branch 'stable' of github.com:pmmp/PocketMine-MP into stable 2021-07-13 18:11:03 +01:00
4d6ac57a26 Fixed particle IDs 2021-07-13 17:54:40 +01:00
73ba1ba224 Bump phpstan/phpstan from 0.12.91 to 0.12.92 (#4309)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.91 to 0.12.92.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.91...0.12.92)

---
updated-dependencies:
- dependency-name: phpstan/phpstan
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-12 12:35:35 +01:00
8b79253d3b Protocol changes for 1.17.10 2021-07-09 19:29:34 +01:00
1122131c8d 3.21.2 is next 2021-07-05 18:49:26 +01:00
a50ef2af6f Release 3.21.1 2021-07-05 18:49:26 +01:00
72e4660800 Updated build/php submodule to pmmp/php-build-scripts@4bf8ec1ad0 2021-07-05 18:42:35 +01:00
e6285a0312 Update composer transitive dependencies 2021-07-05 17:22:32 +01:00
5420e76a9a Bump phpstan/phpstan-strict-rules from 0.12.9 to 0.12.10 (#4295) 2021-07-05 13:20:03 +00:00
de46a81cf4 Bump phpstan/phpstan from 0.12.90 to 0.12.91 (#4296)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.90 to 0.12.91.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.90...0.12.91)

---
updated-dependencies:
- dependency-name: phpstan/phpstan
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-05 14:07:49 +01:00
0cdc04f9b5 Player: Fixed so-called 'pot lag'
this occurred because of transactions arriving before MobEquipmentPacket updating the player's own held item slot. This was only a problem while rapidly changing hotbar slots and simultaneously using items, like projectiles.
closes #4168
2021-06-26 18:56:30 +01:00
8b1a84f2bf Bump phpunit/phpunit from 9.5.5 to 9.5.6 (#4282)
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.5.5 to 9.5.6.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-9.5.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.5.5...9.5.6)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-26 16:49:19 +01:00
155e516f74 phpstan 0.12.90 2021-06-18 18:46:30 +01:00
ea0a47dff7 Updated transitive composer dependency junk 2021-06-18 18:42:08 +01:00
0a6ce18322 CrashDump: Sort plugins list 2021-06-17 20:56:49 +01:00
11d73e5bb8 Bump phpstan/phpstan-phpunit from 0.12.19 to 0.12.20 (#4273)
Bumps [phpstan/phpstan-phpunit](https://github.com/phpstan/phpstan-phpunit) from 0.12.19 to 0.12.20.
- [Release notes](https://github.com/phpstan/phpstan-phpunit/releases)
- [Commits](https://github.com/phpstan/phpstan-phpunit/compare/0.12.19...0.12.20)

---
updated-dependencies:
- dependency-name: phpstan/phpstan-phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-17 15:30:01 +01:00
492ad6bb66 3.21.1 is next 2021-06-13 15:38:22 +01:00
82e8eb46ac Release 3.21.0 2021-06-13 15:38:22 +01:00
c7868a810d Move PHP minimum to 7.4
7.3 isn't actively tested anymore, and since 7.4 has been out for so long already, it doesn't make sense to keep pandering to users who can't be bothered to update their PHP binaries.
In most cases, these users are also experiencing problems caused by older versions of pthreads that were long since fixed.
In addition, pthreads is no longer tested or supported on 7.3, so users can't get newer bug fixes even if they wanted to.
2021-06-13 15:34:24 +01:00
2cc22a29c1 Update composer dependencies 2021-06-13 14:40:46 +01:00
8e2829bdd4 Remove movement workaround from 1.14.30 (#4246) 2021-06-13 14:32:40 +01:00
af79e787ea Bump phpstan/phpstan from 0.12.88 to 0.12.89 (#4262)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.88 to 0.12.89.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.88...0.12.89)

---
updated-dependencies:
- dependency-name: phpstan/phpstan
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-10 15:10:45 +01:00
65c53e6512 actions: use PHP 7.4.20 2021-06-09 13:44:00 +01:00
5503fadf13 3.20.1 is next 2021-06-08 20:21:55 +01:00
99964709c9 Release 3.20.0 2021-06-08 20:21:55 +01:00
b85f3bd149 make-release: abort on no changelog changes 2021-06-08 20:20:30 +01:00
57d274901d Protocol changes for 1.17.0 2021-06-08 19:40:28 +01:00
f3e1c82246 this again :thonkingtempered: 2021-06-08 19:27:49 +01:00
908b627846 3.19.4 is next 2021-06-08 18:52:01 +01:00
afb21c1df2 Release 3.19.3 2021-06-08 18:51:48 +01:00
988be2a96b Bump phpunit/phpunit from 9.5.4 to 9.5.5 (#4247)
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.5.4 to 9.5.5.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-9.5.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.5.4...9.5.5)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-07 21:57:21 +01:00
afe67f7502 Updated build/php submodule to pmmp/php-build-scripts@0a0ac2abb3 2021-06-05 20:18:58 +01:00
b257348a3a Renamed fields of AddEntityPacket and RemoveEntityPacket 2021-06-04 17:18:24 +01:00
12c66d3362 CraftingDataPacket: fixed assert failure on debug builds 2021-06-04 17:13:50 +01:00
92fd2d35a4 SetDisplayObjectivePacket: added order and display slot constants (#4232) 2021-05-24 20:33:24 +01:00
61077c48f1 Worker: fixed quit() usually being useless
Worker::isRunning() returns false after it exits the run() function, even if tasks are stacked and it isn't shutdown.
While this is mostly harmless (since the internal destructor will join the thread anyway), this should be fixed anyway.
2021-05-21 01:24:07 +01:00
e0c61071e1 3.19.3 is next 2021-05-19 22:53:31 +01:00
813d431208 Release 3.19.2 2021-05-19 22:53:30 +01:00
ee112b992d Bump phpstan/phpstan from 0.12.87 to 0.12.88 (#4222)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.87 to 0.12.88.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.87...0.12.88)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-19 00:18:48 +01:00
c9b33e2b9f Bump phpstan/phpstan-phpunit from 0.12.18 to 0.12.19 (#4214)
Bumps [phpstan/phpstan-phpunit](https://github.com/phpstan/phpstan-phpunit) from 0.12.18 to 0.12.19.
- [Release notes](https://github.com/phpstan/phpstan-phpunit/releases)
- [Commits](https://github.com/phpstan/phpstan-phpunit/compare/0.12.18...0.12.19)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-13 15:17:18 +01:00
2f2be84b12 Bump phpstan/phpstan from 0.12.86 to 0.12.87 (#4217)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.86 to 0.12.87.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.86...0.12.87)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-13 12:25:25 +01:00
5a7736b179 actions: go with PHP 7.4.19 2021-05-10 20:30:08 +01:00
e648f1c91e Remove unnecessary script copy 2021-05-10 17:55:52 +01:00
5116e11cea Only install the stuff we need to run PHP, not to build it 2021-05-10 17:55:52 +01:00
9c05e37fbe Bump phpstan/phpstan from 0.12.85 to 0.12.86 (#4212)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.85 to 0.12.86.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.85...0.12.86)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-10 16:53:43 +01:00
fb4796f35e Added PhpStorm code style and file templates 2021-05-07 20:44:46 +01:00
0c2ba66078 Updated build/php submodule to pmmp/php-build-scripts@07129c61d6 2021-05-05 22:15:48 +01:00
c29cd8e2eb actions: added PHP script to update versions 2021-05-04 22:21:45 +01:00
a13b0c98a1 Updated to PHP-CS-Fixer 3.0.0 2021-05-04 22:18:18 +01:00
e6ff908e18 actions: update PHP versions 2021-05-04 21:52:17 +01:00
c47ecb55c0 Sign: Do not allow edits by any player except the one who placed it, and only while that player is online
signs now become finalized if:
- the player quits and rejoins (because the entity runtime ID of the player will not be the same)
- the chunk is unloaded and reloaded (because the tagged entity runtime ID is not saved).

closes #4198
2021-05-02 13:22:31 +01:00
c19d2fe891 Bump phpstan/phpstan from 0.12.84 to 0.12.85 (#4199)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.84 to 0.12.85.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.84...0.12.85)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2021-05-01 23:24:49 +01:00
f195f24f4f Upgrade to GitHub-native Dependabot (#4201) 2021-05-01 23:24:35 +01:00
4b5f279a3e UseItemOnEntityTransactionData: added missing type 2021-04-29 19:13:52 +01:00
89260d788c 3.19.2 is next 2021-04-25 20:34:13 +01:00
a7cd081002 Release 3.19.1 2021-04-25 20:34:13 +01:00
361be8fe36 Normal: drop MOUNTAINS and SMALL_MOUNTAINS from biome selection
this would cause disruption to generation on a patch release, which is unacceptable.
This would be better for 3.20 or 4.0.
2021-04-25 20:27:19 +01:00
b01e4ab417 Bump phpstan/phpstan from 0.12.83 to 0.12.84 (#4189) 2021-04-21 18:49:08 +00:00
177b963d8e TaskScheduler: do not push cancelled repeating tasks back onto the queue 2021-04-19 13:23:31 +01:00
8d1a1628de Item: Remove "ench" tag when all enchantments are removed from an item (#4184)
fixes #4144
2021-04-18 20:56:07 +01:00
6f80b8979d Particle: added some missing IDs 2021-04-16 18:20:47 +01:00
3c8eb29d4e Limit blockitem metadata hack to just blockitems
for some reason putting NBT on some items makes the creative inventory go haywire. Sadly, we currently need this hack, so I limit it to only stuff which actually needs it (blockitems).
closes #4159
2021-04-16 00:41:19 +01:00
b94bbf6f5e Merge branch 'stable' of github.com:pmmp/PocketMine-MP into stable 2021-04-16 00:11:01 +01:00
314a8a1297 protocol: updated particle type constants
closes #4173
2021-04-16 00:10:48 +01:00
547503e8f4 Normal: Fixed bug that never lets mountainous terrain generate (#4170) 2021-04-13 17:56:57 +01:00
f74ff1fcd4 Bump adhocore/json-comment from 1.1.0 to 1.1.2 (#4158)
Bumps [adhocore/json-comment](https://github.com/adhocore/php-json-comment) from 1.1.0 to 1.1.2.
- [Release notes](https://github.com/adhocore/php-json-comment/releases)
- [Changelog](https://github.com/adhocore/php-json-comment/blob/main/CHANGELOG.md)
- [Commits](https://github.com/adhocore/php-json-comment/compare/1.1.0...1.1.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2021-04-11 16:03:41 +01:00
6c351357ab NetworkBinaryStream: bail if finding unexpected trailing data on item extradata
this may help to discover additional bugs and/or missing data on items that we don't know about yet.
2021-04-11 16:02:41 +01:00
3433406cff 3.19.1 is next 2021-04-07 19:03:36 +01:00
b307cd0aa1 Release 3.19.0 2021-04-07 19:03:36 +01:00
c9b83d7276 Protocol changes for 1.16.220 2021-04-07 18:59:01 +01:00
e22b6ff566 Revert "Revert "Backport InventoryTransactionPacket impl from PM4""
This reverts commit c7cdaeae85.
2021-04-07 18:42:07 +01:00
af88f49a21 3.18.3 is next 2021-04-07 18:32:14 +01:00
599d5253db Release 3.18.2 2021-04-07 18:32:10 +01:00
54cb5ee0fa ItemTranslator: ensure that the correct meta value is returned after translation
-1 is a PM-specific thing. Right now there is a hack in the NetworkBinaryStream which prevents this from becoming a problem, but that might not be the case in future.
2021-04-07 13:10:29 +01:00
cdae8b42eb Bump adhocore/json-comment to ^1.1.0, new version strips trailing comma as well (#4146) 2021-04-06 11:58:23 +01:00
Ali
a45a4a91ae Call InventoryCloseEvent in Player::removeWindow() (#4142)
closes #4130
2021-04-04 01:07:58 +01:00
21378b7f27 Regenerate PHPStan baselines
this should be the last time we get baselines randomly rearranging themselves on changes ...
2021-04-03 22:36:15 +01:00
502aed41b0 phpstan 0.12.83 2021-04-03 22:34:48 +01:00
125837324f Player: don't dump cursor contents on mouseover interaction
this can fire while the player has the inventory window open, because it also gets sent when the player swaps their held itemstack for something new.

We already had a special-case for mouseover with entity ID 0, but since
this isn't just a zero problem, a more general fix suits better
(particularly since we might need to handle the 0 case anyway).

closes #4140
closes #4141
2021-04-02 21:35:38 +01:00
Ali
609dff1aae Player: Revert invalid attempts to toggle flight, instead of kicking (#4139)
If allowFlight was toggled by the server (e.g. due to gamemode change), a race could occur due to network latency where the client could try to enable flight, and then get kicked for cheating.

Since this can happen in legitimate, non-cheating cases, we can't make any assumptions about whether a player is cheating, so instead we just revert it, like we do with every other bad input.
2021-04-01 17:57:26 +01:00
b03212053c 3.18.2 is next 2021-03-28 21:24:07 +01:00
fd4ac885bb Release 3.18.1 2021-03-28 21:24:03 +01:00
f35886f18a Updated composer dependencies 2021-03-28 21:14:02 +01:00
a9eaa55427 actions: added a php-cs-fixer run 2021-03-28 20:38:56 +01:00
5c41f79be4 Added php-cs-fixer configuration
this is by no means a complete code style guide, but it fixes a lot of common issues that show up, particularly in PRs.
2021-03-28 19:21:41 +01:00
34c2b62ffe Remove unused import 2021-03-28 19:12:18 +01:00
e42a691da9 Strip trailing whitespace 2021-03-28 19:02:51 +01:00
Ali
3b3fb5e662 fix ItemFrames (#4101)
removing items from item frames was broken due to behavioural changes in 1.16.210.
2021-03-28 18:53:46 +01:00
01ffe8bf57 Updated build/php submodule to pmmp/php-build-scripts@c64baa0f1c 2021-03-28 18:14:40 +01:00
4abf4aecad MainLogger: fixed potential deadlock during syncFlushBuffer()
the notify() to flush the buffer might arrive in between the writeLogStream() and synchronized() calls in the thread body, resulting in a deadlock if the logger thread managed to call wait() before the main thread did.
2021-03-28 18:10:23 +01:00
b29f83ee99 Added preprocessor test build job to Actions
this should catch problems like the one that broke 3.17.6 at the root.
2021-03-25 01:25:04 +00:00
4bc57f00b8 Updated LevelSoundEventPacket constants 2021-03-23 23:36:48 +00:00
ff61e1e018 ClientCacheBlobStatusPacket: fixed field order
miss comes first, not hit.
2021-03-23 19:52:25 +00:00
fb20bb3832 Don't handle NAN/INF in movements 2021-03-23 14:54:39 +00:00
3333df31df Bump phpunit/phpunit from 9.5.3 to 9.5.4 (#4104)
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.5.3 to 9.5.4.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-9.5.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.5.3...9.5.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2021-03-23 13:53:45 +00:00
c09fcb2df2 Merge branch 'stable' of github.com:pmmp/PocketMine-MP into stable 2021-03-22 21:22:56 +00:00
c7cdaeae85 Revert "Backport InventoryTransactionPacket impl from PM4"
This reverts commit cb06be615a.

we can't push this to stable because it would break plugins without any
way to know (no protocol or API change).

At most, this should have been wrapped into a protocol change.
2021-03-22 21:21:11 +00:00
4416cd5a28 Bump phpstan/phpstan from 0.12.81 to 0.12.82 (#4088)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.81 to 0.12.82.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.81...0.12.82)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2021-03-22 13:26:07 +00:00
cb93095857 [ci skip] readme: added link to devdoc.pmmp.io 2021-03-21 16:59:58 +00:00
c8f396ecbc [ci skip] doxygen: link to devdoc.pmmp.io instead of the github repo 2021-03-21 16:56:23 +00:00
cb06be615a Backport InventoryTransactionPacket impl from PM4
this version is far better, and we're going to need it to deal with the PlayerAuthInputPacket bullshit.
2021-03-19 22:16:30 +00:00
0d3c11699c Clean up PHPStan baselines 2021-03-19 22:14:07 +00:00
3667e95ff6 Added PlayerAuthInputFlags 2021-03-19 21:41:22 +00:00
0e2dc51ec8 added some missing things to the protocol 2021-03-19 21:09:53 +00:00
eaf85b028a fix prebuilt binaries link (#4090) 2021-03-19 20:42:21 +00:00
9479a1a0ab Bump phpunit/phpunit from 9.5.2 to 9.5.3 (#4084)
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.5.2 to 9.5.3.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-9.5.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.5.2...9.5.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2021-03-17 14:08:44 +00:00
1bb2d162ab Simplify CommandReader
while stream_select() doesn't work on pipes, if it ever starts working properly in the future, we'll need this code. In the meantime, it's harmless (it just immediately returns 1 anyway).
2021-03-16 21:42:35 +00:00
ee868bcccc update argument type constants (#4082) 2021-03-15 18:22:01 +00:00
cbc8576d4a Implement UPnP support without dotNET (#3378)
UPnP forwarding is now available on all supported platforms.
com_dotnet is no longer required for UPnP forwarding to work.

Closes #3216 .
2021-03-14 22:50:33 +00:00
edcf296086 RakLibInterface: fixed server being unjoinable if gamemode is Spectator
closes #4069
this happens because the client bans any server that has an invalid pong, which is very stupid in this case because the gamemode isn't even shown on the UI anyway ...
2021-03-14 20:35:17 +00:00
9e27c47116 Merge branch 'stable' of github.com:pmmp/PocketMine-MP into stable 2021-03-12 22:08:20 +00:00
a0368a843e 3.18.1 is next 2021-03-12 22:07:01 +00:00
3f64906263 Release 3.18.0 2021-03-12 22:07:01 +00:00
19bb8a00df Updated PHPStan baselines 2021-03-12 22:05:15 +00:00
4816a66fb8 Baseline protocol changes for 1.16.210
this is not a complete changeset, but it's sufficient to get servers back online.
There are additional changes to PlayerAuthInputPacket which need to be reversed.
2021-03-12 21:41:48 +00:00
06f4e1e4c2 Bump phpstan/phpstan from 0.12.80 to 0.12.81 (#4063) 2021-03-11 00:33:05 +00:00
5b8166c1f0 3.17.8 is next 2021-03-11 00:22:17 +00:00
30c5cad5b3 Release 3.17.7 2021-03-11 00:22:17 +00:00
a7a7fe3895 Merge branch 'stable' of github.com:pmmp/PocketMine-MP into stable 2021-03-11 00:15:48 +00:00
55ac2f07dc Updated PreProcessor submodule to pmmp/PreProcessor@1b9304de61 2021-03-11 00:15:33 +00:00
0660888029 Updated NBT dependency (again) 2021-03-11 00:15:00 +00:00
0476e6bcfc Updated PreProcessor submodule to pmmp/PreProcessor@934f92d388 2021-03-10 23:33:45 +00:00
72bd37e442 Updated PreProcessor submodule to pmmp/PreProcessor@652c6d8b4c 2021-03-10 23:02:47 +00:00
f95fcecb5b 3.17.7 is next 2021-03-10 20:49:10 +00:00
61391b6e23 Release 3.17.6 2021-03-10 20:48:57 +00:00
fbb6f1f81c Workaround for cursor sync in 1.13+, closes #4059 2021-03-07 21:17:52 +00:00
712df04bc4 Updated NBT dependency to 0.2.17 2021-03-07 21:06:08 +00:00
1563e25378 Updated composer dependencies 2021-03-07 19:57:16 +00:00
ed84252942 Player: Improved XUID verification
we check if an existing player is online with a matching XUID first; if there isn't, we don't bother loading the playerdata, since that other player couldn't have joined unless they had a match or were allowed to bypass.
2021-03-07 19:53:19 +00:00
3d90625020 Revert "Revert "Use PHP 7.4.16 for Actions""
This reverts commit 9f6b914925.
2021-03-07 16:37:33 +00:00
9f6b914925 Revert "Use PHP 7.4.16 for Actions"
This reverts commit 0e614ea8fd.

apparently php-build doesn't have 7.4.16 yet ...
2021-03-06 00:41:19 +00:00
0e614ea8fd Use PHP 7.4.16 for Actions 2021-03-06 00:32:56 +00:00
401bd09d60 Bump phpstan/phpstan from 0.12.79 to 0.12.80 (#4054) 2021-03-01 16:56:23 +00:00
649671cc69 Bump phpstan/phpstan from 0.12.78 to 0.12.79 (#4051) 2021-02-27 17:42:19 +00:00
e755e1dc23 ResourcePackClientResponsePacket: fixed non-deterministic decoding 2021-02-27 01:08:18 +00:00
e34a444dde Bump phpstan/phpstan from 0.12.77 to 0.12.78 (#4046) 2021-02-26 00:34:38 +00:00
78f9985377 Player: fixed PlayerMoveEvent->getFrom() returning unexpected results on movement reversion
fixes #4043
2021-02-26 00:30:42 +00:00
fac2bd3379 Liquid: mark getSmallestFlowDecay() as impure
this fixes two bogus PHPStan warnings.
2021-02-25 22:41:07 +00:00
fcfd51dfc7 CrashDump: do not put FALSE into crashdumps in case file_get_contents() failed 2021-02-23 19:39:21 +00:00
ccc76cf338 Make less noise about XBL being enabled
this has been in force for years now, it's expected by now.
2021-02-23 19:25:22 +00:00
10a73488ed Merge branch 'stable' of https://github.com/pmmp/pocketmine-mp into stable 2021-02-22 16:43:51 +00:00
9c5114084b Updated Snooze to fix race conditions 2021-02-22 16:42:54 +00:00
11630ab1aa Bump phpstan/phpstan from 0.12.76 to 0.12.77 (#4041) 2021-02-18 11:34:42 +00:00
a3068b39a2 Update composer dependencies 2021-02-16 22:31:01 +00:00
edbc73a72c 3.17.6 is next 2021-02-16 22:13:05 +00:00
3a0c8dd594 Release 3.17.5 2021-02-16 22:13:05 +00:00
16fa26405a Remove remaining usages of LevelDB::close()
this is handled by the object destructor.

closes #4035
2021-02-15 20:10:11 +00:00
57423540f0 BUILDING.md: Document server-phar.php's compression bug (#4037)
This bug is not fixable on PM's side because the fault lies with php-src. It was fixed recently in 1bb2a4f91c.
2021-02-15 19:53:44 +00:00
8f8821c904 Bump phpstan/phpstan from 0.12.75 to 0.12.76 (#4038) 2021-02-15 11:25:36 +00:00
094102fe92 fopen() might return FALSE if permission was denied to read/write the file 2021-02-12 16:16:36 +00:00
2aef83e7d7 MainLogger: fix type ambiguity 2021-02-12 15:05:24 +00:00
5c3e78e1d3 Bump phpstan/phpstan from 0.12.74 to 0.12.75 (#4033) 2021-02-12 14:58:01 +00:00
18666e5a60 Be compatible with newest versions of php-leveldb 2021-02-11 22:33:29 +00:00
f72163c173 Fixed build not failing when PHP build gets borked 2021-02-11 17:06:03 +00:00
7407e504b6 actions: bump PHP versions to 7.3.27 and 7.4.15 2021-02-11 16:35:19 +00:00
0e396dc47d actions: update PHP extension versions 2021-02-11 16:24:09 +00:00
d2204da1d5 [ci skip] center the build badges 2021-02-11 16:05:55 +00:00
2a51269305 Merge branch 'stable' of https://github.com/pmmp/pocketmine-mp into stable 2021-02-11 16:05:24 +00:00
928041ddf1 Bump phpstan/phpstan from 0.12.71 to 0.12.74 (#4028)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.71 to 0.12.74.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.71...0.12.74)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2021-02-08 21:42:08 +00:00
007f4f9350 CraftingDataPacket: Remove useless @var comment 2021-02-08 11:53:50 +00:00
46e9f0cec6 Player: fixed verify-xuid not kicking in by default on old configs 2021-02-07 21:10:23 +00:00
606d56b55d Composer: lock in PHP at ^7.3 || ^8.0, don't leave it unbounded 2021-02-07 17:31:32 +00:00
78a62a8b27 Remember and verify player XUIDs (controlled by player.verify-xuid in pocketmine.yml) 2021-02-05 14:42:57 +00:00
c5bdd7dd64 Added a unit test to ensure valid format of MINECRAFT_VERSION_NETWORK 2021-02-04 22:36:40 +00:00
8ee37a3033 Bump phpunit/phpunit from 9.5.1 to 9.5.2 (#4023) 2021-02-04 16:46:22 +00:00
7e3e63f342 Fixed race condition in MainLogger shutdown
this resulted in a deadlock in https://github.com/pmmp/PocketMine-MP/runs/1831812620?check_suite_focus=true because the notify() arrived while writeLogStream() was executing.
This ensures that either:
- the notification will occur before the sleep, and therefore no sleeping will occur (this->shutdown = true before the wait)
- the notification will arrive during the sleep.
2021-02-04 16:40:10 +00:00
8ef1e54e20 MainLogger: fixing CPU waste on logger thread
this doesn't need to keep spinning every 25ms; it can just wake up when there's actually log messages to write into the buffer.
2021-02-04 15:07:40 +00:00
eaf3a86981 MainLogger: fixed UB in writeLogStream()
notify() has to be used inside a synchronized block.
2021-02-04 15:03:14 +00:00
317a48d9b0 ItemStackRequest: expose filterStrings 2021-02-03 23:40:34 +00:00
bc14660e55 Added missing ItemStackRequest protocol changes 2021-02-03 23:37:41 +00:00
b1bb9fbd1c Reinstall PHP deps on cache hit
the 20.04 actions image doesn't have libzip5 and who knows what else is missing ...
2021-02-03 17:42:11 +00:00
96181f8cf5 Version PHP build caches by image version
we can't safely use `ubuntu-latest` because the build caches will break if they were built for 18.04 and used on 20.04, or vice versa. Instead, we pin the images (and caches) to a specific version.
2021-02-03 17:24:50 +00:00
4771e3dc28 3.17.5 is next 2021-02-02 14:04:51 +00:00
2e9117d102 Release 3.17.4 2021-02-02 14:04:50 +00:00
06493da7d9 Imports cleanup 2021-02-02 13:58:07 +00:00
bd303b1062 RegionLoader: fixed flaky region header validation since 3.17.3 2021-02-02 13:43:52 +00:00
fe731b9018 Added failing test case for region header validation
fucking PHP... what genius thought it was a good idea to cache file stats without even an attempt at keeping the cache up to date on modifications?
2021-02-02 13:43:12 +00:00
1a24afc6d1 InventoryTransaction: Fixed indexes persisting from balance calculation in crafting input/outputs
fixes #4019
the order of the actual items may not be the same across runs, but index 0 will at least be sure to exist.
2021-02-02 00:13:58 +00:00
bef906b0f0 phpstan 0.12.71 2021-02-02 00:05:53 +00:00
37e8dd6444 Fix PHP 8 optional before required parameters deprecation warnings (#4016) 2021-01-31 12:08:47 +00:00
02ee0f23c0 Removed old support requests configuration 2021-01-27 22:53:37 +00:00
cda472333c Add workflow for dessant/support-requests
we're using the legacy github app right now.
2021-01-27 22:47:33 +00:00
47cf58be8a phpstan 0.12.70 2021-01-27 20:11:37 +00:00
ccf9691927 Bump phpunit/phpunit from 9.5.0 to 9.5.1 (#4010) 2021-01-27 19:28:36 +00:00
16fa958416 phpstan: better hack for any-callable parameters
variadics are a bad fit for this because what we really need is to accept callable with any number of arguments. LSP requires that the provided number of arguments must be >= than the required number of arguments.
2021-01-27 19:25:28 +00:00
bac57c159f Player: fix bridging, towering and various other fast building bugs
clickPos is relative to the base block position, so if you keep aiming at the same spot on the block and jump, it thinks you're still spamming.
closes #2730
2021-01-27 00:11:14 +00:00
38b2d83799 MemoryManager: fixed protected properties being dumped multiple times
we don't need to scan the parent classes for anything other than private properties, because protected and public properties will appear on the main reflection as if they were declared directly as such.
2021-01-26 20:32:23 +00:00
c134b1cd8a [ci skip] README: add some badges 2021-01-26 17:34:05 +00:00
62deafda48 CommandReader: removed readline support
readline has been borked for a long time and it's not thread safe.
2021-01-25 17:53:25 +00:00
31b6df4376 3.17.4 is next 2021-01-25 17:15:43 +00:00
b296ae1b87 Release 3.17.3 2021-01-25 17:15:31 +00:00
f9e42b716a Scrub PHPStan baselines
these are now always generated with level 8.
2021-01-24 20:31:22 +00:00
34c1d455a7 phpstan: enable checkMissingCallableSignature 2021-01-24 20:27:53 +00:00
af8936dba5 phpstan 0.12.69 2021-01-24 20:14:42 +00:00
e8ffab1787 RegionLoader: avoid hitting the disk twice during chunk reads
this provides some performance improvement (although it's difficult to measure because of cache).
this does mean that we read some garbage data during chunk reads, but it's less costly than hitting the disk twice.
2021-01-20 21:05:44 +00:00
ecc1e1f698 RegionLoader: improve performance of region header validation
I was unaware that fseek actually makes a syscall which is rather costly, which became painfully obvious during large world conversions on PM4.
On average this problem appeared to be adding about 5ms to the load time for a newly loaded region, which is insanely expensive.
2021-01-20 20:04:21 +00:00
ea5931e274 Updated build/php submodule to pmmp/php-build-scripts@60194e8b14 2021-01-16 19:34:06 +00:00
988cf7f535 Fixed PHP 8.0 deprecation error 2021-01-16 19:31:07 +00:00
e156fb47e8 Disable xdebug on Actions 2021-01-15 21:09:45 +00:00
efc5f34877 wrong place ... when shared defaults :( 2021-01-15 17:53:39 +00:00
dd0d8842d5 actions: disable fail-fast 2021-01-15 17:35:27 +00:00
7bdc564ccc Update first-party dependencies to PHP 8.0 compatible versions
all deps of PM3 are ready (at least as far as PHPStan can show).
2021-01-15 16:59:51 +00:00
69fff23f1a LevelProviderManager: removed bogus @var
I'm not sure why this wasn't detected until 0.12.67...
2021-01-15 16:53:49 +00:00
ae43698e88 phpstan 0.12.67
for some reason dependabot shit itself while trying to scan for updates and thought this wasn't updatable ...
2021-01-15 16:53:49 +00:00
0987e03c03 Bump phpstan/phpstan-strict-rules from 0.12.8 to 0.12.9 (#4003) 2021-01-13 10:55:54 +00:00
97c124edf9 thanks git, this just sneaked in without any questions ................ 2021-01-12 21:43:34 +00:00
56501178b7 Updated composer dependencies 2021-01-12 21:41:25 +00:00
da663deea1 Bump phpstan/phpstan from 0.12.65 to 0.12.66 (#4001) 2021-01-12 10:41:59 +00:00
972c911485 phpstan 0.12.65 2021-01-09 18:04:42 +00:00
0d8858f948 composer.json: sort packages automatically 2021-01-09 17:38:22 +00:00
da71540fce first shot building multi PHP versions on actions 2021-01-05 22:03:51 +00:00
ec9b39862b bootstrap: commit suicide if composer dependencies are not in sync 2020-12-29 17:47:32 +00:00
efca8077d5 3.17.3 is next 2020-12-28 23:03:37 +00:00
5066d5225b Release 3.17.2 2020-12-28 23:03:32 +00:00
aefaf73685 Living: extract an applyConsumptionResults() method from consumeObject()
inspired by #3592, which has gone stale
2020-12-28 22:27:29 +00:00
15401d740f RegionLoader: mark area as garbage in removeChunk() 2020-12-27 19:16:05 +00:00
5920b0ba40 Remove _PHPSTAN_ANALYSIS constant
we don't need this anymore since PHPStan is able to intelligently decide whether to autoload a file or not.
2020-12-27 19:10:40 +00:00
dea75a0687 RegionLoader: do not attempt to auto-repair chunks with oversized lengths
In the old days, we used to try to correct this problem by adjusting the region header to match the
length found at the start of the chunk payload. However, this has a very good chance to cause corruption
of other chunks, since we can't do any fast overlap checks (an upsize might cause the chunk's alloocated
area to overlap into another one, causing corruption when either chunk's space gets written to).

This corruption risk has become more problematic since the
introduction of region garbage sector reuse, since a broken location
header could cause chunks to trash each others' saved data.

In addition, if there is a length mismatch, there's a good chance that the oversized chunk itself will
already be corrupted, so we'd just fail trying to decompress it later on.

So, instead of trying to fix this automatically, we bail and hope this doesn't occur often enough for
users to get upset, and allow external offline tools to attempt to repair the mess instead.
2020-12-27 18:50:52 +00:00
873e8740e0 3.17.2 is next 2020-12-23 22:20:24 +00:00
260c55f23a Release 3.17.1 2020-12-23 22:20:19 +00:00
9ed430acb9 CrashDump: fixed a bug in crashdump generation 2020-12-23 21:53:12 +00:00
f0241043de CrashDump: add server uptime to crash information 2020-12-23 20:26:18 +00:00
135f1c95e4 phpstan 0.12.64 2020-12-23 20:04:40 +00:00
5431807e43 Split tests up into multiple jobs
this gives a more granular view of test failures and also allows independent steps to run in parallel.
2020-12-23 19:48:39 +00:00
d49ae832e8 actions: rename cache miss fallback build step 2020-12-21 21:32:27 +00:00
ff9d013005 build: hash composer cache by lockfile instead of composer.json
this ensures a cache refresh when transitive dependencies are updated.
2020-12-20 23:58:37 +00:00
b0e1317818 Merge branch 'stable' of https://github.com/pmmp/pocketmine-mp into stable 2020-12-20 23:53:26 +00:00
8653afb0fb Updated composer dependencies 2020-12-20 23:53:09 +00:00
995b56aaa0 Fixed Composer package cache 2020-12-20 23:49:28 +00:00
3ecddf312d build.sh: sort configure parameters 2020-12-20 22:49:39 +00:00
470243ca6f experimental: build PHP in a separate build job 2020-12-20 22:30:47 +00:00
3f21e59917 Bump phpstan/phpstan-strict-rules from 0.12.5 to 0.12.7 (#3976) 2020-12-18 13:44:19 +00:00
fdd74a4f46 Bump phpstan/phpstan-phpunit from 0.12.16 to 0.12.17 (#3975) 2020-12-18 13:15:05 +00:00
a43b46a93c Merge branch 'stable' of https://github.com/pmmp/pocketmine-mp into stable 2020-12-18 00:33:10 +00:00
0604dfc9e5 phpstan 0.12.63 2020-12-18 00:32:55 +00:00
dd2c3db285 Fixed a bucket of lava disappearing when used in a furnace (#3973)
fixes #2385
2020-12-17 23:57:34 +00:00
c95e283507 fix CXXFLAGS 2020-12-14 22:02:16 +00:00
6afbd1f55c Squashed commit of the following:
commit 1f42169f0f929958f7d68a68f194c6f3492b7eb4
Author: Dylan K. Taylor <odigiman@gmail.com>
Date:   Mon Dec 14 21:23:44 2020 +0000

    ... install it in the right fucking place

commit d2a88abeda5fa937d3f508c4e0300a949af97846
Author: Dylan K. Taylor <odigiman@gmail.com>
Date:   Mon Dec 14 21:14:21 2020 +0000

    Build PHP using system libraries to reduce rebuild time
2020-12-14 21:58:58 +00:00
0682c93f5a Drop bcmath dependency
we haven't used bcmath since the days of 32-bit.
2020-12-14 20:59:07 +00:00
da90ae85da Updated composer dependencies 2020-12-14 19:24:36 +00:00
e87127f309 readme: drop travis badge in favour of GH Actions badge 2020-12-11 22:38:14 +00:00
0237a50d90 thank you for your service travis 2020-12-11 22:26:53 +00:00
8b53e4150e Setup GitHub Actions (#3966) 2020-12-11 22:25:08 +00:00
1c43538238 Fix that a hoe gets damage applied to it, when it's used to break a block (#3967)
closes #3965
2020-12-11 21:14:52 +00:00
68887105b2 Utils::cleanPath(): drop the square braces
this looks ugly, as well as breaking plugin crash detection (which tbh is too fragile, but it is what it is ...)
2020-12-09 20:26:08 +00:00
104e90b794 CrashDump: more robust core crash detection 2020-12-08 23:27:03 +00:00
994062f6dc CrashDump: fixed plugin detection on eval()'d code
it's possible we could clean the path up to detect which plugin caused the crash, but for now I'll be happy to not have them showing up as core crashes ...
2020-12-08 23:11:29 +00:00
69a41a5ed4 3.17.1 is next 2020-12-08 21:02:14 +00:00
3903b70ef5 Release 3.17.0 2020-12-08 21:02:13 +00:00
692e63ad7c Protocol changes for 1.16.200 2020-12-08 20:31:17 +00:00
4d1be4d41d McRegion: do not create a region file when trying to read a chunk that doesn't exist
fixes #3953
2020-12-07 18:44:49 +00:00
5f0310a8b6 3.16.2 is next 2020-12-07 17:16:11 +00:00
177 changed files with 5592 additions and 2677 deletions

View File

@ -20,8 +20,9 @@ assignees: ''
<!-- try the `version` command | LATEST IS NOT A VALID VERSION -->
* PocketMine-MP:
* PHP:
* Using JIT: yes/no (delete as appropriate) <!-- look for the giant yellow warning in the log that says you're using JIT -->
* Server OS:
* Game version: PE/Win10 (delete as appropriate)
* Game version: Android/iOS/Win10/Xbox/PS4/Switch (delete as appropriate)
### Plugins
<!--- use the `plugins` command and paste the output below -->

8
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
time: "10:00"
open-pull-requests-limit: 10

16
.github/support.yml vendored
View File

@ -1,16 +0,0 @@
# Configuration for support-requests - https://github.com/dessant/support-requests
# Label used to mark issues as support requests
supportLabel: "Support request"
# Comment to post on issues marked as support requests. Add a link
# to a support page, or set to `false` to disable
supportComment: >
Thanks, but this issue tracker is not intended for support requests. Please read the guidelines on [submitting an issue](https://github.com/pmmp/PocketMine-MP/blob/master/CONTRIBUTING.md#creating-an-issue).
[Docs](https://pmmp.rtfd.io) | [Discord](https://discord.gg/bmSAZBG) | [Forums](https://forums.pmmp.io)
# Whether to close issues marked as support requests
close: true
# Whether to lock issues marked as support requests
lock: false

113
.github/workflows/draft-release.yml vendored Normal file
View File

@ -0,0 +1,113 @@
name: Draft release
on:
push:
tags: "*"
jobs:
draft:
name: Create GitHub draft release
if: "startsWith(github.event.head_commit.message, 'Release ')"
runs-on: ubuntu-20.04
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Setup PHP
uses: shivammathur/setup-php@2.12.0
with:
php-version: 8.0
- name: Restore Composer package cache
uses: actions/cache@v2
with:
path: |
~/.cache/composer/files
~/.cache/composer/vcs
key: "composer-v2-cache-${{ hashFiles('./composer.lock') }}"
restore-keys: |
composer-v2-cache-
- name: Install Composer dependencies
run: composer install --no-dev --prefer-dist --no-interaction --ignore-platform-reqs
- name: Patch VersionInfo
run: |
BUILD_NUMBER=2000+$GITHUB_RUN_NUMBER #to stay above jenkins
echo "Build number: $BUILD_NUMBER"
sed -i "s/const BUILD_NUMBER = 0/const BUILD_NUMBER = ${BUILD_NUMBER}/" src/pocketmine/VersionInfo.php
- name: Minify BedrockData JSON files
run: php src/pocketmine/resources/vanilla/.minify_json.php
- name: Run preprocessor
run: |
PM_PREPROCESSOR_PATH="$GITHUB_WORKSPACE/build/preprocessor"
php "$PM_PREPROCESSOR_PATH/PreProcessor.php" --path=src --multisize || (echo "Preprocessor exited with code $?" && exit 1)
#dump the diff of preprocessor replacements to a patch in case it has bugs
git diff > preprocessor_diff.patch
VENDOR_PM="$GITHUB_WORKSPACE/vendor"
VENDOR_PM_BACKUP="$GITHUB_WORKSPACE/vendor-before-preprocess"
cp -r "$VENDOR_PM" "$VENDOR_PM_BACKUP"
for f in $(ls $VENDOR_PM/pocketmine); do
echo "Processing directory \"$f\"..."
php "$PM_PREPROCESSOR_PATH/PreProcessor.php" --path="$VENDOR_PM/pocketmine/$f" --multisize || (echo "Preprocessor exited with code $?" && exit 1)
echo "Checking for changes in \"$f\"..."
DIFF=$(git diff --no-index "$VENDOR_PM_BACKUP/pocketmine/$f" "$VENDOR_PM/pocketmine/$f" || true)
if [ "$DIFF" != "" ]; then
PATCH="$GITHUB_WORKSPACE/preprocessor_diff_$f.patch"
echo "$DIFF" > "$PATCH"
echo "Generated patch file \"$PATCH\""
else
echo "No diff generated for \"$f\" (preprocessor made no changes)"
fi
done
- name: Build PocketMine-MP.phar
run: php -dphar.readonly=0 build/server-phar.php --git ${{ github.sha }}
- name: Get PocketMine-MP release version
id: get-pm-version
run: |
echo ::set-output name=PM_VERSION::$(php -r 'require "vendor/autoload.php"; echo \pocketmine\BASE_VERSION;')
echo ::set-output name=MCPE_VERSION::$(php -r 'require "vendor/autoload.php"; echo \pocketmine\network\mcpe\protocol\ProtocolInfo::MINECRAFT_VERSION_NETWORK;')
echo ::set-output name=PM_VERSION_SHORT::$(php -r 'require "vendor/autoload.php"; $v = explode(".", \pocketmine\BASE_VERSION); array_pop($v); echo implode(".", $v);')
echo ::set-output name=PM_VERSION_MD::$(php -r 'require "vendor/autoload.php"; echo str_replace(".", "", \pocketmine\BASE_VERSION);')
- name: Generate build info
run: php build/generate-build-info-json.php ${{ github.sha }} ${{ steps.get-pm-version.outputs.PM_VERSION }} ${{ github.repository }} > build_info.json
- name: Upload release artifacts
uses: actions/upload-artifact@v2
with:
name: release_artifacts
path: |
${{ github.workspace }}/PocketMine-MP.phar
${{ github.workspace }}/start.*
${{ github.workspace }}/build_info.json
- name: Create draft release
uses: ncipollo/release-action@v1.8.6
with:
artifacts: ${{ github.workspace }}/PocketMine-MP.phar,${{ github.workspace }}/start.*,${{ github.workspace }}/build_info.json
commit: ${{ github.sha }}
draft: true
name: PocketMine-MP ${{ steps.get-pm-version.outputs.PM_VERSION }}
tag: ${{ steps.get-pm-version.outputs.PM_VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
body: |
**For Minecraft: Bedrock Edition ${{ steps.get-pm-version.outputs.MCPE_VERSION }}**
Please see the [changelogs](/changelogs/${{ steps.get-pm-version.outputs.PM_VERSION_SHORT }}.md#${{ steps.get-pm-version.outputs.PM_VERSION_MD }}) for details.
- name: Upload preprocessor diffs
uses: actions/upload-artifact@v2
if: always()
with:
name: preprocessor_diffs
path: ${{ github.workspace }}/preprocessor_diff*.patch

286
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,286 @@
name: CI
on:
push:
pull_request:
workflow_dispatch:
jobs:
build-php:
name: Prepare PHP
runs-on: ${{ matrix.image }}
strategy:
matrix:
image: [ubuntu-20.04]
php: [7.4.22, 8.0.9]
steps:
- uses: actions/checkout@v2 #needed for build.sh
- name: Check for PHP build cache
id: php-build-cache
uses: actions/cache@v2
with:
path: "./bin"
key: "php-build-generic-${{ matrix.php }}-${{ matrix.image }}-${{ hashFiles('./tests/gh-actions/build.sh') }}"
- name: Compile PHP
if: steps.php-build-cache.outputs.cache-hit != 'true'
run: ./tests/gh-actions/build.sh "${{ matrix.php }}"
phpstan:
name: PHPStan analysis
needs: build-php
runs-on: ${{ matrix.image }}
strategy:
fail-fast: false
matrix:
include:
- php: 8.0.9
config: phpstan.neon.dist
image: ubuntu-20.04
- php: 7.4.22
config: phpstan.php7.neon
image: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Restore PHP build cache
id: php-build-cache
uses: actions/cache@v2
with:
path: "./bin"
key: "php-build-generic-${{ matrix.php }}-${{ matrix.image }}-${{ hashFiles('./tests/gh-actions/build.sh') }}"
- name: Kill build on PHP build cache miss (should never happen)
if: steps.php-build-cache.outputs.cache-hit != 'true'
run: exit 1
- name: Install cached PHP's dependencies
if: steps.php-build-cache.outputs.cache-hit == 'true'
run: ./tests/gh-actions/install-dependencies.sh
- name: Prefix PHP to PATH
run: echo "$(pwd)/bin/php7/bin" >> $GITHUB_PATH
- name: Install Composer
run: curl -sS https://getcomposer.org/installer | php
- name: Restore Composer package cache
uses: actions/cache@v2
with:
path: |
~/.cache/composer/files
~/.cache/composer/vcs
key: "composer-v2-cache-${{ matrix.php }}-${{ hashFiles('./composer.lock') }}"
restore-keys: |
composer-v2-cache-
- name: Install Composer dependencies
run: php composer.phar install --prefer-dist --no-interaction
- name: Run PHPStan
run: ./vendor/bin/phpstan analyze --no-progress --memory-limit=2G -c ${{ matrix.config }}
phpunit:
name: PHPUnit tests
needs: build-php
runs-on: ${{ matrix.image }}
strategy:
fail-fast: false
matrix:
image: [ubuntu-20.04]
php: [7.4.22, 8.0.9]
steps:
- uses: actions/checkout@v2
- name: Restore PHP build cache
id: php-build-cache
uses: actions/cache@v2
with:
path: "./bin"
key: "php-build-generic-${{ matrix.php }}-${{ matrix.image }}-${{ hashFiles('./tests/gh-actions/build.sh') }}"
- name: Kill build on PHP build cache miss (should never happen)
if: steps.php-build-cache.outputs.cache-hit != 'true'
run: exit 1
- name: Install cached PHP's dependencies
if: steps.php-build-cache.outputs.cache-hit == 'true'
run: ./tests/gh-actions/install-dependencies.sh
- name: Prefix PHP to PATH
run: echo "$(pwd)/bin/php7/bin" >> $GITHUB_PATH
- name: Install Composer
run: curl -sS https://getcomposer.org/installer | php
- name: Restore Composer package cache
uses: actions/cache@v2
with:
path: |
~/.cache/composer/files
~/.cache/composer/vcs
key: "composer-v2-cache-${{ matrix.php }}-${{ hashFiles('./composer.lock') }}"
restore-keys: |
composer-v2-cache-
- name: Install Composer dependencies
run: php composer.phar install --prefer-dist --no-interaction
- name: Run PHPUnit tests
run: ./vendor/bin/phpunit --bootstrap vendor/autoload.php --fail-on-warning tests/phpunit
integration:
name: Integration tests
needs: build-php
runs-on: ${{ matrix.image }}
strategy:
fail-fast: false
matrix:
image: [ubuntu-20.04]
php: [7.4.22, 8.0.9]
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Restore PHP build cache
id: php-build-cache
uses: actions/cache@v2
with:
path: "./bin"
key: "php-build-generic-${{ matrix.php }}-${{ matrix.image }}-${{ hashFiles('./tests/gh-actions/build.sh') }}"
- name: Kill build on PHP build cache miss (should never happen)
if: steps.php-build-cache.outputs.cache-hit != 'true'
run: exit 1
- name: Install cached PHP's dependencies
if: steps.php-build-cache.outputs.cache-hit == 'true'
run: ./tests/gh-actions/install-dependencies.sh
- name: Prefix PHP to PATH
run: echo "$(pwd)/bin/php7/bin" >> $GITHUB_PATH
- name: Install Composer
run: curl -sS https://getcomposer.org/installer | php
- name: Restore Composer package cache
uses: actions/cache@v2
with:
path: |
~/.cache/composer/files
~/.cache/composer/vcs
key: "composer-v2-cache-${{ matrix.php }}-${{ hashFiles('./composer.lock') }}"
restore-keys: |
composer-v2-cache-
- name: Install Composer dependencies
run: php composer.phar install --no-dev --prefer-dist --no-interaction
- name: Run integration tests
run: ./tests/travis.sh -t4
preprocessor:
name: Preprocessor tests
needs: build-php
runs-on: ${{ matrix.image }}
strategy:
fail-fast: false
matrix:
image: [ubuntu-20.04]
php: [7.4.22, 8.0.9]
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Restore PHP build cache
id: php-build-cache
uses: actions/cache@v2
with:
path: "./bin"
key: "php-build-generic-${{ matrix.php }}-${{ matrix.image }}-${{ hashFiles('./tests/gh-actions/build.sh') }}"
- name: Kill build on PHP build cache miss (should never happen)
if: steps.php-build-cache.outputs.cache-hit != 'true'
run: exit 1
- name: Install cached PHP's dependencies
if: steps.php-build-cache.outputs.cache-hit == 'true'
run: ./tests/gh-actions/install-dependencies.sh
- name: Prefix PHP to PATH
run: echo "$(pwd)/bin/php7/bin" >> $GITHUB_PATH
- name: Install Composer
run: curl -sS https://getcomposer.org/installer | php
- name: Restore Composer package cache
uses: actions/cache@v2
with:
path: |
~/.cache/composer/files
~/.cache/composer/vcs
key: "composer-v2-cache-${{ matrix.php }}-${{ hashFiles('./composer.lock') }}"
restore-keys: |
composer-v2-cache-
- name: Install Composer dependencies
run: php composer.phar install --no-dev --prefer-dist --no-interaction
- name: Run preprocessor
run: |
PM_PREPROCESSOR_PATH="$GITHUB_WORKSPACE/build/preprocessor"
php "$PM_PREPROCESSOR_PATH/PreProcessor.php" --path=src --multisize || (echo "Preprocessor exited with code $?" && exit 1)
#dump the diff of preprocessor replacements to a patch in case it has bugs
git diff > preprocessor_diff.patch
VENDOR_PM="$GITHUB_WORKSPACE/vendor"
VENDOR_PM_BACKUP="$GITHUB_WORKSPACE/vendor-before-preprocess"
cp -r "$VENDOR_PM" "$VENDOR_PM_BACKUP"
for f in $(ls $VENDOR_PM/pocketmine); do
echo "Processing directory \"$f\"..."
php "$PM_PREPROCESSOR_PATH/PreProcessor.php" --path="$VENDOR_PM/pocketmine/$f" --multisize || (echo "Preprocessor exited with code $?" && exit 1)
echo "Checking for changes in \"$f\"..."
DIFF=$(git diff --no-index "$VENDOR_PM_BACKUP/pocketmine/$f" "$VENDOR_PM/pocketmine/$f" || true)
if [ "$DIFF" != "" ]; then
PATCH="$GITHUB_WORKSPACE/preprocessor_diff_$f.patch"
echo "$DIFF" > "$PATCH"
echo "Generated patch file \"$PATCH\""
else
echo "No diff generated for \"$f\" (preprocessor made no changes)"
fi
done
- name: Upload preprocessor diffs
uses: actions/upload-artifact@v2
if: always()
with:
name: preprocessor_diffs_${{ matrix.php }}_${{ matrix.image }}
path: ${{ github.workspace }}/preprocessor_diff*.patch
codestyle:
name: Code Style checks
runs-on: ubuntu-20.04
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Setup PHP and tools
uses: shivammathur/setup-php@2.12.0
with:
php-version: 8.0
tools: php-cs-fixer
- name: Run PHP-CS-Fixer
run: php-cs-fixer fix --dry-run --diff

22
.github/workflows/support.yml vendored Normal file
View File

@ -0,0 +1,22 @@
name: 'Manage support request issues'
on:
issues:
types: [labeled, unlabeled, reopened]
jobs:
support:
runs-on: ubuntu-latest
steps:
- uses: dessant/support-requests@v2
with:
github-token: ${{ github.token }}
support-label: "Support request"
issue-comment: >
Thanks, but this issue tracker is not intended for support requests. Please read the guidelines on [submitting an issue](https://github.com/pmmp/PocketMine-MP/blob/master/CONTRIBUTING.md#creating-an-issue).
[Docs](https://pmmp.rtfd.io) | [Discord](https://discord.gg/bmSAZBG) | [Forums](https://forums.pmmp.io)
close-issue: true
lock-issue: false

View File

@ -0,0 +1,51 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
const VERSIONS = [
"7.3",
"7.4",
"8.0"
];
$workflowFile = file_get_contents(__DIR__ . '/main.yml');
$newWorkflowFile = $workflowFile;
foreach(VERSIONS as $v){
$releaseInfo = file_get_contents("https://secure.php.net/releases?json&version=$v");
if($releaseInfo === false){
throw new \RuntimeException("Failed to contact php.net API");
}
$data = json_decode($releaseInfo, true);
if(!is_array($data) || !isset($data["version"]) || !is_string($data["version"]) || preg_match('/^\d+\.\d+\.\d+(-[A-Za-z\d]+)?$/', $data["version"]) === 0){
throw new \RuntimeException("Invalid data returned by API");
}
$updated = preg_replace("/$v\.\d+/", $data["version"], $newWorkflowFile);
if($updated !== $newWorkflowFile){
echo "Updated $v revision to " . $data["version"] . "\n";
}
$newWorkflowFile = $updated;
}
if($workflowFile !== $newWorkflowFile){
echo "Writing modified workflow file\n";
file_put_contents(__DIR__ . '/main.yml', $newWorkflowFile);
}

View File

@ -0,0 +1,45 @@
name: Update update.pmmp.io API info
on:
release:
types:
- published
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install jq
run: sudo apt update && sudo apt install jq -y
- uses: actions/checkout@v2
with:
repository: pmmp/update.pmmp.io
ssh-key: ${{ secrets.UPDATE_PMMP_IO_DEPLOY_KEY }}
- name: Get actual tag name
id: tag-name
run: echo ::set-output name=TAG_NAME::$(echo "${{ github.ref }}" | sed 's{^refs/tags/{{')
- name: Download new release information
run: curl -f -L ${{ github.server_url }}/${{ github.repository }}/releases/download/${{ steps.tag-name.outputs.TAG_NAME }}/build_info.json -o new_build_info.json
- name: Detect channel
id: channel
run: echo ::set-output name=CHANNEL::$(jq -r '.channel' new_build_info.json)
- name: Copy release information
run: |
cp new_build_info.json channels/${{ steps.channel.outputs.CHANNEL }}.json
rm new_build_info.json
- name: Commit changes
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git diff-index --quiet HEAD || git commit -m "New ${{ steps.channel.outputs.CHANNEL }} release: ${{ github.repository }} ${{ steps.tag-name.outputs.TAG_NAME }}"
- name: Push changes
run: git push

5
.gitignore vendored
View File

@ -16,7 +16,9 @@ server.lock
/phpstan.neon
# Common IDEs
.idea/
.idea/*
!.idea/codeStyles/
!.idea/fileTemplates/
nbproject/*
# Windows image file caches
@ -47,3 +49,4 @@ Documentation/*
# php-cs-fixer
/.php_cs.cache
/.php-cs-fixer.cache

71
.idea/codeStyles/Project.xml generated Normal file
View File

@ -0,0 +1,71 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="LINE_SEPARATOR" value="&#10;" />
<HTMLCodeStyleSettings>
<option name="HTML_TEXT_WRAP" value="0" />
<option name="HTML_DO_NOT_INDENT_CHILDREN_OF" value="thead,tbody,tfoot" />
</HTMLCodeStyleSettings>
<PHPCodeStyleSettings>
<option name="ALIGN_PHPDOC_PARAM_NAMES" value="true" />
<option name="PHPDOC_BLANK_LINES_AROUND_PARAMETERS" value="true" />
<option name="LOWER_CASE_BOOLEAN_CONST" value="true" />
<option name="LOWER_CASE_NULL_CONST" value="true" />
<option name="VARIABLE_NAMING_STYLE" value="CAMEL_CASE" />
<option name="SPACES_WITHIN_SHORT_ECHO_TAGS" value="false" />
<option name="SPACE_BEFORE_CLOSURE_LEFT_PARENTHESIS" value="false" />
<option name="FORCE_SHORT_DECLARATION_ARRAY_STYLE" value="true" />
<option name="SPACE_BEFORE_COLON_IN_RETURN_TYPE" value="true" />
</PHPCodeStyleSettings>
<editorconfig>
<option name="ENABLED" value="false" />
</editorconfig>
<codeStyleSettings language="HTML">
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JSON">
<indentOptions>
<option name="INDENT_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="PHP">
<option name="CLASS_BRACE_STYLE" value="1" />
<option name="METHOD_BRACE_STYLE" value="1" />
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="ALIGN_MULTILINE_FOR" value="false" />
<option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" />
<option name="SPACE_AFTER_TYPE_CAST" value="true" />
<option name="SPACE_BEFORE_IF_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_WHILE_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_FOR_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_CATCH_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_SWITCH_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_CLASS_LBRACE" value="false" />
<option name="SPACE_BEFORE_METHOD_LBRACE" value="false" />
<option name="SPACE_BEFORE_IF_LBRACE" value="false" />
<option name="SPACE_BEFORE_ELSE_LBRACE" value="false" />
<option name="SPACE_BEFORE_WHILE_LBRACE" value="false" />
<option name="SPACE_BEFORE_FOR_LBRACE" value="false" />
<option name="SPACE_BEFORE_DO_LBRACE" value="false" />
<option name="SPACE_BEFORE_SWITCH_LBRACE" value="false" />
<option name="SPACE_BEFORE_TRY_LBRACE" value="false" />
<option name="SPACE_BEFORE_CATCH_LBRACE" value="false" />
<option name="SPACE_BEFORE_FINALLY_LBRACE" value="false" />
<option name="SPACE_BEFORE_ELSE_KEYWORD" value="false" />
<option name="SPACE_BEFORE_WHILE_KEYWORD" value="false" />
<option name="SPACE_BEFORE_CATCH_KEYWORD" value="false" />
<option name="SPACE_BEFORE_FINALLY_KEYWORD" value="false" />
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="neon">
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>

5
.idea/codeStyles/codeStyleConfig.xml generated Normal file
View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View File

@ -0,0 +1,8 @@
#if(${THROWS_DOC} != "")
/**
${THROWS_DOC}
*/
#end
public function __construct(${PARAM_LIST}) {
${BODY}
}

View File

@ -0,0 +1,6 @@
/** @return $this */
public function set${NAME}(#if (${SCALAR_TYPE_HINT})${SCALAR_TYPE_HINT} #else#end$${PARAM_NAME})#if(${RETURN_TYPE}): self#else#end
{
$this->${FIELD_NAME} = $${PARAM_NAME};
return $this;
}

View File

@ -0,0 +1,3 @@
#if(${TYPE_HINT} != ${RETURN_TYPE} && ${TYPE_HINT} != "")/** @return ${TYPE_HINT} */#end
public ${STATIC} function ${GET_OR_IS}${NAME}()#if(${RETURN_TYPE}): ${RETURN_TYPE}#else#end
{ return #if(${STATIC} == "static")self::$${FIELD_NAME};#else$this->${FIELD_NAME};#end }

View File

@ -0,0 +1,2 @@
public ${STATIC} function set${NAME}(#if (${SCALAR_TYPE_HINT})${SCALAR_TYPE_HINT} #end$${PARAM_NAME})#if (${VOID_RETURN_TYPE}):void #end
{#if (${STATIC} == "static") self::$${FIELD_NAME} = $${PARAM_NAME}; #else $this->${FIELD_NAME} = $${PARAM_NAME}; #end}

View File

View File

@ -0,0 +1,21 @@
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);

View File

@ -0,0 +1,5 @@
#if (${THROWS_DOC} != "")
/**
${THROWS_DOC}
*/
#end

View File

@ -0,0 +1 @@
/** @var ${TYPE_HINT} */

View File

View File

@ -0,0 +1,10 @@
<?php
#parse("PHP File Header.php")
#if (${NAMESPACE})
namespace ${NAMESPACE};
#end
final class ${NAME} {
}

View File

@ -0,0 +1,4 @@
<?php
#parse("PHP File Header.php")

View File

@ -0,0 +1,10 @@
<?php
#parse("PHP File Header.php")
#if (${NAMESPACE})
namespace ${NAMESPACE};
#end
interface ${NAME} {
}

View File

@ -0,0 +1,10 @@
<?php
#parse("PHP File Header.php")
#if (${NAMESPACE})
namespace ${NAMESPACE};
#end
trait ${NAME} {
}

72
.php-cs-fixer.php Normal file
View File

@ -0,0 +1,72 @@
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/build')
->in(__DIR__ . '/tests')
->notPath('plugins/DevTools')
->notPath('preprocessor')
->notContains('#ifndef COMPILE') //preprocessor will break if these are changed
->notName('PocketMine.php');
return (new PhpCsFixer\Config)
->setRiskyAllowed(true)
->setRules([
'align_multiline_comment' => [
'comment_type' => 'phpdocs_only'
],
'array_indentation' => true,
'array_syntax' => [
'syntax' => 'short'
],
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => [
'statements' => [
'declare'
]
],
'cast_spaces' => [
'space' => 'single'
],
'concat_space' => [
'spacing' => 'one'
],
'declare_strict_types' => true,
'elseif' => true,
'global_namespace_import' => [
'import_constants' => true,
'import_functions' => true,
'import_classes' => null,
],
'indentation_type' => true,
'native_function_invocation' => [
'scope' => 'namespaced',
'include' => ['@all'],
],
'no_closing_tag' => true,
'no_empty_phpdoc' => true,
'no_extra_blank_lines' => true,
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => true,
],
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_whitespace_in_blank_line' => true,
'no_unused_imports' => true,
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha'
],
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'single_import_per_statement' => true,
'strict_param' => true,
])
->setFinder($finder)
->setIndent("\t")
->setLineEnding("\n");

View File

@ -1,21 +0,0 @@
import:
source: ./tests/travis/setup-php.yml
script:
- composer install --prefer-dist
- ./vendor/bin/phpstan analyze --no-progress --memory-limit=2G
- ./vendor/bin/phpunit --bootstrap vendor/autoload.php --fail-on-warning tests/phpunit
- composer install --no-dev --prefer-dist
- ./tests/travis.sh -t4
cache:
directories:
- $HOME/.composer/cache/files
- $HOME/.composer/cache/vcs
notifications:
email:
recipients:
- team@pmmp.io
on_success: change
on_failure: always

View File

@ -2,13 +2,13 @@
## Pre-requisites
- A bash shell (git bash is sufficient for Windows)
- [`git`](https://git-scm.com) available in your shell
- PHP 7.3 or newer available in your shell
- PHP 7.4 or newer available in your shell
- [`composer`](https://getcomposer.org) available in your shell
## Custom PHP binaries
Because PocketMine-MP requires several non-standard PHP extensions and configuration, PMMP provides scripts to build custom binaries for running PocketMine-MP, as well as prebuilt binaries.
- [Prebuilt binaries](https://jenkins.pmmp.io/job/PHP-7.3-Aggregate)
- [Prebuilt binaries](https://jenkins.pmmp.io/job/PHP-7.4-Aggregate)
- [Compile scripts](https://github.com/pmmp/php-build-scripts) are provided as a submodule in the path `build/php`
If you use a custom binary, you'll need to replace `composer` usages in this guide with `path/to/your/php path/to/your/composer.phar`.
@ -34,5 +34,11 @@ Run `composer make-server` using your preferred PHP binary. It'll drop a `Pocket
You can also use the `--out` option to change the output filename.
There is a bug in PHP that might cause an error which looks like this:
```
Fatal error: Uncaught BadMethodCallException: unable to create temporary file in PocketMine-MP/build/server-phar.php:119
```
You can work around it by setting `ulimit -n` to some bigger number, e.g. `8192`, or by updating your PHP version to at least 7.4.16 or 8.0.3.
## Running PocketMine-MP from source code
Run `src/pocketmine/PocketMine.php` using your preferred PHP binary.

View File

@ -2,125 +2,102 @@
# PocketMine-MP Contribution Guidelines
PocketMine-MP is an open source project, and contributions from the community are welcomed, as long as they comply with our quality standards and licensing.
## Creating an Issue
- If you are reporting a bug:
- **make sure that you are using the latest supported version** before opening an issue.
- **test it on a clean test server, WITHOUT PLUGINS**, to see if the issue still occurs. If not then it may be a plugin issue. Please also indicate the result of such tests.
- **[Search the issue tracker](https://github.com/pmmp/PocketMine-MP/issues?utf8=%E2%9C%93&q=is%3Aissue)** to check if anyone has already reported it, to avoid needlessly creating duplicate issues. Make sure you also check closed issues, as an issue you think is valid may already have been resolved.
- **Do not report plugin issues here.** If your issue is related to a plugin, contact the plugin's original author instead.
- **Support requests are not bugs.** Issues such as "How do I do this" are not bugs and will be closed. If you need help, please see [here](README.md#discussion) and do not misuse our issue tracker.
- **No generic titles** such as "Question", "Help", "Crash Report" etc. A good issue report provides a quick summary in the title. If you just got a crash report but you don't understand it, please look for a line starting with `Message`. It summarizes the bug.
- **Provide information in the issue body, not in the title.** No tags like `[BUG]` are allowed in the title, including `[SOLVED]` for solved issues.
- **No generic issue reports.** For bugs, it is the issue author's responsibility to provide us an issue that is **trackable, debuggable, reproducible, reported professionally and is an actual bug**.
<br>Valid issue reports must include instructions how to reproduce the issue or a crashdump/backtrace (unless the cause of the issue is obvious).
<br>**If you do not provide us with a summary or instructions on how to reproduce the issue, it will be treated as spam and will therefore be closed.**
<br>In simple words, if the issue cannot be properly confirmed to be valid or lacks required information, the issue will be closed until further information is provided.
- To express appreciation, objection, confusion or other supported reactions on pull requests, issues or comments on them, use GitHub [reactions](https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments) rather than posting an individual comment with an emoji only. This helps keeping the issue/pull request conversation clean and readable.
- If your issue is related to the PocketMine-MP website, forums, etc., please [talk to a human directly](README.md#discussion).
Code contributions must be submitted using [GitHub Pull Requests](https://github.com/pmmp/PocketMine-MP/pulls), where they will be reviewed by maintainers.
Small contributions (e.g. minor bug fixes) can be submitted as pull requests directly.
Larger contributions like feature additions should be preceded by a [Change Proposal](#rfcs--change-proposals) to allow maintainers and other people to discuss and decide if it's a good idea or not.
## Contributing
To contribute to the repository, [fork it on GitHub](https://github.com/pmmp/PocketMine-MP/fork), create a branch on your fork, and make your changes on your fork. You can then make a [pull request](https://github.com/pmmp/PocketMine-MP/pull/new) to the project to compare your branch to ours and propose your changes to our repository. We use the Pull Request system to allow members of the team to review changes before they are merged.
## Useful documentation from github.com
- [About pull requests](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)
- [About forks](https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/about-forks)
- [Creating a pull request from a fork](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork)
### Licensing
By proposing a pull request to the project, you agree to your code being distributed within PocketMine-MP under the [LGPL license](LICENSE).
## Other things you'll need
- [git](https://git-scm.com/)
### Contribution standards
- **We enforce a very high standard for contributions**. This is because PocketMine-MP and its related projects are used very widely in production. While this might seem like we are being mean at times, **our priority is what is best for PocketMine-MP itself**.
We try to ensure that our project's codebase is as clean as possible and ensure that only top-quality material makes it through to PocketMine-MP itself.
- **If a contribution does not meet our standards, changes may be requested or the pull request may be closed.**
## Making a pull request
The basic procedure to create a pull request is:
1. [Fork the repository on GitHub](https://github.com/pmmp/PocketMine-MP/fork). This gives you your own copy of the repository to make changes to.
2. Create a branch on your fork for your changes.
3. Make the changes you want to make on this branch.
4. You can then make a [pull request](https://github.com/pmmp/PocketMine-MP/pull/new) to the project.
### Pull requests
- **Create a new branch for each pull request.** Do not create a pull request with commits that exist in another pull request.
## Pull request reviews
Pull requests will be reviewed by maintainers when they are available.
Note that there might be a long wait time before a reviewer looks at your PR.
Depending on the changes, maintainers might ask you to make changes to the PR to fix problems or to improve the code.
**Do not delete your fork** while your pull request remains open, otherwise you won't be able to make any requested changes and the PR will end up being declined.
### Requirements
The following are required as a minimum for pull requests. PRs that don't meet these requirements will be declined unless updated to meet them.
#### Licensing
PocketMine-MP is licensed under [LGPLv3 license](LICENSE).
By proposing a pull request, you agree to your code being distributed within PocketMine-MP under the same license.
If you take code from other projects, that code MUST be licensed under an LGPL-compatible license.
#### PRs should be about exactly ONE thing
If you want to make multiple changes, those changes should each be contributed as separate pull requests. **DO NOT** mix unrelated changes.
#### PRs must not include unnecessary/unrelated changes
Do not include changes which aren't strictly necessary. This makes it harder to review a PR, because the code diff becomes larger and harder to review.
This means:
- don't reformat or rearrange existing code
- don't change things that aren't related to the PR's objective
- don't rewrite existing code just to make it "look nicer"
- don't change PhpDocs to native types in code you didn't write
#### Tests must be provided
Where possible, PHPUnit tests should be written for new or changed code.
If that's not possible (e.g. for in-game functionality), the code must be tested manually and details of the tests done must be provided.
**Simply saying "Tested" is not acceptable** and will lead to your PR being declined.
#### Comments and documentation must be written in American English
English is the shared languages of all current maintainers.
#### Code must be in the PocketMine-MP style
It's your responsibility to ensure your code matches the formatting and styling of the rest of the code.
If you use PhpStorm, a `Project` code style is provided, which you can use to automatically format new code.
You can also use [`php-cs-fixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer) to format your code.
### Recommendations
- **Do not edit code directly on github.com.** We recommend learning how to use [`git`](https://git-scm.com). `git` allows you to "clone" a repository onto your computer, so that you can make changes using an IDE.
- **Use an IDE, not a text editor.** We recommend PhpStorm or VSCode.
- **Create a new branch on your fork for each pull request.** This allows you to use the same fork to make multiple pull requests at the same time.
- **Use descriptive commit titles.** You can see an example [here](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
- **Do not include multiple unrelated changes in one commit.** An atomic style for commits is preferred - this means that changes included in a commit should be part of a single distinct change set. See [this link](https://www.freshconsulting.com/atomic-commits/) for more information on atomic commits. See the [documentation on `git add`](https://git-scm.com/docs/git-add) for information on how to isolate local changes for committing.
- **Your pull request will be checked and discussed in due time.** Since the team is scattered all around the world, your PR may not receive any attention for some time.
- **It is inadvisable to create large pull requests with lots of changes** unless this has been discussed with the team beforehand. Large pull requests are difficult to review, and such pull requests may end up being closed. The only exception is when all features in the pull request are related to each other, and share the same core changes.
- **You may be asked to rebase your pull request** if the branch becomes outdated and/or if possibly conflicting changes are made to the target branch. To see how to do this, read [this page](https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request).
- **Details should be provided of tests done.** Simply saying "Tested" or equivalent is not acceptable.
### Code contributions
- **Avoid committing changes directly on GitHub. This includes use of the web editor, and also uploading files.** The web editor lacks most useful GIT features and **should only be used for very minor changes**. It is immediately clear if the web editor has been used, and if so the PR is more likely to be rejected. If you want to make serious contributions, **please learn how to use [GIT version control](https://git-scm.com/)**.
- **Do not copy-paste code**. There are potential license issues implicit with copy-pasting, and copy-paste usually indicates a lack of understanding of the actual code. Copy-pasted code is obvious a mile off and **any PR like this is likely to be closed**. If you want to use somebody else's code from a Git repository, **use [GIT's cherry-pick feature](https://git-scm.com/docs/git-cherry-pick)** to cherry-pick the commit. **Cherry-picking is the politer way to copy somebody's changes** and retains all the original accreditation, so there is no need for copy-pasted commits with descriptions like `Some code, thanks @exampleperson`.
- **Make sure you can explain your changes**. If you can't provide a good explanation of changes, your PR may be rejected.
- **Code should use the same style as in PocketMine-MP.** See [below](#code-syntax) for an example.
- **The code must be clear** and written in English, comments included.
- **Do not make large pull requests without an RFC.** Large changes should be discussed beforehand using the [RFC / Change Proposal](#rfcs--change-proposals) process. Large changes are much harder to review and are more likely to be declined if maintainers don't have a good idea what you're trying to do in advance.
- **Do not copy-paste code**. There are potential license issues implicit with copy-pasting, and copy-paste usually indicates a lack of understanding of the actual code. Copy-pasted code is obvious a mile off and **any PR like this is likely to be closed**. If you want to use somebody else's code from a Git repository, **use [GIT's cherry-pick feature](https://git-scm.com/docs/git-cherry-pick)** to cherry-pick the commit.
**Thanks for contributing to PocketMine-MP!**
## RFCs / Change Proposals
Change Proposals are issues or discussions which describe a new feature proposal or behavioural change.
They are used to get feedback from maintainers and the community about an idea for a change, to decide whether or not it's a good idea.
### Submitting an RFC
RFCs should be submitted using Issues or Discussions.
RFCs _can_ be submitted as pull requests if you've already written the code, but this is not recommended, since it's not guaranteed that an RFC will pass, in which case your effort would be wasted.
### Code Syntax
RFCs should include the following:
- A summary of what you want to change
- Why you want to change it (e.g. what problems it solves)
- Alternative methods you've considered to solve the problem. This should include any possible ways that what you want can be done without the change.
It is mainly [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md) with a few exceptions.
### Voting on RFCs
Community members can vote on RFCs. This gives maintainers an idea of how popular the idea is.
Votes can be cast using :+1: and :-1: reactions.
- Opening braces MUST go on the same line, and MUST NOT have spaces before.
- `else if` MUST be written as `elseif`. _(It is in PSR-2, but using a SHOULD)_
- Control structure keywords or opening braces MUST NOT have one space before or after them.
- Code MUST use tabs for indenting.
- Long arrays MAY be split across multiple lines, where each subsequent line is indented once.
- Files MUST use only the `<?php` tag.
- Files MUST NOT have an ending `?>` tag.
- Code MUST use namespaces.
- Strings SHOULD use the double quote `"` except when the single quote is required.
- All code SHOULD have parameter and type declarations where possible.
- Strict types SHOULD be enabled on new files where it is sensible to do so.
- All constant declarations SHOULD be preceded by a visibility modifier.
**Please don't downvote without providing a reason why!**
```php
<?php
### Implementing RFCs
Anyone can write the code to implement an RFC, and submit a pull request for it. It doesn't have to be the RFC author.
declare(strict_types=1);
namespace pocketmine\example;
class ExampleClass{
public const EXAMPLE_CLASS_CONSTANT = 1;
public $examplePublicVariable = "defaultValue";
private $examplePrivateVariable;
/**
* Creates an instance of ExampleClass
*
* @param string $firstArgument the first argument
* @param string|null $secondArgument default null
*/
public function __construct(string $firstArgument, ?string &$secondArgument = null){
if($firstArgument === "exampleValue"){ //Remember to use === instead of == when possible
//do things
}elseif($firstArgument === "otherValue"){
$secondArgument = function(){
$this->examplePrivateVariable = [
0 => "value1",
1 => "value2",
2 => "value3",
3 => "value4",
4 => "value5",
5 => "value6",
];
};
}
}
public function doStuff(string $stuff) : string{
return $stuff;
}
}
```
<!-- TODO: RFC and voting on the forums instead -->
### RFC and Voting
* These are big Pull Requests or contributions that change important behavior.
* RFCs will be tagged with the *Type: Request For Comments* label
* A vote will be held once the RFC is ready. All users can vote commenting on the Pull Request
* Comments MUST use "Yes" or "No" on the FIRST sentence to signify the vote, except when they don't want it to be counted.
* If your comment is a voting comment, specify the reason of your vote or it won't be counted.
* After voting has been closed, no further votes will be counted.
* An RFC will be rejected if less than 50% + 1 (simple majority) has voted Yes.
* If the RFC is approved, Team Members have the final word on its implementation or rejection.
* RFCs with complex voting options will specify the vote percentage or other details.
Implementations should be submitted as pull requests. The pull request description must include a link to the RFC.

View File

@ -3,7 +3,12 @@
<b>A highly customisable, open source server software for Minecraft: Bedrock Edition written in PHP</b>
</p>
[![Build Status](https://travis-ci.com/pmmp/PocketMine-MP.svg?branch=master)](https://travis-ci.com/pmmp/PocketMine-MP)
<p align="center">
<img src="https://github.com/pmmp/PocketMine-MP/workflows/CI/badge.svg" alt="CI" />
<a href="https://github.com/pmmp/PocketMine-MP/releases"><img src="https://img.shields.io/github/v/tag/pmmp/PocketMine-MP?label=release&logo=github" alt="GitHub tag (latest semver)" /></a>
<a href="https://hub.docker.com/r/pmmp/pocketmine-mp"><img src="https://img.shields.io/docker/v/pmmp/pocketmine-mp?logo=docker&label=image" alt="Docker image version (latest semver)" /></a>
<a href="https://discord.gg/bmSAZBG"><img src="https://img.shields.io/discord/373199722573201408?label=discord&color=7289DA&logo=discord" alt="Discord" /></a>
</p>
## Getting started
- [Documentation](http://pmmp.readthedocs.org/)
@ -18,6 +23,7 @@
## For developers
* [Building and running from source](BUILDING.md)
* [Developer documentation](https://devdoc.pmmp.io) - General documentation for PocketMine-MP plugin developers
* [Latest API documentation](https://jenkins.pmmp.io/job/PocketMine-MP-doc/doxygen/) - Doxygen documentation generated from development
* [DevTools](https://github.com/pmmp/DevTools/) - Development tools plugin for creating plugins
* [ExamplePlugin](https://github.com/pmmp/ExamplePlugin/) - Example plugin demonstrating some basic API features

View File

@ -1,13 +1,5 @@
# Security Policy
## Supported Versions
The following release lines are currently receiving active security updates and bug fixes:
| Version | Supported |
| -------- | ------------------ |
| 3.15.x | :white_check_mark: |
| < 3.15.0 | :x: |
## Reporting a Vulnerability
**DO NOT report vulnerabilities on the GitHub issue tracker.**

View File

@ -0,0 +1,43 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
require dirname(__DIR__) . '/vendor/autoload.php';
if(count($argv) !== 4){
fwrite(STDERR, "required args: <git hash> <tag name> <github repo (owner/name)>");
exit(1);
}
echo json_encode([
"php_version" => sprintf("%d.%d", PHP_MAJOR_VERSION, PHP_MINOR_VERSION),
"base_version" => \pocketmine\BASE_VERSION,
"build" => \pocketmine\BUILD_NUMBER,
"is_dev" => \pocketmine\IS_DEVELOPMENT_BUILD,
"channel" => \pocketmine\BUILD_CHANNEL,
"git_commit" => $argv[1],
"mcpe_version" => \pocketmine\network\mcpe\protocol\ProtocolInfo::MINECRAFT_VERSION_NETWORK,
"date" => time(), //TODO: maybe we should embed this in VersionInfo?
"details_url" => "https://github.com/$argv[3]/releases/tag/$argv[2]",
"download_url" => "https://github.com/$argv[3]/releases/download/$argv[2]/PocketMine-MP.phar",
"source_url" => "https://github.com/$argv[3]/tree/$argv[2]",
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";

View File

@ -24,21 +24,23 @@ declare(strict_types=1);
namespace pocketmine\build\make_release;
use pocketmine\utils\VersionString;
use function defined;
use function count;
use function dirname;
use function fgets;
use function file_get_contents;
use function file_put_contents;
use function fwrite;
use function preg_replace;
use function sleep;
use function sprintf;
use function system;
use const pocketmine\BASE_VERSION;
use const STDERR;
use const STDIN;
require_once dirname(__DIR__) . '/vendor/autoload.php';
function replaceVersion(string $versionInfoPath, string $newVersion, bool $isDev) : void{
function replaceVersion(string $versionInfoPath, string $newVersion, bool $isDev, string $channel) : void{
$versionInfo = file_get_contents($versionInfoPath);
$versionInfo = preg_replace(
$pattern = '/^const BASE_VERSION = "(\d+)\.(\d+)\.(\d+)(?:-(.*))?";$/m',
@ -50,6 +52,11 @@ function replaceVersion(string $versionInfoPath, string $newVersion, bool $isDev
'const IS_DEVELOPMENT_BUILD = ' . ($isDev ? 'true' : 'false') . ';',
$versionInfo
);
$versionInfo = preg_replace(
'/^const BUILD_CHANNEL = ".*";$/m',
'const BUILD_CHANNEL = "' . $channel . '";',
$versionInfo
);
file_put_contents($versionInfoPath, $versionInfo);
}
@ -58,8 +65,12 @@ function replaceVersion(string $versionInfoPath, string $newVersion, bool $isDev
* @phpstan-param list<string> $argv
*/
function main(array $argv) : void{
if(isset($argv[1])){
$currentVer = new VersionString($argv[1]);
if(count($argv) < 2){
fwrite(STDERR, "Arguments: <channel> [release version]\n");
exit(1);
}
if(isset($argv[2])){
$currentVer = new VersionString($argv[2]);
}else{
$currentVer = new VersionString(BASE_VERSION);
}
@ -70,15 +81,20 @@ function main(array $argv) : void{
$currentVer->getPatch() + 1
));
$versionInfoPath = dirname(__DIR__) . '/src/pocketmine/VersionInfo.php';
replaceVersion($versionInfoPath, $currentVer->getBaseVersion(), false);
echo "About to tag version $currentVer. Next version will be $nextVer.\n";
echo "please add appropriate notes to the changelog and press enter...";
fgets(STDIN);
system('git add "' . dirname(__DIR__) . '/changelogs"');
system('git diff --cached --quiet "' . dirname(__DIR__) . '/changelogs"', $result);
if($result === 0){
echo "error: no changelog changes detected; aborting\n";
exit(1);
}
$versionInfoPath = dirname(__DIR__) . '/src/pocketmine/VersionInfo.php';
replaceVersion($versionInfoPath, $currentVer->getBaseVersion(), false, $argv[1]);
system('git commit -m "Release ' . $currentVer->getBaseVersion() . '" --include "' . $versionInfoPath . '"');
system('git tag ' . $currentVer->getBaseVersion());
replaceVersion($versionInfoPath, $nextVer->getBaseVersion(), true);
replaceVersion($versionInfoPath, $nextVer->getBaseVersion(), true, "");
system('git add "' . $versionInfoPath . '"');
system('git commit -m "' . $nextVer->getBaseVersion() . ' is next" --include "' . $versionInfoPath . '"');
echo "pushing changes in 5 seconds\n";
@ -86,6 +102,4 @@ function main(array $argv) : void{
system('git push origin HEAD ' . $currentVer->getBaseVersion());
}
if(!defined('pocketmine\_PHPSTAN_ANALYSIS')){
main($argv);
}
main($argv);

View File

@ -26,7 +26,6 @@ namespace pocketmine\build\server_phar;
use pocketmine\utils\Git;
use function array_map;
use function count;
use function defined;
use function dirname;
use function file_exists;
use function getcwd;
@ -174,6 +173,4 @@ STUB
}
}
if(!defined('pocketmine\_PHPSTAN_ANALYSIS')){
main();
}
main();

63
changelogs/3.17.md Normal file
View File

@ -0,0 +1,63 @@
**For Minecraft: Bedrock Edition 1.16.200**
### Note about API versions
Plugins which don't touch the protocol and compatible with any previous 3.x.y version will also run on these releases and do not need API bumps.
Plugin developers should **only** update their required API to this version if you need the changes in this build.
**WARNING: If your plugin uses the protocol, you're not shielded by API change constraints.** You should consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if you do.
# 3.17.0
- Added support for Minecraft: Bedrock Edition 1.16.200.
- Removed compatibility with earlier versions.
## Known issues (please don't open issues for these)
- Walls don't connect to each other
- Pumpkin and melon stems may not connect to their corresponding pumpkin/melon
- New blocks, items & mobs aren't implemented
- Nether doesn't exist
# 3.17.1
- Fixed some instances of plugin-caused crashes not being detected (eval()'d code, custom plugin paths).
- Server uptime is now included in crash reports.
- Hoes now take damage when used to break sponges.
- Using lava as fuel in a furnace now leaves behind an empty bucket.
# 3.17.2
- Fixed region header corruption when chunks with larger-than-expected lengths are found. These chunks are now treated as corrupted, instead of automatically attempting to salvage them (which usually fails anyway).
- `RegionLoader->removeChunk()` now allows the space used by the removed chunk to be reused by future region saves.
- Extracted `Living->applyConsumptionResults()` from `Living->consumeObject()` (preparation for a future bug fix).
# 3.17.3
- Improved performance of chunk loading in Region-based worlds.
- Improved performance of region header validation in Region-based worlds (indirect improvement to chunk loading performance).
- Fixed some PHP 8.0 language-level compatibility issues.
- Source installations will now exit with an error when Composer dependencies are not in sync with the current Git revision. Now, it's required to run `composer install` after every git pull to make sure the correct dependency versions are installed.
# 3.17.4
- Removed `readline` support. This hasn't been maintained for many years, never worked correctly, and isn't thread-safe in any case.
- Fixed false-positives of region corruption in Region-based worlds (outdated file stat cache).
- Fixed more deprecation warnings on PHP 8.0 (optional parameter before required).
- `CraftItemEvent->getInputs()` now returns a list starting at offset 0, instead of random offsets. (Note that the contents still won't be ordered.)
- `CraftItemEvent->getOutputs()` now returns a list starting at offset 0, instead of random offsets. (Note that the contents still won't be ordered.)
- Fixed a bug that broke synchronized building, bridging, towering and more.
- Objects in memory dumps no longer show inherited properties multiple times.
# 3.17.5
- Reduced CPU wastage by the logger thread.
- Fixed LevelDB deprecation errors on PHP 8.0.
- Added some protocol changes for 1.16.200 which were previously overlooked.
- Player XUIDs are now tracked. If a player's XUID does not match the previously recorded XUID when they next join the server, they will be kicked. This can be disabled by the `player.verify-xuid` setting in `pocketmine.yml`.
- `BUILDING.md` now has a note about `build/server-phar.php`'s compression bug (a bug in PHP).
# 3.17.6
- Fixed core race conditions that could have led to server freezes (race conditions in pmmp/Snooze).
- The log message about Xbox Live authentication being enabled has been reduced to INFO, and the tip on how to turn it off removed (disabling it should usually only be done by power users anyway).
- Fixed `PlayerMoveEvent->getFrom()` returning incorrect results for players who experienced movement reversions.
- Fixed a bug in `ResourcePackClientResponsePacket` decoding that caused unexpected results when decoding the packet twice.
- XUID verification now compares XUIDs against players who are already on the server to detect mismatches to avoid unnecessary loading of playerdata.
- Fixed an inventory duplication bug which could occur when the same player joined with two devices at the same time.
- Fixed cursor item not being synced on inventory transaction rollbacks.
- Fixed items with TAG_Float in their NBT not being able to be moved around in the inventory.
# 3.17.7
- Fixed crash caused by preprocessor in 3.17.6.

31
changelogs/3.18.md Normal file
View File

@ -0,0 +1,31 @@
**For Minecraft: Bedrock Edition 1.16.210**
### Note about API versions
Plugins which don't touch the protocol and compatible with any previous 3.x.y version will also run on these releases and do not need API bumps.
Plugin developers should **only** update their required API to this version if you need the changes in this build.
**WARNING: If your plugin uses the protocol, you're not shielded by API change constraints.** You should consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if you do.
# 3.18.0
- Added support for Minecraft: Bedrock Edition 1.16.210.
- Removed compatibility with earlier versions.
## Known issues (please don't open issues for these)
- Walls don't connect to each other
- Pumpkin and melon stems may not connect to their corresponding pumpkin/melon
- New blocks, items & mobs aren't implemented
- Nether doesn't exist
- Items can't be removed from item frames in Survival mode
# 3.18.1
- UPnP is now supported on all platforms instead of just Windows. Note that it's still experimental. Please file issues for any bugs that you find.
- Fixed server joining when default game mode is set to Spectator mode.
- Fixed items not being able to be removed from item frames in Survival mode.
- Fixed field order in ClientCacheBlobStatusPacket (hits and misses were inverted).
- Fixed a deadlock that could occur when MainLogger->syncFlushBuffer() was used (usually only used during exception logging).
- Updated constants for various things in the protocol.
# 3.18.2
- Fixed `InventoryCloseEvent` not being called on server-initiated inventory closures.
- `PlayerToggleFlightEvent` may now be pre-cancelled if the player attempted to enable flight when flying was not allowed. This replaces the previous behaviour of kicking the player.
- Fixed being unable to change the item in hand from the inventory window when looking at an entity.

31
changelogs/3.19.md Normal file
View File

@ -0,0 +1,31 @@
**For Minecraft: Bedrock Edition 1.16.220**
### Note about API versions
Plugins which don't touch the protocol and compatible with any previous 3.x.y version will also run on these releases and do not need API bumps.
Plugin developers should **only** update their required API to this version if you need the changes in this build.
**WARNING: If your plugin uses the protocol, you're not shielded by API change constraints.** You should consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if you do.
# 3.19.0
- Added support for Minecraft: Bedrock Edition 1.16.220.
- Removed compatibility with earlier versions.
## Known issues (please don't open issues for these)
- Walls don't connect to each other
- Pumpkin and melon stems may not connect to their corresponding pumpkin/melon
- New blocks, items & mobs aren't implemented
- Nether doesn't exist
# 3.19.1
- Fixed some particles not working since 1.16.220.
- Fixed issues with creative inventory items appearing in the wrong places since 1.16.220.
- `Item->removeEnchantment()` now removes the `ench` tag from item NBT when removing the only enchantment on an item.
- Fixed temporary memory leak of repeating tasks which cancelled themselves during their `onRun()` handler (they were pushed back onto the task queue even though cancelled, and only removed at their next attempted repeat).
# 3.19.2
- Signs can now only be edited by the player who placed them. They will become finalized if the chunk containing them is unloaded and reloaded, or if the creating player quits the server.
# 3.19.3
- Fixed `Worker->quit()` returning without stopping the thread.
- Added some protocol constants in `SetDisplayObjectivePacket`.
- Fixed possible client crash caused by `CraftingDataPacket`.

11
changelogs/3.20.md Normal file
View File

@ -0,0 +1,11 @@
**For Minecraft: Bedrock Edition 1.17.0**
### Note about API versions
Plugins which don't touch the protocol and compatible with any previous 3.x.y version will also run on these releases and do not need API bumps.
Plugin developers should **only** update their required API to this version if you need the changes in this build.
**WARNING: If your plugin uses the protocol, you're not shielded by API change constraints.** You should consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if you do.
# 3.20.0
- Added support for Minecraft: Bedrock Edition 1.17.0
- Removed compatibility with earlier versions.

15
changelogs/3.21.md Normal file
View File

@ -0,0 +1,15 @@
**For Minecraft: Bedrock Edition 1.17.0**
### Note about API versions
Plugins which don't touch the protocol and compatible with any previous 3.x.y version will also run on these releases and do not need API bumps.
Plugin developers should **only** update their required API to this version if you need the changes in this build.
**WARNING: If your plugin uses the protocol, you're not shielded by API change constraints.** You should consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if you do.
# 3.21.0
- PHP 7.4 is now required as a minimum.
- A workaround for player movement added in 1.14.30 has been removed.
# 3.21.1
- Fixed so-called 'pot lag' - a bug that could occur when using items while rapidly switching hotbar slots.
- Plugins in crashdumps are now ordered alphabetically for easier reading.

33
changelogs/3.22.md Normal file
View File

@ -0,0 +1,33 @@
**For Minecraft: Bedrock Edition 1.17.10**
### Note about API versions
Plugins which don't touch the protocol and compatible with any previous 3.x.y version will also run on these releases and do not need API bumps.
Plugin developers should **only** update their required API to this version if you need the changes in this build.
**WARNING: If your plugin uses the protocol, you're not shielded by API change constraints.** You should consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if you do.
# 3.22.0
- Added support for Minecraft: Bedrock Edition 1.17.10.
- Removed compatibility with earlier versions.
# 3.22.1
- Added a giant yellow startup warning if using OPcache JIT on PHP 8.0. JIT is currently considered highly unstable and not recommended for production use.
- When using a bad PHP binary, the bootstrap will now report the used `php.ini` path. This can be useful for debugging issues with extension loading when the wrong `php.ini` file is loaded for some reason.
- Fixed `start.cmd` causing the wrong `php.ini` to be loaded on Windows when a global PHP installation is used.
- A debug message is now logged containing expected vs. actual XUID of players when an XUID mismatch is detected.
- Improved the documentation for `Player->getUniqueId()`.
- Fixed a mistake in the documentation of `PlayerAuthInputFlags`.
- Fixed incorrect encoding of `NpcDialoguePacket`.
# 3.22.2
- PHP 8.0 is now the primary supported version. PHP 7.4 is still supported for now, but it will be dropped in the coming weeks. It's recommended to start testing your servers on 8.0 now so you're ready.
- Fixed items in the crafting grid getting deleted on server-side disconnect or session timeout.
- A warning is now logged on startup if a debug build of PHP is used to run the server (because it has a significant performance impact).
- GitHub Actions is now used to build new releases, instead of Jenkins. You can see build logs [here](https://github.com/pmmp/PocketMine-MP/actions/workflows/draft-release.yml).
# 3.22.3
- Fixed a bug in the release build of 3.22.2 which caused the crash archive to reject all crashdumps.
- Fixed possible server crash during player spawning.
# 3.22.4
- Fixed a bug which broke the build of 3.22.3.

View File

@ -1,15 +1,14 @@
{
"name": "pocketmine/pocketmine-mp",
"description": "A server software for Minecraft: Pocket Edition written in PHP",
"description": "A server software for Minecraft: Bedrock Edition written in PHP",
"type": "project",
"homepage": "https://pmmp.io",
"license": "LGPL-3.0",
"require": {
"php": ">=7.3.0",
"php": "^7.4 || ^8.0",
"php-64bit": "*",
"ext-bcmath": "*",
"ext-curl": "*",
"ext-ctype": "*",
"ext-curl": "*",
"ext-date": "*",
"ext-hash": "*",
"ext-json": "*",
@ -19,26 +18,27 @@
"ext-phar": "*",
"ext-pthreads": "~3.2.0",
"ext-reflection": "*",
"ext-simplexml": "*",
"ext-sockets": "*",
"ext-spl": "*",
"ext-yaml": ">=2.0.0",
"ext-zip": "*",
"ext-zlib": ">=1.2.11",
"pocketmine/raklib": "^0.12.7",
"pocketmine/spl": "^0.4.0",
"composer-runtime-api": "^2.0",
"adhocore/json-comment": "^1.1",
"pocketmine/binaryutils": "^0.1.9",
"pocketmine/nbt": "^0.2.10",
"pocketmine/math": "^0.2.0",
"pocketmine/snooze": "^0.1.0",
"pocketmine/callback-validator": "^1.0.2",
"pocketmine/classloader": "^0.1.0",
"pocketmine/log": "^0.2.0",
"pocketmine/log-pthreads": "^0.1.0",
"pocketmine/callback-validator": "^1.0.2",
"adhocore/json-comment": "^0.1.0",
"composer-runtime-api": "^2.0"
"pocketmine/math": "^0.2.0",
"pocketmine/nbt": "^0.2.18",
"pocketmine/raklib": "^0.12.7",
"pocketmine/snooze": "^0.1.0",
"pocketmine/spl": "^0.4.0"
},
"require-dev": {
"phpstan/phpstan": "0.12.59",
"phpstan/phpstan": "0.12.98",
"phpstan/phpstan-phpunit": "^0.12.6",
"phpstan/phpstan-strict-rules": "^0.12.2",
"phpunit/phpunit": "^9.2"
@ -60,13 +60,14 @@
},
"config": {
"platform": {
"php": "7.3.0"
}
"php": "7.4.0"
},
"sort-packages": true
},
"scripts": {
"make-devtools": "@php -dphar.readonly=0 tests/plugins/DevTools/src/DevTools/ConsoleScript.php --make tests/plugins/DevTools --out plugins/DevTools.phar",
"make-server": [
"@composer install --no-dev --classmap-authoritative",
"@composer install --no-dev --classmap-authoritative --ignore-platform-reqs",
"@php -dphar.readonly=0 build/server-phar.php"
]
}

422
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,4 +7,4 @@ This site can be accessed via https://apidoc.pmmp.io.
### Additional developer resources
- [DevTools](https://github.com/pmmp/DevTools/) - Development tools plugin for creating plugins
- [ExamplePlugin](https://github.com/pmmp/ExamplePlugin/) - Example plugin demonstrating some basic API features
- [DeveloperDocs](https://github.com/pmmp/DeveloperDocs/) - Reference, guides and specifications for the PocketMine-MP API
- [DeveloperDocs](https://devdoc.pmmp.io) - General documentation for PocketMine-MP plugin developers

View File

@ -1,15 +1,16 @@
includes:
- tests/phpstan/configs/actual-problems.neon
- tests/phpstan/configs/check-explicit-mixed-baseline.neon
- tests/phpstan/configs/com-dotnet-magic.neon
- tests/phpstan/configs/gc-hacks.neon
- tests/phpstan/configs/l7-baseline.neon
- tests/phpstan/configs/l8-baseline.neon
- tests/phpstan/configs/php74-compat.neon
- tests/phpstan/configs/php-bugs.neon
- tests/phpstan/configs/phpstan-bugs.neon
- tests/phpstan/configs/phpunit-wiring-tests.neon
- tests/phpstan/configs/pthreads-bugs.neon
- tests/phpstan/configs/runtime-type-checks.neon
- tests/phpstan/configs/spl-fixed-array-sucks.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
@ -17,10 +18,11 @@ includes:
parameters:
level: 8
checkExplicitMixed: true
checkMissingCallableSignature: true
bootstrapFiles:
- tests/phpstan/bootstrap.php
scanDirectories:
- tests/plugins/TesterPlugin
- tests/plugins/TesterPlugin
scanFiles:
- src/pocketmine/PocketMine.php
- build/make-release.php
@ -41,3 +43,11 @@ parameters:
reportUnmatchedIgnoredErrors: false #no other way to silence platform-specific non-warnings
staticReflectionClassNamePatterns:
- "#^COM$#"
typeAliases:
#variadics don't work for this - mixed probably shouldn't work either, but for now it does
#what we actually need is something that accepts an infinite number of parameters, but in the absence of that,
#we'll just fill it with 10 - it's very unlikely to encounter a callable with 10 parameters anyway.
anyCallable: 'callable(mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed) : mixed'
anyClosure: '\Closure(mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed) : mixed'
PhpSocket: '\Socket'
PhpCurlHandle: '\CurlHandle'

9
phpstan.php7.neon Normal file
View File

@ -0,0 +1,9 @@
includes:
- phpstan.neon.dist
- tests/phpstan/configs/php7.neon
parameters:
phpVersion: 70400
typeAliases:
PhpSocket: resource
PhpCurlHandle: resource

View File

@ -28,6 +28,7 @@ use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\plugin\PluginBase;
use pocketmine\plugin\PluginLoadOrder;
use pocketmine\plugin\PluginManager;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Utils;
use pocketmine\utils\VersionString;
use function base64_encode;
@ -45,7 +46,9 @@ use function is_dir;
use function is_resource;
use function json_encode;
use function json_last_error_msg;
use function ksort;
use function max;
use function microtime;
use function mkdir;
use function ob_end_clean;
use function ob_get_contents;
@ -58,7 +61,6 @@ use function sprintf;
use function str_split;
use function strpos;
use function substr;
use function time;
use function zend_version;
use function zlib_encode;
use const E_COMPILE_ERROR;
@ -80,6 +82,7 @@ use const FILE_IGNORE_NEW_LINES;
use const JSON_UNESCAPED_SLASHES;
use const PHP_EOL;
use const PHP_OS;
use const SORT_STRING;
class CrashDump{
@ -89,7 +92,7 @@ class CrashDump{
* having their content changed, version format changing, etc.
* It is not necessary to increase this when adding new fields.
*/
private const FORMAT_VERSION = 3;
private const FORMAT_VERSION = 4;
private const PLUGIN_INVOLVEMENT_NONE = "none";
private const PLUGIN_INVOLVEMENT_DIRECT = "direct";
@ -99,7 +102,7 @@ class CrashDump{
private $server;
/** @var resource */
private $fp;
/** @var int */
/** @var float */
private $time;
/**
* @var mixed[]
@ -112,12 +115,12 @@ class CrashDump{
private $path;
public function __construct(Server $server){
$this->time = time();
$this->time = microtime(true);
$this->server = $server;
if(!is_dir($this->server->getDataPath() . "crashdumps")){
mkdir($this->server->getDataPath() . "crashdumps");
}
$this->path = $this->server->getDataPath() . "crashdumps/" . date("D_M_j-H.i.s-T_Y", $this->time) . ".log";
$this->path = $this->server->getDataPath() . "crashdumps/" . date("D_M_j-H.i.s-T_Y", (int) $this->time) . ".log";
$fp = @fopen($this->path, "wb");
if(!is_resource($fp)){
throw new \RuntimeException("Could not create Crash Dump");
@ -125,7 +128,8 @@ class CrashDump{
$this->fp = $fp;
$this->data["format_version"] = self::FORMAT_VERSION;
$this->data["time"] = $this->time;
$this->addLine($this->server->getName() . " Crash Dump " . date("D M j H:i:s T Y", $this->time));
$this->data["uptime"] = $this->time - \pocketmine\START_TIME;
$this->addLine($this->server->getName() . " Crash Dump " . date("D M j H:i:s T Y", (int) $this->time));
$this->addLine();
$this->baseCrash();
$this->generalData();
@ -166,7 +170,9 @@ class CrashDump{
if($json === false){
throw new \RuntimeException("Failed to encode crashdump JSON: " . json_last_error_msg());
}
$this->encodedData = zlib_encode($json, ZLIB_ENCODING_DEFLATE, 9);
$zlibEncoded = zlib_encode($json, ZLIB_ENCODING_DEFLATE, 9);
if($zlibEncoded === false) throw new AssumptionFailedError("ZLIB compression failed");
$this->encodedData = $zlibEncoded;
foreach(str_split(base64_encode($this->encodedData), 76) as $line){
$this->addLine($line);
}
@ -178,7 +184,9 @@ class CrashDump{
$this->addLine();
$this->addLine("Loaded plugins:");
$this->data["plugins"] = [];
foreach($this->server->getPluginManager()->getPlugins() as $p){
$plugins = $this->server->getPluginManager()->getPlugins();
ksort($plugins, SORT_STRING);
foreach($plugins as $p){
$d = $p->getDescription();
$this->data["plugins"][$d->getName()] = [
"name" => $d->getName(),
@ -202,9 +210,16 @@ class CrashDump{
if($this->server->getProperty("auto-report.send-settings", true) !== false){
$this->data["parameters"] = (array) $argv;
$this->data["server.properties"] = @file_get_contents($this->server->getDataPath() . "server.properties");
$this->data["server.properties"] = preg_replace("#^rcon\\.password=(.*)$#m", "rcon.password=******", $this->data["server.properties"]);
$this->data["pocketmine.yml"] = @file_get_contents($this->server->getDataPath() . "pocketmine.yml");
if(($serverDotProperties = @file_get_contents($this->server->getDataPath() . "server.properties")) !== false){
$this->data["server.properties"] = preg_replace("#^rcon\\.password=(.*)$#m", "rcon.password=******", $serverDotProperties);
}else{
$this->data["server.properties"] = $serverDotProperties;
}
if(($pocketmineDotYml = @file_get_contents($this->server->getDataPath() . "pocketmine.yml")) !== false){
$this->data["pocketmine.yml"] = $pocketmineDotYml;
}else{
$this->data["pocketmine.yml"] = "";
}
}else{
$this->data["pocketmine.yml"] = "";
$this->data["server.properties"] = "";
@ -310,8 +325,8 @@ class CrashDump{
}
private function determinePluginFromFile(string $filePath, bool $crashFrame) : bool{
$frameCleanPath = Utils::cleanPath($filePath); //this will be empty in phar stub
if(strpos($frameCleanPath, "plugins") === 0 and file_exists($filePath)){
$frameCleanPath = Utils::cleanPath($filePath);
if(strpos($frameCleanPath, Utils::CLEAN_PATH_SRC_PREFIX) !== 0){
$this->addLine();
if($crashFrame){
$this->addLine("THIS CRASH WAS CAUSED BY A PLUGIN");
@ -321,15 +336,17 @@ class CrashDump{
$this->data["plugin_involvement"] = self::PLUGIN_INVOLVEMENT_INDIRECT;
}
$reflection = new \ReflectionClass(PluginBase::class);
$file = $reflection->getProperty("file");
$file->setAccessible(true);
foreach($this->server->getPluginManager()->getPlugins() as $plugin){
$filePath = Utils::cleanPath($file->getValue($plugin));
if(strpos($frameCleanPath, $filePath) === 0){
$this->data["plugin"] = $plugin->getName();
$this->addLine("BAD PLUGIN: " . $plugin->getDescription()->getFullName());
break;
if(file_exists($filePath)){
$reflection = new \ReflectionClass(PluginBase::class);
$file = $reflection->getProperty("file");
$file->setAccessible(true);
foreach($this->server->getPluginManager()->getPlugins() as $plugin){
$filePath = Utils::cleanPath($file->getValue($plugin));
if(strpos($frameCleanPath, $filePath) === 0){
$this->data["plugin"] = $plugin->getName();
$this->addLine("BAD PLUGIN: " . $plugin->getDescription()->getFullName());
break;
}
}
}
return true;

View File

@ -423,8 +423,12 @@ class MemoryManager{
}
$name = $property->getName();
if($reflection !== $original and !$property->isPublic()){
$name = $reflection->getName() . ":" . $name;
if($reflection !== $original){
if($property->isPrivate()){
$name = $reflection->getName() . ":" . $name;
}else{
continue;
}
}
if(!$property->isPublic()){
$property->setAccessible(true);

View File

@ -100,6 +100,7 @@ use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\convert\ItemTypeDictionary;
use pocketmine\network\mcpe\PlayerNetworkSessionAdapter;
use pocketmine\network\mcpe\protocol\ActorEventPacket;
@ -151,10 +152,17 @@ use pocketmine\network\mcpe\protocol\types\ContainerIds;
use pocketmine\network\mcpe\protocol\types\DimensionIds;
use pocketmine\network\mcpe\protocol\types\Experiments;
use pocketmine\network\mcpe\protocol\types\GameMode;
use pocketmine\network\mcpe\protocol\types\inventory\MismatchTransactionData;
use pocketmine\network\mcpe\protocol\types\inventory\NormalTransactionData;
use pocketmine\network\mcpe\protocol\types\inventory\ReleaseItemTransactionData;
use pocketmine\network\mcpe\protocol\types\inventory\UIInventorySlotOffset;
use pocketmine\network\mcpe\protocol\types\inventory\UseItemOnEntityTransactionData;
use pocketmine\network\mcpe\protocol\types\inventory\UseItemTransactionData;
use pocketmine\network\mcpe\protocol\types\NetworkInventoryAction;
use pocketmine\network\mcpe\protocol\types\PersonaPieceTintColor;
use pocketmine\network\mcpe\protocol\types\PersonaSkinPiece;
use pocketmine\network\mcpe\protocol\types\PlayerMovementSettings;
use pocketmine\network\mcpe\protocol\types\PlayerMovementType;
use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
use pocketmine\network\mcpe\protocol\types\SkinAdapterSingleton;
use pocketmine\network\mcpe\protocol\types\SkinAnimation;
@ -193,7 +201,9 @@ use function get_class;
use function gettype;
use function implode;
use function in_array;
use function is_infinite;
use function is_int;
use function is_nan;
use function is_object;
use function is_string;
use function json_encode;
@ -205,6 +215,7 @@ use function min;
use function preg_match;
use function round;
use function spl_object_hash;
use function sprintf;
use function sqrt;
use function strlen;
use function strpos;
@ -408,8 +419,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** @var float */
protected $lastRightClickTime = 0.0;
/** @var Vector3|null */
protected $lastRightClickPos = null;
/** @var UseItemTransactionData|null */
protected $lastRightClickData = null;
/**
* @return TranslationContainer|string
@ -472,19 +483,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
/**
* Returns the player's UUID. This should be preferred over their Xbox user ID (XUID) because UUID is a standard
* format which will never change, and all players will have one regardless of whether they are logged into Xbox
* Live.
* Returns the player's UUID. This should be the preferred method to identify a player.
* It does not change if the player changes their username.
*
* The UUID is comprised of:
* - when logged into XBL: a hash of their XUID (and as such will not change for the lifetime of the XBL account)
* - when NOT logged into XBL: a hash of their name + clientID + secret device ID.
* All players will have a UUID, regardless of whether they are logged into Xbox Live or not. However, note that
* non-XBL players can fake their UUIDs.
*
* WARNING: UUIDs of players **not logged into Xbox Live** CAN BE FAKED and SHOULD NOT be trusted!
*
* (In the olden days this method used to return a fake UUID computed by the server, which was used by plugins such
* as SimpleAuth for authentication. This is NOT SAFE anymore as this UUID is now what was given by the client, NOT
* a server-computed UUID.)
* WARNING: DO NOT trust this before PlayerLoginEvent. Before PlayerLoginEvent, the player hasn't yet been
* authenticated, and any of their data might be faked.
*/
public function getUniqueId() : ?UUID{
return parent::getUniqueId();
@ -1067,7 +1073,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* @return void
*/
public function doFirstSpawn(){
if($this->spawned){
if($this->spawned || !$this->constructed){
return; //avoid player spawning twice (this can only happen on 3.x with a custom malicious client)
}
$this->spawned = true;
@ -1652,13 +1658,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch);
if($delta > 0.0001 or $deltaAngle > 1.0){
$this->lastX = $to->x;
$this->lastY = $to->y;
$this->lastZ = $to->z;
$this->lastYaw = $to->yaw;
$this->lastPitch = $to->pitch;
$ev = new PlayerMoveEvent($this, $from, $to);
$ev->call();
@ -1673,6 +1672,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return;
}
$this->lastX = $to->x;
$this->lastY = $to->y;
$this->lastZ = $to->z;
$this->lastYaw = $to->yaw;
$this->lastPitch = $to->pitch;
$this->broadcastMovement();
$distance = sqrt((($from->x - $to->x) ** 2) + (($from->z - $to->z) ** 2));
@ -1695,13 +1700,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
protected function revertMovement(Location $from) : void{
$this->lastX = $from->x;
$this->lastY = $from->y;
$this->lastZ = $from->z;
$this->lastYaw = $from->yaw;
$this->lastPitch = $from->pitch;
$this->setPosition($from);
$this->sendPosition($from, $from->yaw, $from->pitch, MovePlayerPacket::MODE_RESET);
}
@ -1964,6 +1962,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$skinData = new SkinData(
$packet->clientData["SkinId"],
$packet->clientData["PlayFabId"],
base64_decode($packet->clientData["SkinResourcePatch"] ?? "", true),
new SkinImage(
$packet->clientData["SkinImageHeight"],
@ -2080,17 +2079,43 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* @return void
*/
protected function processLogin(){
$checkXUID = (bool) $this->server->getProperty("player.verify-xuid", true);
$kickForXUIDMismatch = function(string $xuid) use ($checkXUID) : bool{
if($checkXUID && $this->xuid !== $xuid){
$this->server->getLogger()->debug($this->getName() . " XUID mismatch: expected '$xuid', but got '$this->xuid'");
if($this->kick("XUID does not match (possible impersonation attempt)", false)){
//TODO: Longer term, we should be identifying playerdata using something more reliable, like XUID or UUID.
//However, that would be a very disruptive change, so this will serve as a stopgap for now.
//Side note: this will also prevent offline players hijacking XBL playerdata on online servers, since their
//XUID will always be empty.
return true;
}
$this->server->getLogger()->debug("XUID mismatch for " . $this->getName() . ", but plugin cancelled event allowing them to join anyway");
}
return false;
};
foreach($this->server->getLoggedInPlayers() as $p){
if($p !== $this and ($p->iusername === $this->iusername or $this->getUniqueId()->equals($p->getUniqueId()))){
if($kickForXUIDMismatch($p->getXuid())){
return;
}
if(!$p->kick("logged in from another location")){
$this->close($this->getLeaveMessage(), "Logged in from another location");
return;
}
}
}
$this->namedtag = $this->server->getOfflinePlayerData($this->username);
if($checkXUID){
$recordedXUID = $this->namedtag->getTag("LastKnownXUID");
if(!($recordedXUID instanceof StringTag)){
$this->server->getLogger()->debug("No previous XUID recorded for " . $this->getName() . ", no choice but to trust this player");
}elseif(!$kickForXUIDMismatch($recordedXUID->getValue())){
$this->server->getLogger()->debug("XUID match for " . $this->getName());
}
}
$this->playedBefore = ($this->getLastPlayed() - $this->getFirstPlayed()) > 1; // microtime(true) - microtime(true) may have less than one millisecond difference
$this->namedtag->setString("NameTag", $this->username);
@ -2250,6 +2275,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$pk->worldName = $this->server->getMotd();
$pk->experiments = new Experiments([], false);
$pk->itemTable = ItemTypeDictionary::getInstance()->getEntries();
$pk->playerMovementSettings = new PlayerMovementSettings(PlayerMovementType::LEGACY, 0, false);
$pk->serverSoftwareVersion = sprintf("%s %s", \pocketmine\NAME, \pocketmine\VERSION);
$this->dataPacket($pk);
$this->sendDataPacket(new AvailableActorIdentifiersPacket());
@ -2335,8 +2362,15 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
public function handleMovePlayer(MovePlayerPacket $packet) : bool{
$newPos = $packet->position->round(4)->subtract(0, $this->baseOffset, 0);
$rawPos = $packet->position;
foreach([$rawPos->x, $rawPos->y, $rawPos->z, $packet->yaw, $packet->headYaw, $packet->pitch] as $float){
if(is_infinite($float) || is_nan($float)){
$this->server->getLogger()->debug("Invalid movement from " . $this->getName() . ", contains NAN/INF components");
return false;
}
}
$newPos = $rawPos->round(4)->subtract(0, $this->baseOffset, 0);
if($this->forceMoveSync !== null and $newPos->distanceSquared($this->forceMoveSync) > 1){ //Tolerate up to 1 block to avoid problems with client-sided physics when spawning in blocks
$this->server->getLogger()->debug("Got outdated pre-teleport movement from " . $this->getName() . ", received " . $newPos . ", expected " . $this->asVector3());
//Still getting movements from before teleport, ignore them
@ -2404,14 +2438,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** @var InventoryAction[] $actions */
$actions = [];
$isCraftingPart = false;
foreach($packet->actions as $networkInventoryAction){
foreach($packet->trData->getActions() as $networkInventoryAction){
if(
$networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_TODO and (
$networkInventoryAction->windowId === NetworkInventoryAction::SOURCE_TYPE_CRAFTING_RESULT or
$networkInventoryAction->windowId === NetworkInventoryAction::SOURCE_TYPE_CRAFTING_USE_INGREDIENT
) or (
$this->craftingTransaction !== null &&
!$networkInventoryAction->oldItem->equalsExact($networkInventoryAction->newItem) &&
!$networkInventoryAction->oldItem->getItemStack()->equalsExact($networkInventoryAction->newItem->getItemStack()) &&
$networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_CONTAINER &&
$networkInventoryAction->windowId === ContainerIds::UI &&
$networkInventoryAction->inventorySlot === UIInventorySlotOffset::CREATED_ITEM_OUTPUT
@ -2462,317 +2496,325 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->craftingTransaction = null;
}
switch($packet->transactionType){
case InventoryTransactionPacket::TYPE_NORMAL:
$this->setUsingItem(false);
$transaction = new InventoryTransaction($this, $actions);
if($packet->trData instanceof NormalTransactionData){
$this->setUsingItem(false);
$transaction = new InventoryTransaction($this, $actions);
try{
$transaction->execute();
}catch(TransactionValidationException $e){
$this->server->getLogger()->debug("Failed to execute inventory transaction from " . $this->getName() . ": " . $e->getMessage());
$this->server->getLogger()->debug("Actions: " . json_encode($packet->actions));
try{
$transaction->execute();
}catch(TransactionValidationException $e){
$this->server->getLogger()->debug("Failed to execute inventory transaction from " . $this->getName() . ": " . $e->getMessage());
$this->server->getLogger()->debug("Actions: " . json_encode($packet->trData->getActions()));
return false;
}
return false;
}
//TODO: fix achievement for getting iron from furnace
//TODO: fix achievement for getting iron from furnace
return true;
case InventoryTransactionPacket::TYPE_MISMATCH:
if(count($packet->actions) > 0){
$this->server->getLogger()->debug("Expected 0 actions for mismatch, got " . count($packet->actions) . ", " . json_encode($packet->actions));
}
$this->setUsingItem(false);
$this->sendAllInventories();
return true;
}elseif($packet->trData instanceof MismatchTransactionData){
if(count($packet->trData->getActions()) > 0){
$this->server->getLogger()->debug("Expected 0 actions for mismatch, got " . count($packet->trData->getActions()) . ", " . json_encode($packet->trData->getActions()));
}
$this->setUsingItem(false);
$this->sendAllInventories();
return true;
case InventoryTransactionPacket::TYPE_USE_ITEM:
$blockVector = new Vector3($packet->trData->x, $packet->trData->y, $packet->trData->z);
$face = $packet->trData->face;
return true;
}elseif($packet->trData instanceof UseItemTransactionData){
$type = $packet->trData->actionType;
switch($type){
case InventoryTransactionPacket::USE_ITEM_ACTION_CLICK_BLOCK:
//TODO: start hack for client spam bug
$spamBug = ($this->lastRightClickPos !== null and
microtime(true) - $this->lastRightClickTime < 0.1 and //100ms
$this->lastRightClickPos->distanceSquared($packet->trData->clickPos) < 0.00001 //signature spam bug has 0 distance, but allow some error
);
//get rid of continued spam if the player clicks and holds right-click
$this->lastRightClickPos = clone $packet->trData->clickPos;
$this->lastRightClickTime = microtime(true);
if($spamBug){
return true;
}
//TODO: end hack for client spam bug
$blockVector = $packet->trData->getBlockPos();
$face = $packet->trData->getFace();
$this->setUsingItem(false);
if(!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13)){
}elseif($this->isCreative()){
$item = $this->inventory->getItemInHand();
if($this->level->useItemOn($blockVector, $item, $face, $packet->trData->clickPos, $this, true)){
return true;
}
}elseif(!$this->inventory->getItemInHand()->equals($packet->trData->itemInHand)){
$this->inventory->sendHeldItem($this);
}else{
$item = $this->inventory->getItemInHand();
$oldItem = clone $item;
if($this->level->useItemOn($blockVector, $item, $face, $packet->trData->clickPos, $this, true)){
if(!$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
$this->inventory->setItemInHand($item);
$this->inventory->sendHeldItem($this->hasSpawned);
}
return true;
}
}
$this->inventory->sendHeldItem($this);
if($blockVector->distanceSquared($this) > 10000){
return true;
}
$target = $this->level->getBlock($blockVector);
$block = $target->getSide($face);
/** @var Block[] $blocks */
$blocks = array_merge($target->getAllSides(), $block->getAllSides()); //getAllSides() on each of these will include $target and $block because they are next to each other
$this->level->sendBlocks([$this], $blocks, UpdateBlockPacket::FLAG_ALL_PRIORITY);
if($this->inventory->getHeldItemIndex() !== $packet->trData->getHotbarSlot()){
$this->inventory->equipItem($packet->trData->getHotbarSlot());
}
switch($packet->trData->getActionType()){
case UseItemTransactionData::ACTION_CLICK_BLOCK:
//TODO: start hack for client spam bug
$spamBug = ($this->lastRightClickData !== null and
microtime(true) - $this->lastRightClickTime < 0.1 and //100ms
$this->lastRightClickData->getPlayerPos()->distanceSquared($packet->trData->getPlayerPos()) < 0.00001 and
$this->lastRightClickData->getBlockPos()->equals($packet->trData->getBlockPos()) and
$this->lastRightClickData->getClickPos()->distanceSquared($packet->trData->getClickPos()) < 0.00001 //signature spam bug has 0 distance, but allow some error
);
//get rid of continued spam if the player clicks and holds right-click
$this->lastRightClickData = $packet->trData;
$this->lastRightClickTime = microtime(true);
if($spamBug){
return true;
case InventoryTransactionPacket::USE_ITEM_ACTION_BREAK_BLOCK:
$this->doCloseInventory();
}
//TODO: end hack for client spam bug
$this->setUsingItem(false);
if(!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13)){
}elseif($this->isCreative()){
$item = $this->inventory->getItemInHand();
if($this->level->useItemOn($blockVector, $item, $face, $packet->trData->getClickPos(), $this, true)){
return true;
}
}elseif(!$this->inventory->getItemInHand()->equals($packet->trData->getItemInHand()->getItemStack())){
$this->inventory->sendHeldItem($this);
}else{
$item = $this->inventory->getItemInHand();
$oldItem = clone $item;
if($this->canInteract($blockVector->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 7) and $this->level->useBreakOn($blockVector, $item, $this, true)){
if($this->isSurvival()){
if(!$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
$this->inventory->setItemInHand($item);
$this->inventory->sendHeldItem($this->hasSpawned);
}
$this->exhaust(0.025, PlayerExhaustEvent::CAUSE_MINING);
if($this->level->useItemOn($blockVector, $item, $face, $packet->trData->getClickPos(), $this, true)){
if(!$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
$this->inventory->setItemInHand($item);
$this->inventory->sendHeldItem($this->hasSpawned);
}
return true;
}
}
$this->inventory->sendContents($this);
$this->inventory->sendHeldItem($this);
$target = $this->level->getBlock($blockVector);
/** @var Block[] $blocks */
$blocks = $target->getAllSides();
$blocks[] = $target;
$this->level->sendBlocks([$this], $blocks, UpdateBlockPacket::FLAG_ALL_PRIORITY);
foreach($blocks as $b){
$tile = $this->level->getTile($b);
if($tile instanceof Spawnable){
$tile->spawnTo($this);
}
}
$this->inventory->sendHeldItem($this);
if($blockVector->distanceSquared($this) > 10000){
return true;
case InventoryTransactionPacket::USE_ITEM_ACTION_CLICK_AIR:
if($this->isUsingItem()){
$slot = $this->inventory->getItemInHand();
if($slot instanceof Consumable and !($slot instanceof MaybeConsumable and !$slot->canBeConsumed())){
$ev = new PlayerItemConsumeEvent($this, $slot);
if($this->hasItemCooldown($slot)){
$ev->setCancelled();
}
$ev->call();
if($ev->isCancelled() or !$this->consumeObject($slot)){
$this->inventory->sendContents($this);
return true;
}
$this->resetItemCooldown($slot);
if($this->isSurvival()){
$slot->pop();
$this->inventory->setItemInHand($slot);
$this->inventory->addItem($slot->getResidue());
}
$this->setUsingItem(false);
}
$target = $this->level->getBlock($blockVector);
$block = $target->getSide($face);
/** @var Block[] $blocks */
$blocks = array_merge($target->getAllSides(), $block->getAllSides()); //getAllSides() on each of these will include $target and $block because they are next to each other
$this->level->sendBlocks([$this], $blocks, UpdateBlockPacket::FLAG_ALL_PRIORITY);
return true;
case UseItemTransactionData::ACTION_BREAK_BLOCK:
$this->doCloseInventory();
$item = $this->inventory->getItemInHand();
$oldItem = clone $item;
if($this->canInteract($blockVector->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 7) and $this->level->useBreakOn($blockVector, $item, $this, true)){
if($this->isSurvival()){
if(!$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
$this->inventory->setItemInHand($item);
$this->inventory->sendHeldItem($this->hasSpawned);
}
}
$directionVector = $this->getDirectionVector();
if($this->isCreative()){
$item = $this->inventory->getItemInHand();
}elseif(!$this->inventory->getItemInHand()->equals($packet->trData->itemInHand)){
$this->inventory->sendHeldItem($this);
return true;
}else{
$item = $this->inventory->getItemInHand();
$this->exhaust(0.025, PlayerExhaustEvent::CAUSE_MINING);
}
return true;
}
$ev = new PlayerInteractEvent($this, $item, null, $directionVector, $face, PlayerInteractEvent::RIGHT_CLICK_AIR);
if($this->hasItemCooldown($item) or $this->isSpectator()){
$ev->setCancelled();
$this->inventory->sendContents($this);
$this->inventory->sendHeldItem($this);
$target = $this->level->getBlock($blockVector);
/** @var Block[] $blocks */
$blocks = $target->getAllSides();
$blocks[] = $target;
$this->level->sendBlocks([$this], $blocks, UpdateBlockPacket::FLAG_ALL_PRIORITY);
foreach($blocks as $b){
$tile = $this->level->getTile($b);
if($tile instanceof Spawnable){
$tile->spawnTo($this);
}
}
$ev->call();
if($ev->isCancelled()){
$this->inventory->sendHeldItem($this);
return true;
}
if($item->onClickAir($this, $directionVector)){
$this->resetItemCooldown($item);
return true;
case UseItemTransactionData::ACTION_CLICK_AIR:
if($this->isUsingItem()){
$slot = $this->inventory->getItemInHand();
if($slot instanceof Consumable and !($slot instanceof MaybeConsumable and !$slot->canBeConsumed())){
$ev = new PlayerItemConsumeEvent($this, $slot);
if($this->hasItemCooldown($slot)){
$ev->setCancelled();
}
$ev->call();
if($ev->isCancelled() or !$this->consumeObject($slot)){
$this->inventory->sendContents($this);
return true;
}
$this->resetItemCooldown($slot);
if($this->isSurvival()){
$slot->pop();
$this->inventory->setItemInHand($slot);
$this->inventory->addItem($slot->getResidue());
}
$this->setUsingItem(false);
}
}
$directionVector = $this->getDirectionVector();
if($this->isCreative()){
$item = $this->inventory->getItemInHand();
}elseif(!$this->inventory->getItemInHand()->equals($packet->trData->getItemInHand()->getItemStack())){
$this->inventory->sendHeldItem($this);
return true;
}else{
$item = $this->inventory->getItemInHand();
}
$ev = new PlayerInteractEvent($this, $item, null, $directionVector, $face, PlayerInteractEvent::RIGHT_CLICK_AIR);
if($this->hasItemCooldown($item) or $this->isSpectator()){
$ev->setCancelled();
}
$ev->call();
if($ev->isCancelled()){
$this->inventory->sendHeldItem($this);
return true;
}
if($item->onClickAir($this, $directionVector)){
$this->resetItemCooldown($item);
if($this->isSurvival()){
$this->inventory->setItemInHand($item);
}
}
$this->setUsingItem(true);
return true;
default:
//unknown
break;
}
$this->inventory->sendContents($this);
return false;
}elseif($packet->trData instanceof UseItemOnEntityTransactionData){
$target = $this->level->getEntity($packet->trData->getEntityRuntimeId());
if($target === null){
return false;
}
if($this->inventory->getHeldItemIndex() !== $packet->trData->getHotbarSlot()){
$this->inventory->equipItem($packet->trData->getHotbarSlot());
}
switch($packet->trData->getActionType()){
case UseItemOnEntityTransactionData::ACTION_INTERACT:
break; //TODO
case UseItemOnEntityTransactionData::ACTION_ATTACK:
if(!$target->isAlive()){
return true;
}
if($target instanceof ItemEntity or $target instanceof Arrow){
$this->kick("Attempting to attack an invalid entity");
$this->server->getLogger()->warning($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidEntity", [$this->getName()]));
return false;
}
$cancelled = false;
$heldItem = $this->inventory->getItemInHand();
$oldItem = clone $heldItem;
if(!$this->canInteract($target, 8) or $this->isSpectator()){
$cancelled = true;
}elseif($target instanceof Player){
if(!$this->server->getConfigBool("pvp")){
$cancelled = true;
}
}
$ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $heldItem->getAttackPoints());
$meleeEnchantmentDamage = 0;
/** @var EnchantmentInstance[] $meleeEnchantments */
$meleeEnchantments = [];
foreach($heldItem->getEnchantments() as $enchantment){
$type = $enchantment->getType();
if($type instanceof MeleeWeaponEnchantment and $type->isApplicableTo($target)){
$meleeEnchantmentDamage += $type->getDamageBonus($enchantment->getLevel());
$meleeEnchantments[] = $enchantment;
}
}
$ev->setModifier($meleeEnchantmentDamage, EntityDamageEvent::MODIFIER_WEAPON_ENCHANTMENTS);
if($cancelled){
$ev->setCancelled();
}
if(!$this->isSprinting() and !$this->isFlying() and $this->fallDistance > 0 and !$this->hasEffect(Effect::BLINDNESS) and !$this->isUnderwater()){
$ev->setModifier($ev->getFinalDamage() / 2, EntityDamageEvent::MODIFIER_CRITICAL);
}
$target->attack($ev);
if($ev->isCancelled()){
if($heldItem instanceof Durable and $this->isSurvival()){
$this->inventory->sendContents($this);
}
return true;
}
if($ev->getModifier(EntityDamageEvent::MODIFIER_CRITICAL) > 0){
$pk = new AnimatePacket();
$pk->action = AnimatePacket::ACTION_CRITICAL_HIT;
$pk->entityRuntimeId = $target->getId();
$this->server->broadcastPacket($target->getViewers(), $pk);
if($target instanceof Player){
$target->dataPacket($pk);
}
}
foreach($meleeEnchantments as $enchantment){
$type = $enchantment->getType();
assert($type instanceof MeleeWeaponEnchantment);
$type->onPostAttack($this, $target, $enchantment->getLevel());
}
if($this->isAlive()){
//reactive damage like thorns might cause us to be killed by attacking another mob, which
//would mean we'd already have dropped the inventory by the time we reached here
if($heldItem->onAttackEntity($target) and $this->isSurvival() and $oldItem->equalsExact($this->inventory->getItemInHand())){ //always fire the hook, even if we are survival
$this->inventory->setItemInHand($heldItem);
}
$this->exhaust(0.3, PlayerExhaustEvent::CAUSE_ATTACK);
}
return true;
default:
break; //unknown
}
$this->inventory->sendContents($this);
return false;
}elseif($packet->trData instanceof ReleaseItemTransactionData){
if($this->inventory->getHeldItemIndex() !== $packet->trData->getHotbarSlot()){
$this->inventory->equipItem($packet->trData->getHotbarSlot());
}
try{
switch($packet->trData->getActionType()){
case ReleaseItemTransactionData::ACTION_RELEASE:
if($this->isUsingItem()){
$item = $this->inventory->getItemInHand();
if($this->hasItemCooldown($item)){
$this->inventory->sendContents($this);
return false;
}
if($item->onReleaseUsing($this)){
$this->resetItemCooldown($item);
$this->inventory->setItemInHand($item);
}
return true;
}
$this->setUsingItem(true);
return true;
break;
default:
//unknown
break;
}
break;
case InventoryTransactionPacket::TYPE_USE_ITEM_ON_ENTITY:
$target = $this->level->getEntity($packet->trData->entityRuntimeId);
if($target === null){
return false;
}
$type = $packet->trData->actionType;
switch($type){
case InventoryTransactionPacket::USE_ITEM_ON_ENTITY_ACTION_INTERACT:
break; //TODO
case InventoryTransactionPacket::USE_ITEM_ON_ENTITY_ACTION_ATTACK:
if(!$target->isAlive()){
return true;
}
if($target instanceof ItemEntity or $target instanceof Arrow){
$this->kick("Attempting to attack an invalid entity");
$this->server->getLogger()->warning($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidEntity", [$this->getName()]));
return false;
}
$cancelled = false;
$heldItem = $this->inventory->getItemInHand();
$oldItem = clone $heldItem;
if(!$this->canInteract($target, 8) or $this->isSpectator()){
$cancelled = true;
}elseif($target instanceof Player){
if(!$this->server->getConfigBool("pvp")){
$cancelled = true;
}
}
$ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $heldItem->getAttackPoints());
$meleeEnchantmentDamage = 0;
/** @var EnchantmentInstance[] $meleeEnchantments */
$meleeEnchantments = [];
foreach($heldItem->getEnchantments() as $enchantment){
$type = $enchantment->getType();
if($type instanceof MeleeWeaponEnchantment and $type->isApplicableTo($target)){
$meleeEnchantmentDamage += $type->getDamageBonus($enchantment->getLevel());
$meleeEnchantments[] = $enchantment;
}
}
$ev->setModifier($meleeEnchantmentDamage, EntityDamageEvent::MODIFIER_WEAPON_ENCHANTMENTS);
if($cancelled){
$ev->setCancelled();
}
if(!$this->isSprinting() and !$this->isFlying() and $this->fallDistance > 0 and !$this->hasEffect(Effect::BLINDNESS) and !$this->isUnderwater()){
$ev->setModifier($ev->getFinalDamage() / 2, EntityDamageEvent::MODIFIER_CRITICAL);
}
$target->attack($ev);
if($ev->isCancelled()){
if($heldItem instanceof Durable and $this->isSurvival()){
$this->inventory->sendContents($this);
}
return true;
}
if($ev->getModifier(EntityDamageEvent::MODIFIER_CRITICAL) > 0){
$pk = new AnimatePacket();
$pk->action = AnimatePacket::ACTION_CRITICAL_HIT;
$pk->entityRuntimeId = $target->getId();
$this->server->broadcastPacket($target->getViewers(), $pk);
if($target instanceof Player){
$target->dataPacket($pk);
}
}
foreach($meleeEnchantments as $enchantment){
$type = $enchantment->getType();
assert($type instanceof MeleeWeaponEnchantment);
$type->onPostAttack($this, $target, $enchantment->getLevel());
}
if($this->isAlive()){
//reactive damage like thorns might cause us to be killed by attacking another mob, which
//would mean we'd already have dropped the inventory by the time we reached here
if($heldItem->onAttackEntity($target) and $this->isSurvival() and $oldItem->equalsExact($this->inventory->getItemInHand())){ //always fire the hook, even if we are survival
$this->inventory->setItemInHand($heldItem);
}
$this->exhaust(0.3, PlayerExhaustEvent::CAUSE_ATTACK);
}
return true;
default:
break; //unknown
}
break;
case InventoryTransactionPacket::TYPE_RELEASE_ITEM:
try{
$type = $packet->trData->actionType;
switch($type){
case InventoryTransactionPacket::RELEASE_ITEM_ACTION_RELEASE:
if($this->isUsingItem()){
$item = $this->inventory->getItemInHand();
if($this->hasItemCooldown($item)){
$this->inventory->sendContents($this);
return false;
}
if($item->onReleaseUsing($this)){
$this->resetItemCooldown($item);
$this->inventory->setItemInHand($item);
}
}else{
break;
}
return true;
default:
break;
}
}finally{
$this->setUsingItem(false);
}
$this->inventory->sendContents($this);
break;
default:
$this->inventory->sendContents($this);
break;
}finally{
$this->setUsingItem(false);
}
$this->inventory->sendContents($this);
return false;
}else{
$this->inventory->sendContents($this);
return false;
}
return false; //TODO
}
public function handleMobEquipment(MobEquipmentPacket $packet) : bool{
@ -2782,8 +2824,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$item = $this->inventory->getItem($packet->hotbarSlot);
if(!$item->equals($packet->item)){
$this->server->getLogger()->debug("Tried to equip " . $packet->item . " but have " . $item . " in target slot");
if(!$item->equals($packet->item->getItemStack())){
$this->server->getLogger()->debug("Tried to equip " . $packet->item->getItemStack() . " but have " . $item . " in target slot");
$this->inventory->sendContents($this);
return false;
}
@ -2799,15 +2841,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if(!$this->spawned or !$this->isAlive()){
return true;
}
if($packet->action === InteractPacket::ACTION_MOUSEOVER and $packet->target === 0){
//TODO HACK: silence useless spam (MCPE 1.8)
//this packet is EXPECTED to only be sent when interacting with an entity, but due to some messy Mojang
//hacks, it also sends it when changing the held item now, which causes us to think the inventory was closed
//when it wasn't.
return true;
}
$this->doCloseInventory();
if($packet->action !== InteractPacket::ACTION_MOUSEOVER){
//mouseover fires when the player swaps their held itemstack in the inventory menu
$this->doCloseInventory();
}
$target = $this->level->getEntity($packet->target);
if($target === null){
@ -2902,6 +2940,16 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
break;
}
$tile = $this->level->getTile($pos);
if($tile instanceof ItemFrame and $tile->hasItem()){
if (lcg_value() <= $tile->getItemDropChance()){
$this->level->dropItem($tile->getBlock(), $tile->getItem());
}
$tile->setItem(null);
$tile->setItemRotation(0);
break;
}
$block = $target->getSide($packet->face);
if($block->getId() === Block::FIRE){
$this->level->setBlock($block, BlockFactory::get(Block::AIR));
@ -2953,7 +3001,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
case PlayerActionPacket::ACTION_START_GLIDE:
case PlayerActionPacket::ACTION_STOP_GLIDE:
break; //TODO
case PlayerActionPacket::ACTION_CONTINUE_BREAK:
case PlayerActionPacket::ACTION_CRACK_BREAK:
$block = $this->level->getBlock($pos);
$this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, $block->getRuntimeId() | ($packet->face << 24));
//TODO: destroy-progress level event
@ -3071,7 +3119,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
if(isset($this->windowIndex[$packet->windowId])){
$this->closingWindowId = $packet->windowId;
(new InventoryCloseEvent($this->windowIndex[$packet->windowId], $this))->call();
$this->removeWindow($this->windowIndex[$packet->windowId]);
$this->closingWindowId = null;
//removeWindow handles sending the appropriate
@ -3089,11 +3136,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$handled = false;
$isFlying = $packet->getFlag(AdventureSettingsPacket::FLYING);
if($isFlying and !$this->allowFlight){
$this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"]));
return true;
}elseif($isFlying !== $this->isFlying()){
if($isFlying !== $this->isFlying()){
$ev = new PlayerToggleFlightEvent($this, $isFlying);
if($isFlying and !$this->allowFlight){
$ev->setCancelled();
}
$ev->call();
if($ev->isCancelled()){
$this->sendSettings();
@ -3657,6 +3705,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->stopSleep();
if($this->spawned){
$this->doCloseInventory();
$ev = new PlayerQuitEvent($this, $message, $reason);
$ev->call();
if($ev->getQuitMessage() != ""){
@ -3752,6 +3802,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
parent::saveNBT();
$this->namedtag->setString("LastKnownXUID", $this->xuid);
if($this->isValid()){
$this->namedtag->setString("Level", $this->level->getFolderName());
}
@ -4092,6 +4144,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
if($id !== null){
(new InventoryCloseEvent($inventory, $this))->call();
$inventory->close($this);
unset($this->windows[$hash], $this->windowIndex[$id], $this->permanentWindows[$id]);
}

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine {
use Composer\InstalledVersions;
use pocketmine\utils\Git;
use pocketmine\utils\MainLogger;
use pocketmine\utils\Process;
@ -35,7 +36,7 @@ namespace pocketmine {
require_once __DIR__ . '/VersionInfo.php';
const MIN_PHP_VERSION = "7.3.0";
const MIN_PHP_VERSION = "7.4.0";
/**
* @param string $message
@ -73,7 +74,6 @@ namespace pocketmine {
}
$extensions = [
"bcmath" => "BC Math",
"curl" => "cURL",
"ctype" => "ctype",
"date" => "Date",
@ -127,6 +127,9 @@ namespace pocketmine {
* @return void
*/
function emit_performance_warnings(\Logger $logger){
if(PHP_DEBUG !== 0){
$logger->warning("This PHP binary was compiled in debug mode. This has a major impact on performance.");
}
if(extension_loaded("xdebug")){
$logger->warning("Xdebug extension is enabled. This has a major impact on performance.");
}
@ -139,6 +142,24 @@ namespace pocketmine {
if(\Phar::running(true) === ""){
$logger->warning("Non-packaged installation detected. This will degrade autoloading speed and make startup times longer.");
}
if(function_exists('opcache_get_status') && ($opcacheStatus = opcache_get_status(false)) !== false){
$jitEnabled = $opcacheStatus["jit"]["on"] ?? false;
if($jitEnabled !== false){
$logger->warning(<<<'JIT_WARNING'
--------------------------------------- ! WARNING ! ---------------------------------------
You're using PHP 8.0 with JIT enabled. This provides significant performance improvements.
HOWEVER, it is EXPERIMENTAL, and has already been seen to cause weird and unexpected bugs.
Proceed with caution.
If you want to report any bugs, make sure to mention that you are using PHP 8.0 with JIT.
To turn off JIT, change `opcache.jit` to `0` in your php.ini file.
-------------------------------------------------------------------------------------------
JIT_WARNING
);
}
}
}
/**
@ -159,10 +180,12 @@ namespace pocketmine {
if(count($messages = check_platform_dependencies()) > 0){
echo PHP_EOL;
$binary = version_compare(PHP_VERSION, "5.4") >= 0 ? PHP_BINARY : "unknown";
critical_error("Selected PHP binary ($binary) does not satisfy some requirements.");
critical_error("Selected PHP binary does not satisfy some requirements.");
foreach($messages as $m){
echo " - $m" . PHP_EOL;
}
critical_error("PHP binary used: " . $binary);
critical_error("Loaded php.ini: " . (($file = php_ini_loaded_file()) !== false ? $file : "none"));
critical_error("Please recompile PHP with the needed configuration, or refer to the installation instructions at http://pmmp.rtfd.io/en/rtfd/installation.html.");
echo PHP_EOL;
exit(1);
@ -206,6 +229,19 @@ namespace pocketmine {
define('pocketmine\GIT_COMMIT', $gitHash);
$composerGitHash = InstalledVersions::getReference('pocketmine/pocketmine-mp');
if($composerGitHash !== null){
$currentGitHash = explode("-", \pocketmine\GIT_COMMIT)[0];
if($currentGitHash !== $composerGitHash){
critical_error("Composer dependencies and/or autoloader are out of sync.");
critical_error("- Current revision is $currentGitHash");
critical_error("- Composer dependencies were last synchronized for revision $composerGitHash");
critical_error("Out-of-sync Composer dependencies may result in crashes and classes not being found.");
critical_error("Please synchronize Composer dependencies before running the server.");
exit(1);
}
}
$opts = getopt("", ["data:", "plugins:", "no-wizard", "enable-ansi", "disable-ansi"]);
define('pocketmine\DATA', isset($opts["data"]) ? $opts["data"] . DIRECTORY_SEPARATOR : realpath(getcwd()) . DIRECTORY_SEPARATOR);
@ -215,7 +251,12 @@ namespace pocketmine {
mkdir(\pocketmine\DATA, 0777, true);
}
define('pocketmine\LOCK_FILE', fopen(\pocketmine\DATA . 'server.lock', "a+b"));
$lockFile = fopen(\pocketmine\DATA . 'server.lock', "a+b");
if($lockFile === false){
critical_error("Unable to open server.lock file. Please check that the current user has read/write permissions to it.");
exit(1);
}
define('pocketmine\LOCK_FILE', $lockFile);
if(!flock(\pocketmine\LOCK_FILE, 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
//other server wrote its PID and released exclusive lock before we get our lock
@ -280,7 +321,7 @@ namespace pocketmine {
if(ThreadManager::getInstance()->stopAll() > 0){
$logger->debug("Some threads could not be stopped, performing a force-kill");
Process::kill(getmypid());
Process::kill(Process::pid());
}
}while(false);
@ -300,7 +341,5 @@ namespace pocketmine {
exit($exitCode);
}
if(!defined('pocketmine\_PHPSTAN_ANALYSIS')){
\pocketmine\server();
}
\pocketmine\server();
}

View File

@ -126,7 +126,6 @@ use function file_put_contents;
use function filemtime;
use function function_exists;
use function get_class;
use function getmypid;
use function getopt;
use function gettype;
use function implode;
@ -1462,8 +1461,7 @@ class Server{
$this->onlineMode = $this->getConfigBool("xbox-auth", true);
if($this->onlineMode){
$this->logger->notice($this->getLanguage()->translateString("pocketmine.server.auth.enabled"));
$this->logger->notice($this->getLanguage()->translateString("pocketmine.server.authProperty.enabled"));
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.auth.enabled"));
}else{
$this->logger->warning($this->getLanguage()->translateString("pocketmine.server.auth.disabled"));
$this->logger->warning($this->getLanguage()->translateString("pocketmine.server.authWarning"));
@ -1939,7 +1937,7 @@ class Server{
}catch(\Throwable $e){
$this->logger->logException($e);
$this->logger->emergency("Crashed while crashing, killing process");
@Process::kill(getmypid());
@Process::kill(Process::pid());
}
}
@ -2132,7 +2130,7 @@ class Server{
echo "--- Waiting $spacing seconds to throttle automatic restart (you can kill the process safely now) ---" . PHP_EOL;
sleep($spacing);
}
@Process::kill(getmypid());
@Process::kill(Process::pid());
exit(1);
}

View File

@ -33,6 +33,7 @@ if(defined('pocketmine\_VERSION_INFO_INCLUDED')){
const _VERSION_INFO_INCLUDED = true;
const NAME = "PocketMine-MP";
const BASE_VERSION = "3.16.1";
const BASE_VERSION = "3.22.4";
const IS_DEVELOPMENT_BUILD = false;
const BUILD_NUMBER = 0;
const BUILD_CHANNEL = "stable";

View File

@ -95,7 +95,7 @@ abstract class Worker extends \Worker{
public function quit(){
$this->isKilled = true;
if($this->isRunning()){
if(!$this->isShutdown()){
while($this->unstack() !== null);
$this->notify();
$this->shutdown();

View File

@ -35,5 +35,6 @@ interface BlockToolType{
public const TYPE_PICKAXE = 1 << 2;
public const TYPE_AXE = 1 << 3;
public const TYPE_SHEARS = 1 << 4;
public const TYPE_HOE = 1 << 5;
}

View File

@ -418,6 +418,9 @@ abstract class Liquid extends Transparent{
return $isOptimalFlowDirection;
}
/**
* @phpstan-impure This function modifies the adjacent sources count (premature optimisation)
*/
private function getSmallestFlowDecay(Block $block, int $decay) : int{
$blockDecay = $this->getFlowDecay($block);

View File

@ -68,7 +68,10 @@ class SignPost extends Transparent{
$this->getLevelNonNull()->setBlock($blockReplace, BlockFactory::get(Block::WALL_SIGN, $this->meta), true);
}
Tile::createTile(Tile::SIGN, $this->getLevelNonNull(), TileSign::createNBT($this, $face, $item, $player));
$sign = Tile::createTile(Tile::SIGN, $this->getLevelNonNull(), TileSign::createNBT($this, $face, $item, $player));
if($player !== null && $sign instanceof TileSign){
$sign->setEditorEntityRuntimeId($player->getId());
}
return true;
}

View File

@ -31,6 +31,10 @@ class Sponge extends Solid{
$this->meta = $meta;
}
public function getToolType() : int{
return BlockToolType::TYPE_HOE;
}
public function getHardness() : float{
return 0.6;
}

View File

@ -25,23 +25,17 @@ namespace pocketmine\command;
use pocketmine\snooze\SleeperNotifier;
use pocketmine\Thread;
use pocketmine\utils\Utils;
use function extension_loaded;
use function fclose;
use function fgets;
use function fopen;
use function fstat;
use function getopt;
use function is_resource;
use function microtime;
use function preg_replace;
use function readline;
use function readline_add_history;
use function stream_isatty;
use function stream_select;
use function trim;
use function usleep;
use const STDIN;
class CommandReader extends Thread{
@ -65,12 +59,6 @@ class CommandReader extends Thread{
public function __construct(?SleeperNotifier $notifier = null){
$this->buffer = new \Threaded;
$this->notifier = $notifier;
$opts = getopt("", ["disable-readline", "enable-readline"]);
if(extension_loaded("readline") and (Utils::getOS() === Utils::OS_WINDOWS ? isset($opts["enable-readline"]) : !isset($opts["disable-readline"])) and !$this->isPipe(STDIN)){
$this->type = self::TYPE_READLINE;
}
}
/**
@ -127,44 +115,28 @@ class CommandReader extends Thread{
* @return bool if the main execution should continue reading lines
*/
private function readLine() : bool{
$line = "";
if($this->type === self::TYPE_READLINE){
if(($raw = readline("> ")) !== false and ($line = trim($raw)) !== ""){
readline_add_history($line);
}else{
return true;
}
}else{
if(!is_resource(self::$stdin)){
$this->initStdin();
}
switch($this->type){
/** @noinspection PhpMissingBreakStatementInspection */
case self::TYPE_STREAM:
//stream_select doesn't work on piped streams for some reason
$r = [self::$stdin];
$w = $e = null;
if(($count = stream_select($r, $w, $e, 0, 200000)) === 0){ //nothing changed in 200000 microseconds
return true;
}elseif($count === false){ //stream error
$this->initStdin();
}
case self::TYPE_PIPED:
if(($raw = fgets(self::$stdin)) === false){ //broken pipe or EOF
$this->initStdin();
$this->synchronized(function() : void{
$this->wait(200000);
}); //prevent CPU waste if it's end of pipe
return true; //loop back round
}
$line = trim($raw);
break;
}
if(!is_resource(self::$stdin)){
$this->initStdin();
}
$r = [self::$stdin];
$w = $e = null;
if(($count = stream_select($r, $w, $e, 0, 200000)) === 0){ //nothing changed in 200000 microseconds
return true;
}elseif($count === false){ //stream error
$this->initStdin();
}
if(($raw = fgets(self::$stdin)) === false){ //broken pipe or EOF
$this->initStdin();
$this->synchronized(function() : void{
$this->wait(200000);
}); //prevent CPU waste if it's end of pipe
return true; //loop back round
}
$line = trim($raw);
if($line !== ""){
$this->buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line);
if($this->notifier !== null){
@ -193,17 +165,11 @@ class CommandReader extends Thread{
*/
public function run(){
$this->registerClassLoader();
if($this->type !== self::TYPE_READLINE){
$this->initStdin();
}
$this->initStdin();
while(!$this->shutdown and $this->readLine());
if($this->type !== self::TYPE_READLINE){
fclose(self::$stdin);
}
fclose(self::$stdin);
}
public function getThreadName() : string{

View File

@ -175,56 +175,56 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
public const DATA_RIDER_ROTATION_LOCKED = 57; //byte
public const DATA_RIDER_MAX_ROTATION = 58; //float
public const DATA_RIDER_MIN_ROTATION = 59; //float
public const DATA_AREA_EFFECT_CLOUD_RADIUS = 60; //float
public const DATA_AREA_EFFECT_CLOUD_WAITING = 61; //int
public const DATA_AREA_EFFECT_CLOUD_PARTICLE_ID = 62; //int
/* 63 (int) shulker-related */
public const DATA_SHULKER_ATTACH_FACE = 64; //byte
/* 65 (short) shulker-related */
public const DATA_SHULKER_ATTACH_POS = 66; //block coords
public const DATA_TRADING_PLAYER_EID = 67; //long
public const DATA_AREA_EFFECT_CLOUD_RADIUS = 61; //float
public const DATA_AREA_EFFECT_CLOUD_WAITING = 62; //int
public const DATA_AREA_EFFECT_CLOUD_PARTICLE_ID = 63; //int
/* 64 (int) shulker-related */
public const DATA_SHULKER_ATTACH_FACE = 65; //byte
/* 66 (short) shulker-related */
public const DATA_SHULKER_ATTACH_POS = 67; //block coords
public const DATA_TRADING_PLAYER_EID = 68; //long
/* 69 (byte) command-block */
public const DATA_COMMAND_BLOCK_COMMAND = 70; //string
public const DATA_COMMAND_BLOCK_LAST_OUTPUT = 71; //string
public const DATA_COMMAND_BLOCK_TRACK_OUTPUT = 72; //byte
public const DATA_CONTROLLING_RIDER_SEAT_NUMBER = 73; //byte
public const DATA_STRENGTH = 74; //int
public const DATA_MAX_STRENGTH = 75; //int
/* 76 (int) */
public const DATA_LIMITED_LIFE = 77;
public const DATA_ARMOR_STAND_POSE_INDEX = 78; //int
public const DATA_ENDER_CRYSTAL_TIME_OFFSET = 79; //int
public const DATA_ALWAYS_SHOW_NAMETAG = 80; //byte: -1 = default, 0 = only when looked at, 1 = always
public const DATA_COLOR_2 = 81; //byte
/* 82 (unknown) */
public const DATA_SCORE_TAG = 83; //string
public const DATA_BALLOON_ATTACHED_ENTITY = 84; //int64, entity unique ID of owner
public const DATA_PUFFERFISH_SIZE = 85; //byte
public const DATA_BOAT_BUBBLE_TIME = 86; //int (time in bubble column)
public const DATA_PLAYER_AGENT_EID = 87; //long
/* 88 (float) related to panda sitting
* 89 (float) related to panda sitting */
public const DATA_EAT_COUNTER = 90; //int (used by pandas)
public const DATA_FLAGS2 = 91; //long (extended data flags)
/* 92 (float) related to panda lying down
* 93 (float) related to panda lying down */
public const DATA_AREA_EFFECT_CLOUD_DURATION = 94; //int
public const DATA_AREA_EFFECT_CLOUD_SPAWN_TIME = 95; //int
public const DATA_AREA_EFFECT_CLOUD_RADIUS_PER_TICK = 96; //float, usually negative
public const DATA_AREA_EFFECT_CLOUD_RADIUS_CHANGE_ON_PICKUP = 97; //float
public const DATA_AREA_EFFECT_CLOUD_PICKUP_COUNT = 98; //int
public const DATA_INTERACTIVE_TAG = 99; //string (button text)
public const DATA_TRADE_TIER = 100; //int
public const DATA_MAX_TRADE_TIER = 101; //int
public const DATA_TRADE_XP = 102; //int
public const DATA_SKIN_ID = 103; //int ???
/* 104 (int) related to wither */
public const DATA_COMMAND_BLOCK_TICK_DELAY = 105; //int
public const DATA_COMMAND_BLOCK_EXECUTE_ON_FIRST_TICK = 106; //byte
public const DATA_AMBIENT_SOUND_INTERVAL_MIN = 107; //float
public const DATA_AMBIENT_SOUND_INTERVAL_RANGE = 108; //float
public const DATA_AMBIENT_SOUND_EVENT = 109; //string
/* 70 (byte) command-block */
public const DATA_COMMAND_BLOCK_COMMAND = 71; //string
public const DATA_COMMAND_BLOCK_LAST_OUTPUT = 72; //string
public const DATA_COMMAND_BLOCK_TRACK_OUTPUT = 73; //byte
public const DATA_CONTROLLING_RIDER_SEAT_NUMBER = 74; //byte
public const DATA_STRENGTH = 75; //int
public const DATA_MAX_STRENGTH = 76; //int
/* 77 (int) */
public const DATA_LIMITED_LIFE = 78;
public const DATA_ARMOR_STAND_POSE_INDEX = 79; //int
public const DATA_ENDER_CRYSTAL_TIME_OFFSET = 80; //int
public const DATA_ALWAYS_SHOW_NAMETAG = 81; //byte: -1 = default, 0 = only when looked at, 1 = always
public const DATA_COLOR_2 = 82; //byte
/* 83 (unknown) */
public const DATA_SCORE_TAG = 84; //string
public const DATA_BALLOON_ATTACHED_ENTITY = 85; //int64, entity unique ID of owner
public const DATA_PUFFERFISH_SIZE = 86; //byte
public const DATA_BOAT_BUBBLE_TIME = 87; //int (time in bubble column)
public const DATA_PLAYER_AGENT_EID = 88; //long
/* 89 (float) related to panda sitting
* 90 (float) related to panda sitting */
public const DATA_EAT_COUNTER = 91; //int (used by pandas)
public const DATA_FLAGS2 = 92; //long (extended data flags)
/* 93 (float) related to panda lying down
* 94 (float) related to panda lying down */
public const DATA_AREA_EFFECT_CLOUD_DURATION = 95; //int
public const DATA_AREA_EFFECT_CLOUD_SPAWN_TIME = 96; //int
public const DATA_AREA_EFFECT_CLOUD_RADIUS_PER_TICK = 97; //float, usually negative
public const DATA_AREA_EFFECT_CLOUD_RADIUS_CHANGE_ON_PICKUP = 98; //float
public const DATA_AREA_EFFECT_CLOUD_PICKUP_COUNT = 99; //int
public const DATA_INTERACTIVE_TAG = 100; //string (button text)
public const DATA_TRADE_TIER = 101; //int
public const DATA_MAX_TRADE_TIER = 102; //int
public const DATA_TRADE_XP = 103; //int
public const DATA_SKIN_ID = 104; //int ???
/* 105 (int) related to wither */
public const DATA_COMMAND_BLOCK_TICK_DELAY = 106; //int
public const DATA_COMMAND_BLOCK_EXECUTE_ON_FIRST_TICK = 107; //byte
public const DATA_AMBIENT_SOUND_INTERVAL_MIN = 108; //float
public const DATA_AMBIENT_SOUND_INTERVAL_RANGE = 109; //float
public const DATA_AMBIENT_SOUND_EVENT = 110; //string
public const DATA_FLAG_ONFIRE = 0;
public const DATA_FLAG_SNEAKING = 1;

View File

@ -51,9 +51,9 @@ use pocketmine\network\mcpe\protocol\ActorEventPacket;
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\PlayerSkinPacket;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
use pocketmine\network\mcpe\protocol\types\SkinAdapterSingleton;
use pocketmine\Player;
@ -300,17 +300,20 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($consumable instanceof MaybeConsumable and !$consumable->canBeConsumed()){
return false;
}
if($consumable instanceof FoodSource && $consumable->requiresHunger() and !$this->isHungry()){
return false;
}
return parent::consumeObject($consumable);
}
protected function applyConsumptionResults(Consumable $consumable) : void{
if($consumable instanceof FoodSource){
if($consumable->requiresHunger() and !$this->isHungry()){
return false;
}
$this->addFood($consumable->getFoodRestore());
$this->addSaturation($consumable->getSaturationRestore());
}
return parent::consumeObject($consumable);
parent::applyConsumptionResults($consumable);
}
/**
@ -810,7 +813,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$pk->motion = $this->getMotion();
$pk->yaw = $this->yaw;
$pk->pitch = $this->pitch;
$pk->item = $this->getInventory()->getItemInHand();
$pk->item = ItemStackWrapper::legacy($this->getInventory()->getItemInHand());
$pk->metadata = $this->propertyManager->getAll();
$player->dataPacket($pk);
@ -827,23 +830,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
}
}
public function broadcastMovement(bool $teleport = false) : void{
//TODO: workaround 1.14.30 bug: MoveActor(Absolute|Delta)Packet don't work on players anymore :(
$pk = new MovePlayerPacket();
$pk->entityRuntimeId = $this->getId();
$pk->position = $this->getOffsetPosition($this);
$pk->yaw = $this->yaw;
$pk->pitch = $this->pitch;
$pk->headYaw = $this->yaw;
$pk->mode = $teleport ? MovePlayerPacket::MODE_TELEPORT : MovePlayerPacket::MODE_NORMAL;
//we can't assume that everyone who is using our chunk wants to see this movement,
//because this human might be a player who shouldn't be receiving his own movement.
//this didn't matter when we were able to use MoveActorPacket because
//the client just ignored MoveActor for itself, but it doesn't ignore MovePlayer for itself.
$this->server->broadcastPacket($this->hasSpawned, $pk);
}
public function close() : void{
if(!$this->closed){
if($this->inventory !== null){

View File

@ -363,13 +363,20 @@ abstract class Living extends Entity implements Damageable{
return false;
}
$this->applyConsumptionResults($consumable);
return true;
}
/**
* Applies effects from consuming the object. This shouldn't do any can-consume checks (those are expected to be
* handled by the caller).
*/
protected function applyConsumptionResults(Consumable $consumable) : void{
foreach($consumable->getAdditionalEffects() as $effect){
$this->addEffect($effect);
}
$consumable->onConsume($this);
return true;
}
/**

View File

@ -30,6 +30,7 @@ use pocketmine\event\inventory\InventoryPickupItemEvent;
use pocketmine\item\Item;
use pocketmine\network\mcpe\protocol\AddItemActorPacket;
use pocketmine\network\mcpe\protocol\TakeItemActorPacket;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use pocketmine\Player;
use function get_class;
@ -173,7 +174,7 @@ class ItemEntity extends Entity{
$pk->entityRuntimeId = $this->getId();
$pk->position = $this->asVector3();
$pk->motion = $this->getMotion();
$pk->item = $this->getItem();
$pk->item = ItemStackWrapper::legacy($this->getItem());
$pk->metadata = $this->propertyManager->getAll();
$player->dataPacket($pk);

View File

@ -48,7 +48,7 @@ class BlockBreakEvent extends BlockEvent implements Cancellable{
/**
* @param Item[] $drops
*/
public function __construct(Player $player, Block $block, Item $item, bool $instaBreak = false, array $drops, int $xpDrops = 0){
public function __construct(Player $player, Block $block, Item $item, bool $instaBreak = false, array $drops = [], int $xpDrops = 0){
parent::__construct($block);
$this->item = $item;
$this->player = $player;

View File

@ -98,10 +98,10 @@ class ArmorInventory extends BaseInventory{
$pk = new MobArmorEquipmentPacket();
$pk->entityRuntimeId = $this->getHolder()->getId();
$pk->head = $this->getHelmet();
$pk->chest = $this->getChestplate();
$pk->legs = $this->getLeggings();
$pk->feet = $this->getBoots();
$pk->head = ItemStackWrapper::legacy($this->getHelmet());
$pk->chest = ItemStackWrapper::legacy($this->getChestplate());
$pk->legs = ItemStackWrapper::legacy($this->getLeggings());
$pk->feet = ItemStackWrapper::legacy($this->getBoots());
$pk->encode();
foreach($target as $player){
@ -126,10 +126,10 @@ class ArmorInventory extends BaseInventory{
$pk = new MobArmorEquipmentPacket();
$pk->entityRuntimeId = $this->getHolder()->getId();
$pk->head = $this->getHelmet();
$pk->chest = $this->getChestplate();
$pk->legs = $this->getLeggings();
$pk->feet = $this->getBoots();
$pk->head = ItemStackWrapper::legacy($this->getHelmet());
$pk->chest = ItemStackWrapper::legacy($this->getChestplate());
$pk->legs = ItemStackWrapper::legacy($this->getLeggings());
$pk->feet = ItemStackWrapper::legacy($this->getBoots());
$pk->encode();
foreach($target as $player){

View File

@ -53,4 +53,13 @@ class PlayerCursorInventory extends BaseInventory{
public function getHolder(){
return $this->holder;
}
public function sendContents($target) : void{
//TODO: HACK!
//Since 1.13, this is now part of a larger "UI inventory", and sending contents for this larger inventory does
//not work the way it's intended to. Even if it did, it would be necessary to send all 51 slots just to update
//this one, which is just not worth it.
//This workaround isn't great, but it's at least simple.
$this->sendSlot(0, $target);
}
}

View File

@ -30,6 +30,7 @@ use pocketmine\network\mcpe\protocol\CreativeContentPacket;
use pocketmine\network\mcpe\protocol\MobEquipmentPacket;
use pocketmine\network\mcpe\protocol\types\ContainerIds;
use pocketmine\network\mcpe\protocol\types\inventory\CreativeContentEntry;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use pocketmine\Player;
use function array_map;
use function in_array;
@ -165,7 +166,7 @@ class PlayerInventory extends BaseInventory{
$pk = new MobEquipmentPacket();
$pk->entityRuntimeId = $this->getHolder()->getId();
$pk->item = $item;
$pk->item = ItemStackWrapper::legacy($item);
$pk->inventorySlot = $pk->hotbarSlot = $this->getHeldItemIndex();
$pk->windowId = ContainerIds::INVENTORY;

View File

@ -30,6 +30,7 @@ use pocketmine\inventory\transaction\action\SlotChangeAction;
use pocketmine\item\Item;
use pocketmine\Player;
use function array_keys;
use function array_values;
use function assert;
use function count;
use function get_class;
@ -168,6 +169,8 @@ class InventoryTransaction{
}
}
}
$needItems = array_values($needItems);
$haveItems = array_values($haveItems);
}
/**

View File

@ -50,6 +50,14 @@ class Bucket extends Item implements MaybeConsumable{
return 0;
}
public function getFuelResidue() : Item{
if($this->meta === Block::LAVA or $this->meta === Block::FLOWING_LAVA){
return ItemFactory::get(Item::BUCKET);
}
return parent::getFuelResidue();
}
public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : bool{
$resultBlock = BlockFactory::get($this->meta);

View File

@ -23,11 +23,24 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockToolType;
use pocketmine\entity\Entity;
class Hoe extends TieredTool{
public function getBlockToolType() : int{
return BlockToolType::TYPE_HOE;
}
public function onAttackEntity(Entity $victim) : bool{
return $this->applyDamage(1);
}
public function onDestroyBlock(Block $block) : bool{
if($block->getHardness() > 0){
return $this->applyDamage(1);
}
return false;
}
}

View File

@ -339,7 +339,11 @@ class Item implements ItemIds, \JsonSerializable{
}
}
$this->setNamedTagEntry($ench);
if($ench->getCount() > 0){
$this->setNamedTagEntry($ench);
}else{
$this->removeNamedTagEntry(self::TAG_ENCH);
}
}
public function removeEnchantments() : void{
@ -655,6 +659,16 @@ class Item implements ItemIds, \JsonSerializable{
return 0;
}
/**
* Returns an item after burning fuel
*/
public function getFuelResidue() : Item{
$item = clone $this;
$item->pop();
return $item;
}
/**
* Returns how many points of damage this item will deal to an entity when used as a weapon.
*/

View File

@ -921,7 +921,9 @@ class Chunk{
$biomeIds = $stream->get(256);
if($lightPopulated){
$heightMap = array_values(unpack("v*", $stream->get(512)));
/** @var int[] $unpackedHeightMap */
$unpackedHeightMap = unpack("v*", $stream->get(512)); //unpack() will never fail here
$heightMap = array_values($unpackedHeightMap);
}
}

View File

@ -63,7 +63,6 @@ abstract class LevelProviderManager{
throw new \InvalidArgumentException("Class $class cannot be constructed");
}
/** @var LevelProvider $class */
self::$providers[strtolower($class::getProviderName())] = $class;
}

View File

@ -183,8 +183,6 @@ class LevelDB extends BaseLevelProvider{
if(!$this->levelData->hasTag("generatorOptions", StringTag::class)){
$this->levelData->setString("generatorOptions", "");
}
$db->close();
}
public static function getProviderName() : string{
@ -269,9 +267,6 @@ class LevelDB extends BaseLevelProvider{
$db->put(self::ENTRY_FLAT_WORLD_LAYERS, $out); //Add vanilla flatworld layers to allow terrain generation by MCPE to continue seamlessly
}
}
$db->close();
}
public function saveLevelData(){
@ -368,7 +363,9 @@ class LevelDB extends BaseLevelProvider{
if(($maps2d = $this->db->get($index . self::TAG_DATA_2D)) !== false){
$binaryStream->setBuffer($maps2d, 0);
$heightMap = array_values(unpack("v*", $binaryStream->get(512)));
/** @var int[] $unpackedHeightMap */
$unpackedHeightMap = unpack("v*", $binaryStream->get(512)); //unpack() will never fail here
$heightMap = array_values($unpackedHeightMap);
$biomeIds = $binaryStream->get(256);
}
break;
@ -411,8 +408,13 @@ class LevelDB extends BaseLevelProvider{
$subChunks[$yy] = new SubChunk($ids, $data, $skyLight, $blockLight);
}
$heightMap = array_values(unpack("C*", $binaryStream->get(256)));
$biomeIds = ChunkUtils::convertBiomeColors(array_values(unpack("N*", $binaryStream->get(1024))));
/** @var int[] $unpackedHeightMap */
$unpackedHeightMap = unpack("C*", $binaryStream->get(256)); //unpack() will never fail here, but static analysers don't know that
$heightMap = array_values($unpackedHeightMap);
/** @var int[] $unpackedBiomeIds */
$unpackedBiomeIds = unpack("N*", $binaryStream->get(1024)); //nor here
$biomeIds = ChunkUtils::convertBiomeColors(array_values($unpackedBiomeIds));
break;
default:
//TODO: set chunks read-only so the version on disk doesn't get overwritten
@ -548,6 +550,6 @@ class LevelDB extends BaseLevelProvider{
}
public function close(){
$this->db->close();
unset($this->db);
}
}

View File

@ -182,7 +182,9 @@ class McRegion extends BaseLevelProvider{
$heightMap = [];
if($chunk->hasTag("HeightMap", ByteArrayTag::class)){
$heightMap = array_values(unpack("C*", $chunk->getByteArray("HeightMap")));
/** @var int[] $unpackedHeightMap */
$unpackedHeightMap = unpack("C*", $chunk->getByteArray("HeightMap")); //unpack() will never fail here
$heightMap = array_values($unpackedHeightMap);
}elseif($chunk->hasTag("HeightMap", IntArrayTag::class)){
$heightMap = $chunk->getIntArray("HeightMap"); #blameshoghicp
}
@ -391,6 +393,9 @@ class McRegion extends BaseLevelProvider{
self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ);
assert(is_int($regionX) and is_int($regionZ));
if(!file_exists($this->pathToRegion($regionX, $regionZ))){
return null;
}
$this->loadRegion($regionX, $regionZ);
$chunkData = $this->getRegion($regionX, $regionZ)->readChunk($chunkX & 0x1f, $chunkZ & 0x1f);

View File

@ -27,12 +27,13 @@ use pocketmine\level\format\ChunkException;
use pocketmine\level\format\io\exception\CorruptedChunkException;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Binary;
use pocketmine\utils\MainLogger;
use pocketmine\utils\BinaryDataException;
use pocketmine\utils\BinaryStream;
use function assert;
use function ceil;
use function chr;
use function clearstatcache;
use function fclose;
use function feof;
use function file_exists;
use function filesize;
use function fopen;
@ -43,14 +44,12 @@ use function fwrite;
use function is_resource;
use function ksort;
use function max;
use function ord;
use function pack;
use function str_pad;
use function str_repeat;
use function stream_set_read_buffer;
use function stream_set_write_buffer;
use function strlen;
use function substr;
use function time;
use function touch;
use function unpack;
@ -99,6 +98,7 @@ class RegionLoader{
* @throws CorruptedRegionException
*/
public function open(){
clearstatcache(false, $this->filePath);
$exists = file_exists($this->filePath);
if(!$exists){
touch($this->filePath);
@ -146,37 +146,34 @@ class RegionLoader{
fseek($this->filePointer, $this->locationTable[$index]->getFirstSector() << 12);
$prefix = fread($this->filePointer, 4);
if($prefix === false or strlen($prefix) !== 4){
throw new CorruptedChunkException("Corrupted chunk header detected (unexpected end of file reading length prefix)");
}
$length = Binary::readInt($prefix);
/*
* this might cause us to read some junk, but under normal circumstances it won't be any more than 4096 bytes wasted.
* doing this in a single call is faster than making two seeks and reads to fetch the chunk.
* this relies on the assumption that the end of the file is always padded to a multiple of 4096 bytes.
*/
$bytesToRead = $this->locationTable[$index]->getSectorCount() << 12;
$payload = fread($this->filePointer, $bytesToRead);
if($length <= 0){ //TODO: if we reached here, the locationTable probably needs updating
return null;
}
if($length > self::MAX_SECTOR_LENGTH){ //corrupted
throw new CorruptedChunkException("Length for chunk x=$x,z=$z ($length) is larger than maximum " . self::MAX_SECTOR_LENGTH);
if($payload === false || strlen($payload) !== $bytesToRead){
throw new CorruptedChunkException("Corrupted chunk detected (unexpected EOF, truncated or non-padded chunk found)");
}
$stream = new BinaryStream($payload);
if($length > ($this->locationTable[$index]->getSectorCount() << 12)){ //Invalid chunk, bigger than defined number of sectors
MainLogger::getLogger()->error("Chunk x=$x,z=$z length mismatch (expected " . ($this->locationTable[$index]->getSectorCount() << 12) . " sectors, got $length sectors)");
$old = $this->locationTable[$index];
$this->locationTable[$index] = new RegionLocationTableEntry($old->getFirstSector(), $length >> 12, time());
$this->writeLocationIndex($index);
}
try{
$length = $stream->getInt();
if($length <= 0){ //TODO: if we reached here, the locationTable probably needs updating
return null;
}
$chunkData = fread($this->filePointer, $length);
if($chunkData === false or strlen($chunkData) !== $length){
throw new CorruptedChunkException("Corrupted chunk detected (unexpected end of file reading chunk data)");
}
$compression = $stream->getByte();
if($compression !== self::COMPRESSION_ZLIB and $compression !== self::COMPRESSION_GZIP){
throw new CorruptedChunkException("Invalid compression type (got $compression, expected " . self::COMPRESSION_ZLIB . " or " . self::COMPRESSION_GZIP . ")");
}
$compression = ord($chunkData[0]);
if($compression !== self::COMPRESSION_ZLIB and $compression !== self::COMPRESSION_GZIP){
throw new CorruptedChunkException("Invalid compression type (got $compression, expected " . self::COMPRESSION_ZLIB . " or " . self::COMPRESSION_GZIP . ")");
return $stream->get($length - 1); //length prefix includes the compression byte
}catch(BinaryDataException $e){
throw new CorruptedChunkException("Corrupted chunk detected: " . $e->getMessage(), 0, $e);
}
return substr($chunkData, 1);
}
/**
@ -186,6 +183,23 @@ class RegionLoader{
return $this->isChunkGenerated(self::getChunkOffset($x, $z));
}
private function disposeGarbageArea(RegionLocationTableEntry $oldLocation) : void{
/* release the area containing the old copy to the garbage pool */
$this->garbageTable->add($oldLocation);
$endGarbage = $this->garbageTable->end();
$nextSector = $this->nextSector;
for(; $endGarbage !== null and $endGarbage->getLastSector() + 1 === $nextSector; $endGarbage = $this->garbageTable->end()){
$nextSector = $endGarbage->getFirstSector();
$this->garbageTable->remove($endGarbage);
}
if($nextSector !== $this->nextSector){
$this->nextSector = $nextSector;
ftruncate($this->filePointer, $this->nextSector << 12);
}
}
/**
* @return void
* @throws ChunkException
@ -230,20 +244,7 @@ class RegionLoader{
$this->writeLocationIndex($index);
if($oldLocation !== null){
/* release the area containing the old copy to the garbage pool */
$this->garbageTable->add($oldLocation);
$endGarbage = $this->garbageTable->end();
$nextSector = $this->nextSector;
for(; $endGarbage !== null and $endGarbage->getLastSector() + 1 === $nextSector; $endGarbage = $this->garbageTable->end()){
$nextSector = $endGarbage->getFirstSector();
$this->garbageTable->remove($endGarbage);
}
if($nextSector !== $this->nextSector){
$this->nextSector = $nextSector;
ftruncate($this->filePointer, $this->nextSector << 12);
}
$this->disposeGarbageArea($oldLocation);
}
}
@ -253,8 +254,12 @@ class RegionLoader{
*/
public function removeChunk(int $x, int $z){
$index = self::getChunkOffset($x, $z);
$oldLocation = $this->locationTable[$index];
$this->locationTable[$index] = null;
$this->writeLocationIndex($index);
if($oldLocation !== null){
$this->disposeGarbageArea($oldLocation);
}
}
/**
@ -336,6 +341,8 @@ class RegionLoader{
/** @var int[] $usedOffsets */
$usedOffsets = [];
$fileSize = filesize($this->filePath);
if($fileSize === false) throw new AssumptionFailedError("filesize() should not return false here");
for($i = 0; $i < 1024; ++$i){
$entry = $this->locationTable[$i];
if($entry === null){
@ -348,8 +355,7 @@ class RegionLoader{
//TODO: more validity checks
fseek($this->filePointer, $fileOffset);
if(feof($this->filePointer)){
if($fileOffset >= $fileSize){
throw new CorruptedRegionException("Region file location offset x=$x,z=$z points to invalid file location $fileOffset");
}
if(isset($usedOffsets[$offset])){
@ -402,6 +408,7 @@ class RegionLoader{
fwrite($this->filePointer, Binary::writeInt($entry !== null ? ($entry->getFirstSector() << 8) | $entry->getSectorCount() : 0), 4);
fseek($this->filePointer, 4096 + ($index << 2));
fwrite($this->filePointer, Binary::writeInt($entry !== null ? $entry->getTimestamp() : 0), 4);
clearstatcache(false, $this->filePath);
}
/**

View File

@ -144,16 +144,9 @@ class Normal extends Generator{
return Biome::BIRCH_FOREST;
}
}else{
//FIXME: This will always cause River to be used since the rainfall is always greater than 0.8 if we
//reached this branch. However I don't think that substituting temperature for rainfall is correct given
//that mountain biomes are supposed to be pretty cold.
if($rainfall < 0.25){
return Biome::MOUNTAINS;
}elseif($rainfall < 0.70){
return Biome::SMALL_MOUNTAINS;
}else{
return Biome::RIVER;
}
//Previously here, we had a (broken) condition to generate mountains, but fixing it would have
//caused generation changes on a patch release, so we can't keep it here for now.
return Biome::RIVER;
}
}
};

View File

@ -31,6 +31,7 @@ use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\RemoveActorPacket;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
use pocketmine\network\mcpe\protocol\types\SkinAdapterSingleton;
use pocketmine\utils\UUID;
@ -104,7 +105,7 @@ class FloatingTextParticle extends Particle{
$pk->username = $name;
$pk->entityRuntimeId = $this->entityId;
$pk->position = $this->asVector3(); //TODO: check offset
$pk->item = ItemFactory::get(Item::AIR, 0, 0);
$pk->item = ItemStackWrapper::legacy(ItemFactory::get(Item::AIR, 0, 0));
$flags = (
1 << Entity::DATA_FLAG_IMMOBILE

View File

@ -36,65 +36,79 @@ abstract class Particle extends Vector3{
public const TYPE_EXPLODE = 6;
public const TYPE_EVAPORATION = 7;
public const TYPE_FLAME = 8;
public const TYPE_LAVA = 9;
public const TYPE_LARGE_SMOKE = 10;
public const TYPE_REDSTONE = 11;
public const TYPE_RISING_RED_DUST = 12;
public const TYPE_ITEM_BREAK = 13;
public const TYPE_SNOWBALL_POOF = 14;
public const TYPE_HUGE_EXPLODE = 15;
public const TYPE_HUGE_EXPLODE_SEED = 16;
public const TYPE_MOB_FLAME = 17;
public const TYPE_HEART = 18;
public const TYPE_TERRAIN = 19;
public const TYPE_SUSPENDED_TOWN = 20, TYPE_TOWN_AURA = 20;
public const TYPE_PORTAL = 21;
//22 same as 21
public const TYPE_SPLASH = 23, TYPE_WATER_SPLASH = 23;
public const TYPE_WATER_SPLASH_MANUAL = 24;
public const TYPE_WATER_WAKE = 25;
public const TYPE_DRIP_WATER = 26;
public const TYPE_DRIP_LAVA = 27;
public const TYPE_DRIP_HONEY = 28;
public const TYPE_FALLING_DUST = 29, TYPE_DUST = 29;
public const TYPE_MOB_SPELL = 30;
public const TYPE_MOB_SPELL_AMBIENT = 31;
public const TYPE_MOB_SPELL_INSTANTANEOUS = 32;
public const TYPE_INK = 33;
public const TYPE_SLIME = 34;
public const TYPE_RAIN_SPLASH = 35;
public const TYPE_VILLAGER_ANGRY = 36;
public const TYPE_VILLAGER_HAPPY = 37;
public const TYPE_ENCHANTMENT_TABLE = 38;
public const TYPE_TRACKING_EMITTER = 39;
public const TYPE_NOTE = 40;
public const TYPE_WITCH_SPELL = 41;
public const TYPE_CARROT = 42;
public const TYPE_MOB_APPEARANCE = 43;
public const TYPE_END_ROD = 44;
public const TYPE_DRAGONS_BREATH = 45;
public const TYPE_SPIT = 46;
public const TYPE_TOTEM = 47;
public const TYPE_FOOD = 48;
public const TYPE_FIREWORKS_STARTER = 49;
public const TYPE_FIREWORKS_SPARK = 50;
public const TYPE_FIREWORKS_OVERLAY = 51;
public const TYPE_BALLOON_GAS = 52;
public const TYPE_COLORED_FLAME = 53;
public const TYPE_SPARKLER = 54;
public const TYPE_CONDUIT = 55;
public const TYPE_BUBBLE_COLUMN_UP = 56;
public const TYPE_BUBBLE_COLUMN_DOWN = 57;
public const TYPE_SNEEZE = 58;
public const TYPE_SHULKER_BULLET = 59;
public const TYPE_BLEACH = 60;
public const TYPE_DRAGON_DESTROY_BLOCK = 61;
public const TYPE_MYCELIUM_DUST = 62;
public const TYPE_FALLING_RED_DUST = 63;
public const TYPE_CAMPFIRE_SMOKE = 64;
public const TYPE_TALL_CAMPFIRE_SMOKE = 65;
public const TYPE_DRAGON_BREATH_FIRE = 66;
public const TYPE_DRAGON_BREATH_TRAIL = 67;
public const TYPE_CANDLE_FLAME = 9;
public const TYPE_LAVA = 10;
public const TYPE_LARGE_SMOKE = 11;
public const TYPE_REDSTONE = 12;
public const TYPE_RISING_RED_DUST = 13;
public const TYPE_ITEM_BREAK = 14;
public const TYPE_SNOWBALL_POOF = 15;
public const TYPE_HUGE_EXPLODE = 16;
public const TYPE_HUGE_EXPLODE_SEED = 17;
public const TYPE_MOB_FLAME = 18;
public const TYPE_HEART = 19;
public const TYPE_TERRAIN = 20;
public const TYPE_SUSPENDED_TOWN = 21, TYPE_TOWN_AURA = 21;
public const TYPE_PORTAL = 22;
//23 same as 22
public const TYPE_SPLASH = 24, TYPE_WATER_SPLASH = 24;
public const TYPE_WATER_SPLASH_MANUAL = 25;
public const TYPE_WATER_WAKE = 26;
public const TYPE_DRIP_WATER = 27;
public const TYPE_DRIP_LAVA = 28;
public const TYPE_DRIP_HONEY = 29;
public const TYPE_STALACTITE_DRIP_WATER = 30;
public const TYPE_STALACTITE_DRIP_LAVA = 31;
public const TYPE_FALLING_DUST = 32, TYPE_DUST = 32;
public const TYPE_MOB_SPELL = 33;
public const TYPE_MOB_SPELL_AMBIENT = 34;
public const TYPE_MOB_SPELL_INSTANTANEOUS = 35;
public const TYPE_INK = 36;
public const TYPE_SLIME = 37;
public const TYPE_RAIN_SPLASH = 38;
public const TYPE_VILLAGER_ANGRY = 39;
public const TYPE_VILLAGER_HAPPY = 40;
public const TYPE_ENCHANTMENT_TABLE = 41;
public const TYPE_TRACKING_EMITTER = 42;
public const TYPE_NOTE = 43;
public const TYPE_WITCH_SPELL = 44;
public const TYPE_CARROT = 45;
public const TYPE_MOB_APPEARANCE = 46;
public const TYPE_END_ROD = 47;
public const TYPE_DRAGONS_BREATH = 48;
public const TYPE_SPIT = 49;
public const TYPE_TOTEM = 50;
public const TYPE_FOOD = 51;
public const TYPE_FIREWORKS_STARTER = 52;
public const TYPE_FIREWORKS_SPARK = 53;
public const TYPE_FIREWORKS_OVERLAY = 54;
public const TYPE_BALLOON_GAS = 55;
public const TYPE_COLORED_FLAME = 56;
public const TYPE_SPARKLER = 57;
public const TYPE_CONDUIT = 58;
public const TYPE_BUBBLE_COLUMN_UP = 59;
public const TYPE_BUBBLE_COLUMN_DOWN = 60;
public const TYPE_SNEEZE = 61;
public const TYPE_SHULKER_BULLET = 62;
public const TYPE_BLEACH = 63;
public const TYPE_DRAGON_DESTROY_BLOCK = 64;
public const TYPE_MYCELIUM_DUST = 65;
public const TYPE_FALLING_RED_DUST = 66;
public const TYPE_CAMPFIRE_SMOKE = 67;
public const TYPE_TALL_CAMPFIRE_SMOKE = 68;
public const TYPE_DRAGON_BREATH_FIRE = 69;
public const TYPE_DRAGON_BREATH_TRAIL = 70;
public const TYPE_BLUE_FLAME = 71;
public const TYPE_SOUL = 72;
public const TYPE_OBSIDIAN_TEAR = 73;
public const TYPE_PORTAL_REVERSE = 74;
public const TYPE_SNOWFLAKE = 75;
public const TYPE_VIBRATION_SIGNAL = 76;
public const TYPE_SCULK_SENSOR_REDSTONE = 77;
public const TYPE_SPORE_BLOSSOM_SHOWER = 78;
public const TYPE_SPORE_BLOSSOM_AMBIENT = 79;
public const TYPE_WAX = 80;
public const TYPE_ELECTRIC_SPARK = 81;
/**
* @return DataPacket|DataPacket[]

View File

@ -29,7 +29,10 @@ namespace pocketmine\metadata;
use pocketmine\plugin\Plugin;
abstract class MetadataStore{
/** @var \SplObjectStorage[]|MetadataValue[][] */
/**
* @var \SplObjectStorage[]|MetadataValue[][]
* @phpstan-var array<string, \SplObjectStorage<Plugin, MetadataValue>>
*/
private $metadataMap;
/**
@ -41,6 +44,7 @@ abstract class MetadataStore{
$owningPlugin = $newMetadataValue->getOwningPlugin();
if(!isset($this->metadataMap[$key])){
/** @phpstan-var \SplObjectStorage<Plugin, MetadataValue> $entry */
$entry = new \SplObjectStorage();
$this->metadataMap[$key] = $entry;
}else{
@ -92,7 +96,6 @@ abstract class MetadataStore{
* @return void
*/
public function invalidateAll(Plugin $owningPlugin){
/** @var \SplObjectStorage|MetadataValue[] $values */
foreach($this->metadataMap as $values){
if(isset($values[$owningPlugin])){
$values[$owningPlugin]->invalidate();

View File

@ -25,6 +25,7 @@ namespace pocketmine\network\mcpe;
#include <rules/DataPacket.h>
use pocketmine\block\BlockIds;
use pocketmine\entity\Attribute;
use pocketmine\entity\Entity;
use pocketmine\item\Durable;
@ -32,12 +33,14 @@ use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\ItemIds;
use pocketmine\math\Vector3;
use pocketmine\nbt\LittleEndianNBTStream;
use pocketmine\nbt\NetworkLittleEndianNBTStream;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\NamedTag;
use pocketmine\network\mcpe\convert\ItemTranslator;
use pocketmine\network\mcpe\convert\ItemTypeDictionary;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\protocol\types\CommandOriginData;
use pocketmine\network\mcpe\protocol\types\EntityLink;
use pocketmine\network\mcpe\protocol\types\GameRuleType;
@ -58,6 +61,7 @@ class NetworkBinaryStream extends BinaryStream{
private const DAMAGE_TAG = "Damage"; //TAG_Int
private const DAMAGE_TAG_CONFLICT_RESOLUTION = "___Damage_ProtocolCollisionResolution___";
private const PM_META_TAG = "___Meta___";
public function getString() : string{
return $this->get($this->getUnsignedVarInt());
@ -87,6 +91,7 @@ class NetworkBinaryStream extends BinaryStream{
public function getSkin() : SkinData{
$skinId = $this->getString();
$skinPlayFabId = $this->getString();
$skinResourcePatch = $this->getString();
$skinData = $this->getSkinImage();
$animationCount = $this->getLInt();
@ -133,7 +138,7 @@ class NetworkBinaryStream extends BinaryStream{
);
}
return new SkinData($skinId, $skinResourcePatch, $skinData, $animations, $capeData, $geometryData, $animationData, $premium, $persona, $capeOnClassic, $capeId, $fullSkinId, $armSize, $skinColor, $personaPieces, $pieceTintColors);
return new SkinData($skinId, $skinPlayFabId, $skinResourcePatch, $skinData, $animations, $capeData, $geometryData, $animationData, $premium, $persona, $capeOnClassic, $capeId, $fullSkinId, $armSize, $skinColor, $personaPieces, $pieceTintColors);
}
/**
@ -141,6 +146,7 @@ class NetworkBinaryStream extends BinaryStream{
*/
public function putSkin(SkinData $skin){
$this->putString($skin->getSkinId());
$this->putString($skin->getPlayFabId());
$this->putString($skin->getResourcePatch());
$this->putSkinImage($skin->getSkinImage());
$this->putLInt(count($skin->getAnimations()));
@ -191,83 +197,134 @@ class NetworkBinaryStream extends BinaryStream{
$this->putString($image->getData());
}
public function getSlot() : Item{
public function getItemStackWithoutStackId() : Item{
return $this->getItemStack(function() : void{
//NOOP
});
}
public function putItemStackWithoutStackId(Item $item) : void{
$this->putItemStack($item, function() : void{
//NOOP
});
}
/**
* @phpstan-param \Closure(NetworkBinaryStream) : void $readExtraCrapInTheMiddle
*/
public function getItemStack(\Closure $readExtraCrapInTheMiddle) : Item{
$netId = $this->getVarInt();
if($netId === 0){
return ItemFactory::get(0, 0, 0);
}
$auxValue = $this->getVarInt();
$netData = $auxValue >> 8;
$cnt = $auxValue & 0xff;
$cnt = $this->getLShort();
$netData = $this->getUnsignedVarInt();
[$id, $meta] = ItemTranslator::getInstance()->fromNetworkId($netId, $netData);
$nbtLen = $this->getLShort();
$readExtraCrapInTheMiddle($this);
/** @var CompoundTag|null $nbt */
$nbt = null;
if($nbtLen === 0xffff){
$nbtDataVersion = $this->getByte();
if($nbtDataVersion !== 1){
throw new \UnexpectedValueException("Unexpected NBT data version $nbtDataVersion");
$this->getVarInt();
$extraData = new NetworkBinaryStream($this->getString());
return (static function() use ($extraData, $netId, $id, $meta, $cnt) : Item{
$nbtLen = $extraData->getLShort();
/** @var CompoundTag|null $nbt */
$nbt = null;
if($nbtLen === 0xffff){
$nbtDataVersion = $extraData->getByte();
if($nbtDataVersion !== 1){
throw new \UnexpectedValueException("Unexpected NBT data version $nbtDataVersion");
}
$decodedNBT = (new LittleEndianNBTStream())->read($extraData->buffer, false, $extraData->offset, 512);
if(!($decodedNBT instanceof CompoundTag)){
throw new \UnexpectedValueException("Unexpected root tag type for itemstack");
}
$nbt = $decodedNBT;
}elseif($nbtLen !== 0){
throw new \UnexpectedValueException("Unexpected fake NBT length $nbtLen");
}
$decodedNBT = (new NetworkLittleEndianNBTStream())->read($this->buffer, false, $this->offset, 512);
if(!($decodedNBT instanceof CompoundTag)){
throw new \UnexpectedValueException("Unexpected root tag type for itemstack");
//TODO
for($i = 0, $canPlaceOn = $extraData->getLInt(); $i < $canPlaceOn; ++$i){
$extraData->get($extraData->getLShort());
}
$nbt = $decodedNBT;
}elseif($nbtLen !== 0){
throw new \UnexpectedValueException("Unexpected fake NBT length $nbtLen");
}
//TODO
for($i = 0, $canPlaceOn = $this->getVarInt(); $i < $canPlaceOn; ++$i){
$this->getString();
}
//TODO
for($i = 0, $canDestroy = $extraData->getLInt(); $i < $canDestroy; ++$i){
$extraData->get($extraData->getLShort());
}
//TODO
for($i = 0, $canDestroy = $this->getVarInt(); $i < $canDestroy; ++$i){
$this->getString();
}
if($netId === ItemTypeDictionary::getInstance()->fromStringId("minecraft:shield")){
$extraData->getLLong(); //"blocking tick" (ffs mojang)
}
if($netId === ItemTypeDictionary::getInstance()->fromStringId("minecraft:shield")){
$this->getVarLong(); //"blocking tick" (ffs mojang)
}
if($nbt !== null){
if($nbt->hasTag(self::DAMAGE_TAG, IntTag::class)){
$meta = $nbt->getInt(self::DAMAGE_TAG);
$nbt->removeTag(self::DAMAGE_TAG);
if(($conflicted = $nbt->getTag(self::DAMAGE_TAG_CONFLICT_RESOLUTION)) !== null){
$nbt->removeTag(self::DAMAGE_TAG_CONFLICT_RESOLUTION);
$conflicted->setName(self::DAMAGE_TAG);
$nbt->setTag($conflicted);
}elseif($nbt->count() === 0){
$nbt = null;
if(!$extraData->feof()){
throw new \UnexpectedValueException("Unexpected trailing extradata for network item $netId");
}
if($nbt !== null){
if($nbt->hasTag(self::DAMAGE_TAG, IntTag::class)){
$meta = $nbt->getInt(self::DAMAGE_TAG);
$nbt->removeTag(self::DAMAGE_TAG);
if(($conflicted = $nbt->getTag(self::DAMAGE_TAG_CONFLICT_RESOLUTION)) !== null){
$nbt->removeTag(self::DAMAGE_TAG_CONFLICT_RESOLUTION);
$conflicted->setName(self::DAMAGE_TAG);
$nbt->setTag($conflicted);
}elseif($nbt->count() === 0){
$nbt = null;
}
}elseif(($metaTag = $nbt->getTag(self::PM_META_TAG)) instanceof IntTag){
//TODO HACK: This foul-smelling code ensures that we can correctly deserialize an item when the
//client sends it back to us, because as of 1.16.220, blockitems quietly discard their metadata
//client-side. Aside from being very annoying, this also breaks various server-side behaviours.
$meta = $metaTag->getValue();
$nbt->removeTag(self::PM_META_TAG);
if($nbt->count() === 0){
$nbt = null;
}
}
}
}
return ItemFactory::get($id, $meta, $cnt, $nbt);
return ItemFactory::get($id, $meta, $cnt, $nbt);
})();
}
public function putSlot(Item $item) : void{
/**
* @phpstan-param \Closure(NetworkBinaryStream) : void $writeExtraCrapInTheMiddle
*/
public function putItemStack(Item $item, \Closure $writeExtraCrapInTheMiddle) : void{
if($item->getId() === 0){
$this->putVarInt(0);
return;
}
[$netId, $netData] = ItemTranslator::getInstance()->toNetworkId($item->getId(), $item->getDamage());
$coreData = $item->getDamage();
[$netId, $netData] = ItemTranslator::getInstance()->toNetworkId($item->getId(), $coreData);
$this->putVarInt($netId);
$auxValue = (($netData & 0x7fff) << 8) | $item->getCount();
$this->putVarInt($auxValue);
$this->putLShort($item->getCount());
$this->putUnsignedVarInt($netData);
$writeExtraCrapInTheMiddle($this);
$blockRuntimeId = 0;
$isBlockItem = $item->getId() < 256;
if($isBlockItem){
$block = $item->getBlock();
if($block->getId() !== BlockIds::AIR){
$blockRuntimeId = RuntimeBlockMapping::toStaticRuntimeId($block->getId(), $block->getDamage());
}
}
$this->putVarInt($blockRuntimeId);
$nbt = null;
if($item->hasCompoundTag()){
$nbt = clone $item->getNamedTag();
}
if($item instanceof Durable and $item->getDamage() > 0){
if($item instanceof Durable and $coreData > 0){
if($nbt !== null){
if(($existing = $nbt->getTag(self::DAMAGE_TAG)) !== null){
$nbt->removeTag(self::DAMAGE_TAG);
@ -277,23 +334,37 @@ class NetworkBinaryStream extends BinaryStream{
}else{
$nbt = new CompoundTag();
}
$nbt->setInt(self::DAMAGE_TAG, $item->getDamage());
$nbt->setInt(self::DAMAGE_TAG, $coreData);
}elseif($isBlockItem && $coreData !== 0){
//TODO HACK: This foul-smelling code ensures that we can correctly deserialize an item when the
//client sends it back to us, because as of 1.16.220, blockitems quietly discard their metadata
//client-side. Aside from being very annoying, this also breaks various server-side behaviours.
if($nbt === null){
$nbt = new CompoundTag();
}
$nbt->setInt(self::PM_META_TAG, $coreData);
}
if($nbt !== null){
$this->putLShort(0xffff);
$this->putByte(1); //TODO: NBT data version (?)
$this->put((new NetworkLittleEndianNBTStream())->write($nbt));
}else{
$this->putLShort(0);
}
$this->putString(
(static function() use ($nbt, $netId) : string{
$extraData = new NetworkBinaryStream();
$this->putVarInt(0); //CanPlaceOn entry count (TODO)
$this->putVarInt(0); //CanDestroy entry count (TODO)
if($nbt !== null){
$extraData->putLShort(0xffff);
$extraData->putByte(1); //TODO: NBT data version (?)
$extraData->put((new LittleEndianNBTStream())->write($nbt));
}else{
$extraData->putLShort(0);
}
if($netId === ItemTypeDictionary::getInstance()->fromStringId("minecraft:shield")){
$this->putVarLong(0); //"blocking tick" (ffs mojang)
}
$extraData->putLInt(0); //CanPlaceOn entry count (TODO)
$extraData->putLInt(0); //CanDestroy entry count (TODO)
if($netId === ItemTypeDictionary::getInstance()->fromStringId("minecraft:shield")){
$extraData->putLLong(0); //"blocking tick" (ffs mojang)
}
return $extraData->getBuffer();
})());
}
public function getRecipeIngredient() : Item{
@ -600,14 +671,15 @@ class NetworkBinaryStream extends BinaryStream{
* Reads gamerules
* TODO: implement this properly
*
* @return mixed[][], members are in the structure [name => [type, value]]
* @phpstan-return array<string, array{0: int, 1: bool|int|float}>
* @return mixed[][], members are in the structure [name => [type, value, isPlayerModifiable]]
* @phpstan-return array<string, array{0: int, 1: bool|int|float, 2: bool}>
*/
public function getGameRules() : array{
$count = $this->getUnsignedVarInt();
$rules = [];
for($i = 0; $i < $count; ++$i){
$name = $this->getString();
$isPlayerModifiable = $this->getBool();
$type = $this->getUnsignedVarInt();
$value = null;
switch($type){
@ -622,23 +694,24 @@ class NetworkBinaryStream extends BinaryStream{
break;
}
$rules[$name] = [$type, $value];
$rules[$name] = [$type, $value, $isPlayerModifiable];
}
return $rules;
}
/**
* Writes a gamerule array, members should be in the structure [name => [type, value]]
* Writes a gamerule array, members should be in the structure [name => [type, value, isPlayerModifiable]]
* TODO: implement this properly
*
* @param mixed[][] $rules
* @phpstan-param array<string, array{0: int, 1: bool|int|float}> $rules
* @phpstan-param array<string, array{0: int, 1: bool|int|float, 2: bool}> $rules
*/
public function putGameRules(array $rules) : void{
$this->putUnsignedVarInt(count($rules));
foreach($rules as $name => $rule){
$this->putString($name);
$this->putBool($rule[2]);
$this->putUnsignedVarInt($rule[0]);
switch($rule[0]){
case GameRuleType::BOOL:

View File

@ -31,6 +31,7 @@ use pocketmine\network\mcpe\protocol\AddEntityPacket;
use pocketmine\network\mcpe\protocol\AddItemActorPacket;
use pocketmine\network\mcpe\protocol\AddPaintingPacket;
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
use pocketmine\network\mcpe\protocol\AddVolumeEntityPacket;
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket;
use pocketmine\network\mcpe\protocol\AnimateEntityPacket;
use pocketmine\network\mcpe\protocol\AnimatePacket;
@ -48,6 +49,7 @@ use pocketmine\network\mcpe\protocol\CameraPacket;
use pocketmine\network\mcpe\protocol\CameraShakePacket;
use pocketmine\network\mcpe\protocol\ChangeDimensionPacket;
use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket;
use pocketmine\network\mcpe\protocol\ClientboundDebugRendererPacket;
use pocketmine\network\mcpe\protocol\ClientboundMapItemDataPacket;
use pocketmine\network\mcpe\protocol\ClientCacheBlobStatusPacket;
use pocketmine\network\mcpe\protocol\ClientCacheMissResponsePacket;
@ -72,6 +74,7 @@ use pocketmine\network\mcpe\protocol\EducationSettingsPacket;
use pocketmine\network\mcpe\protocol\EmoteListPacket;
use pocketmine\network\mcpe\protocol\EmotePacket;
use pocketmine\network\mcpe\protocol\EventPacket;
use pocketmine\network\mcpe\protocol\FilterTextPacket;
use pocketmine\network\mcpe\protocol\GameRulesChangedPacket;
use pocketmine\network\mcpe\protocol\GuiDataPickItemPacket;
use pocketmine\network\mcpe\protocol\HurtArmorPacket;
@ -107,6 +110,7 @@ use pocketmine\network\mcpe\protocol\MultiplayerSettingsPacket;
use pocketmine\network\mcpe\protocol\NetworkChunkPublisherUpdatePacket;
use pocketmine\network\mcpe\protocol\NetworkSettingsPacket;
use pocketmine\network\mcpe\protocol\NetworkStackLatencyPacket;
use pocketmine\network\mcpe\protocol\NpcDialoguePacket;
use pocketmine\network\mcpe\protocol\NpcRequestPacket;
use pocketmine\network\mcpe\protocol\OnScreenTextureAnimationPacket;
use pocketmine\network\mcpe\protocol\PacketViolationWarningPacket;
@ -128,6 +132,7 @@ use pocketmine\network\mcpe\protocol\PurchaseReceiptPacket;
use pocketmine\network\mcpe\protocol\RemoveActorPacket;
use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
use pocketmine\network\mcpe\protocol\RemoveObjectivePacket;
use pocketmine\network\mcpe\protocol\RemoveVolumeEntityPacket;
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkDataPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket;
@ -162,6 +167,7 @@ use pocketmine\network\mcpe\protocol\ShowCreditsPacket;
use pocketmine\network\mcpe\protocol\ShowProfilePacket;
use pocketmine\network\mcpe\protocol\ShowStoreOfferPacket;
use pocketmine\network\mcpe\protocol\SimpleEventPacket;
use pocketmine\network\mcpe\protocol\SimulationTypePacket;
use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket;
use pocketmine\network\mcpe\protocol\SpawnParticleEffectPacket;
use pocketmine\network\mcpe\protocol\StartGamePacket;
@ -170,6 +176,7 @@ use pocketmine\network\mcpe\protocol\StructureBlockUpdatePacket;
use pocketmine\network\mcpe\protocol\StructureTemplateDataRequestPacket;
use pocketmine\network\mcpe\protocol\StructureTemplateDataResponsePacket;
use pocketmine\network\mcpe\protocol\SubClientLoginPacket;
use pocketmine\network\mcpe\protocol\SyncActorPropertyPacket;
use pocketmine\network\mcpe\protocol\TakeItemActorPacket;
use pocketmine\network\mcpe\protocol\TextPacket;
use pocketmine\network\mcpe\protocol\TickSyncPacket;
@ -816,4 +823,32 @@ abstract class NetworkSession{
public function handleItemComponent(ItemComponentPacket $packet) : bool{
return false;
}
public function handleFilterText(FilterTextPacket $packet) : bool{
return false;
}
public function handleClientboundDebugRenderer(ClientboundDebugRendererPacket $packet) : bool{
return false;
}
public function handleSyncActorProperty(SyncActorPropertyPacket $packet) : bool{
return false;
}
public function handleAddVolumeEntity(AddVolumeEntityPacket $packet) : bool{
return false;
}
public function handleRemoveVolumeEntity(RemoveVolumeEntityPacket $packet) : bool{
return false;
}
public function handleSimulationType(SimulationTypePacket $packet) : bool{
return false;
}
public function handleNpcDialogue(NpcDialoguePacket $packet) : bool{
return false;
}
}

View File

@ -212,7 +212,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
$info->getMaxPlayerCount(),
$this->rakLib->getServerId(),
$this->server->getName(),
Server::getGamemodeName($this->server->getGamemode())
Server::getGamemodeName(Player::getClientFriendlyGamemode($this->server->getGamemode()))
]) . ";"
);
}

View File

@ -85,6 +85,10 @@ final class ItemTranslator{
if(!is_string($oldId) || !is_string($newId)){
throw new AssumptionFailedError("Invalid item table format");
}
if(!isset($legacyStringToIntMap[$oldId])){
//new item without a fixed legacy ID - we can't handle this right now
continue;
}
$simpleMappings[$newId] = $legacyStringToIntMap[$oldId];
}
foreach($legacyStringToIntMap as $stringId => $intId){
@ -128,8 +132,9 @@ final class ItemTranslator{
}elseif(isset($simpleMappings[$stringId])){
$this->simpleCoreToNetMapping[$simpleMappings[$stringId]] = $netId;
$this->simpleNetToCoreMapping[$netId] = $simpleMappings[$stringId];
}elseif($stringId !== "minecraft:unknown"){
throw new \InvalidArgumentException("Unmapped entry " . $stringId);
}else{
//not all items have a legacy mapping - for now, we only support the ones that do
continue;
}
}
}
@ -139,6 +144,9 @@ final class ItemTranslator{
* @phpstan-return array{int, int}
*/
public function toNetworkId(int $internalId, int $internalMeta) : array{
if($internalMeta === -1){
$internalMeta = 0x7fff;
}
if(isset($this->complexCoreToNetMapping[$internalId][$internalMeta])){
return [$this->complexCoreToNetMapping[$internalId][$internalMeta], 0];
}

View File

@ -31,24 +31,24 @@ class AddEntityPacket extends DataPacket/* implements ClientboundPacket*/{
public const NETWORK_ID = ProtocolInfo::ADD_ENTITY_PACKET;
/** @var int */
private $uvarint1;
private $entityNetId;
public static function create(int $uvarint1) : self{
public static function create(int $entityNetId) : self{
$result = new self;
$result->uvarint1 = $uvarint1;
$result->entityNetId = $entityNetId;
return $result;
}
public function getUvarint1() : int{
return $this->uvarint1;
public function getEntityNetId() : int{
return $this->entityNetId;
}
protected function decodePayload() : void{
$this->uvarint1 = $this->getUnsignedVarInt();
$this->entityNetId = $this->getUnsignedVarInt();
}
protected function encodePayload() : void{
$this->putUnsignedVarInt($this->uvarint1);
$this->putUnsignedVarInt($this->entityNetId);
}
public function handle(NetworkSession $handler) : bool{

View File

@ -25,9 +25,9 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
class AddItemActorPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::ADD_ITEM_ACTOR_PACKET;
@ -36,7 +36,7 @@ class AddItemActorPacket extends DataPacket{
public $entityUniqueId = null; //TODO
/** @var int */
public $entityRuntimeId;
/** @var Item */
/** @var ItemStackWrapper */
public $item;
/** @var Vector3 */
public $position;
@ -53,7 +53,7 @@ class AddItemActorPacket extends DataPacket{
protected function decodePayload(){
$this->entityUniqueId = $this->getEntityUniqueId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->item = $this->getSlot();
$this->item = ItemStackWrapper::read($this);
$this->position = $this->getVector3();
$this->motion = $this->getVector3();
$this->metadata = $this->getEntityMetadata();
@ -63,7 +63,7 @@ class AddItemActorPacket extends DataPacket{
protected function encodePayload(){
$this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putSlot($this->item);
$this->item->write($this);
$this->putVector3($this->position);
$this->putVector3Nullable($this->motion);
$this->putEntityMetadata($this->metadata);

View File

@ -25,11 +25,11 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\types\DeviceOS;
use pocketmine\network\mcpe\protocol\types\EntityLink;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use pocketmine\utils\UUID;
use function count;
@ -56,7 +56,7 @@ class AddPlayerPacket extends DataPacket{
public $yaw = 0.0;
/** @var float|null */
public $headYaw = null; //TODO
/** @var Item */
/** @var ItemStackWrapper */
public $item;
/**
* @var mixed[][]
@ -98,7 +98,7 @@ class AddPlayerPacket extends DataPacket{
$this->pitch = $this->getLFloat();
$this->yaw = $this->getLFloat();
$this->headYaw = $this->getLFloat();
$this->item = $this->getSlot();
$this->item = ItemStackWrapper::read($this);
$this->metadata = $this->getEntityMetadata();
$this->uvarint1 = $this->getUnsignedVarInt();
@ -129,7 +129,7 @@ class AddPlayerPacket extends DataPacket{
$this->putLFloat($this->pitch);
$this->putLFloat($this->yaw);
$this->putLFloat($this->headYaw ?? $this->yaw);
$this->putSlot($this->item);
$this->item->write($this);
$this->putEntityMetadata($this->metadata);
$this->putUnsignedVarInt($this->uvarint1);

View File

@ -0,0 +1,64 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\nbt\NetworkLittleEndianNBTStream;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\NetworkSession;
class AddVolumeEntityPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::ADD_VOLUME_ENTITY_PACKET;
/** @var int */
private $entityNetId;
/** @var CompoundTag */
private $data;
public static function create(int $entityNetId, CompoundTag $data) : self{
$result = new self;
$result->entityNetId = $entityNetId;
$result->data = $data;
return $result;
}
public function getEntityNetId() : int{ return $this->entityNetId; }
public function getData() : CompoundTag{ return $this->data; }
protected function decodePayload() : void{
$this->entityNetId = $this->getUnsignedVarInt();
$this->data = $this->getNbtCompoundRoot();
}
protected function encodePayload() : void{
$this->putUnsignedVarInt($this->entityNetId);
$this->put((new NetworkLittleEndianNBTStream())->write($this->data));
}
public function handle(NetworkSession $handler) : bool{
return $handler->handleAddVolumeEntity($this);
}
}

View File

@ -54,13 +54,15 @@ class AdventureSettingsPacket extends DataPacket{
public const FLYING = 0x200;
public const MUTED = 0x400;
public const BUILD_AND_MINE = 0x01 | self::BITFLAG_SECOND_SET;
public const MINE = 0x01 | self::BITFLAG_SECOND_SET;
public const DOORS_AND_SWITCHES = 0x02 | self::BITFLAG_SECOND_SET;
public const OPEN_CONTAINERS = 0x04 | self::BITFLAG_SECOND_SET;
public const ATTACK_PLAYERS = 0x08 | self::BITFLAG_SECOND_SET;
public const ATTACK_MOBS = 0x10 | self::BITFLAG_SECOND_SET;
public const OPERATOR = 0x20 | self::BITFLAG_SECOND_SET;
public const TELEPORT = 0x80 | self::BITFLAG_SECOND_SET;
public const BUILD = 0x100 | self::BITFLAG_SECOND_SET;
public const DEFAULT = 0x200 | self::BITFLAG_SECOND_SET;
/** @var int */
public $flags = 0;

View File

@ -49,25 +49,26 @@ class AvailableCommandsPacket extends DataPacket{
* ARG_FLAG_VALID | (type const)
*/
public const ARG_TYPE_INT = 0x01;
public const ARG_TYPE_FLOAT = 0x02;
public const ARG_TYPE_VALUE = 0x03;
public const ARG_TYPE_WILDCARD_INT = 0x04;
public const ARG_TYPE_OPERATOR = 0x05;
public const ARG_TYPE_TARGET = 0x06;
public const ARG_TYPE_FLOAT = 0x03;
public const ARG_TYPE_VALUE = 0x04;
public const ARG_TYPE_WILDCARD_INT = 0x05;
public const ARG_TYPE_OPERATOR = 0x06;
public const ARG_TYPE_TARGET = 0x07;
public const ARG_TYPE_WILDCARD_TARGET = 0x08;
public const ARG_TYPE_FILEPATH = 0x0e;
public const ARG_TYPE_FILEPATH = 0x10;
public const ARG_TYPE_STRING = 0x1d;
public const ARG_TYPE_STRING = 0x20;
public const ARG_TYPE_POSITION = 0x25;
public const ARG_TYPE_POSITION = 0x28;
public const ARG_TYPE_MESSAGE = 0x29;
public const ARG_TYPE_MESSAGE = 0x2c;
public const ARG_TYPE_RAWTEXT = 0x2b;
public const ARG_TYPE_RAWTEXT = 0x2e;
public const ARG_TYPE_JSON = 0x2f;
public const ARG_TYPE_JSON = 0x32;
public const ARG_TYPE_COMMAND = 0x36;
public const ARG_TYPE_COMMAND = 0x3f;
/**
* Enums are a little different: they are composed as follows:
@ -280,7 +281,7 @@ class AvailableCommandsPacket extends DataPacket{
$retval = new CommandData();
$retval->commandName = $this->getString();
$retval->commandDescription = $this->getString();
$retval->flags = $this->getByte();
$retval->flags = $this->getLShort();
$retval->permission = $this->getByte();
$retval->aliases = $enums[$this->getLInt()] ?? null;
@ -323,7 +324,7 @@ class AvailableCommandsPacket extends DataPacket{
protected function putCommandData(CommandData $data, array $enumIndexes, array $postfixIndexes) : void{
$this->putString($data->commandName);
$this->putString($data->commandDescription);
$this->putByte($data->flags);
$this->putLShort($data->flags);
$this->putByte($data->permission);
if($data->aliases !== null){

View File

@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\network\mcpe\NetworkBinaryStream;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\utils\AssumptionFailedError;
use function assert;
use function get_class;
use function strlen;
@ -72,7 +73,9 @@ class BatchPacket extends DataPacket{
}
protected function encodePayload(){
$this->put(zlib_encode($this->payload, ZLIB_ENCODING_RAW, $this->compressionLevel));
$encoded = zlib_encode($this->payload, ZLIB_ENCODING_RAW, $this->compressionLevel);
if($encoded === false) throw new AssumptionFailedError("ZLIB compression failed");
$this->put($encoded);
}
/**

View File

@ -33,18 +33,24 @@ class CameraShakePacket extends DataPacket/* implements ClientboundPacket*/{
public const TYPE_POSITIONAL = 0;
public const TYPE_ROTATIONAL = 1;
public const ACTION_ADD = 0;
public const ACTION_STOP = 1;
/** @var float */
private $intensity;
/** @var float */
private $duration;
/** @var int */
private $shakeType;
/** @var int */
private $shakeAction;
public static function create(float $intensity, float $duration, int $shakeType) : self{
public static function create(float $intensity, float $duration, int $shakeType, int $shakeAction) : self{
$result = new self;
$result->intensity = $intensity;
$result->duration = $duration;
$result->shakeType = $shakeType;
$result->shakeAction = $shakeAction;
return $result;
}
@ -54,16 +60,20 @@ class CameraShakePacket extends DataPacket/* implements ClientboundPacket*/{
public function getShakeType() : int{ return $this->shakeType; }
public function getShakeAction() : int{ return $this->shakeAction; }
protected function decodePayload() : void{
$this->intensity = $this->getLFloat();
$this->duration = $this->getLFloat();
$this->shakeType = $this->getByte();
$this->shakeAction = $this->getByte();
}
protected function encodePayload() : void{
$this->putLFloat($this->intensity);
$this->putLFloat($this->duration);
$this->putByte($this->shakeType);
$this->putByte($this->shakeAction);
}
public function handle(NetworkSession $handler) : bool{

View File

@ -66,23 +66,23 @@ class ClientCacheBlobStatusPacket extends DataPacket/* implements ServerboundPac
}
protected function decodePayload() : void{
$hitCount = $this->getUnsignedVarInt();
$missCount = $this->getUnsignedVarInt();
for($i = 0; $i < $hitCount; ++$i){
$this->hitHashes[] = $this->getLLong();
}
$hitCount = $this->getUnsignedVarInt();
for($i = 0; $i < $missCount; ++$i){
$this->missHashes[] = $this->getLLong();
}
for($i = 0; $i < $hitCount; ++$i){
$this->hitHashes[] = $this->getLLong();
}
}
protected function encodePayload() : void{
$this->putUnsignedVarInt(count($this->hitHashes));
$this->putUnsignedVarInt(count($this->missHashes));
foreach($this->hitHashes as $hash){
$this->putUnsignedVarInt(count($this->hitHashes));
foreach($this->missHashes as $hash){
$this->putLLong($hash);
}
foreach($this->missHashes as $hash){
foreach($this->hitHashes as $hash){
$this->putLLong($hash);
}
}

View File

@ -0,0 +1,137 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession;
class ClientboundDebugRendererPacket extends DataPacket/* implements ClientboundPacket*/{
public const NETWORK_ID = ProtocolInfo::CLIENTBOUND_DEBUG_RENDERER_PACKET;
public const TYPE_CLEAR = 1;
public const TYPE_ADD_CUBE = 2;
/** @var int */
private $type;
//TODO: if more types are added, we'll probably want to make a separate data type and interfaces
/** @var string */
private $text;
/** @var Vector3 */
private $position;
/** @var float */
private $red;
/** @var float */
private $green;
/** @var float */
private $blue;
/** @var float */
private $alpha;
/** @var int */
private $durationMillis;
private static function base(int $type) : self{
$result = new self;
$result->type = $type;
return $result;
}
public static function clear() : self{ return self::base(self::TYPE_CLEAR); }
public static function addCube(string $text, Vector3 $position, float $red, float $green, float $blue, float $alpha, int $durationMillis) : self{
$result = self::base(self::TYPE_ADD_CUBE);
$result->text = $text;
$result->position = $position;
$result->red = $red;
$result->green = $green;
$result->blue = $blue;
$result->alpha = $alpha;
$result->durationMillis = $durationMillis;
return $result;
}
public function getType() : int{ return $this->type; }
public function getText() : string{ return $this->text; }
public function getPosition() : Vector3{ return $this->position; }
public function getRed() : float{ return $this->red; }
public function getGreen() : float{ return $this->green; }
public function getBlue() : float{ return $this->blue; }
public function getAlpha() : float{ return $this->alpha; }
public function getDurationMillis() : int{ return $this->durationMillis; }
protected function decodePayload() : void{
$this->type = $this->getLInt();
switch($this->type){
case self::TYPE_CLEAR:
//NOOP
break;
case self::TYPE_ADD_CUBE:
$this->text = $this->getString();
$this->position = $this->getVector3();
$this->red = $this->getLFloat();
$this->green = $this->getLFloat();
$this->blue = $this->getLFloat();
$this->alpha = $this->getLFloat();
$this->durationMillis = $this->getLLong();
break;
default:
throw new \UnexpectedValueException("Unknown type " . $this->type);
}
}
protected function encodePayload() : void{
$this->putLInt($this->type);
switch($this->type){
case self::TYPE_CLEAR:
//NOOP
break;
case self::TYPE_ADD_CUBE:
$this->putString($this->text);
$this->putVector3($this->position);
$this->putLFloat($this->red);
$this->putLFloat($this->green);
$this->putLFloat($this->blue);
$this->putLFloat($this->alpha);
$this->putLLong($this->durationMillis);
break;
default:
throw new \InvalidArgumentException("Unknown type " . $this->type);
}
}
public function handle(NetworkSession $session) : bool{
return $session->handleClientboundDebugRenderer($this);
}
}

View File

@ -33,6 +33,11 @@ use function count;
class CommandOutputPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::COMMAND_OUTPUT_PACKET;
public const TYPE_LAST = 1;
public const TYPE_SILENT = 2;
public const TYPE_ALL = 3;
public const TYPE_DATA_SET = 4;
/** @var CommandOriginData */
public $originData;
/** @var int */
@ -53,7 +58,7 @@ class CommandOutputPacket extends DataPacket{
$this->messages[] = $this->getCommandMessage();
}
if($this->outputType === 4){
if($this->outputType === self::TYPE_DATA_SET){
$this->unknownString = $this->getString();
}
}
@ -81,7 +86,7 @@ class CommandOutputPacket extends DataPacket{
$this->putCommandMessage($message);
}
if($this->outputType === 4){
if($this->outputType === self::TYPE_DATA_SET){
$this->putString($this->unknownString);
}
}

View File

@ -28,7 +28,6 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\inventory\FurnaceRecipe;
use pocketmine\inventory\ShapedRecipe;
use pocketmine\inventory\ShapelessRecipe;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\network\mcpe\convert\ItemTranslator;
use pocketmine\network\mcpe\NetworkBinaryStream;
@ -84,7 +83,6 @@ class CraftingDataPacket extends DataPacket{
case self::ENTRY_SHAPELESS_CHEMISTRY:
$entry["recipe_id"] = $this->getString();
$ingredientCount = $this->getUnsignedVarInt();
/** @var Item */
$entry["input"] = [];
for($j = 0; $j < $ingredientCount; ++$j){
$entry["input"][] = $in = $this->getRecipeIngredient();
@ -93,7 +91,7 @@ class CraftingDataPacket extends DataPacket{
$resultCount = $this->getUnsignedVarInt();
$entry["output"] = [];
for($k = 0; $k < $resultCount; ++$k){
$entry["output"][] = $this->getSlot();
$entry["output"][] = $this->getItemStackWithoutStackId();
}
$entry["uuid"] = $this->getUUID()->toString();
$entry["block"] = $this->getString();
@ -115,7 +113,7 @@ class CraftingDataPacket extends DataPacket{
$resultCount = $this->getUnsignedVarInt();
$entry["output"] = [];
for($k = 0; $k < $resultCount; ++$k){
$entry["output"][] = $this->getSlot();
$entry["output"][] = $this->getItemStackWithoutStackId();
}
$entry["uuid"] = $this->getUUID()->toString();
$entry["block"] = $this->getString();
@ -133,7 +131,7 @@ class CraftingDataPacket extends DataPacket{
[$inputId, $inputData] = ItemTranslator::getInstance()->fromNetworkIdWithWildcardHandling($inputIdNet, $inputMetaNet);
}
$entry["input"] = ItemFactory::get($inputId, $inputData);
$entry["output"] = $out = $this->getSlot();
$entry["output"] = $out = $this->getItemStackWithoutStackId();
if($out->getDamage() === 0x7fff){
$out->setDamage(0); //TODO HACK: some 1.12 furnace recipe outputs have wildcard damage values
}
@ -200,7 +198,7 @@ class CraftingDataPacket extends DataPacket{
$results = $recipe->getResults();
$stream->putUnsignedVarInt(count($results));
foreach($results as $item){
$stream->putSlot($item);
$stream->putItemStackWithoutStackId($item);
}
$stream->put(str_repeat("\x00", 16)); //Null UUID
@ -225,7 +223,7 @@ class CraftingDataPacket extends DataPacket{
$results = $recipe->getResults();
$stream->putUnsignedVarInt(count($results));
foreach($results as $item){
$stream->putSlot($item);
$stream->putItemStackWithoutStackId($item);
}
$stream->put(str_repeat("\x00", 16)); //Null UUID
@ -246,7 +244,7 @@ class CraftingDataPacket extends DataPacket{
}
$stream->putVarInt($netId);
$stream->putVarInt($netData);
$stream->putSlot($recipe->getResult());
$stream->putItemStackWithoutStackId($recipe->getResult());
$stream->putString("furnace"); //TODO: blocktype (no prefix) (this might require internal API breaks)
return CraftingDataPacket::ENTRY_FURNACE_DATA;
}
@ -278,7 +276,7 @@ class CraftingDataPacket extends DataPacket{
$writer = new NetworkBinaryStream();
$counter = 0;
foreach($this->entries as $d){
$entryType = self::writeEntry($d, $writer, $counter++);
$entryType = self::writeEntry($d, $writer, ++$counter);
if($entryType >= 0){
$this->putVarInt($entryType);
$this->put($writer->getBuffer());

View File

@ -25,8 +25,8 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\item\Item;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use pocketmine\utils\UUID;
use function count;
@ -39,9 +39,9 @@ class CraftingEventPacket extends DataPacket{
public $type;
/** @var UUID */
public $id;
/** @var Item[] */
/** @var ItemStackWrapper[] */
public $input = [];
/** @var Item[] */
/** @var ItemStackWrapper[] */
public $output = [];
public function clean(){
@ -57,12 +57,12 @@ class CraftingEventPacket extends DataPacket{
$size = $this->getUnsignedVarInt();
for($i = 0; $i < $size and $i < 128; ++$i){
$this->input[] = $this->getSlot();
$this->input[] = ItemStackWrapper::read($this);
}
$size = $this->getUnsignedVarInt();
for($i = 0; $i < $size and $i < 128; ++$i){
$this->output[] = $this->getSlot();
$this->output[] = ItemStackWrapper::read($this);
}
}
@ -73,12 +73,12 @@ class CraftingEventPacket extends DataPacket{
$this->putUnsignedVarInt(count($this->input));
foreach($this->input as $item){
$this->putSlot($item);
$item->write($this);
}
$this->putUnsignedVarInt(count($this->output));
foreach($this->output as $item){
$this->putSlot($item);
$item->write($this);
}
}

View File

@ -174,7 +174,7 @@ abstract class DataPacket extends NetworkBinaryStream{
public function __debugInfo(){
$data = [];
foreach((array) $this as $k => $v){
if($k === "buffer" and is_string($v)){
if($k === "buffer"){
$data[$k] = bin2hex($v);
}elseif(is_string($v) or (is_object($v) and method_exists($v, "__toString"))){
$data[$k] = Utils::printable((string) $v);

View File

@ -48,6 +48,13 @@ class EventPacket extends DataPacket{
public const TYPE_CAULDRON_BLOCK_USED = 15;
public const TYPE_COMPOSTER_BLOCK_USED = 16;
public const TYPE_BELL_BLOCK_USED = 17;
public const TYPE_ACTOR_DEFINITION = 18;
public const TYPE_RAID_UPDATE = 19;
public const TYPE_PLAYER_MOVEMENT_ANOMALY = 20; //anti cheat
public const TYPE_PLAYER_MOVEMENT_CORRECTED = 21;
public const TYPE_HONEY_HARVESTED = 22;
public const TYPE_TARGET_BLOCK_HIT = 23;
public const TYPE_PIGLIN_BARTER = 24;
/** @var int */
public $playerRuntimeId;

View File

@ -0,0 +1,62 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession;
class FilterTextPacket extends DataPacket/* implements ClientboundPacket, ServerboundPacket*/{
public const NETWORK_ID = ProtocolInfo::FILTER_TEXT_PACKET;
/** @var string */
private $text;
/** @var bool */
private $fromServer;
public static function create(string $text, bool $server) : self{
$result = new self;
$result->text = $text;
$result->fromServer = $server;
return $result;
}
public function getText() : string{ return $this->text; }
public function isFromServer() : bool{ return $this->fromServer; }
protected function decodePayload() : void{
$this->text = $this->getString();
$this->fromServer = $this->getBool();
}
protected function encodePayload() : void{
$this->putString($this->text);
$this->putBool($this->fromServer);
}
public function handle(NetworkSession $handler) : bool{
return $handler->handleFilterText($this);
}
}

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