Compare commits

...

300 Commits

Author SHA1 Message Date
323d96d5c1 Release 3.13.0 2020-06-04 20:01:27 +01:00
f495ba1d0b Merge branch 'next-minor' into stable 2020-06-04 19:59:46 +01:00
643cf0ebf8 3.12.7 is next 2020-06-04 19:55:09 +01:00
1614206a6d Release 3.12.6 2020-06-04 19:55:09 +01:00
0ae2c6302a Merge branch 'stable' into next-minor 2020-06-04 13:59:30 +01:00
4f59c1b26c .gitignore: ignore some extra crap 2020-06-04 13:58:46 +01:00
00916ade0c update build/php submodule to pmmp/php-build-scripts@0aa88d2765 2020-06-04 13:55:03 +01:00
f4ee2912db Server: tell me what is wrong when crash archive submission fails 2020-06-04 13:48:40 +01:00
a0de9b0d46 Player: use real time to update rate limit, fixes #3554 (except in very extreme cases) 2020-06-04 13:39:26 +01:00
03e8cd3ed4 Player: fixing ground state handling in spectator mode, closes #3552, closes #3553 2020-06-04 11:10:21 +01:00
7af4e70f64 Entity: fixed movement updates not firing after teleport
this became obvious by teleporting non-moving entities into the air and observing that they didn't fall.
2020-06-04 10:52:04 +01:00
c864647cd1 Merge branch 'stable' into next-minor 2020-06-03 13:04:08 +01:00
92ed9e6125 3.12.6 is next 2020-06-03 10:59:33 +01:00
c32026333f Release 3.12.5 2020-06-03 10:59:33 +01:00
915224c8e5 Living: fix being unable to die in the void 2020-06-02 23:18:40 +01:00
734bc6c4a7 3.12.5 is next 2020-06-02 18:40:33 +01:00
d36b24c518 Release 3.12.4 2020-06-02 18:40:33 +01:00
d554d8060b fixed absorption hearts not being consumed, closes #3546
this was caused by a bad fix for switching. we can't consider zero-damage attacks as cancelled because zero-damage might have been the result of things like consuming absorption hearts, so the aftereffects need to be processed even when the net damage is zero.
2020-06-02 10:09:18 +01:00
b48243fd09 Bump phpstan/phpstan-phpunit from 0.12.10 to 0.12.11 (#3547) 2020-06-01 18:05:51 +00:00
5c63e06b0f piece together a changelog for release 2020-06-01 14:57:27 +01:00
3be83e09f2 Revert BC-breaking backport from b38c81c96
this can't be applied to a minor version because it places additional requirements on the Inventory contract.
2020-06-01 13:51:36 +01:00
f24be2b055 Merge branch 'stable' into next-minor
# Conflicts:
#	src/pocketmine/Player.php
#	src/pocketmine/block/SnowLayer.php
2020-06-01 13:42:59 +01:00
92cffc00d0 3.12.4 is next 2020-06-01 13:18:28 +01:00
e87e974323 Release 3.12.3 2020-06-01 13:18:28 +01:00
a3f6338626 Player: fixed internal server error when using insert-before on a client-sided book page 2020-06-01 12:59:18 +01:00
21aef97ba7 Player: fixed swapping book pages that only exist client-side, closes #3322 2020-06-01 12:50:39 +01:00
ed0d1978aa WritableBook: fixed thrown exception when asking for a page that doesn't exist (it's allowed to return null for a reason ...) 2020-06-01 12:46:41 +01:00
d64561b0b1 Fixed internal server error when deleting book pages that only exist client side 2020-06-01 12:39:17 +01:00
d234d3e45e ParticleCommand: added mobflame, closes #3102 2020-05-31 20:28:57 +01:00
5056754cea NetworkBinaryStream: do not round vectors directly on reading
fixes #3199
2020-05-31 20:17:42 +01:00
2dc3cf8162 InventoryTransaction: sync inventories before throwing validation exception to caller
fixes #3226

really the transaction shouldn't be handling inventory sync at all, but that's a job for another commit.
2020-05-31 20:10:29 +01:00
8c5a81cf5c Living: improved projectile knockback
this isn't pretty, but it works. I have a nicer idea how to do this on PM4, but it's going to involve BC breaks (as usual).
closes #3382
2020-05-31 20:04:12 +01:00
2b58f2bafd FallingBlock: remove superfluous transparent check, closes #3339 2020-05-31 19:54:47 +01:00
5dadf12374 Living: fixed cooldown damage logic, closes #2939 2020-05-31 19:46:51 +01:00
0d4e473bdd Reduce ResourcePackChunkData chunk size to 128 KB
while this is slightly less bandwidth efficient (1 in 92 datagrams not full vs 1 in 733), this is significantly less memory-hard.
I made this decision looking at the memory pressures that 1MB chunks exert - especially on RakNet. Client-side, these resource pack chunks all hang around in RakNet memory until the whole thing is received, and it's a lot more costly to receive 733 datagrams than it is to receive 92, especially since it's much more likely that some of the 733 will disappear along the way.
If, for example, the first couple of hundred KB split parts arrived out of 1MB, and then one of the parts got lost, all the already-received parts would hang around in memory not getting processed. With smaller chunks this is much less of a problem.
I explored taking the chunk size all the way down to 1KB to reduce the bandwidth waste caused by split packets (split headers), but this made resource pack downloading unbearably slow, so it wasn't acceptable.
2020-05-31 19:29:26 +01:00
11cedc4011 Player: added a constant for resource pack chunk sending size 2020-05-31 19:23:21 +01:00
3f2455f090 SnowLayer: fixed layer stacking, closes #2775 2020-05-31 17:38:24 +01:00
9d26a224a2 DoublePlant: add flammability info, closes #2465 2020-05-31 17:04:50 +01:00
c4ad390463 pocketmine.yml: raise default population-queue-size to 32
the old limit was made in the php5 days when performance was far worse and it was much more costly to generate chunks that weren't needed. Now it's significantly less and having a higher limit allows terrain to be sent more quickly in new worlds and to fast-moving players.
This limit really ought to go away completely but considering the technical barriers in the way it'll have to stay for now.
2020-05-31 16:58:53 +01:00
42e14f749e Do not blanket-ban all inventory transactions in spectator mode, fixes #2627
instead, we cancel the appropriate events before they are called, so that plugins can uncancel them if they choose.
2020-05-31 16:32:06 +01:00
484557935e Level: remove dead block placement code (player movements are now always processed immediately, just not immediately broadcasted) 2020-05-31 16:06:48 +01:00
485f573955 Player: remove move buffering, implement simple rate limited movement… (#3167)
Introduction
This PR is a second attempt at improving movement processing to fix #1215 , #2730 and more.

This is significantly less complex than the previous attempt #2646 -- it gets rid of the movement buffering system entirely and instead relies on a simple rate limit counter to restrict on-the-fly movement processing.

Movement is rate limited to a max average of 2 per tick. It allows up to 5 seconds' backlog to accommodate network lag. The rate limit counter is increased by 2 per tick and decreased once for every movement processed. This prevents movement processing being abused for denial of service attacks.

Changes
API changes
This PR, while obviously highly beneficial for most current users, poses some BC-breaking issues because of changes to the internal Player API.

Player->processMovement() (protected) has been removed. This is a BC concern for custom player classes which overrode it and called it as a parent. In addition, child implementations won't be called every tick any more, which could break some custom movement processing systems.
Player->newPosition (protected) has been removed. This internal field may have been accessed by custom movement implementations.
Player->isTeleporting (protected) has been removed. BC concern is same as previous point.
Player->getNextPosition() (public) has been @deprecated.
Added the following protected Player class members:
int $moveRateLimit
?Vector3 $forceMoveSync
handleMovement()
processMostRecentMovements()
revertMovement()
Behavioural changes
Player movement is now subject to less rubberbanding and has more reliable behaviour.
2020-05-31 15:51:30 +01:00
71e0521286 Merge branch 'stable' into next-minor
# Conflicts:
#	composer.lock
2020-05-31 14:43:53 +01:00
3f07f06874 updated composer lockfile 2020-05-31 14:42:31 +01:00
10279e11ed updated build/php submodule to pmmp/php-build-scripts@d475b694e4 2020-05-31 14:33:26 +01:00
673e444456 phpstan: fix build failure 2020-05-31 13:02:32 +01:00
89c49d77c6 ditch irstea/phpunit-shim, more trouble than it's worth 2020-05-31 12:03:38 +01:00
c3a795e876 Fix walk sounds (#3492)
Co-authored-by: Govdim <govdim.govorek@gmail.com>
2020-05-24 14:03:14 +01:00
4199c3796f Water: Remove duplicate call to Entity->resetFallDistance() (#3524)
It's not clear what the intended goal of this code was, but the duplicate call is obviously useless.
2020-05-24 14:00:19 +01:00
ecbf21acea Utils: added OS constants, remove hardcoded OS strings everywhere 2020-05-23 11:05:58 +01:00
45c89d084c TimeCommand: add time aliases "noon", "sunset", "midnight", "sunrise"
closes #3508
2020-05-20 20:42:21 +01:00
56f90a2901 Merge branch 'stable' into next-minor 2020-05-20 20:05:00 +01:00
bf6af269c8 StartGamePacket: use PUBLIC visibility by default 2020-05-20 20:04:39 +01:00
73d1f84072 Merge branch 'stable' into next-minor 2020-05-20 19:36:20 +01:00
a29424f5b3 UIProfile: name constants as they appear in the MC user-facing settings
I think these names are stupid, but it'll be easier for people to figure out what they refer to if they match the client-sided naming.
2020-05-20 15:06:50 +01:00
ff3af492f8 Random: remove multiline formatting in nextSignedInt()
I'm sick to death of formatting tools messing with this...
2020-05-20 14:34:29 +01:00
80b804f7aa automated imports cleanup 2020-05-20 14:31:31 +01:00
3a78735982 added UIProfile protocol constants
these are only used in the LoginPacket, but plugin devs will probably find them useful anyway
2020-05-20 14:27:50 +01:00
ab32784c74 UpdateBlockSyncedPacket: remove default values for fields 2020-05-20 13:58:36 +01:00
816234a379 UpdateBlockSyncedPacket: populate missing information for second field 2020-05-20 13:57:08 +01:00
b7bf92a5e9 SimpleEventPacket: added missing type constant 2020-05-20 13:50:43 +01:00
dcca000ead PlayerActionPacket: added missing constant 2020-05-20 13:44:52 +01:00
c4ea51f985 NpcRequestPacket: added request type constants 2020-05-20 13:42:40 +01:00
8202bb1cd8 MoveActorAbsolutePacket: added missing flag 2020-05-20 13:39:56 +01:00
b75758e35e MoveActorDeltaPacket: added missing flags 2020-05-20 13:39:37 +01:00
38a06f76f8 LoginPacket: remove unused constant 2020-05-20 13:15:43 +01:00
84f99ed418 CommandOriginData: Rename previously unknown field 2020-05-20 13:00:03 +01:00
fd63f19199 make use of new GameRuleType constants 2020-05-20 12:35:29 +01:00
66d44aa814 added GameRuleType protocol constants 2020-05-20 12:35:07 +01:00
f3089f577e StartGamePacket: use new protocol constants for multiplayer visibility 2020-05-20 12:22:33 +01:00
9516ef1632 added GamePublishSetting protocol constants 2020-05-20 12:22:12 +01:00
e982a57cb5 StartGamePacket: use EducationEditionOffer constants 2020-05-20 12:08:56 +01:00
f57fa2252b added EducationEditionOffer protocol constants 2020-05-20 12:08:36 +01:00
02cc370855 StartGamePacket: use GeneratorType constants 2020-05-20 12:05:41 +01:00
0a5d14a840 added GeneratorType protocol constants 2020-05-20 12:05:41 +01:00
3ec2994d7f added protocol GameMode constants 2020-05-20 11:53:35 +01:00
da4a2d8552 Fixed a bunch of missed Position->getLevel() usages
these were not in the usage search because PhpStorm decided to refer to ChunkLoader->getLevel() for any Player references, which caused them to only show when that was searched.

There's also an undetected LSP violation with ChunkLoader because it requires returning Level and Position->getLevel() returns Level|null. I don't know why PHPStan doesn't complain about that.
2020-05-19 21:01:18 +01:00
dc9351b024 Merge remote-tracking branch 'origin/stable' into next-minor 2020-05-19 11:26:25 +01:00
786f416f2e Improved support for paths with backslashes on Unix filesystems (#3501)
Fixes #3497
2020-05-19 10:34:51 +01:00
a67d2ae978 parity: burning players no longer shoot burning arrows (#3509)
this behaviour doesn't exist in vanilla.
2020-05-19 10:31:39 +01:00
089180fef4 Players no longer burn when hit by other players, closes #3170 (#3470) 2020-05-18 21:13:56 +01:00
15baf09339 update l7 and l8 baselines for next-minor branch 2020-05-18 20:16:03 +01:00
083dde8395 Merge branch 'stable' into next-minor 2020-05-18 20:10:47 +01:00
fffa4b9501 phpstan: baseline our way to level 8
we really need the level 8 checks on new code now, and waiting until old code is clean is not going to benefit us much because the issues that are there already exist.
2020-05-18 20:09:25 +01:00
22b5de09b4 added colours to EnchantParticle and InstantEnchantParticle, closes #3368 2020-05-18 20:00:51 +01:00
71a8b0340c BUILDING.md: EOF newline [ci skip] 2020-05-18 19:23:18 +01:00
e544055bbc BUILDING.md: change build/server.phar to build/server-phar.php
closes #3507
2020-05-18 18:54:14 +01:00
8f5db7c297 3.12.2 changelog typo (#3505) 2020-05-18 12:26:07 +01:00
a5edfa368e Merge branch 'stable' into next-minor 2020-05-18 10:25:25 +01:00
27f55e4c96 3.12.3 is next 2020-05-18 10:17:08 +01:00
9b6b3f50a1 Release 3.12.2 2020-05-18 10:17:02 +01:00
1fb0ba6fc0 travis: update PHP extension versions 2020-05-18 09:47:56 +01:00
f1d378468e updated build/php submodule to pmmp/php-build-scripts@a6ab41089e 2020-05-18 09:44:43 +01:00
9ebd6d6b0f Timezone: remove rogue newline 2020-05-17 14:03:22 +01:00
58e32086c0 Level: Updated TIME_* constants (#3385)
- Added Level::TIME_NOON
- Added Level::TIME_MIDNIGHT
- Changed values of Level::TIME_DAY and Level::TIME_NIGHT
2020-05-17 10:10:35 +01:00
8c0d441a13 Merge branch 'stable' into next-minor 2020-05-17 10:03:17 +01:00
25fb5140a2 Merge #3456: Added protocol DeviceOS constants
close #3456

since this is a protocol addition and not API, this belongs on stable so
that protocol changes can consistently use it without worrying about
branch compatibility.
2020-05-17 09:57:39 +01:00
f5a49b6d55 LightUpdate: improve quality of property type info 2020-05-17 09:33:18 +01:00
189f12a644 PermissionManager: fix timings not being stopped for default calculation (#3502) 2020-05-17 08:55:11 +01:00
5a8917f6f2 TaskScheduler: queue contains TaskHandler, not Task 2020-05-16 15:27:20 +01:00
f3e436592a ZippedResourcePack: detect location of manifest.json if it's not in the root
this isn't quite as bulletproof as I'd like it to be, but it should work...
2020-05-15 19:41:45 +01:00
35747874f6 Cocoa: fix drops, closes #3326
this doesn't really do a whole lot, but I want this issue off my tracker, it's worthless...
2020-05-14 00:56:39 +01:00
59445902b8 Entity: do not spawn to players who haven't received the target chunk yet, closes #3355
this might cause some delays on chunk resend as documented on master, but entities all get respawned on a resend, so this doesn't matter much. It's better than whatever side effects might come with spawning an entity in a chunk that the player doesn't have yet.
2020-05-14 00:46:54 +01:00
2eb62c85f6 Server: cast network.compression-level to int, closes #3393 2020-05-14 00:37:54 +01:00
ad2a39bf13 Merge #3489: fix spawn protection check for placement checking the wrong block, close #3488, close #3489 2020-05-14 00:30:11 +01:00
0847358070 SkinImage: fix inverted auto-detect height/width, closes #3490
it seems like the client doesn't care if the h/w are inverted for skins anyway, but this is still wrong anyway...
2020-05-14 00:22:12 +01:00
8766d4050c Merge branch 'stable' into next-minor 2020-05-13 13:18:55 +01:00
54f41dc145 3.12.2 is next 2020-05-13 13:10:25 +01:00
ded45bddfe Release 3.12.1 2020-05-13 13:10:10 +01:00
b044550475 Player: duct tape for yet another login sequence bug in the shitty net architecture 2020-05-13 12:59:43 +01:00
a70fa15690 phpstan 0.12.25, drop some bug-filtering error patterns 2020-05-13 12:51:52 +01:00
bd1d7b8d75 asserts 👏 are 👏 not 👏 error 👏 checking 2020-05-13 12:39:55 +01:00
1513a0e092 VerifyLoginTask: beware wrong number of parts when splitting JWT 2020-05-13 12:39:53 +01:00
c4150d4520 Bump phpstan/phpstan from 0.12.23 to 0.12.25 (#3486) 2020-05-11 20:19:30 +00:00
2f47597d75 BaseLevelProvider: stop crashing the server on invalid level.dat
broken userdata isn't a core bug, so it shouldn't be flooding our crash archives.
2020-05-11 15:34:53 +01:00
56883f9ff9 MemoryManager: explicitly assume return type of ini_get() 2020-05-10 11:35:53 +01:00
7cdd26add5 Player: make handleLogin() less unreadable 2020-05-10 11:23:11 +01:00
717b866605 Merge branch 'stable' into next-minor 2020-05-06 20:25:11 +01:00
ef97c8f99e Utils: fix parsing of single-line doc comments, closes #3388 (#3469)
* Utils: fix parsing of single-line doc comments, closes #3388

* correctly handle the empty doc-comment case, add another test case

* ignore an extra phpstan bug
2020-05-06 14:17:08 +01:00
84932ce908 Bump phpstan/phpstan from 0.12.22 to 0.12.23 (#3468) 2020-05-05 15:59:22 +00:00
6bfc309a0a phpstan 0.12.22 2020-05-04 22:26:44 +01:00
06e8c6a3ad Entity: new data flags 2020-05-04 21:58:44 +01:00
71271a0e03 Use env to locate bash (#3439)
This change uses env to locate bash, instead of hard-coding it. This is necessary on FreeBSD. Tested on Linux as well.
2020-04-30 17:34:13 +01:00
f87e96026c Merge branch 'stable' into next-minor 2020-04-26 00:28:09 +01:00
b63ad032a9 phpstan 0.12.19 2020-04-26 00:08:41 +01:00
d9b0e373bb Populator: fix return type of populate() 2020-04-26 00:04:17 +01:00
8e1b3edd2c Merge branch 'stable' into next-minor 2020-04-25 12:06:52 +01:00
32262d9bb5 Merge branch 'stable' of https://github.com/pmmp/pocketmine-mp into stable 2020-04-25 11:59:35 +01:00
4c1b10b24b restructure ignoreErrors to allow regenerating them file by file 2020-04-25 11:59:06 +01:00
61dc9d7f6b phpstan: split up phpstan-bugs and phpstan-bugs-generated configs 2020-04-25 11:26:54 +01:00
da9731ef59 phpstan: add stub defines to improve analysis 2020-04-25 11:07:05 +01:00
e6f64c609e bootstrap: avoid making COMPOSER_AUTOLOADER_PATH having a possible false type 2020-04-25 11:04:09 +01:00
8c7fbf379b Bump irstea/phpunit-shim from 8.5.3 to 8.5.4 (#3435) 2020-04-24 20:45:43 +00:00
3d2ca457f8 protocol: Added missing Window Types (#3420) 2020-04-19 15:43:11 +01:00
1579f41056 Added missing Enchantment IDs (#3419) 2020-04-19 15:42:27 +01:00
34a3e0d8b1 Level: fix sneaking use-item logic (thanks @95CivicSi)
inspired by, but closes #3403
fixes #3401
fixes #2539
fixes #1904
2020-04-19 15:38:12 +01:00
d42217ff57 Bump phpstan/phpstan-phpunit from 0.12.6 to 0.12.8 (#3421) 2020-04-19 14:26:22 +00:00
70a4f73d73 Drop PHP 7.2 support 2020-04-19 12:49:25 +01:00
7d43dffac4 updated phpstan/phpstan-phpunit 2020-04-19 12:44:26 +01:00
804a062c3a CrashDump: report the versions of all Composer libraries installed 2020-04-19 12:11:34 +01:00
22a4639162 Merge branch 'stable' into next-minor 2020-04-18 13:32:52 +01:00
39d02a67d2 3.12.1 is next 2020-04-17 18:39:20 +01:00
77d45bf116 Release 3.12.0 2020-04-17 18:39:15 +01:00
f79182852b Fixed typo in login handler (wrong variable to store persona pieces) (#3422) 2020-04-17 14:36:51 +01:00
a107ad7404 1.14.60 support (#3407) 2020-04-17 09:18:00 +01:00
7a072931df Merge branch 'stable' of https://github.com/pmmp/pocketmine-mp into stable 2020-04-17 01:58:26 +01:00
f428a9bf52 protocol: rename some useless fields 2020-04-17 01:58:06 +01:00
2e720b48d9 AnimatePacket: added a new constant 2020-04-17 01:57:20 +01:00
a6e79bedf5 ActorEventPacket: plug some gaps 2020-04-17 01:56:56 +01:00
a5ba570fdf StructureBlockUpdatePacket: Added encode/decode (#3148) 2020-04-17 01:11:16 +01:00
0d5164af02 LabTablePacket: updated type field and added constants 2020-04-16 22:03:36 +01:00
534af770f8 InteractPacket: new constant 2020-04-16 22:03:34 +01:00
619a9892e5 RCON: properly handle potential errors during socket setup 2020-04-16 01:29:28 +01:00
63b109f23e RCONInstance: fixed incorrect doc comment for field 2020-04-15 21:16:47 +01:00
79ed377c7a Bump pocketmine/nbt from 0.2.13 to 0.2.14 (#3406)
Bumps [pocketmine/nbt](https://github.com/pmmp/NBT) from 0.2.13 to 0.2.14.
- [Release notes](https://github.com/pmmp/NBT/releases)
- [Commits](https://github.com/pmmp/NBT/compare/0.2.13...0.2.14)

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

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-04-15 13:45:52 +01:00
2da8ce7a20 PluginBase: account for fopen() maybe returning false
again, the error handler will normally take care of this, but we can't assume that the error handler is always set.
2020-04-15 13:05:41 +01:00
959dd4cbf1 PluginManager: explicitly assume the result of FilesystemIterator arrayification 2020-04-15 12:59:15 +01:00
0a3788f9ac ScriptPluginLoader: properly handle the case where the script itself is somehow missing
this won't ever happen during PocketMine runtime, but it might happen if something else tries to use it.
2020-04-15 12:54:45 +01:00
cdda74ef93 PluginDescription: use result of phpversion() to check if extension is loaded
technically phpstan should account for this with the extension_loaded() check, but it currently doesn't and it's not worth fighting with it when the fix is so simple anyway.
2020-04-15 12:50:53 +01:00
bbe428a874 Spawnable: explicitly assume that NBTStream->write() will not return false
it will never return false under these circumstances
2020-04-15 12:43:44 +01:00
755919c496 SendUsageTask: explicitly assume that json_encode() will not return false 2020-04-15 12:43:05 +01:00
88b216a17b AsyncTask: fix another phpstan level 7 error about wrong types
this should really be a dedicated type, but everything done with pthreads sucks.
2020-04-15 12:42:18 +01:00
8020912448 AsyncPool: add phpstan array type information to all fields 2020-04-15 12:40:54 +01:00
5571ae05b5 AsyncPool: silence a warning about wrong key type
getTaskId() returns int|null, although it won't happen after the ID has been set.
2020-04-15 12:40:23 +01:00
bc985198a0 Config: do not expect string keys on parseProperties(), because of key casting (PHP sucks) 2020-04-15 12:20:23 +01:00
27b2710c56 Config: make phpstan happy for load()
currently this will never be reached if the regular exception handler has been set, but it might not be set if the class is used on its own.
2020-04-15 12:18:22 +01:00
1755b25808 Utils: make explicit assumption about result of scandir() in recursiveUnlink()
TODO: this assumption might be flawed in the case of threading...
2020-04-15 12:13:26 +01:00
a78133d0e3 Utils: provide phpstan type information for testValidInstance() 2020-04-15 12:12:18 +01:00
a51a16a55c Utils: silence PHPStan warning about array_combine() result
phpstan doesn't account for having 2 arrays of the same size, and even if it did, the size cannot be inferred easily here.
2020-04-15 12:11:13 +01:00
099562d582 Utils: assume explicitly that ob_get_contents() will not return false in getReferenceCount() based on context 2020-04-15 12:10:21 +01:00
ae76e8f08f Utils: fix some implicit casts to boolean on result of preg_match_all() 2020-04-15 12:09:10 +01:00
42a08e7e4a Utils: don't assume that callable is only array|string implicitly
this should really support closures too, but since it's not used anywhere, I feel OK with this change.
2020-04-15 12:08:33 +01:00
b193d9f919 Process: shut up PHPStan about possible float returns on getMemoryUsage and friends
this can never actually happen because the given data sources will never have such large numbers, but PHPStan doesn't know this.
2020-04-15 12:07:24 +01:00
24d64eedab Process: make some assumptions about I/O explicit for type safety 2020-04-15 12:05:13 +01:00
0c9d16f1ef Internet: explicitly assume return of curl_exec() is string after error checking
this is documented as string|bool, but it's actually string|false if CURLOPT_RETURNTRANSFER is set, and bool if not.
2020-04-15 12:02:38 +01:00
d246933e3e TextFormat: account for failure to encode JSON in toJSON() 2020-04-15 11:29:50 +01:00
41d7b8c0e4 TextFormat: properly handle pcre errors in some cases
these would previously just hit type errors.
2020-04-15 11:29:04 +01:00
2622c34542 Terminal: explicitly assume that fopen(stdin) will not fail 2020-04-15 11:12:03 +01:00
5c9419b55c Timezone: use false checks instead of file existing for static analysis 2020-04-15 10:59:36 +01:00
83c40f4502 Timezone: properly account for failure to read timezone file 2020-04-15 10:23:07 +01:00
372202b3dc Utils: use type-safe checks to ensure file validity
this gives the same results while keeping phpstan happy.
2020-04-15 10:19:51 +01:00
917c744266 Properly handle error conditions in Utils::decodeJWT() 2020-04-15 10:18:02 +01:00
2281fe4e67 Account for reflection filename being false (in the case of classes/functions defined by builtins) 2020-04-15 10:15:38 +01:00
cf538d83bf Timezone: shut phpstan up about impossible ini_get() errors 2020-04-15 09:48:20 +01:00
7e9c38a9d9 Timezone::parseOffset() returns string|false, not string|bool 2020-04-15 09:47:52 +01:00
ccad97727f UUID: properly account for garbage inputs which aren't valid hexadecimal
this would previously throw a TypeError and crash.
2020-04-15 09:44:14 +01:00
e3ebf8bb61 Internet::getIP() returns string|false, not string|bool 2020-04-15 09:39:38 +01:00
cb6b59a52a Internet: curl_init() may return false on error (unclear on reasons) 2020-04-15 09:38:39 +01:00
53dbbd5f97 Internet: account for socket_create() maybe failing in getInternalIP() 2020-04-15 09:37:17 +01:00
51908ec45a Player: allow provision of a custom cooldown duration for items
this would be more useful to plugins, so that it's not necessary to extend any item classes for this trivial purpose.
2020-04-15 09:32:48 +01:00
a2543ff80d Position: add getLevelNonNull()
this allows assuming that a position has a valid world in places where it's never expected to not be valid. Since this is the vast majority of usages, it eliminates a lot of possible null-pointer warnings given by static analysers.
TODO: Consider whether we can make Position->getLevel/World use this behaviour out of the box in the next major version.
2020-04-14 11:08:37 +01:00
20f3030709 3.11.8 is next 2020-04-14 02:54:41 +01:00
3aa58f54dc Release 3.11.7 2020-04-14 02:54:40 +01:00
6e08b622b3 Merge branch 'stable' into next-minor 2020-04-14 01:43:23 +01:00
5c12a95151 phpstan: force static reflection for COM class
com_dotnet has crap reflection exports and the class name case doesn't match.
2020-04-14 01:43:02 +01:00
604900d4c5 Merge branch 'stable' into next-minor 2020-04-14 01:38:01 +01:00
5f07c5df1c Bump irstea/phpunit-shim from 8.5.2 to 8.5.3 (#3384) 2020-04-12 03:40:14 +00:00
6422ed7722 Added RakLibInterface::setPacketLimit() (#3398) 2020-04-11 23:27:17 +01:00
5f33ef35e3 build: allow providing a git hash 2020-04-09 21:13:54 +01:00
ec949840b2 Do not crash on failure to decompress region chunks
this could happen when a chunk was partially overwritten with one of the same sector size.
2020-04-01 21:30:25 +01:00
e45e84b236 Updated composer dependencies 2020-03-31 18:43:30 +01:00
dfe68c9788 Bump phpstan/phpstan from 0.12.17 to 0.12.18 (#3372)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.17 to 0.12.18.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.17...0.12.18)

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

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-03-23 15:21:00 +00:00
35b8f0bf25 Bump phpstan/phpstan from 0.12.15 to 0.12.17 (#3363) 2020-03-18 13:06:14 +00:00
d4dc1c8a0c AttributeMap: be aware of possible NULL offset in ArrayAccess
reported by phpstan 0.12.17
2020-03-18 12:59:01 +00:00
517f9a3c3a Player: fix weapons not taking damage from attacks (bug introduced by #3348) 2020-03-18 12:51:05 +00:00
636c35dcf1 replace daverandom/callback-validator with pocketmine/callback-validator, closes #3359 2020-03-17 12:24:50 +00:00
d22f0da1de Bump phpstan/phpstan from 0.12.14 to 0.12.15 (#3362) 2020-03-17 12:20:55 +00:00
310de5a2b2 RCON: set SO_REUSEADDR to fix RCON start failure after restart (#3357) 2020-03-16 12:00:45 +00:00
06a9c98ded MemoryManager: fix strict-rules error on phpstan level 7 2020-03-15 15:49:04 +00:00
5c7b05c2ba CrashDump: do not assign possibly-false return value of fopen() directly to non-union field
this would become a problem with typed properties, and also phpstan level 7 doesn't like it.
2020-03-15 15:48:09 +00:00
9c86763322 CrashDump: do not assume that error_get_last() always returns array
this returns NULL if there was no error before the shutdown handler was triggered (usually caused by a plugin calling exit() prematurely).
2020-03-15 15:47:07 +00:00
35490ca41c CrashDump: do not assume that file() always returns array
phpstan level 7 prep
2020-03-15 15:46:03 +00:00
47c7872c88 Merge branch 'stable' into next-minor 2020-03-14 13:42:39 +00:00
f84abcd1fe sync composer.lock with 0dd68e587f 2020-03-14 13:36:35 +00:00
b5dd147ec7 PlayerQuitEvent: fix types of quitMessage 2020-03-14 13:24:40 +00:00
f8ce01e2fd ItemFactory: extract fromStringSingle() from fromString()
on PM4, the multiple functionality is removed, but on PM3 this is a problem for phpstan.
2020-03-13 17:54:25 +00:00
3907a2b6ba Process: split getMemoryUsage() into 2 functions
this isn't released yet so it's OK to change.
phpstan level 7 doesn't like these kinds of ambiguous return types because there's no way for it to tell which type is returned without a return type specifying extension, and it's easier to just change the API than to make PHPStan understand it.
2020-03-13 17:32:17 +00:00
0dd68e587f require phpstan ^0.12.14 (for incremental analysis) 2020-03-13 16:30:35 +00:00
1171cd2493 Merge branch 'stable' into next-minor 2020-03-13 15:16:42 +00:00
330e93e5e3 Player: do not handle inbound ActorEvents that are not for self 2020-03-13 15:15:20 +00:00
e2579e0a2a Merge branch 'stable' into next-minor 2020-03-12 11:47:33 +00:00
2020fcd18e updated build/php submodule 2020-03-12 11:47:15 +00:00
5a9a576bfa AddActorPacket: remove unused import 2020-03-10 12:45:52 +00:00
b8caf34e62 Merge branch 'stable' into next-minor 2020-03-10 12:45:00 +00:00
456d9a722a reduce some doc comments to single line 2020-03-10 12:36:19 +00:00
344c980cff GlobalConstants: add strict_types 2020-03-10 12:35:13 +00:00
167492087f Chunk: specify expected bounds for Y coordinates 2020-03-10 12:33:53 +00:00
db215283a2 Effect: add desc for color parameter 2020-03-10 12:28:44 +00:00
6a507bb149 further CS fixes 2020-03-10 12:18:16 +00:00
dc757c25c8 cleanup CS from 8ec0a4d0d6 2020-03-10 12:14:38 +00:00
73267ae077 Merge branch 'stable' into next-minor 2020-03-10 12:11:36 +00:00
a72e6ee706 Player: be aware of held item changing during click-block
this caused bugs if the inventory was cleared while using a hoe.
2020-03-10 12:10:01 +00:00
8ec0a4d0d6 Allow specifying compatible OS in plugin manifest (#3192) 2020-03-10 10:12:56 +00:00
89ea7f0a76 Player: Stop setting held item post entity attack if changed (#3348)
closes #3340
2020-03-10 10:09:31 +00:00
df65f1009c Merge branch 'stable' into next-minor 2020-03-09 14:33:37 +00:00
a6ca37429c Player: do not set held item post block-break if changed (#3345)
this usually happens when a plugin replaces the held item during BlockBreakEvent.
closes #2010
2020-03-09 13:45:58 +00:00
4bf9fb278b Bump phpstan/phpstan from 0.12.11 to 0.12.14 (#3338) 2020-03-09 13:31:23 +00:00
15d81154e6 PluginDescription: drop unenforceable type constraint on array keys
the data that comes through here isn't validated, and there's also no guarantee that all the keys will be strings in spite of our best efforts even if it was validated, because PHP is fucking stupid and casts int-like string keys to int keys.
2020-03-05 19:53:01 +00:00
93e5c80962 MultiplayerSettingsPacket is bothways, close #3331 2020-03-03 12:32:57 +00:00
c19ab97610 AddActorPacket: move BC hack to higher level
we shouldn't hack the protocol impl for BC.
2020-02-27 17:37:45 +00:00
dbaf851be7 Merge branch 'stable' into next-minor 2020-02-27 16:51:06 +00:00
7aa8bd18d3 Revert "Item: restrict bounds of count to 0-255"
This reverts commit 10317527e4.

this breaks user code which exceeds stack limits in legitimate
circumstances. For example, it should be OK to add 6000x diamond to a
player's inventory without being forced to manually split the count up
for addItem().
2020-02-25 20:42:03 +00:00
53067c26d7 BaseInventory: stop mutating item for no reason in canAddItem() 2020-02-25 20:30:37 +00:00
04581e2700 DataPacket: account for splitscreen header when decoding 2020-02-24 21:20:25 +00:00
93597dcd50 SkinData: fixed loss of data from packet decode 2020-02-24 20:48:03 +00:00
778814a35e changelog: fix typo 2020-02-24 20:18:47 +00:00
3cd1da196a UpdateTradePacket: fix order of fields, closes #3327 2020-02-24 20:16:07 +00:00
365d4a1592 better fix for 1.14.30 movement bug 2020-02-23 19:31:32 +00:00
2d7f37ac47 avoid direct mutation of Item->count field, use Item->pop() instead
I think this change was already applied on the master branch, but I don't remember for sure.
2020-02-23 17:37:25 +00:00
50fcdd6e7e Item: fixed documentation of pop() return type (it's not fluent) 2020-02-23 17:32:50 +00:00
10317527e4 Item: restrict bounds of count to 0-255 2020-02-23 17:23:53 +00:00
46ac4cbca1 3.11.7 is next 2020-02-21 19:18:48 +00:00
19bd283807 Process: drop a blank line 2020-02-10 12:23:11 +00:00
20d1a048dd fixup imports 2020-02-10 12:21:56 +00:00
15b76a24b7 scrub useless phpdoc 2020-02-10 12:21:07 +00:00
2d51971b84 Revert "ClosureTask: drop requirement for void return type"
This reverts commit 9e993aa83f.

apparently PHPStan isn't cool with this ...
2020-02-10 11:40:47 +00:00
f08e411cad Merge branch 'stable' into next-minor 2020-02-10 11:40:08 +00:00
870c66d1fe Merge branch 'stable' into next-minor 2019-12-12 18:29:04 +00:00
1a467420e3 Merge branch 'stable' into next-minor 2019-12-12 13:07:02 +00:00
02fcfcc383 Merge branch 'stable' into next-minor 2019-12-09 10:47:53 +00:00
09961b5cd0 Merge branch 'stable' into next-minor 2019-12-04 22:16:04 +00:00
71a472e0eb Merge branch 'stable' into next-minor 2019-12-04 19:52:01 +00:00
e65bc5c3ae Merge branch 'stable' into next-minor 2019-12-04 11:11:29 +00:00
2ae37cc1c5 Merge branch 'stable' into next-minor 2019-12-03 19:59:35 +00:00
9a67192f74 Merge branch 'stable' into next-minor 2019-12-03 10:45:51 +00:00
4cfceeeb8e bootstrap: fix merge error introduced by cb76f8a5df
this error is harmless since it points to a deprecated function, but it showed up as conflicted in master merge.
2019-11-29 12:03:07 +00:00
3e4e0d51df Merge branch 'stable' into next-minor 2019-11-29 11:55:12 +00:00
cb76f8a5df Merge branch 'stable' into next-minor 2019-11-21 23:21:16 +08:00
0591458ef6 Merge branch 'stable' into next-minor 2019-10-22 18:49:22 +01:00
eeddaced9f PluginManager: Remove useless deprecation warning message
this message just confuses end users and is of little use to a developer. It doesn't make any sense to make a special case for events when we have lots of other deprecated things to think about anyway which won't be shown warnings for.
2019-08-02 16:34:00 +01:00
c237ff538c Merge branch 'stable' into next-minor 2019-08-02 16:32:00 +01:00
23b00bea5b Merge branch 'stable' into next-minor 2019-07-29 17:31:06 +01:00
cde2c10c1d AsyncTask: partial backport of 6ac0c517f5 (simplify TLS)
- deprecated AsyncTask::peekLocal()
- AsyncTask::fetchLocal() no longer deletes stored data
2019-07-27 15:09:42 +01:00
87fb42cabd Merge branch 'stable' into next-minor 2019-07-27 14:53:13 +01:00
6566dd8c8f AsyncPool: Remove useless warning about complex data leftovers
this is automatically cleaned up anyway, so this warning is just redundant noise.
2019-07-27 14:44:40 +01:00
1e65ac0d85 Merge branch 'stable' into next-minor 2019-07-27 14:40:31 +01:00
cb247a5f28 AsyncTask: Deprecate methods removed in 2c4f2810d2 2019-07-26 19:52:26 +01:00
bb048fb361 Merge branch 'stable' into next-minor 2019-07-26 19:50:17 +01:00
9e993aa83f ClosureTask: drop requirement for void return type
this creates unnecessary boilerplate for many inline usages.
2019-07-01 17:19:19 +01:00
fab12707ae Merge branch 'stable' into next-minor 2019-07-01 17:18:20 +01:00
51f299f196 Merge branch 'stable' into next-minor 2019-06-22 19:46:23 +01:00
2bb52cf811 Merge branch 'stable' into next-minor 2019-06-22 16:03:28 +01:00
6afc689529 Add Level->getTimeOfDay(), closes #2908 (#2979) 2019-06-22 16:00:18 +01:00
5a17a0d1aa Merge branch 'stable' into next-minor 2019-06-16 16:37:23 +01:00
b38c81c96f backport f84a1729c: Inventory: added swap() function 2019-06-16 16:35:34 +01:00
0fabc0c199 backport b8d1eb20b: EntityDeathEvent: add XP amount API, closes #2690 2019-06-16 16:31:03 +01:00
ec5598dbb1 Deprecate things removed in acb794e72 and 97c836f19 2019-06-16 15:37:27 +01:00
7b98d203f4 Merge branch 'stable' into next-minor 2019-06-16 14:47:01 +01:00
4635b93f4d backport 23071d257 + deprecations: Extract process-related functions from Utils into a separate Process class 2019-06-16 14:40:51 +01:00
a8433697ad backport aaaddd1fd: Terminal: stick a RESET on the end when writing a newline 2019-06-16 14:25:16 +01:00
680cdb8e3e backport f5dbbea5f: Utils: added recursiveUnlink() 2019-06-16 14:20:05 +01:00
eaa78fe849 backport 205e13d88: Config: add getPath() (#2758)
Config->getPath() returns the path of the config i.e. the place where the config file is located.
2019-06-16 14:18:50 +01:00
eedea4998b Terminal: Added write() and writeLine() to allow easily emitting Minecraft-formatted text to the console 2019-06-16 14:16:14 +01:00
4e5a80c481 Recipe: deprecate interface 2019-06-16 14:12:49 +01:00
4d54dc30c1 crafting: deprecate some stuff that's been removed on bleeding edge 2019-06-16 14:11:08 +01:00
ac5339414a Merge branch 'stable' into next-minor
# Conflicts:
#	build/preprocessor
2019-06-16 14:08:06 +01:00
9fd922fe6a Merge branch 'stable' into next-minor 2019-05-02 17:25:29 +01:00
fdaf9dce73 Merge branch 'stable' into next-minor 2019-05-02 16:39:05 +01:00
732e27751c Merge branch 'stable' into next-minor 2019-05-02 15:04:23 +01:00
932c489de1 Rename addTitle/addSubTitle/addActionBarMessage prefixes to "send", deprecated old variants
closes #2896

these deprecated methods will be removed in 4.0.
2019-05-01 18:54:20 +01:00
230 changed files with 7751 additions and 1167 deletions

6
.gitignore vendored
View File

@ -41,3 +41,9 @@ test_data/*
# Doxygen
Documentation/*
# PHPUnit
/.phpunit.result.cache
# php-cs-fixer
/.php_cs.cache

View File

@ -1,16 +1,14 @@
language: php
php:
- 7.2
- 7.3
before_script:
- phpenv config-rm xdebug.ini
# - pecl install channel://pecl.php.net/pthreads-3.1.6
- echo | pecl install channel://pecl.php.net/yaml-2.0.4
- echo | pecl install channel://pecl.php.net/yaml-2.1.0
- git clone https://github.com/pmmp/pthreads.git
- cd pthreads
- git checkout 1b7da492b944146fa9680f6399bd9c6c6c6095e0
- git checkout 646dac62ae0d48c1ada7b007e15575fb84f7d71d
- phpize
- ./configure
- make

View File

@ -2,7 +2,7 @@
## Pre-requisites
- A bash shell (git bash is sufficient for Windows)
- [`git`](https://git-scm.com) available in your shell
- PHP 7.2 or newer available in your shell
- PHP 7.3 or newer available in your shell
- [`composer`](https://getcomposer.org) available in your shell
## Custom PHP binaries
@ -30,9 +30,9 @@ If you use a custom binary, you'll need to replace `composer` usages in this gui
Preprocessor requires that the `cpp` (c preprocessor) is available in your PATH.
## Building `PocketMine-MP.phar`
Run `build/server.phar` using your preferred PHP binary. It'll drop a `PocketMine-MP.phar` into the current working directory.
Run `build/server-phar.php` using your preferred PHP binary. It'll drop a `PocketMine-MP.phar` into the current working directory.
You can also use the `--out` option to change the output filename.
## Running PocketMine-MP from source code
Run `src/pocketmine/PocketMine.php` using your preferred PHP binary.
Run `src/pocketmine/PocketMine.php` using your preferred PHP binary.

View File

@ -130,9 +130,13 @@ function main() : void{
exit(1);
}
$opts = getopt("", ["out:"]);
$gitHash = Git::getRepositoryStatePretty(dirname(__DIR__));
echo "Git hash detected as $gitHash" . PHP_EOL;
$opts = getopt("", ["out:", "git:"]);
if(isset($opts["git"])){
$gitHash = $opts["git"];
}else{
$gitHash = Git::getRepositoryStatePretty(dirname(__DIR__));
echo "Git hash detected as $gitHash" . PHP_EOL;
}
foreach(buildPhar(
$opts["out"] ?? getcwd() . DIRECTORY_SEPARATOR . "PocketMine-MP.phar",
dirname(__DIR__) . DIRECTORY_SEPARATOR,

View File

@ -65,7 +65,7 @@ Plugin developers should **only** update their required API to this version if y
- `build/server-phar.php` now uses GZIP compression on created phars, providing a 75% size reduction.
- `ClientboundMapItemDataPacket` now uses `MapDecoration` objects for decorations instead of associative arrays.
- Updated Composer dependencies to get bug fixes in `pocketmine/nbt` and other libraries.
- Packages `pocketmine/classloader` and `pockegtmine/log` are now required; these provide classes previously part of `pocketmine/spl`. This change has no effect on API compatibility.
- Packages `pocketmine/classloader` and `pocketmine/log` are now required; these provide classes previously part of `pocketmine/spl`. This change has no effect on API compatibility.
# 3.11.6
- Core code, tests and build scripts are now analyzed using `phpstan-strict-rules` and `phpstan-phpunit` rules.
@ -79,3 +79,19 @@ Plugin developers should **only** update their required API to this version if y
- `ThreadManager` is now lazily initialized.
- Removed raw NBT storage from `Item` internals. The following methods are now deprecated:
- `Item::setCompoundTag()`
# 3.11.7
- Build system: Fixed crash reports of Jenkins builds being rejected by the crash archive as invalid.
- Introduced a new dependency on `pocketmine/log-pthreads`, which contains classes separated from `pocketmine/log`.
- Fixed minimum composer stability preventing any newer version of `pocketmine/pocketmine-mp` being installed than 3.3.4 by replacing `daverandom/callback-validator` with [`pocketmine/callback-validator`](https://github.com/pmmp/CallbackValidator).
- Fixed every player seeing eating particles when any player eats.
- Fixed setting held item not working during `BlockBreakEvent`, `PlayerInteractEvent` and `EntityDamageEvent`.
- Fixed some incorrect documented types in `PlayerQuitEvent` reported by PHPStan.
- Fixed documentation of `Item->pop()` return value.
- Fixed server crash on encountering corrupted compressed data stored in region files.
- Protocol: Split screen header is now properly accounted for during decoding. Note that split screen is still not supported natively, but their packets can be decoded properly now.
- Protocol: Fixed wrong order of fields in `UpdateTradePacket`.
- Protocol: Fixed loss of `fullSkinId` when decoding network skins.
- Fixed RCON not being able to bind to port after a fast server restart.

53
changelogs/3.12.md Normal file
View File

@ -0,0 +1,53 @@
**For Minecraft: Bedrock Edition 1.14.60**
### 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.12.0
- Added support for Minecraft: Bedrock Edition 1.14.60
- Removed compatibility with 1.14.0-1.14.30
# 3.12.1
- Fixed parsing of single-line doc comments for event handlers, e.g. `/** @ignoreCancelled */` should now work correctly.
- The server will no longer crash on failure to load `level.dat` contents, but will gracefully shutdown instead without producing a crashdump.
- Fixed some bugs in login verification that could cause undefined behaviour.
- Fixed item-use behaviour when sneaking - sneaking and clicking a block with an empty hand, and sneaking and using an item, both now follow vanilla behaviour.
- `start.sh` will now work on platforms where `/bin/bash` is not available, as long as `/usr/bin/env` knows where bash is.
# 3.12.2
- Fixed permission default timings not being reported in timings reports (they were never stopped, only started).
- Resource packs with a directory tree like `pack.zip/MyPack/manifest.json` are now supported. Note that the manifest closest to the root will be used.
- Fixed `SkinImage` height and width being inverted at the protocol layer.
- Fixed blocks being able to be placed inside the spawn protection radius by clicking the side of a block outside the radius.
- Fixed server crash when `network.compression-level` is overridden by a CLI parameter.
- Fixed moving entities spawning themselves to players registered on chunks when the players haven't received the chunk yet.
- Cocoa pods now drop cocoa beans when broken instead of the block itself.
# 3.12.3
- Core code is now analyzed using PHPStan level 8 (using baselines). While not all the code is level 8 compliant, this does mean that new code will be held to a higher standard, ensuring quality going forwards.
- Players no longer burn when melee-attacked by other players. (vanilla parity)
- Arrows shot by burning players are no longer on fire. (vanilla parity)
- Fixed a crash that could occur with plugins on Unix filesystems that had backslashes in their names.
- Cleaned up a whole bunch of unknowns in the protocol layer. Many new constants have been added.
- Fixed player walking sounds.
- Default generation queue size has been raised to 32 (previously 8). The previous default was selected in a time when PHP was much less performant than it is today, and in today's world it just needlessly slows things down.
- Double plants are now burned away by fire.
- Snow layers can now be stacked. (vanilla parity)
- Resource pack sending chunk size has been reduced to 128 KB (previously 1 MB). This change was made after analyzing the effects that larger pack chunk sizes have on RakNet. Given the technical evidence, a smaller size, while slightly less bandwidth-efficient, should be more manageable for RakNet due to lower split reassembly overhead and reduced memory pressure.
- Fixed "switching" (an exploit often complained about by PvP players). Now, the previous damage is subtracted from current damage when an entity is attacked while on cooldown. This means that attacking with a wooden sword and then diamond sword while attack cooldown is active will only deal as much damage as the diamond sword would have, instead of the combined total. This can be controlled using the `EntityDamageEvent::MODIFIER_PREVIOUS_DAMAGE_COOLDOWN` modifier. (vanilla parity)
- Fixed projectiles knocking mobs back in unexpected directions on collision.
- Fixed inventories not being synchronized on failed inventory transactions.
- Vector3s decoded from packets are no longer rounded directly. Instead, the player movement handler takes responsibility for rounding the coordinates to prevent anti cheat doing something it's not supposed to.
- `mobflame` particle can now be spawned using the `/particle` command.
- Fixed several internal errors that could occur while modifying writable books.
- Fixed swapping writable book pages not working in some cases.
- `WritableBook->getPageText()` no longer throws an exception when the page doesn't exist, but returns null (as it was originally intended to).
# 3.12.4
- Fixed absorption hearts not being consumed.
# 3.12.5
- Fixed broken attack cooldowns.

111
changelogs/3.13.md Normal file
View File

@ -0,0 +1,111 @@
**For Minecraft: Bedrock Edition 1.14.60**
This is a feature release, containing various minor API additions, deprecations and a few minor features.
### 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.13.0
## Core
- PHP 7.3.0 or newer is now required.
- Player movement processing has been revamped. It's now more tolerant of network lag and doesn't have as many problems with falling.
## User Interface
- `/time` now supports additional aliases `noon`, `sunset`, `midnight` and `sunrise`.
- Removed warnings when a plugin registers a handler for a deprecated event. Since this warning is developer-focused, and too specific to be useful, it just caused annoyance and confusion to users who didn't know what it meant.
## API
### General
- It's now possible to require a specific operating system using the `os` directive in `plugin.yml`. More information about this directive can be found in the [developer documentation](https://github.com/pmmp/DeveloperDocs).
### Player
- `Player->resetItemCooldown()` now accepts a second parameter, allowing plugins to provide a custom duration.
- The following methods have been deprecated and have recommended replacements:
- `Player->addTitle()` -> `Player->sendTitle()`
- `Player->addSubTitle()` -> `Player->sendSubTitle()`
- `Player->addActionBarMessage()` -> `Player->sendActionBarMessage()`
### Event
- The following methods have been deprecated:
- `EntityDespawnEvent->getType()`
- `EntityDespawnEvent->getPosition()`
- `EntityDespawnEvent->isCreature()`
- `EntityDespawnEvent->isHuman()`
- `EntityDespawnEvent->isProjectile()`
- `EntityDespawnEvent->isVehicle()`
- `EntityDespawnEvent->isItem()`
- `EntitySpawnEvent->getType()`
- `EntitySpawnEvent->getPosition()`
- `EntitySpawnEvent->isCreature()`
- `EntitySpawnEvent->isHuman()`
- `EntitySpawnEvent->isProjectile()`
- `EntitySpawnEvent->isVehicle()`
- `EntitySpawnEvent->isItem()`
- Added the following API methods:
- `EntityDeathEvent->getXpDropAmount()`
- `EntityDeathEvent->setXpDropAmount()`
- `PlayerDeathEvent::__construct()` now accepts a fourth (optional) parameter `int $xp`.
- `EntityDeathEvent::__construct()` now accepts a third (optional) parameter `int $xp`.
### Inventory
- The following classes have been deprecated:
- `Recipe`
- The following methods have been deprecated:
- `CraftingManager->registerRecipe()`
- `Recipe->registerToCraftingManager()` (and all its implementations)
### Item
- New `Enchantment` type ID constants have been added.
- `ItemFactory::fromStringSingle()` has been added. This works exactly the same as `ItemFactory::fromString()`, but it has a return type of `Item` instead of `Item|Item[]` (more static analysis friendly).
### Level
- Added the following API methods:
- `Position->getLevelNonNull()`: this is the same as `Position->getLevel()`, but throws an `AssumptionFailedError` if the level is null or invalid (more static analysis friendly).
- `Level->getTimeOfDay()`
- The following constants have been changed:
- `Level::TIME_DAY` now has a value of `1000`
- `Level::TIME_NIGHT` now has a value of `13000`
- Added the following constants:
- `Level::TIME_MIDNIGHT`
- `Level::TIME_NOON`
- The following types of particles now accept optional `Color` parameters in the constructor:
- `EnchantParticle`
- `InstantEnchantParticle`
### Network
- Added the following API methods:
- `RakLibInterface->setPacketLimit()`
### Scheduler
AsyncTask thread-local storage has been improved, making it simpler and easier to use.
- `AsyncTask->fetchLocal()` no longer deletes stored thread-local data. Instead, the storage behaves more like properties, and gets deleted when the AsyncTask object goes out of scope.
- `AsyncTask->peekLocal()` has been `@deprecated` (use `fetchLocal()` instead).
- Notices are no longer emitted if an async task doesn't fetch its locally stored data.
- The following methods have been deprecated:
- `AsyncTask->getFromThreadStore()` (use its worker's corresponding method)
- `AsyncTask->saveToThreadStore()` (use its worker's corresponding method)
- `AsyncTask->removeFromThreadStore()` (use its worker's corresponding method)
### Utils
- The following functions have been deprecated and have recommended replacements:
- `Utils::getMemoryUsage()` -> split into `Process::getMemoryUsage()` and `Process::getAdvancedMemoryUsage()` (not 1:1 replacement!!)
- `Utils::getRealMemoryUsage()` -> `Process::getRealMemoryUsage()`
- `Utils::getThreadCount()` -> `Process::getThreadCount()`
- `Utils::kill()` -> `Process::kill()`
- `Utils::execute()` -> `Process::execute()`
- Added the following constants:
- `Utils::OS_WINDOWS`
- `Utils::OS_IOS`
- `Utils::OS_MACOS`
- `Utils::OS_ANDROID`
- `Utils::OS_LINUX`
- `Utils::OS_BSD`
- `Utils::OS_UNKNOWN`
- Added the following API methods:
- `Config->getPath()`
- `Utils::recursiveUnlink()`
- `Terminal::write()`
- `Terminal::writeLine()`

View File

@ -5,7 +5,7 @@
"homepage": "https://pmmp.io",
"license": "LGPL-3.0",
"require": {
"php": ">=7.2.0",
"php": ">=7.3.0",
"php-64bit": "*",
"ext-bcmath": "*",
"ext-curl": "*",
@ -31,15 +31,17 @@
"pocketmine/math": "^0.2.0",
"pocketmine/snooze": "^0.1.0",
"pocketmine/classloader": "^0.1.0",
"pocketmine/log": "^0.1.0",
"daverandom/callback-validator": "dev-master",
"adhocore/json-comment": "^0.1.0"
"pocketmine/log": "^0.2.0",
"pocketmine/log-pthreads": "^0.1.0",
"pocketmine/callback-validator": "^1.0.1",
"adhocore/json-comment": "^0.1.0",
"ocramius/package-versions": "^1.5"
},
"require-dev": {
"phpstan/phpstan": "^0.12.9",
"irstea/phpunit-shim": "^8.5",
"phpstan/phpstan": "^0.12.25",
"phpstan/phpstan-phpunit": "^0.12.6",
"phpstan/phpstan-strict-rules": "^0.12.2"
"phpstan/phpstan-strict-rules": "^0.12.2",
"phpunit/phpunit": "^8.5"
},
"autoload": {
"psr-4": {

1729
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,10 @@
includes:
- tests/phpstan/configs/actual-problems.neon
- tests/phpstan/configs/com-dotnet-magic.neon
- tests/phpstan/configs/custom-leveldb.neon
- tests/phpstan/configs/gc-hacks.neon
- tests/phpstan/configs/l7-baseline.neon
- tests/phpstan/configs/l8-baseline.neon
- tests/phpstan/configs/php-bugs.neon
- tests/phpstan/configs/phpstan-bugs.neon
- tests/phpstan/configs/phpunit-wiring-tests.neon
@ -12,13 +15,12 @@ includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
level: 6
level: 8
autoload_files:
- tests/phpstan/bootstrap.php
- src/pocketmine/PocketMine.php
- build/make-release.php
- build/server-phar.php
- vendor/irstea/phpunit-shim/phpunit
paths:
- src
- build/make-release.php
@ -31,158 +33,5 @@ parameters:
- tests/phpstan/stubs/pthreads.stub
- tests/phpstan/stubs/chunkutils.stub
reportUnmatchedIgnoredErrors: false #no other way to silence platform-specific non-warnings
ignoreErrors:
-
message: "#^Instanceof between pocketmine\\\\plugin\\\\PluginManager and pocketmine\\\\plugin\\\\PluginManager will always evaluate to true\\.$#"
count: 1
path: src/pocketmine/CrashDump.php
-
message: "#^pocketmine\\\\Player\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\entity\\\\Human\\.$#"
count: 1
path: src/pocketmine/Player.php
-
message: "#^Cannot instantiate interface pocketmine\\\\level\\\\format\\\\io\\\\LevelProvider\\.$#"
count: 1
path: src/pocketmine/Server.php
-
message: "#^Instanceof between pocketmine\\\\plugin\\\\PluginManager and pocketmine\\\\plugin\\\\PluginManager will always evaluate to true\\.$#"
count: 1
path: src/pocketmine/Server.php
-
message: "#^Instanceof between pocketmine\\\\scheduler\\\\AsyncPool and pocketmine\\\\scheduler\\\\AsyncPool will always evaluate to true\\.$#"
count: 1
path: src/pocketmine/Server.php
-
message: "#^Instanceof between pocketmine\\\\command\\\\CommandReader and pocketmine\\\\command\\\\CommandReader will always evaluate to true\\.$#"
count: 1
path: src/pocketmine/Server.php
-
message: "#^Instanceof between pocketmine\\\\network\\\\Network and pocketmine\\\\network\\\\Network will always evaluate to true\\.$#"
count: 1
path: src/pocketmine/Server.php
-
message: "#^pocketmine\\\\block\\\\[A-Za-z\\d]+\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\block\\\\Block\\.$#"
path: src/pocketmine/block
-
message: "#^pocketmine\\\\block\\\\Block\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\level\\\\Position\\.$#"
count: 1
path: src/pocketmine/block/Block.php
-
message: "#^Call to an undefined method pocketmine\\\\command\\\\CommandSender\\:\\:teleport\\(\\)\\.$#"
count: 1
path: src/pocketmine/command/defaults/TeleportCommand.php
# comment: "not actually possible, but high cost to fix warning"
-
message: "#^Method pocketmine\\\\event\\\\entity\\\\EntityDeathEvent\\:\\:getEntity\\(\\) should return pocketmine\\\\entity\\\\Living but returns pocketmine\\\\entity\\\\Entity\\.$#"
count: 1
path: src/pocketmine/event/entity/EntityDeathEvent.php
-
message: "#^Method pocketmine\\\\event\\\\entity\\\\EntityShootBowEvent\\:\\:getEntity\\(\\) should return pocketmine\\\\entity\\\\Living but returns pocketmine\\\\entity\\\\Entity\\.$#"
count: 1
path: src/pocketmine/event/entity/EntityShootBowEvent.php
-
message: "#^Property pocketmine\\\\event\\\\entity\\\\EntityShootBowEvent\\:\\:\\$projectile \\(pocketmine\\\\entity\\\\projectile\\\\Projectile\\) does not accept pocketmine\\\\entity\\\\Entity\\.$#"
count: 1
path: src/pocketmine/event/entity/EntityShootBowEvent.php
-
message: "#^Method pocketmine\\\\event\\\\entity\\\\ItemDespawnEvent\\:\\:getEntity\\(\\) should return pocketmine\\\\entity\\\\object\\\\ItemEntity but returns pocketmine\\\\entity\\\\Entity\\.$#"
count: 1
path: src/pocketmine/event/entity/ItemDespawnEvent.php
-
message: "#^Method pocketmine\\\\event\\\\entity\\\\ItemSpawnEvent\\:\\:getEntity\\(\\) should return pocketmine\\\\entity\\\\object\\\\ItemEntity but returns pocketmine\\\\entity\\\\Entity\\.$#"
count: 1
path: src/pocketmine/event/entity/ItemSpawnEvent.php
-
message: "#^Method pocketmine\\\\event\\\\entity\\\\ProjectileHitEvent\\:\\:getEntity\\(\\) should return pocketmine\\\\entity\\\\projectile\\\\Projectile but returns pocketmine\\\\entity\\\\Entity\\.$#"
count: 1
path: src/pocketmine/event/entity/ProjectileHitEvent.php
-
message: "#^Method pocketmine\\\\event\\\\entity\\\\ProjectileLaunchEvent\\:\\:getEntity\\(\\) should return pocketmine\\\\entity\\\\projectile\\\\Projectile but returns pocketmine\\\\entity\\\\Entity\\.$#"
count: 1
path: src/pocketmine/event/entity/ProjectileLaunchEvent.php
-
message: "#^pocketmine\\\\inventory\\\\DoubleChestInventory\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\inventory\\\\ChestInventory\\.$#"
count: 1
path: src/pocketmine/inventory/DoubleChestInventory.php
-
message: "#^pocketmine\\\\inventory\\\\EnderChestInventory\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\inventory\\\\ChestInventory\\.$#"
count: 1
path: src/pocketmine/inventory/EnderChestInventory.php
-
message: "#^pocketmine\\\\item\\\\GoldenAppleEnchanted\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\item\\\\GoldenApple\\.$#"
count: 1
path: src/pocketmine/item/GoldenAppleEnchanted.php
-
message: "#^pocketmine\\\\item\\\\WrittenBook\\:\\:__construct\\(\\) does not call parent constructor from pocketmine\\\\item\\\\WritableBook\\.$#"
count: 1
path: src/pocketmine/item/WrittenBook.php
-
message: "#^Variable property access on \\$this\\(pocketmine\\\\level\\\\generator\\\\PopulationTask\\)\\.$#"
count: 4
path: src/pocketmine/level/generator/PopulationTask.php
-
message: "#^Constructor of class pocketmine\\\\level\\\\generator\\\\hell\\\\Nether has an unused parameter \\$options\\.$#"
count: 1
path: src/pocketmine/level/generator/hell/Nether.php
-
message: "#^Constructor of class pocketmine\\\\level\\\\generator\\\\normal\\\\Normal has an unused parameter \\$options\\.$#"
count: 1
path: src/pocketmine/level/generator/normal/Normal.php
-
message: "#^Variable method call on pocketmine\\\\event\\\\Listener\\.$#"
count: 1
path: src/pocketmine/plugin/MethodEventExecutor.php
-
message: "#^Constructor of class pocketmine\\\\scheduler\\\\TaskScheduler has an unused parameter \\$logger\\.$#"
count: 1
path: src/pocketmine/scheduler/TaskScheduler.php
-
message: "#^Constant pocketmine\\\\COMPOSER_AUTOLOADER_PATH not found\\.$#"
path: src
-
message: "#^Constant pocketmine\\\\DATA not found\\.$#"
path: src
-
message: "#^Constant pocketmine\\\\GIT_COMMIT not found\\.$#"
path: src
-
message: "#^Constant pocketmine\\\\PLUGIN_PATH not found\\.$#"
path: src
-
message: "#^Constant pocketmine\\\\START_TIME not found\\.$#"
path: src
-
message: "#^Constant pocketmine\\\\VERSION not found\\.$#"
path: src
staticReflectionClassNamePatterns:
- "#^COM$#"

View File

@ -23,6 +23,10 @@ declare(strict_types=1);
namespace pocketmine;
use function define;
use function defined;
use function dirname;
// composer autoload doesn't use require_once and also pthreads can inherit things
if(defined('pocketmine\_CORE_CONSTANTS_INCLUDED')){
return;

View File

@ -23,13 +23,13 @@ declare(strict_types=1);
namespace pocketmine;
use PackageVersions\Versions;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\plugin\PluginBase;
use pocketmine\plugin\PluginLoadOrder;
use pocketmine\plugin\PluginManager;
use pocketmine\utils\Utils;
use pocketmine\utils\VersionString;
use raklib\RakLib;
use function base64_encode;
use function date;
use function error_get_last;
@ -88,7 +88,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 = 2;
private const FORMAT_VERSION = 3;
private const PLUGIN_INVOLVEMENT_NONE = "none";
private const PLUGIN_INVOLVEMENT_DIRECT = "direct";
@ -117,10 +117,11 @@ class CrashDump{
mkdir($this->server->getDataPath() . "crashdumps");
}
$this->path = $this->server->getDataPath() . "crashdumps/" . date("D_M_j-H.i.s-T_Y", $this->time) . ".log";
$this->fp = @fopen($this->path, "wb");
if(!is_resource($this->fp)){
$fp = @fopen($this->path, "wb");
if(!is_resource($fp)){
throw new \RuntimeException("Could not create Crash Dump");
}
$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));
@ -228,7 +229,10 @@ class CrashDump{
if(isset($lastExceptionError)){
$error = $lastExceptionError;
}else{
$error = (array) error_get_last();
$error = error_get_last();
if($error === null){
throw new \RuntimeException("Crash error information missing - did something use exit()?");
}
$error["trace"] = Utils::currentTrace(3); //Skipping CrashDump->baseCrash, CrashDump->construct, Server->crashDump
$errorConversion = [
E_ERROR => "E_ERROR",
@ -288,9 +292,11 @@ class CrashDump{
if($this->server->getProperty("auto-report.send-code", true) !== false and file_exists($error["fullFile"])){
$file = @file($error["fullFile"], FILE_IGNORE_NEW_LINES);
for($l = max(0, $error["line"] - 10); $l < $error["line"] + 10 and isset($file[$l]); ++$l){
$this->addLine("[" . ($l + 1) . "] " . $file[$l]);
$this->data["code"][$l + 1] = $file[$l];
if($file !== false){
for($l = max(0, $error["line"] - 10); $l < $error["line"] + 10 and isset($file[$l]); ++$l){
$this->addLine("[" . ($l + 1) . "] " . $file[$l]);
$this->data["code"][$l + 1] = $file[$l];
}
}
}
@ -339,18 +345,22 @@ class CrashDump{
$this->data["general"]["is_dev"] = \pocketmine\IS_DEVELOPMENT_BUILD;
$this->data["general"]["protocol"] = ProtocolInfo::CURRENT_PROTOCOL;
$this->data["general"]["git"] = \pocketmine\GIT_COMMIT;
$this->data["general"]["raklib"] = RakLib::VERSION;
$this->data["general"]["uname"] = php_uname("a");
$this->data["general"]["php"] = phpversion();
$this->data["general"]["zend"] = zend_version();
$this->data["general"]["php_os"] = PHP_OS;
$this->data["general"]["os"] = Utils::getOS();
$this->data["general"]["composer_libraries"] = Versions::VERSIONS;
$this->addLine($this->server->getName() . " version: " . $version->getFullVersion(true) . " [Protocol " . ProtocolInfo::CURRENT_PROTOCOL . "]");
$this->addLine("Git commit: " . \pocketmine\GIT_COMMIT);
$this->addLine("uname -a: " . php_uname("a"));
$this->addLine("PHP Version: " . phpversion());
$this->addLine("Zend version: " . zend_version());
$this->addLine("OS : " . PHP_OS . ", " . Utils::getOS());
$this->addLine("Composer libraries: ");
foreach(Versions::VERSIONS as $library => $libraryVersion){
$this->addLine("- $library $libraryVersion");
}
}
/**

View File

@ -19,6 +19,8 @@
*
*/
declare(strict_types=1);
// composer autoload doesn't use require_once and also pthreads can inherit things
if(defined('pocketmine\_GLOBAL_CONSTANTS_INCLUDED')){
return;

View File

@ -27,6 +27,8 @@ use pocketmine\event\server\LowMemoryEvent;
use pocketmine\scheduler\DumpWorkerMemoryTask;
use pocketmine\scheduler\GarbageCollectionTask;
use pocketmine\timings\Timings;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Process;
use pocketmine\utils\Utils;
use function arsort;
use function count;
@ -225,7 +227,7 @@ class MemoryManager{
if(($this->memoryLimit > 0 or $this->globalMemoryLimit > 0) and ++$this->checkTicker >= $this->checkRate){
$this->checkTicker = 0;
$memory = Utils::getMemoryUsage(true);
$memory = Process::getAdvancedMemoryUsage();
$trigger = false;
if($this->memoryLimit > 0 and $memory[0] > $this->memoryLimit){
$trigger = 0;
@ -304,6 +306,7 @@ class MemoryManager{
*/
public static function dumpMemory($startingObject, string $outputFolder, int $maxNesting, int $maxStringSize, \Logger $logger){
$hardLimit = ini_get('memory_limit');
if($hardLimit === false) throw new AssumptionFailedError("memory_limit INI directive should always exist");
ini_set('memory_limit', '-1');
gc_disable();
@ -403,8 +406,8 @@ class MemoryManager{
"properties" => []
];
if($reflection->getParentClass()){
$info["parent"] = $reflection->getParentClass()->getName();
if(($parent = $reflection->getParentClass()) !== false){
$info["parent"] = $parent->getName();
}
if(count($reflection->getInterfaceNames()) > 0){

View File

@ -146,6 +146,9 @@ use pocketmine\network\mcpe\protocol\types\CommandEnum;
use pocketmine\network\mcpe\protocol\types\CommandParameter;
use pocketmine\network\mcpe\protocol\types\ContainerIds;
use pocketmine\network\mcpe\protocol\types\DimensionIds;
use pocketmine\network\mcpe\protocol\types\GameMode;
use pocketmine\network\mcpe\protocol\types\PersonaPieceTintColor;
use pocketmine\network\mcpe\protocol\types\PersonaSkinPiece;
use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
use pocketmine\network\mcpe\protocol\types\SkinAdapterSingleton;
use pocketmine\network\mcpe\protocol\types\SkinAnimation;
@ -214,6 +217,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
public const SPECTATOR = 3;
public const VIEW = Player::SPECTATOR;
private const MOVES_PER_TICK = 2;
private const MOVE_BACKLOG_SIZE = 100 * self::MOVES_PER_TICK; //100 ticks backlog (5 seconds)
private const RESOURCE_PACK_CHUNK_SIZE = 128 * 1024; //128KB
/**
* Validates the given username.
*/
@ -259,6 +267,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** @var bool */
public $loggedIn = false;
/** @var bool */
private $seenLoginPacket = false;
/** @var bool */
private $resourcePacksDone = false;
@ -324,10 +334,13 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** @var bool[] map: raw UUID (string) => bool */
protected $hiddenPlayers = [];
/** @var float */
protected $moveRateLimit = 10 * self::MOVES_PER_TICK;
/** @var float|null */
protected $lastMovementProcess = null;
/** @var Vector3|null */
protected $newPosition;
/** @var bool */
protected $isTeleporting = false;
protected $forceMoveSync = null;
/** @var int */
protected $inAirTicks = 0;
/** @var float */
@ -517,7 +530,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
public function spawnTo(Player $player) : void{
if($this->spawned and $player->spawned and $this->isAlive() and $player->isAlive() and $player->getLevel() === $this->level and $player->canSee($this) and !$this->isSpectator()){
if($this->spawned and $player->spawned and $this->isAlive() and $player->isAlive() and $player->getLevelNonNull() === $this->level and $player->canSee($this) and !$this->isSpectator()){
parent::spawnTo($player);
}
}
@ -860,8 +873,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->lastPingMeasure = $pingMS;
}
/**
* @deprecated
*/
public function getNextPosition() : Position{
return $this->newPosition !== null ? Position::fromObject($this->newPosition, $this->level) : $this->getPosition();
return $this->getPosition();
}
public function getInAirTicks() : int{
@ -902,8 +918,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/**
* Resets the player's cooldown time for the given item back to the maximum.
*/
public function resetItemCooldown(Item $item) : void{
$ticks = $item->getCooldownTicks();
public function resetItemCooldown(Item $item, ?int $ticks = null) : void{
$ticks = $ticks ?? $item->getCooldownTicks();
if($ticks > 0){
$this->usedItemsCooldown[$item->getId()] = $this->server->getTick() + $ticks;
}
@ -1207,7 +1223,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if(!($pos instanceof Position)){
$level = $this->level;
}else{
$level = $pos->getLevel();
$level = $pos->getLevelNonNull();
}
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level);
$pk = new SetSpawnPositionPacket();
@ -1329,12 +1345,13 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* TODO: remove this when Spectator Mode gets added properly to MCPE
*/
public static function getClientFriendlyGamemode(int $gamemode) : int{
$gamemode &= 0x03;
if($gamemode === Player::SPECTATOR){
return Player::CREATIVE;
}
return $gamemode;
static $map = [
self::SURVIVAL => GameMode::SURVIVAL,
self::CREATIVE => GameMode::CREATIVE,
self::ADVENTURE => GameMode::ADVENTURE,
self::SPECTATOR => GameMode::CREATIVE
];
return $map[$gamemode & 0x3];
}
/**
@ -1362,9 +1379,16 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if($this->isSpectator()){
$this->setFlying(true);
$this->keepMovement = true;
$this->onGround = false;
//TODO: HACK! this syncs the onground flag with the client so that flying works properly
//this is a yucky hack but we don't have any other options :(
$this->sendPosition($this, null, null, MovePlayerPacket::MODE_TELEPORT);
$this->despawnFromAll();
}else{
$this->keepMovement = $this->allowMovementCheats;
$this->checkGroundState(0, 0, 0, 0, 0, 0);
if($this->isSurvival()){
$this->setFlying(false);
}
@ -1485,11 +1509,15 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz) : void{
$bb = clone $this->boundingBox;
$bb->minY = $this->y - 0.2;
$bb->maxY = $this->y + 0.2;
if($this->isSpectator()){
$this->onGround = false;
}else{
$bb = clone $this->boundingBox;
$bb->minY = $this->y - 0.2;
$bb->maxY = $this->y + 0.2;
$this->onGround = $this->isCollided = count($this->level->getCollisionBlocks($bb, true)) > 0;
$this->onGround = $this->isCollided = count($this->level->getCollisionBlocks($bb, true)) > 0;
}
}
public function canBeMovedByCurrents() : bool{
@ -1511,23 +1539,19 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
}
/**
* @return void
*/
protected function processMovement(int $tickDiff){
if(!$this->isAlive() or !$this->spawned or $this->newPosition === null or $this->isSleeping()){
protected function handleMovement(Vector3 $newPos) : void{
$this->moveRateLimit--;
if($this->moveRateLimit < 0){
return;
}
assert($this->x !== null and $this->y !== null and $this->z !== null);
assert($this->newPosition->x !== null and $this->newPosition->y !== null and $this->newPosition->z !== null);
$newPos = $this->newPosition;
$distanceSquared = $newPos->distanceSquared($this);
$oldPos = $this->asLocation();
$distanceSquared = $newPos->distanceSquared($oldPos);
$revert = false;
if(($distanceSquared / ($tickDiff ** 2)) > 100){
if($distanceSquared > 100){
//TODO: this is probably too big if we process every movement
/* !!! BEWARE YE WHO ENTER HERE !!!
*
* This is NOT an anti-cheat check. It is a safety check.
@ -1539,7 +1563,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* asking for help if you suffer the consequences of messing with this.
*/
$this->server->getLogger()->debug($this->getName() . " moved too fast, reverting movement");
$this->server->getLogger()->debug("Old position: " . $this->asVector3() . ", new position: " . $this->newPosition);
$this->server->getLogger()->debug("Old position: " . $this->asVector3() . ", new position: " . $newPos);
$revert = true;
}elseif(!$this->level->isInLoadedTerrain($newPos) or !$this->level->isChunkGenerated($newPos->getFloorX() >> 4, $newPos->getFloorZ() >> 4)){
$revert = true;
@ -1553,7 +1577,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->move($dx, $dy, $dz);
$diff = $this->distanceSquared($newPos) / $tickDiff ** 2;
$diff = $this->distanceSquared($newPos);
if($this->isSurvival() and $diff > 0.0625){
$ev = new PlayerIllegalMoveEvent($this, $newPos, new Vector3($this->lastX, $this->lastY, $this->lastZ));
@ -1564,7 +1588,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if(!$ev->isCancelled()){
$revert = true;
$this->server->getLogger()->debug($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidMove", [$this->getName()]));
$this->server->getLogger()->debug("Old position: " . $this->asVector3() . ", new position: " . $this->newPosition);
$this->server->getLogger()->debug("Old position: " . $this->asVector3() . ", new position: " . $newPos);
}
}
@ -1573,13 +1597,28 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
}
if($revert){
$this->revertMovement($oldPos);
}
}
/**
* Fires movement events and synchronizes player movement, every tick.
*/
protected function processMostRecentMovements() : void{
$now = microtime(true);
$multiplier = $this->lastMovementProcess !== null ? ($now - $this->lastMovementProcess) * 20 : 1;
$exceededRateLimit = $this->moveRateLimit < 0;
$this->moveRateLimit = min(self::MOVE_BACKLOG_SIZE, max(0, $this->moveRateLimit) + self::MOVES_PER_TICK * $multiplier);
$this->lastMovementProcess = $now;
$from = new Location($this->lastX, $this->lastY, $this->lastZ, $this->lastYaw, $this->lastPitch, $this->level);
$to = $this->getLocation();
$delta = (($this->lastX - $to->x) ** 2) + (($this->lastY - $to->y) ** 2) + (($this->lastZ - $to->z) ** 2);
$deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch);
if(!$revert and ($delta > 0.0001 or $deltaAngle > 1.0)){
if($delta > 0.0001 or $deltaAngle > 1.0){
$this->lastX = $to->x;
$this->lastY = $to->y;
$this->lastZ = $to->z;
@ -1591,42 +1630,47 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$ev->call();
if(!($revert = $ev->isCancelled())){ //Yes, this is intended
if($to->distanceSquared($ev->getTo()) > 0.01){ //If plugins modify the destination
$this->teleport($ev->getTo());
}else{
//TODO: workaround 1.14.30 bug: MoveActor(Absolute|Delta)Packet don't work on players anymore :(
$this->sendPosition($this, $this->yaw, $this->pitch, MovePlayerPacket::MODE_NORMAL, $this->hasSpawned);
$distance = sqrt((($from->x - $to->x) ** 2) + (($from->z - $to->z) ** 2));
//TODO: check swimming (adds 0.015 exhaustion in MCPE)
if($this->isSprinting()){
$this->exhaust(0.1 * $distance, PlayerExhaustEvent::CAUSE_SPRINTING);
}else{
$this->exhaust(0.01 * $distance, PlayerExhaustEvent::CAUSE_WALKING);
}
}
if($ev->isCancelled()){
$this->revertMovement($from);
return;
}
}
if($revert){
if($to->distanceSquared($ev->getTo()) > 0.01){ //If plugins modify the destination
$this->teleport($ev->getTo());
return;
}
$this->lastX = $from->x;
$this->lastY = $from->y;
$this->lastZ = $from->z;
$this->broadcastMovement();
$this->lastYaw = $from->yaw;
$this->lastPitch = $from->pitch;
$distance = sqrt((($from->x - $to->x) ** 2) + (($from->z - $to->z) ** 2));
//TODO: check swimming (adds 0.015 exhaustion in MCPE)
if($this->isSprinting()){
$this->exhaust(0.1 * $distance, PlayerExhaustEvent::CAUSE_SPRINTING);
}else{
$this->exhaust(0.01 * $distance, PlayerExhaustEvent::CAUSE_WALKING);
}
$this->setPosition($from);
$this->sendPosition($from, $from->yaw, $from->pitch, MovePlayerPacket::MODE_RESET);
}else{
if($distanceSquared != 0 and $this->nextChunkOrderRun > 20){
if($this->nextChunkOrderRun > 20){
$this->nextChunkOrderRun = 20;
}
}
$this->newPosition = null;
if($exceededRateLimit){ //client and server positions will be out of sync if this happens
$this->server->getLogger()->debug("Player " . $this->getName() . " exceeded movement rate limit, forcing to last accepted position");
$this->sendPosition($this, $this->yaw, $this->pitch, MovePlayerPacket::MODE_RESET);
}
}
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);
}
public function fall(float $fallDistance) : void{
@ -1698,7 +1742,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->timings->startTiming();
if($this->spawned){
$this->processMovement($tickDiff);
$this->processMostRecentMovements();
$this->motion->x = $this->motion->y = $this->motion->z = 0; //TODO: HACK! (Fixes player knockback being messed up)
if($this->onGround){
$this->inAirTicks = 0;
@ -1815,9 +1859,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
public function handleLogin(LoginPacket $packet) : bool{
if($this->loggedIn){
if($this->seenLoginPacket){
return false;
}
$this->seenLoginPacket = true;
if($packet->protocol !== ProtocolInfo::CURRENT_PROTOCOL){
if($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL){
@ -1857,21 +1902,58 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$animations = [];
foreach($packet->clientData["AnimatedImageData"] as $animation){
$animations[] = new SkinAnimation(new SkinImage($animation["ImageHeight"], $animation["ImageWidth"], base64_decode($animation["Image"], true)), $animation["Type"], $animation["Frames"]);
$animations[] = new SkinAnimation(
new SkinImage(
$animation["ImageHeight"],
$animation["ImageWidth"],
base64_decode($animation["Image"], true)),
$animation["Type"],
$animation["Frames"]
);
}
$personaPieces = [];
foreach($packet->clientData["PersonaPieces"] as $piece){
$personaPieces[] = new PersonaSkinPiece(
$piece["PieceId"],
$piece["PieceType"],
$piece["PackId"],
$piece["IsDefault"],
$piece["ProductId"]
);
}
$pieceTintColors = [];
foreach($packet->clientData["PieceTintColors"] as $tintColor){
$pieceTintColors[] = new PersonaPieceTintColor($tintColor["PieceType"], $tintColor["Colors"]);
}
$skinData = new SkinData(
$packet->clientData["SkinId"],
base64_decode($packet->clientData["SkinResourcePatch"] ?? "", true),
new SkinImage($packet->clientData["SkinImageHeight"], $packet->clientData["SkinImageWidth"], base64_decode($packet->clientData["SkinData"], true)),
new SkinImage(
$packet->clientData["SkinImageHeight"],
$packet->clientData["SkinImageWidth"],
base64_decode($packet->clientData["SkinData"], true)
),
$animations,
new SkinImage($packet->clientData["CapeImageHeight"], $packet->clientData["CapeImageWidth"], base64_decode($packet->clientData["CapeData"] ?? "", true)),
new SkinImage(
$packet->clientData["CapeImageHeight"],
$packet->clientData["CapeImageWidth"],
base64_decode($packet->clientData["CapeData"] ?? "", true)
),
base64_decode($packet->clientData["SkinGeometryData"] ?? "", true),
base64_decode($packet->clientData["SkinAnimationData"] ?? "", true),
$packet->clientData["PremiumSkin"] ?? false,
$packet->clientData["PersonaSkin"] ?? false,
$packet->clientData["CapeOnClassicSkin"] ?? false,
$packet->clientData["CapeId"] ?? ""
$packet->clientData["CapeId"] ?? "",
null,
$packet->clientData["ArmSize"] ?? SkinData::ARM_SIZE_WIDE,
$packet->clientData["SkinColor"] ?? "",
$personaPieces,
$pieceTintColors,
true
);
$skin = SkinAdapterSingleton::get()->fromSkinData($skinData);
@ -2048,7 +2130,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$pk = new ResourcePackDataInfoPacket();
$pk->packId = $pack->getPackId();
$pk->maxChunkSize = 1048576; //1MB
$pk->maxChunkSize = self::RESOURCE_PACK_CHUNK_SIZE;
$pk->chunkCount = (int) ceil($pack->getPackSize() / $pk->maxChunkSize);
$pk->compressedPackSize = $pack->getPackSize();
$pk->sha256 = $pack->getSha256();
@ -2214,10 +2296,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
public function handleMovePlayer(MovePlayerPacket $packet) : bool{
$newPos = $packet->position->subtract(0, $this->baseOffset, 0);
$newPos = $packet->position->round(4)->subtract(0, $this->baseOffset, 0);
if($this->isTeleporting and $newPos->distanceSquared($this) > 1){ //Tolerate up to 1 block to avoid problems with client-sided physics when spawning in blocks
$this->sendPosition($this, null, null, MovePlayerPacket::MODE_RESET);
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
}elseif((!$this->isAlive() or !$this->spawned) and $newPos->distanceSquared($this) > 0.01){
@ -2225,9 +2306,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->server->getLogger()->debug("Reverted movement of " . $this->getName() . " due to not alive or not spawned, received " . $newPos . ", locked at " . $this->asVector3());
}else{
// Once we get a movement within a reasonable distance, treat it as a teleport ACK and remove position lock
if($this->isTeleporting){
$this->isTeleporting = false;
}
$this->forceMoveSync = null;
$packet->yaw = fmod($packet->yaw, 360);
$packet->pitch = fmod($packet->pitch, 360);
@ -2237,7 +2316,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
$this->setRotation($packet->yaw, $packet->pitch);
$this->newPosition = $newPos;
$this->handleMovement($newPos);
}
return true;
@ -2245,11 +2324,15 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{
//TODO: add events so plugins can change this
$this->getLevel()->broadcastPacketToViewers($this, $packet);
$this->getLevelNonNull()->broadcastPacketToViewers($this, $packet);
return true;
}
public function handleEntityEvent(ActorEventPacket $packet) : bool{
if($packet->entityRuntimeId !== $this->id){
//TODO HACK: EATING_ITEM is sent back to the server when the server sends it for other players (1.14 bug, maybe earlier)
return $packet->event === ActorEventPacket::EATING_ITEM;
}
if(!$this->spawned or !$this->isAlive()){
return true;
}
@ -2279,11 +2362,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return false;
}
if($this->isSpectator()){
$this->sendAllInventories();
return true;
}
/** @var InventoryAction[] $actions */
$actions = [];
foreach($packet->actions as $networkInventoryAction){
@ -2377,7 +2455,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->setUsingItem(false);
if(!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13) or $this->isSpectator()){
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)){
@ -2389,7 +2467,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$item = $this->inventory->getItemInHand();
$oldItem = clone $item;
if($this->level->useItemOn($blockVector, $item, $face, $packet->trData->clickPos, $this, true)){
if(!$item->equalsExact($oldItem)){
if(!$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
$this->inventory->setItemInHand($item);
$this->inventory->sendHeldItem($this->hasSpawned);
}
@ -2421,7 +2499,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
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)){
if(!$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
$this->inventory->setItemInHand($item);
$this->inventory->sendHeldItem($this->hasSpawned);
}
@ -2483,7 +2561,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
$ev = new PlayerInteractEvent($this, $item, null, $directionVector, $face, PlayerInteractEvent::RIGHT_CLICK_AIR);
if($this->hasItemCooldown($item)){
if($this->hasItemCooldown($item) or $this->isSpectator()){
$ev->setCancelled();
}
@ -2532,8 +2610,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$cancelled = false;
$heldItem = $this->inventory->getItemInHand();
$oldItem = clone $heldItem;
if(!$this->canInteract($target, 8)){
if(!$this->canInteract($target, 8) or $this->isSpectator()){
$cancelled = true;
}elseif($target instanceof Player){
if(!$this->server->getConfigBool("pvp")){
@ -2591,7 +2670,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
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()){ //always fire the hook, even if we are survival
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);
}
@ -2702,7 +2781,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$item = $block->getPickedItem();
if($packet->addUserData){
$tile = $this->getLevel()->getTile($block);
$tile = $this->getLevelNonNull()->getTile($block);
if($tile instanceof Tile){
$nbt = $tile->getCleanedNBT();
if($nbt instanceof CompoundTag){
@ -3031,8 +3110,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$pk = new ResourcePackChunkDataPacket();
$pk->packId = $pack->getPackId();
$pk->chunkIndex = $packet->chunkIndex;
$pk->data = $pack->getPackChunk(1048576 * $packet->chunkIndex, 1048576);
$pk->progress = (1048576 * $packet->chunkIndex);
$pk->data = $pack->getPackChunk(self::RESOURCE_PACK_CHUNK_SIZE * $packet->chunkIndex, self::RESOURCE_PACK_CHUNK_SIZE);
$pk->progress = (self::RESOURCE_PACK_CHUNK_SIZE * $packet->chunkIndex);
$this->dataPacket($pk);
return true;
}
@ -3053,14 +3132,26 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$modifiedPages[] = $packet->pageNumber;
break;
case BookEditPacket::TYPE_ADD_PAGE:
if(!$newBook->pageExists($packet->pageNumber)){
//this may only come before a page which already exists
//TODO: the client can send insert-before actions on trailing client-side pages which cause odd behaviour on the server
return false;
}
$newBook->insertPage($packet->pageNumber, $packet->text);
$modifiedPages[] = $packet->pageNumber;
break;
case BookEditPacket::TYPE_DELETE_PAGE:
if(!$newBook->pageExists($packet->pageNumber)){
return false;
}
$newBook->deletePage($packet->pageNumber);
$modifiedPages[] = $packet->pageNumber;
break;
case BookEditPacket::TYPE_SWAP_PAGES:
if(!$newBook->pageExists($packet->pageNumber) or !$newBook->pageExists($packet->secondaryPageNumber)){
//the client will create pages on its own without telling us until it tries to switch them
$newBook->addPage(max($packet->pageNumber, $packet->secondaryPageNumber));
}
$newBook->swapPages($packet->pageNumber, $packet->secondaryPageNumber);
$modifiedPages = [$packet->pageNumber, $packet->secondaryPageNumber];
break;
@ -3222,7 +3313,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
/**
* Adds a title text to the user's screen, with an optional subtitle.
* @deprecated
* @see Player::sendTitle()
*
* @param int $fadeIn Duration in ticks for fade-in. If -1 is given, client-sided defaults will be used.
* @param int $stay Duration in ticks to stay on screen for
@ -3231,28 +3323,55 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* @return void
*/
public function addTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1){
$this->sendTitle($title, $subtitle, $fadeIn, $stay, $fadeOut);
}
/**
* Adds a title text to the user's screen, with an optional subtitle.
*
* @param int $fadeIn Duration in ticks for fade-in. If -1 is given, client-sided defaults will be used.
* @param int $stay Duration in ticks to stay on screen for
* @param int $fadeOut Duration in ticks for fade-out.
*/
public function sendTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1) : void{
$this->setTitleDuration($fadeIn, $stay, $fadeOut);
if($subtitle !== ""){
$this->addSubTitle($subtitle);
$this->sendSubTitle($subtitle);
}
$this->sendTitleText($title, SetTitlePacket::TYPE_SET_TITLE);
}
/**
* Sets the subtitle message, without sending a title.
* @deprecated
* @see Player::sendSubTitle()
*
* @return void
*/
public function addSubTitle(string $subtitle){
$this->sendSubTitle($subtitle);
}
/**
* Sets the subtitle message, without sending a title.
*/
public function sendSubTitle(string $subtitle) : void{
$this->sendTitleText($subtitle, SetTitlePacket::TYPE_SET_SUBTITLE);
}
/**
* Adds small text to the user's screen.
* @deprecated
* @see Player::sendActionBarMessage()
*
* @return void
*/
public function addActionBarMessage(string $message){
$this->sendActionBarMessage($message);
}
/**
* Adds small text to the user's screen.
*/
public function sendActionBarMessage(string $message) : void{
$this->sendTitleText($message, SetTitlePacket::TYPE_SET_ACTIONBAR_MESSAGE);
}
@ -3551,7 +3670,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
if($this->hasValidSpawnPosition()){
$this->namedtag->setString("SpawnLevel", $this->spawnPosition->getLevel()->getFolderName());
$this->namedtag->setString("SpawnLevel", $this->spawnPosition->getLevelNonNull()->getFolderName());
$this->namedtag->setInt("SpawnX", $this->spawnPosition->getFloorX());
$this->namedtag->setInt("SpawnY", $this->spawnPosition->getFloorY());
$this->namedtag->setInt("SpawnZ", $this->spawnPosition->getFloorZ());
@ -3595,7 +3714,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
//main inventory and drops the rest on the ground.
$this->doCloseInventory();
$ev = new PlayerDeathEvent($this, $this->getDrops());
$ev = new PlayerDeathEvent($this, $this->getDrops(), null, $this->getXpDropAmount());
$ev->call();
if(!$ev->getKeepInventory()){
@ -3612,8 +3731,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
}
//TODO: allow this number to be manipulated during PlayerDeathEvent
$this->level->dropExperience($this, $this->getXpDropAmount());
$this->level->dropExperience($this, $ev->getXpDropAmount());
$this->setXpAndProgress(0, 0);
if($ev->getDeathMessage() != ""){
@ -3635,7 +3753,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$ev = new PlayerRespawnEvent($this, $this->getSpawn());
$ev->call();
$realSpawn = Position::fromObject($ev->getRespawnPosition()->add(0.5, 0, 0.5), $ev->getRespawnPosition()->getLevel());
$realSpawn = Position::fromObject($ev->getRespawnPosition()->add(0.5, 0, 0.5), $ev->getRespawnPosition()->getLevelNonNull());
$this->teleport($realSpawn);
$this->setSprinting(false);
@ -3716,14 +3834,17 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$pk->headYaw = $yaw;
$pk->yaw = $yaw;
$pk->mode = $mode;
$pk->onGround = $this->onGround;
if($targets !== null){
if(in_array($this, $targets, true)){
$this->forceMoveSync = $pos->asVector3();
}
$this->server->broadcastPacket($targets, $pk);
}else{
$this->forceMoveSync = $pos->asVector3();
$this->dataPacket($pk);
}
$this->newPosition = null;
}
/**
@ -3741,11 +3862,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->resetFallDistance();
$this->nextChunkOrderRun = 0;
$this->newPosition = null;
$this->stopSleep();
$this->isTeleporting = true;
//TODO: workaround for player last pos not getting updated
//Entity::updateMovement() normally handles this, but it's overridden with an empty function in Player
$this->resetLastMovements();

View File

@ -25,6 +25,7 @@ namespace pocketmine {
use pocketmine\utils\Git;
use pocketmine\utils\MainLogger;
use pocketmine\utils\Process;
use pocketmine\utils\ServerKiller;
use pocketmine\utils\Terminal;
use pocketmine\utils\Timezone;
@ -34,7 +35,7 @@ namespace pocketmine {
require_once __DIR__ . '/VersionInfo.php';
const MIN_PHP_VERSION = "7.2.0";
const MIN_PHP_VERSION = "7.3.0";
/**
* @param string $message
@ -177,15 +178,14 @@ namespace pocketmine {
}else{
$bootstrap = dirname(__FILE__, 3) . '/vendor/autoload.php';
}
define('pocketmine\COMPOSER_AUTOLOADER_PATH', $bootstrap);
if(\pocketmine\COMPOSER_AUTOLOADER_PATH !== false and is_file(\pocketmine\COMPOSER_AUTOLOADER_PATH)){
require_once(\pocketmine\COMPOSER_AUTOLOADER_PATH);
}else{
if($bootstrap === false or !is_file($bootstrap)){
critical_error("Composer autoloader not found at " . $bootstrap);
critical_error("Please install/update Composer dependencies or use provided builds.");
exit(1);
}
define('pocketmine\COMPOSER_AUTOLOADER_PATH', $bootstrap);
require_once(\pocketmine\COMPOSER_AUTOLOADER_PATH);
set_error_handler([Utils::class, 'errorExceptionHandler']);
@ -280,7 +280,7 @@ namespace pocketmine {
if(ThreadManager::getInstance()->stopAll() > 0){
$logger->debug("Some threads could not be stopped, performing a force-kill");
Utils::kill(getmypid());
Process::kill(getmypid());
}
}while(false);

View File

@ -102,6 +102,7 @@ use pocketmine\updater\AutoUpdater;
use pocketmine\utils\Config;
use pocketmine\utils\Internet;
use pocketmine\utils\MainLogger;
use pocketmine\utils\Process;
use pocketmine\utils\Terminal;
use pocketmine\utils\TextFormat;
use pocketmine\utils\Utils;
@ -1396,7 +1397,7 @@ class Server{
Network::$BATCH_THRESHOLD = -1;
}
$this->networkCompressionLevel = $this->getProperty("network.compression-level", 7);
$this->networkCompressionLevel = (int) $this->getProperty("network.compression-level", 7);
if($this->networkCompressionLevel < 1 or $this->networkCompressionLevel > 9){
$this->logger->warning("Invalid network compression level $this->networkCompressionLevel set, setting to default 7");
$this->networkCompressionLevel = 7;
@ -1665,7 +1666,7 @@ class Server{
}
foreach($recipients as $recipient){
$recipient->addTitle($title, $subtitle, $fadeIn, $stay, $fadeOut);
$recipient->sendTitle($title, $subtitle, $fadeIn, $stay, $fadeOut);
}
return count($recipients);
@ -1935,7 +1936,7 @@ class Server{
}catch(\Throwable $e){
$this->logger->logException($e);
$this->logger->emergency("Crashed while crashing, killing process");
@Utils::kill(getmypid());
@Process::kill(getmypid());
}
}
@ -2091,17 +2092,24 @@ class Server{
if($report){
$url = ((bool) $this->getProperty("auto-report.use-https", true) ? "https" : "http") . "://" . $this->getProperty("auto-report.host", "crash.pmmp.io") . "/submit/api";
$postUrlError = "Unknown error";
$reply = Internet::postURL($url, [
"report" => "yes",
"name" => $this->getName() . " " . $this->getPocketMineVersion(),
"email" => "crash@pocketmine.net",
"reportPaste" => base64_encode($dump->getEncodedData())
]);
], 10, [], $postUrlError);
if($reply !== false and ($data = json_decode($reply)) !== null and isset($data->crashId) and isset($data->crashUrl)){
$reportId = $data->crashId;
$reportUrl = $data->crashUrl;
$this->logger->emergency($this->getLanguage()->translateString("pocketmine.crash.archive", [$reportUrl, $reportId]));
if($reply !== false and ($data = json_decode($reply)) !== null){
if(isset($data->crashId) and isset($data->crashUrl)){
$reportId = $data->crashId;
$reportUrl = $data->crashUrl;
$this->logger->emergency($this->getLanguage()->translateString("pocketmine.crash.archive", [$reportUrl, $reportId]));
}elseif(isset($data->error)){
$this->logger->emergency("Automatic crash report submission failed: $data->error");
}
}else{
$this->logger->emergency("Failed to communicate with crash archive: $postUrlError");
}
}
}
@ -2121,7 +2129,7 @@ class Server{
echo "--- Waiting $spacing seconds to throttle automatic restart (you can kill the process safely now) ---" . PHP_EOL;
sleep($spacing);
}
@Utils::kill(getmypid());
@Process::kill(getmypid());
exit(1);
}
@ -2322,10 +2330,10 @@ class Server{
private function titleTick() : void{
Timings::$titleTickTimer->startTiming();
$d = Utils::getRealMemoryUsage();
$d = Process::getRealMemoryUsage();
$u = Utils::getMemoryUsage(true);
$usage = sprintf("%g/%g/%g/%g MB @ %d threads", round(($u[0] / 1024) / 1024, 2), round(($d[0] / 1024) / 1024, 2), round(($u[1] / 1024) / 1024, 2), round(($u[2] / 1024) / 1024, 2), Utils::getThreadCount());
$u = Process::getAdvancedMemoryUsage();
$usage = sprintf("%g/%g/%g/%g MB @ %d threads", round(($u[0] / 1024) / 1024, 2), round(($d[0] / 1024) / 1024, 2), round(($u[1] / 1024) / 1024, 2), round(($u[2] / 1024) / 1024, 2), Process::getThreadCount());
echo "\x1b]0;" . $this->getName() . " " .
$this->getPocketMineVersion() .

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine;
use const PTHREADS_INHERIT_ALL;
/**
* This class must be extended by all custom threading classes
*/
@ -78,7 +80,7 @@ abstract class Thread extends \Thread{
*
* @return bool
*/
public function start(?int $options = \PTHREADS_INHERIT_ALL){
public function start(?int $options = PTHREADS_INHERIT_ALL){
ThreadManager::getInstance()->add($this);
if($this->getClassLoader() === null){

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine;
use function defined;
// composer autoload doesn't use require_once and also pthreads can inherit things
// TODO: drop this file and use a final class with constants
if(defined('pocketmine\_VERSION_INFO_INCLUDED')){
@ -31,6 +33,6 @@ if(defined('pocketmine\_VERSION_INFO_INCLUDED')){
const _VERSION_INFO_INCLUDED = true;
const NAME = "PocketMine-MP";
const BASE_VERSION = "3.11.6";
const BASE_VERSION = "3.13.0";
const IS_DEVELOPMENT_BUILD = false;
const BUILD_NUMBER = 0;

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine;
use const PTHREADS_INHERIT_ALL;
/**
* This class must be extended by all custom threading classes
*/
@ -78,7 +80,7 @@ abstract class Worker extends \Worker{
*
* @return bool
*/
public function start(?int $options = \PTHREADS_INHERIT_ALL){
public function start(?int $options = PTHREADS_INHERIT_ALL){
ThreadManager::getInstance()->add($this);
if($this->getClassLoader() === null){

View File

@ -110,6 +110,6 @@ class Anvil extends Fallable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$direction = ($player !== null ? $player->getDirection() : 0) & 0x03;
$this->meta = $this->getVariant() | $direction;
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
return $this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
}
}

View File

@ -91,7 +91,7 @@ abstract class BaseRail extends Flowable{
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if(!$blockReplace->getSide(Vector3::SIDE_DOWN)->isTransparent() and $this->getLevel()->setBlock($blockReplace, $this, true, true)){
if(!$blockReplace->getSide(Vector3::SIDE_DOWN)->isTransparent() and $this->getLevelNonNull()->setBlock($blockReplace, $this, true, true)){
$this->tryReconnect();
return true;
}
@ -279,7 +279,7 @@ abstract class BaseRail extends Flowable{
isset(self::ASCENDING_SIDES[$this->meta & 0x07]) and
$this->getSide(self::ASCENDING_SIDES[$this->meta & 0x07])->isTransparent()
)){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}

View File

@ -83,7 +83,7 @@ class Bed extends Transparent{
$this->meta &= ~self::BITFLAG_OCCUPIED;
}
$this->getLevel()->setBlock($this, $this, false, false);
$this->getLevelNonNull()->setBlock($this, $this, false, false);
if(($other = $this->getOtherHalf()) !== null and $other->isOccupied() !== $occupied){
$other->setOccupied($occupied);
@ -137,7 +137,7 @@ class Bed extends Transparent{
return true;
}
$time = $this->getLevel()->getTime() % Level::TIME_FULL;
$time = $this->getLevelNonNull()->getTimeOfDay();
$isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE);
@ -168,11 +168,11 @@ class Bed extends Transparent{
$meta = (($player instanceof Player ? $player->getDirection() : 0) - 1) & 0x03;
$next = $this->getSide(self::getOtherHalfSide($meta));
if($next->canBeReplaced() and !$next->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->id, $meta), true, true);
$this->getLevel()->setBlock($next, BlockFactory::get($this->id, $meta | self::BITFLAG_HEAD), true, true);
$this->getLevelNonNull()->setBlock($blockReplace, BlockFactory::get($this->id, $meta), true, true);
$this->getLevelNonNull()->setBlock($next, BlockFactory::get($this->id, $meta | self::BITFLAG_HEAD), true, true);
Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($this, $face, $item, $player));
Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($next, $face, $item, $player));
Tile::createTile(Tile::BED, $this->getLevelNonNull(), TileBed::createNBT($this, $face, $item, $player));
Tile::createTile(Tile::BED, $this->getLevelNonNull(), TileBed::createNBT($next, $face, $item, $player));
return true;
}
@ -194,7 +194,7 @@ class Bed extends Transparent{
}
private function getItem() : Item{
$tile = $this->getLevel()->getTile($this);
$tile = $this->getLevelNonNull()->getTile($this);
if($tile instanceof TileBed){
return ItemFactory::get($this->getItemId(), $tile->getColor());
}

View File

@ -154,7 +154,7 @@ class Block extends Position implements BlockIds, Metadatable{
* Places the Block, using block space and block target, and side. Returns if the block has been placed.
*/
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
return $this->getLevel()->setBlock($this, $this, true, true);
return $this->getLevelNonNull()->setBlock($this, $this, true, true);
}
/**
@ -204,7 +204,7 @@ class Block extends Position implements BlockIds, Metadatable{
* Do the actions needed so the block is broken with the Item
*/
public function onBreak(Item $item, Player $player = null) : bool{
return $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
return $this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
}
/**
@ -479,7 +479,7 @@ class Block extends Position implements BlockIds, Metadatable{
*/
public function getSide(int $side, int $step = 1){
if($this->isValid()){
return $this->getLevel()->getBlock(Vector3::getSide($side, $step));
return $this->getLevelNonNull()->getBlock(Vector3::getSide($side, $step));
}
return BlockFactory::get(Block::AIR, 0, Position::fromObject(Vector3::getSide($side, $step)));

View File

@ -55,7 +55,7 @@ class BoneBlock extends Solid{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face);
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
return $this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
}
public function getVariantBitmask() : int{

View File

@ -68,18 +68,18 @@ class BurningFurnace extends Solid{
3 => 3
];
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this, $face, $item, $player));
Tile::createTile(Tile::FURNACE, $this->getLevelNonNull(), TileFurnace::createNBT($this, $face, $item, $player));
return true;
}
public function onActivate(Item $item, Player $player = null) : bool{
if($player instanceof Player){
$furnace = $this->getLevel()->getTile($this);
$furnace = $this->getLevelNonNull()->getTile($this);
if(!($furnace instanceof TileFurnace)){
$furnace = Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this));
$furnace = Tile::createTile(Tile::FURNACE, $this->getLevelNonNull(), TileFurnace::createNBT($this));
if(!($furnace instanceof TileFurnace)){
return true;
}

View File

@ -72,12 +72,12 @@ class Cactus extends Transparent{
public function onNearbyBlockChange() : void{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() !== self::SAND and $down->getId() !== self::CACTUS){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}else{
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b->isSolid()){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
break;
}
}
@ -92,23 +92,23 @@ class Cactus extends Transparent{
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::CACTUS){
if($this->meta === 0x0f){
for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
$b = $this->getLevelNonNull()->getBlockAt($this->x, $this->y + $y, $this->z);
if($b->getId() === self::AIR){
$ev = new BlockGrowEvent($b, BlockFactory::get(Block::CACTUS));
$ev->call();
if($ev->isCancelled()){
break;
}
$this->getLevel()->setBlock($b, $ev->getNewState(), true);
$this->getLevelNonNull()->setBlock($b, $ev->getNewState(), true);
}else{
break;
}
}
$this->meta = 0;
$this->getLevel()->setBlock($this, $this);
$this->getLevelNonNull()->setBlock($this, $this);
}else{
++$this->meta;
$this->getLevel()->setBlock($this, $this);
$this->getLevelNonNull()->setBlock($this, $this);
}
}
}
@ -121,7 +121,7 @@ class Cactus extends Transparent{
$block2 = $this->getSide(Vector3::SIDE_WEST);
$block3 = $this->getSide(Vector3::SIDE_EAST);
if(!$block0->isSolid() and !$block1->isSolid() and !$block2->isSolid() and !$block3->isSolid()){
$this->getLevel()->setBlock($this, $this, true);
$this->getLevelNonNull()->setBlock($this, $this, true);
return true;
}

View File

@ -66,7 +66,7 @@ class Cake extends Transparent implements FoodSource{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() !== self::AIR){
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}
@ -76,7 +76,7 @@ class Cake extends Transparent implements FoodSource{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::AIR), true);
}
}

View File

@ -64,7 +64,7 @@ class Carpet extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() !== self::AIR){
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}
@ -74,7 +74,7 @@ class Carpet extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}

View File

@ -81,7 +81,7 @@ class Chest extends Transparent{
}
$c = $this->getSide($side);
if($c->getId() === $this->id and $c->getDamage() === $this->meta){
$tile = $this->getLevel()->getTile($c);
$tile = $this->getLevelNonNull()->getTile($c);
if($tile instanceof TileChest and !$tile->isPaired()){
$chest = $tile;
break;
@ -89,8 +89,8 @@ class Chest extends Transparent{
}
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$tile = Tile::createTile(Tile::CHEST, $this->getLevel(), TileChest::createNBT($this, $face, $item, $player));
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
$tile = Tile::createTile(Tile::CHEST, $this->getLevelNonNull(), TileChest::createNBT($this, $face, $item, $player));
if($chest instanceof TileChest and $tile instanceof TileChest){
$chest->pairWith($tile);
@ -103,12 +103,12 @@ class Chest extends Transparent{
public function onActivate(Item $item, Player $player = null) : bool{
if($player instanceof Player){
$t = $this->getLevel()->getTile($this);
$t = $this->getLevelNonNull()->getTile($this);
$chest = null;
if($t instanceof TileChest){
$chest = $t;
}else{
$chest = Tile::createTile(Tile::CHEST, $this->getLevel(), TileChest::createNBT($this));
$chest = Tile::createTile(Tile::CHEST, $this->getLevelNonNull(), TileChest::createNBT($this));
if(!($chest instanceof TileChest)){
return true;
}

View File

@ -23,6 +23,11 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\ItemIds;
use function mt_rand;
class CocoaBlock extends Transparent{
protected $id = self::COCOA_BLOCK;
@ -48,4 +53,14 @@ class CocoaBlock extends Transparent{
public function isAffectedBySilkTouch() : bool{
return false;
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(ItemIds::DYE, 3, ($this->meta >> 2) === 2 ? mt_rand(2, 3) : 1)
];
}
public function getPickedItem() : Item{
return ItemFactory::get(ItemIds::DYE, 3);
}
}

View File

@ -33,7 +33,7 @@ abstract class Crops extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($blockReplace->getSide(Vector3::SIDE_DOWN)->getId() === Block::FARMLAND){
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}
@ -52,10 +52,10 @@ abstract class Crops extends Flowable{
$ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
$this->getLevelNonNull()->setBlock($this, $ev->getNewState(), true, true);
}
$item->count--;
$item->pop();
return true;
}
@ -65,7 +65,7 @@ abstract class Crops extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::FARMLAND){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}
@ -81,7 +81,7 @@ abstract class Crops extends Flowable{
$ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
$this->getLevelNonNull()->setBlock($this, $ev->getNewState(), true, true);
}
}
}

View File

@ -42,7 +42,7 @@ class Dandelion extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}
@ -52,7 +52,7 @@ class Dandelion extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}

View File

@ -51,7 +51,7 @@ class DeadBush extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}

View File

@ -54,9 +54,9 @@ class Dirt extends Solid{
if($item instanceof Hoe){
$item->applyDamage(1);
if($this->meta === 1){
$this->getLevel()->setBlock($this, BlockFactory::get(Block::DIRT), true);
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::DIRT), true);
}else{
$this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND), true);
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::FARMLAND), true);
}
return true;

View File

@ -201,9 +201,9 @@ abstract class Door extends Transparent{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false);
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::AIR), false);
if($this->getSide(Vector3::SIDE_UP) instanceof Door){
$this->getLevel()->setBlock($this->getSide(Vector3::SIDE_UP), BlockFactory::get(Block::AIR), false);
$this->getLevelNonNull()->setBlock($this->getSide(Vector3::SIDE_UP), BlockFactory::get(Block::AIR), false);
}
}
}
@ -230,8 +230,8 @@ abstract class Door extends Transparent{
}
$this->setDamage($player->getDirection() & 0x03);
$this->getLevel()->setBlock($blockReplace, $this, true, true); //Bottom
$this->getLevel()->setBlock($blockUp, BlockFactory::get($this->getId(), $metaUp), true); //Top
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true); //Bottom
$this->getLevelNonNull()->setBlock($blockUp, BlockFactory::get($this->getId(), $metaUp), true); //Top
return true;
}

View File

@ -57,8 +57,8 @@ class DoublePlant extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$id = $blockReplace->getSide(Vector3::SIDE_DOWN)->getId();
if(($id === Block::GRASS or $id === Block::DIRT) and $blockReplace->getSide(Vector3::SIDE_UP)->canBeReplaced()){
$this->getLevel()->setBlock($blockReplace, $this, false, false);
$this->getLevel()->setBlock($blockReplace->getSide(Vector3::SIDE_UP), BlockFactory::get($this->id, $this->meta | self::BITFLAG_TOP), false, false);
$this->getLevelNonNull()->setBlock($blockReplace, $this, false, false);
$this->getLevelNonNull()->setBlock($blockReplace->getSide(Vector3::SIDE_UP), BlockFactory::get($this->id, $this->meta | self::BITFLAG_TOP), false, false);
return true;
}
@ -85,7 +85,7 @@ class DoublePlant extends Flowable{
public function onNearbyBlockChange() : void{
if(!$this->isValidHalfPlant() or (($this->meta & self::BITFLAG_TOP) === 0 and $this->getSide(Vector3::SIDE_DOWN)->isTransparent())){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}
@ -124,4 +124,12 @@ class DoublePlant extends Flowable{
return parent::getAffectedBlocks();
}
public function getFlameEncouragement() : int{
return 60;
}
public function getFlammability() : int{
return 100;
}
}

View File

@ -40,9 +40,9 @@ class EnchantingTable extends Transparent{
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel(), TileEnchantTable::createNBT($this, $face, $item, $player));
Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevelNonNull(), TileEnchantTable::createNBT($this, $face, $item, $player));
return true;
}

View File

@ -69,8 +69,8 @@ class EnderChest extends Chest{
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
$this->getLevel()->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this, $face, $item, $player));
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::ENDER_CHEST, $this->getLevelNonNull(), TileEnderChest::createNBT($this, $face, $item, $player));
return true;
}
@ -78,12 +78,12 @@ class EnderChest extends Chest{
public function onActivate(Item $item, Player $player = null) : bool{
if($player instanceof Player){
$t = $this->getLevel()->getTile($this);
$t = $this->getLevelNonNull()->getTile($this);
$enderChest = null;
if($t instanceof TileEnderChest){
$enderChest = $t;
}else{
$enderChest = Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this));
$enderChest = Tile::createTile(Tile::ENDER_CHEST, $this->getLevelNonNull(), TileEnderChest::createNBT($this));
if(!($enderChest instanceof TileEnderChest)){
return true;
}

View File

@ -37,7 +37,7 @@ abstract class Fallable extends Solid{
$nbt->setInt("TileID", $this->getId());
$nbt->setByte("Data", $this->getDamage());
$fall = Entity::createEntity("FallingSand", $this->getLevel(), $nbt);
$fall = Entity::createEntity("FallingSand", $this->getLevelNonNull(), $nbt);
if($fall !== null){
$fall->spawnToAll();

View File

@ -69,7 +69,7 @@ class FenceGate extends Transparent{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta = ($player instanceof Player ? ($player->getDirection() - 1) & 0x03 : 0);
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}
@ -85,7 +85,7 @@ class FenceGate extends Transparent{
$this->meta |= (($player->getDirection() - 1) & 0x02);
}
$this->getLevel()->setBlock($this, $this, true);
$this->getLevelNonNull()->setBlock($this, $this, true);
$this->level->addSound(new DoorSound($this));
return true;
}

View File

@ -82,7 +82,7 @@ class Fire extends Flowable{
public function onNearbyBlockChange() : void{
if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::AIR), true);
}else{
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
}

View File

@ -62,7 +62,7 @@ class Flower extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){
$this->getLevel()->setBlock($blockReplace, $this, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true);
return true;
}
@ -72,7 +72,7 @@ class Flower extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}

View File

@ -62,19 +62,19 @@ class FlowerPot extends Flowable{
return false;
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::FLOWER_POT, $this->getLevel(), TileFlowerPot::createNBT($this, $face, $item, $player));
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::FLOWER_POT, $this->getLevelNonNull(), TileFlowerPot::createNBT($this, $face, $item, $player));
return true;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}
public function onActivate(Item $item, Player $player = null) : bool{
$pot = $this->getLevel()->getTile($this);
$pot = $this->getLevelNonNull()->getTile($this);
if(!($pot instanceof TileFlowerPot)){
return false;
}
@ -83,7 +83,7 @@ class FlowerPot extends Flowable{
}
$this->setDamage(self::STATE_FULL); //specific damage value is unnecessary, it just needs to be non-zero to show an item.
$this->getLevel()->setBlock($this, $this, true, false);
$this->getLevelNonNull()->setBlock($this, $this, true, false);
$pot->setItem($item->pop());
return true;
@ -96,7 +96,7 @@ class FlowerPot extends Flowable{
public function getDropsForCompatibleTool(Item $item) : array{
$items = parent::getDropsForCompatibleTool($item);
$tile = $this->getLevel()->getTile($this);
$tile = $this->getLevelNonNull()->getTile($this);
if($tile instanceof TileFlowerPot){
$item = $tile->getItem();
if($item->getId() !== Item::AIR){

View File

@ -53,7 +53,7 @@ class GlazedTerracotta extends Solid{
$this->meta = $faces[(~($player->getDirection() - 1)) & 0x03];
}
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
return $this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
}
public function getVariantBitmask() : int{

View File

@ -53,6 +53,6 @@ class GlowingRedstoneOre extends RedstoneOre{
}
public function onRandomTick() : void{
$this->getLevel()->setBlock($this, BlockFactory::get(Block::REDSTONE_ORE, $this->meta), false, false);
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::REDSTONE_ORE, $this->meta), false, false);
}
}

View File

@ -99,18 +99,18 @@ class Grass extends Solid{
public function onActivate(Item $item, Player $player = null) : bool{
if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){
$item->count--;
TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);
$item->pop();
TallGrassObject::growGrass($this->getLevelNonNull(), $this, new Random(mt_rand()), 8, 2);
return true;
}elseif($item instanceof Hoe){
$item->applyDamage(1);
$this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND));
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::FARMLAND));
return true;
}elseif($item instanceof Shovel and $this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR){
$item->applyDamage(1);
$this->getLevel()->setBlock($this, BlockFactory::get(Block::GRASS_PATH));
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::GRASS_PATH));
return true;
}

View File

@ -46,7 +46,7 @@ class HayBale extends Solid{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face);
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}

View File

@ -57,7 +57,7 @@ class Ice extends Transparent{
public function onBreak(Item $item, Player $player = null) : bool{
if(($player === null or $player->isSurvival()) and !$item->hasEnchantment(Enchantment::SILK_TOUCH)){
return $this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true);
return $this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::WATER), true);
}
return parent::onBreak($item, $player);
}

View File

@ -46,7 +46,7 @@ class ItemFrame extends Flowable{
public function onActivate(Item $item, Player $player = null) : bool{
$tile = $this->level->getTile($this);
if(!($tile instanceof TileItemFrame)){
$tile = Tile::createTile(Tile::ITEM_FRAME, $this->getLevel(), TileItemFrame::createNBT($this));
$tile = Tile::createTile(Tile::ITEM_FRAME, $this->getLevelNonNull(), TileItemFrame::createNBT($this));
if(!($tile instanceof TileItemFrame)){
return true;
}
@ -88,7 +88,7 @@ class ItemFrame extends Flowable{
$this->meta = $faces[$face];
$this->level->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::ITEM_FRAME, $this->getLevel(), TileItemFrame::createNBT($this, $face, $item, $player));
Tile::createTile(Tile::ITEM_FRAME, $this->getLevelNonNull(), TileItemFrame::createNBT($this, $face, $item, $player));
return true;

View File

@ -100,7 +100,7 @@ class Ladder extends Transparent{
];
if(isset($faces[$face])){
$this->meta = $faces[$face];
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}

View File

@ -115,8 +115,8 @@ class Lava extends Liquid{
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$ret = $this->getLevel()->setBlock($this, $this, true, false);
$this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate());
$ret = $this->getLevelNonNull()->setBlock($this, $this, true, false);
$this->getLevelNonNull()->scheduleDelayedBlockUpdate($this, $this->tickRate());
return $ret;
}

View File

@ -139,7 +139,7 @@ class Leaves extends Transparent{
public function onNearbyBlockChange() : void{
if(($this->meta & 0b00001100) === 0){
$this->meta |= 0x08;
$this->getLevel()->setBlock($this, $this, true, false);
$this->getLevelNonNull()->setBlock($this, $this, true, false);
}
}
@ -155,16 +155,16 @@ class Leaves extends Transparent{
$ev = new LeavesDecayEvent($this);
$ev->call();
if($ev->isCancelled() or $this->findLog($this, $visited, 0)){
$this->getLevel()->setBlock($this, $this, false, false);
$this->getLevelNonNull()->setBlock($this, $this, false, false);
}else{
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta |= 0x04;
return $this->getLevel()->setBlock($this, $this, true);
return $this->getLevelNonNull()->setBlock($this, $this, true);
}
public function getVariantBitmask() : int{

View File

@ -49,7 +49,7 @@ class MelonStem extends Crops{
$ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true);
$this->getLevelNonNull()->setBlock($this, $ev->getNewState(), true);
}
}else{
for($side = 2; $side <= 5; ++$side){
@ -64,7 +64,7 @@ class MelonStem extends Crops{
$ev = new BlockGrowEvent($side, BlockFactory::get(Block::MELON_BLOCK));
$ev->call();
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($side, $ev->getNewState(), true);
$this->getLevelNonNull()->setBlock($side, $ev->getNewState(), true);
}
}
}

View File

@ -64,13 +64,13 @@ class Mycelium extends Solid{
$x = mt_rand($this->x - 1, $this->x + 1);
$y = mt_rand($this->y - 2, $this->y + 2);
$z = mt_rand($this->z - 1, $this->z + 1);
$block = $this->getLevel()->getBlockAt($x, $y, $z);
$block = $this->getLevelNonNull()->getBlockAt($x, $y, $z);
if($block->getId() === Block::DIRT){
if($block->getSide(Vector3::SIDE_UP) instanceof Transparent){
$ev = new BlockSpreadEvent($block, $this, BlockFactory::get(Block::MYCELIUM));
$ev->call();
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($block, $ev->getNewState());
$this->getLevelNonNull()->setBlock($block, $ev->getNewState());
}
}
}

View File

@ -46,7 +46,7 @@ class NetherWartPlant extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === Block::SOUL_SAND){
$this->getLevel()->setBlock($blockReplace, $this, false, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, false, true);
return true;
}
@ -56,7 +56,7 @@ class NetherWartPlant extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::SOUL_SAND){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}
@ -71,7 +71,7 @@ class NetherWartPlant extends Flowable{
$ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), false, true);
$this->getLevelNonNull()->setBlock($this, $ev->getNewState(), false, true);
}
}
}

View File

@ -51,7 +51,7 @@ class Pumpkin extends Solid{
if($player instanceof Player){
$this->meta = ((int) $player->getDirection() + 1) % 4;
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}

View File

@ -49,7 +49,7 @@ class PumpkinStem extends Crops{
$ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true);
$this->getLevelNonNull()->setBlock($this, $ev->getNewState(), true);
}
}else{
for($side = 2; $side <= 5; ++$side){
@ -64,7 +64,7 @@ class PumpkinStem extends Crops{
$ev = new BlockGrowEvent($side, BlockFactory::get(Block::PUMPKIN));
$ev->call();
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($side, $ev->getNewState(), true);
$this->getLevelNonNull()->setBlock($side, $ev->getNewState(), true);
}
}
}

View File

@ -58,7 +58,7 @@ class Quartz extends Solid{
if($this->getVariant() !== self::NORMAL){
$this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face);
}
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
return $this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
}
public function getToolType() : int{

View File

@ -45,14 +45,14 @@ class RedMushroom extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if(!$down->isTransparent()){
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}

View File

@ -47,16 +47,16 @@ class RedstoneOre extends Solid{
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
return $this->getLevel()->setBlock($this, $this, true, false);
return $this->getLevelNonNull()->setBlock($this, $this, true, false);
}
public function onActivate(Item $item, Player $player = null) : bool{
$this->getLevel()->setBlock($this, BlockFactory::get(Block::GLOWING_REDSTONE_ORE, $this->meta));
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::GLOWING_REDSTONE_ORE, $this->meta));
return false; //this shouldn't prevent block placement
}
public function onNearbyBlockChange() : void{
$this->getLevel()->setBlock($this, BlockFactory::get(Block::GLOWING_REDSTONE_ORE, $this->meta));
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::GLOWING_REDSTONE_ORE, $this->meta));
}
public function getToolType() : int{

View File

@ -59,7 +59,7 @@ class Sapling extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::FARMLAND){
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}
@ -70,9 +70,9 @@ class Sapling extends Flowable{
public function onActivate(Item $item, Player $player = null) : bool{
if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
//TODO: change log type
Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->getVariant());
Tree::growTree($this->getLevelNonNull(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->getVariant());
$item->count--;
$item->pop();
return true;
}
@ -82,7 +82,7 @@ class Sapling extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}
@ -93,10 +93,10 @@ class Sapling extends Flowable{
public function onRandomTick() : void{
if($this->level->getFullLightAt($this->x, $this->y, $this->z) >= 8 and mt_rand(1, 7) === 1){
if(($this->meta & 0x08) === 0x08){
Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->getVariant());
Tree::growTree($this->getLevelNonNull(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->getVariant());
}else{
$this->meta |= 0x08;
$this->getLevel()->setBlock($this, $this, true);
$this->getLevelNonNull()->setBlock($this, $this, true);
}
}
}

View File

@ -62,13 +62,13 @@ class SignPost extends Transparent{
if($face === Vector3::SIDE_UP){
$this->meta = $player !== null ? (floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0f) : 0;
$this->getLevel()->setBlock($blockReplace, $this, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true);
}else{
$this->meta = $face;
$this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::WALL_SIGN, $this->meta), true);
$this->getLevelNonNull()->setBlock($blockReplace, BlockFactory::get(Block::WALL_SIGN, $this->meta), true);
}
Tile::createTile(Tile::SIGN, $this->getLevel(), TileSign::createNBT($this, $face, $item, $player));
Tile::createTile(Tile::SIGN, $this->getLevelNonNull(), TileSign::createNBT($this, $face, $item, $player));
return true;
}
@ -78,7 +78,7 @@ class SignPost extends Transparent{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}

View File

@ -65,8 +65,8 @@ class Skull extends Flowable{
}
$this->meta = $face;
$this->getLevel()->setBlock($blockReplace, $this, true);
Tile::createTile(Tile::SKULL, $this->getLevel(), TileSkull::createNBT($this, $face, $item, $player));
$this->getLevelNonNull()->setBlock($blockReplace, $this, true);
Tile::createTile(Tile::SKULL, $this->getLevelNonNull(), TileSkull::createNBT($this, $face, $item, $player));
return true;
}

View File

@ -56,11 +56,11 @@ abstract class Slab extends Transparent{
$this->meta &= 0x07;
if($face === Vector3::SIDE_DOWN){
if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0x08 and $blockClicked->getVariant() === $this->getVariant()){
$this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true);
$this->getLevelNonNull()->setBlock($blockClicked, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true);
return true;
}elseif($blockReplace->getId() === $this->id and $blockReplace->getVariant() === $this->getVariant()){
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true);
$this->getLevelNonNull()->setBlock($blockReplace, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true);
return true;
}else{
@ -68,18 +68,18 @@ abstract class Slab extends Transparent{
}
}elseif($face === Vector3::SIDE_UP){
if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0 and $blockClicked->getVariant() === $this->getVariant()){
$this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true);
$this->getLevelNonNull()->setBlock($blockClicked, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true);
return true;
}elseif($blockReplace->getId() === $this->id and $blockReplace->getVariant() === $this->getVariant()){
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true);
$this->getLevelNonNull()->setBlock($blockReplace, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true);
return true;
}
}else{ //TODO: collision
if($blockReplace->getId() === $this->id){
if($blockReplace->getVariant() === $this->getVariant()){
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true);
$this->getLevelNonNull()->setBlock($blockReplace, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true);
return true;
}
@ -95,7 +95,7 @@ abstract class Slab extends Transparent{
if($blockReplace->getId() === $this->id and $blockClicked->getVariant() !== $this->getVariant()){
return false;
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}

View File

@ -42,7 +42,7 @@ class SnowLayer extends Flowable{
}
public function canBeReplaced() : bool{
return true;
return $this->meta < 7; //8 snow layers
}
public function getHardness() : float{
@ -57,10 +57,16 @@ class SnowLayer extends Flowable{
return TieredTool::TIER_WOODEN;
}
private function canBeSupportedBy(Block $b) : bool{
return $b->isSolid() or ($b->getId() === $this->getId() and $b->getDamage() === 7);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($blockReplace->getSide(Vector3::SIDE_DOWN)->isSolid()){
//TODO: fix placement
$this->getLevel()->setBlock($blockReplace, $this, true);
if($blockReplace->getId() === $this->getId() and $blockReplace->getDamage() < 7){
$this->setDamage($blockReplace->getDamage() + 1);
}
if($this->canBeSupportedBy($blockReplace->getSide(Vector3::SIDE_DOWN))){
$this->getLevelNonNull()->setBlock($blockReplace, $this, true);
return true;
}
@ -69,8 +75,8 @@ class SnowLayer extends Flowable{
}
public function onNearbyBlockChange() : void{
if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid()){
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false, false);
if(!$this->canBeSupportedBy($this->getSide(Vector3::SIDE_DOWN))){
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::AIR), false, false);
}
}
@ -80,7 +86,7 @@ class SnowLayer extends Flowable{
public function onRandomTick() : void{
if($this->level->getBlockLightAt($this->x, $this->y, $this->z) >= 12){
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false, false);
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::AIR), false, false);
}
}

View File

@ -93,7 +93,7 @@ abstract class Stair extends Transparent{
if(($clickVector->y > 0.5 and $face !== Vector3::SIDE_UP) or $face === Vector3::SIDE_DOWN){
$this->meta |= 0x04; //Upside-down stairs
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}

View File

@ -62,13 +62,13 @@ class StandingBanner extends Transparent{
if($face !== Vector3::SIDE_DOWN){
if($face === Vector3::SIDE_UP and $player !== null){
$this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0f;
$this->getLevel()->setBlock($blockReplace, $this, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true);
}else{
$this->meta = $face;
$this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::WALL_BANNER, $this->meta), true);
$this->getLevelNonNull()->setBlock($blockReplace, BlockFactory::get(Block::WALL_BANNER, $this->meta), true);
}
Tile::createTile(Tile::BANNER, $this->getLevel(), TileBanner::createNBT($this, $face, $item, $player));
Tile::createTile(Tile::BANNER, $this->getLevelNonNull(), TileBanner::createNBT($this, $face, $item, $player));
return true;
}
@ -77,7 +77,7 @@ class StandingBanner extends Transparent{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}

View File

@ -46,23 +46,23 @@ class Sugarcane extends Flowable{
if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::SUGARCANE_BLOCK){
for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
$b = $this->getLevelNonNull()->getBlockAt($this->x, $this->y + $y, $this->z);
if($b->getId() === self::AIR){
$ev = new BlockGrowEvent($b, BlockFactory::get(Block::SUGARCANE_BLOCK));
$ev->call();
if($ev->isCancelled()){
break;
}
$this->getLevel()->setBlock($b, $ev->getNewState(), true);
$this->getLevelNonNull()->setBlock($b, $ev->getNewState(), true);
}else{
break;
}
}
$this->meta = 0;
$this->getLevel()->setBlock($this, $this, true);
$this->getLevelNonNull()->setBlock($this, $this, true);
}
$item->count--;
$item->pop();
return true;
}
@ -73,7 +73,7 @@ class Sugarcane extends Flowable{
public function onNearbyBlockChange() : void{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->isTransparent() and $down->getId() !== self::SUGARCANE_BLOCK){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}
@ -85,17 +85,17 @@ class Sugarcane extends Flowable{
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::SUGARCANE_BLOCK){
if($this->meta === 0x0F){
for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
$b = $this->getLevelNonNull()->getBlockAt($this->x, $this->y + $y, $this->z);
if($b->getId() === self::AIR){
$this->getLevel()->setBlock($b, BlockFactory::get(Block::SUGARCANE_BLOCK), true);
$this->getLevelNonNull()->setBlock($b, BlockFactory::get(Block::SUGARCANE_BLOCK), true);
break;
}
}
$this->meta = 0;
$this->getLevel()->setBlock($this, $this, true);
$this->getLevelNonNull()->setBlock($this, $this, true);
}else{
++$this->meta;
$this->getLevel()->setBlock($this, $this, true);
$this->getLevelNonNull()->setBlock($this, $this, true);
}
}
}
@ -103,7 +103,7 @@ class Sugarcane extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === self::SUGARCANE_BLOCK){
$this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true);
$this->getLevelNonNull()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true);
return true;
}elseif($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::SAND){
@ -112,7 +112,7 @@ class Sugarcane extends Flowable{
$block2 = $down->getSide(Vector3::SIDE_WEST);
$block3 = $down->getSide(Vector3::SIDE_EAST);
if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){
$this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true);
$this->getLevelNonNull()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true);
return true;
}

View File

@ -78,13 +78,13 @@ class TNT extends Solid{
* @return void
*/
public function ignite(int $fuse = 80){
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::AIR), true);
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
$nbt = Entity::createBaseNBT($this->add(0.5, 0, 0.5), new Vector3(-sin($mot) * 0.02, 0.2, -cos($mot) * 0.02));
$nbt->setShort("Fuse", $fuse);
$tnt = Entity::createEntity("PrimedTNT", $this->getLevel(), $nbt);
$tnt = Entity::createEntity("PrimedTNT", $this->getLevelNonNull(), $nbt);
if($tnt !== null){
$tnt->spawnToAll();

View File

@ -53,7 +53,7 @@ class TallGrass extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN)->getId();
if($down === self::GRASS or $down === self::DIRT){
$this->getLevel()->setBlock($blockReplace, $this, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true);
return true;
}
@ -63,7 +63,7 @@ class TallGrass extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ //Replace with common break method
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
}
}

View File

@ -57,7 +57,7 @@ class Torch extends Flowable{
$face = $faces[$meta] ?? Vector3::SIDE_DOWN;
if($this->getSide($face)->isTransparent() and !($face === Vector3::SIDE_DOWN and ($below->getId() === self::FENCE or $below->getId() === self::COBBLESTONE_WALL))){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}
@ -73,12 +73,12 @@ class Torch extends Flowable{
Vector3::SIDE_EAST => 1
];
$this->meta = $faces[$face];
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}elseif(!$below->isTransparent() or $below->getId() === self::FENCE or $below->getId() === self::COBBLESTONE_WALL){
$this->meta = 0;
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}

View File

@ -136,7 +136,7 @@ class Trapdoor extends Transparent{
if(($clickVector->y > 0.5 and $face !== self::SIDE_UP) or $face === self::SIDE_DOWN){
$this->meta |= self::MASK_UPPER; //top half of block
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}
@ -146,7 +146,7 @@ class Trapdoor extends Transparent{
public function onActivate(Item $item, Player $player = null) : bool{
$this->meta ^= self::MASK_OPENED;
$this->getLevel()->setBlock($this, $this, true);
$this->getLevelNonNull()->setBlock($this, $this, true);
$this->level->addSound(new DoorSound($this));
return true;
}

View File

@ -150,7 +150,7 @@ class Vine extends Flowable{
$this->meta |= $blockReplace->meta;
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
return true;
}

View File

@ -33,7 +33,7 @@ class WallBanner extends StandingBanner{
public function onNearbyBlockChange() : void{
if($this->getSide($this->meta ^ 0x01)->getId() === self::AIR){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}
}

View File

@ -33,7 +33,7 @@ class WallSign extends SignPost{
public function onNearbyBlockChange() : void{
if($this->getSide($this->meta ^ 0x01)->getId() === self::AIR){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}
}

View File

@ -70,13 +70,11 @@ class Water extends Liquid{
if($entity->isOnFire()){
$entity->extinguish();
}
$entity->resetFallDistance();
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$ret = $this->getLevel()->setBlock($this, $this, true, false);
$this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate());
$ret = $this->getLevelNonNull()->setBlock($this, $this, true, false);
$this->getLevelNonNull()->scheduleDelayedBlockUpdate($this, $this->tickRate());
return $ret;
}

View File

@ -59,7 +59,7 @@ class WaterLily extends Flowable{
if($blockClicked instanceof Water){
$up = $blockClicked->getSide(Vector3::SIDE_UP);
if($up->getId() === Block::AIR){
$this->getLevel()->setBlock($up, $this, true, true);
$this->getLevelNonNull()->setBlock($up, $this, true, true);
return true;
}
}
@ -69,7 +69,7 @@ class WaterLily extends Flowable{
public function onNearbyBlockChange() : void{
if(!($this->getSide(Vector3::SIDE_DOWN) instanceof Water)){
$this->getLevel()->useBreakOn($this);
$this->getLevelNonNull()->useBreakOn($this);
}
}

View File

@ -56,7 +56,7 @@ class Wood extends Solid{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face);
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
return $this->getLevelNonNull()->setBlock($blockReplace, $this, true, true);
}
public function getVariantBitmask() : int{

View File

@ -68,7 +68,7 @@ class CommandReader extends Thread{
$opts = getopt("", ["disable-readline", "enable-readline"]);
if(extension_loaded("readline") and (Utils::getOS() === "win" ? isset($opts["enable-readline"]) : !isset($opts["disable-readline"])) and !$this->isPipe(STDIN)){
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;
}
}

View File

@ -62,7 +62,7 @@ class GiveCommand extends VanillaCommand{
}
try{
$item = ItemFactory::fromString($args[1]);
$item = ItemFactory::fromStringSingle($args[1]);
}catch(\InvalidArgumentException $e){
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.give.item.notFound", [$args[1]]));
return true;

View File

@ -37,6 +37,7 @@ use pocketmine\level\particle\CriticalParticle;
use pocketmine\level\particle\DustParticle;
use pocketmine\level\particle\EnchantmentTableParticle;
use pocketmine\level\particle\EnchantParticle;
use pocketmine\level\particle\EntityFlameParticle;
use pocketmine\level\particle\ExplodeParticle;
use pocketmine\level\particle\FlameParticle;
use pocketmine\level\particle\HappyVillagerParticle;
@ -91,7 +92,7 @@ class ParticleCommand extends VanillaCommand{
}
if($sender instanceof Player){
$level = $sender->getLevel();
$level = $sender->getLevelNonNull();
$pos = new Vector3(
$this->getRelativeDouble($sender->getX(), $sender, $args[1]),
$this->getRelativeDouble($sender->getY(), $sender, $args[2], 0, Level::Y_MAX),
@ -204,7 +205,8 @@ class ParticleCommand extends VanillaCommand{
return new AngryVillagerParticle($pos);
case "forcefield":
return new BlockForceFieldParticle($pos, $data ?? 0);
case "mobflame":
return new EntityFlameParticle($pos);
}
if(strpos($name, "iconcrack_") === 0){

View File

@ -44,7 +44,7 @@ class SeedCommand extends VanillaCommand{
}
if($sender instanceof Player){
$seed = $sender->getLevel()->getSeed();
$seed = $sender->getLevelNonNull()->getSeed();
}else{
$seed = $sender->getServer()->getDefaultLevel()->getSeed();
}

View File

@ -51,7 +51,7 @@ class SetWorldSpawnCommand extends VanillaCommand{
if(count($args) === 0){
if($sender instanceof Player){
$level = $sender->getLevel();
$level = $sender->getLevelNonNull();
$pos = (new Vector3($sender->x, $sender->y, $sender->z))->round();
}else{
$sender->sendMessage(TextFormat::RED . "You can only perform this command as a player");

View File

@ -71,7 +71,7 @@ class SpawnpointCommand extends VanillaCommand{
if(count($args) === 4){
if($target->isValid()){
$level = $target->getLevel();
$level = $target->getLevelNonNull();
$pos = $sender instanceof Player ? $sender->getPosition() : $level->getSpawnLocation();
$x = $this->getRelativeDouble($pos->x, $sender, $args[1]);
$y = $this->getRelativeDouble($pos->y, $sender, $args[2], 0, Level::Y_MAX);
@ -84,7 +84,7 @@ class SpawnpointCommand extends VanillaCommand{
}
}elseif(count($args) <= 1){
if($sender instanceof Player){
$pos = new Position($sender->getFloorX(), $sender->getFloorY(), $sender->getFloorZ(), $sender->getLevel());
$pos = new Position($sender->getFloorX(), $sender->getFloorY(), $sender->getFloorZ(), $sender->getLevelNonNull());
$target->setSpawn($pos);
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.spawnpoint.success", [$target->getName(), round($pos->x, 2), round($pos->y, 2), round($pos->z, 2)]));

View File

@ -24,8 +24,8 @@ declare(strict_types=1);
namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\utils\Process;
use pocketmine\utils\TextFormat;
use pocketmine\utils\Utils;
use function count;
use function floor;
use function microtime;
@ -48,8 +48,8 @@ class StatusCommand extends VanillaCommand{
return true;
}
$rUsage = Utils::getRealMemoryUsage();
$mUsage = Utils::getMemoryUsage(true);
$rUsage = Process::getRealMemoryUsage();
$mUsage = Process::getAdvancedMemoryUsage();
$server = $sender->getServer();
$sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::WHITE . "Server status" . TextFormat::GREEN . " ----");
@ -94,7 +94,7 @@ class StatusCommand extends VanillaCommand{
$sender->sendMessage(TextFormat::GOLD . "Network upload: " . TextFormat::RED . round($server->getNetwork()->getUpload() / 1024, 2) . " kB/s");
$sender->sendMessage(TextFormat::GOLD . "Network download: " . TextFormat::RED . round($server->getNetwork()->getDownload() / 1024, 2) . " kB/s");
$sender->sendMessage(TextFormat::GOLD . "Thread count: " . TextFormat::RED . Utils::getThreadCount());
$sender->sendMessage(TextFormat::GOLD . "Thread count: " . TextFormat::RED . Process::getThreadCount());
$sender->sendMessage(TextFormat::GOLD . "Main thread memory: " . TextFormat::RED . number_format(round(($mUsage[0] / 1024) / 1024, 2), 2) . " MB.");
$sender->sendMessage(TextFormat::GOLD . "Total memory: " . TextFormat::RED . number_format(round(($mUsage[1] / 1024) / 1024, 2), 2) . " MB.");

View File

@ -77,7 +77,7 @@ class TimeCommand extends VanillaCommand{
return true;
}
if($sender instanceof Player){
$level = $sender->getLevel();
$level = $sender->getLevelNonNull();
}else{
$level = $sender->getServer()->getDefaultLevel();
}
@ -96,12 +96,28 @@ class TimeCommand extends VanillaCommand{
return true;
}
if($args[1] === "day"){
$value = Level::TIME_DAY;
}elseif($args[1] === "night"){
$value = Level::TIME_NIGHT;
}else{
$value = $this->getInteger($sender, $args[1], 0);
switch($args[1]){
case "day":
$value = Level::TIME_DAY;
break;
case "noon":
$value = Level::TIME_NOON;
break;
case "sunset":
$value = Level::TIME_SUNSET;
break;
case "night":
$value = Level::TIME_NIGHT;
break;
case "midnight":
$value = Level::TIME_MIDNIGHT;
break;
case "sunrise":
$value = Level::TIME_SUNRISE;
break;
default:
$value = $this->getInteger($sender, $args[1], 0);
break;
}
foreach($sender->getServer()->getLevels() as $level){

View File

@ -68,21 +68,21 @@ class TitleCommand extends VanillaCommand{
throw new InvalidCommandSyntaxException();
}
$player->addTitle(implode(" ", array_slice($args, 2)));
$player->sendTitle(implode(" ", array_slice($args, 2)));
break;
case "subtitle":
if(count($args) < 3){
throw new InvalidCommandSyntaxException();
}
$player->addSubTitle(implode(" ", array_slice($args, 2)));
$player->sendSubTitle(implode(" ", array_slice($args, 2)));
break;
case "actionbar":
if(count($args) < 3){
throw new InvalidCommandSyntaxException();
}
$player->addActionBarMessage(implode(" ", array_slice($args, 2)));
$player->sendActionBarMessage(implode(" ", array_slice($args, 2)));
break;
case "times":
if(count($args) < 5){

View File

@ -71,10 +71,13 @@ class AttributeMap implements \ArrayAccess{
}
/**
* @param int $offset
* @param float $value
* @param int|null $offset
* @param float $value
*/
public function offsetSet($offset, $value) : void{
if($offset === null){
throw new \InvalidArgumentException("Array push syntax is not supported");
}
$this->attributes[$offset]->setValue($value);
}

View File

@ -125,7 +125,7 @@ class Effect{
/**
* @param int $id Effect ID as per Minecraft PE
* @param string $name Translation key used for effect name
* @param Color $color
* @param Color $color Color of bubbles given by this effect
* @param bool $isBad Whether the effect is harmful
* @param int $defaultDuration Duration in ticks the effect will last for by default if applied without a duration.
* @param bool $hasBubbles Whether the effect has potion bubbles. Some do not (e.g. Instant Damage has its own particles instead of bubbles)

View File

@ -297,11 +297,11 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
public const DATA_FLAG_OVER_SCAFFOLDING = 69;
public const DATA_FLAG_FALL_THROUGH_SCAFFOLDING = 70;
public const DATA_FLAG_BLOCKING = 71; //shield
public const DATA_FLAG_DISABLE_BLOCKING = 72;
//73 is set when a player is attacked while using shield, unclear on purpose
//74 related to shield usage, needs further investigation
public const DATA_FLAG_TRANSITION_BLOCKING = 72;
public const DATA_FLAG_BLOCKED_USING_SHIELD = 73;
public const DATA_FLAG_BLOCKED_USING_DAMAGED_SHIELD = 74;
public const DATA_FLAG_SLEEPING = 75;
//76 related to sleeping, unclear usage
public const DATA_FLAG_WANTS_TO_WAKE = 76;
public const DATA_FLAG_TRADE_INTEREST = 77;
public const DATA_FLAG_DOOR_BREAKER = 78; //...
public const DATA_FLAG_BREAKING_OBSTRUCTION = 79;
@ -311,8 +311,12 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
public const DATA_FLAG_ROARING = 83;
public const DATA_FLAG_DELAYED_ATTACKING = 84;
public const DATA_FLAG_AVOIDING_MOBS = 85;
//86 used by RangedAttackGoal
//87 used by NearestAttackableTargetGoal
public const DATA_FLAG_FACING_TARGET_TO_RANGE_ATTACK = 86;
public const DATA_FLAG_HIDDEN_WHEN_INVISIBLE = 87; //??????????????????
public const DATA_FLAG_IS_IN_UI = 88;
public const DATA_FLAG_STALKING = 89;
public const DATA_FLAG_EMOTING = 90;
public const DATA_FLAG_CELEBRATING = 91;
public const DATA_PLAYER_FLAG_SLEEP = 1;
public const DATA_PLAYER_FLAG_DEAD = 2; //TODO: CHECK
@ -1164,6 +1168,9 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
if($teleport){
$pk->flags |= MoveActorAbsolutePacket::FLAG_TELEPORT;
}
if($this->onGround){
$pk->flags |= MoveActorAbsolutePacket::FLAG_GROUND;
}
$this->level->broadcastPacketToViewers($this, $pk);
}
@ -1743,7 +1750,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
if($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level){
if(!$this->switchLevel($pos->getLevel())){
if(!$this->switchLevel($pos->getLevelNonNull())){
return false;
}
}
@ -1849,7 +1856,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$pitch = $pitch ?? $pos->pitch;
}
$from = Position::fromObject($this, $this->level);
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level);
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevelNonNull() : $this->level);
$ev = new EntityTeleportEvent($this, $from, $to);
$ev->call();
if($ev->isCancelled()){
@ -1861,7 +1868,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->setMotion($this->temporalVector->setComponents(0, 0, 0));
if($this->setPositionAndRotation($pos, $yaw ?? $this->yaw, $pitch ?? $this->pitch)){
$this->resetFallDistance();
$this->onGround = true;
$this->setForceMovementUpdate();
$this->updateMovement(true);
@ -1914,7 +1921,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
protected function sendSpawnPacket(Player $player) : void{
$pk = new AddActorPacket();
$pk->entityRuntimeId = $this->getId();
$pk->type = static::NETWORK_ID;
$pk->type = AddActorPacket::LEGACY_ID_MAP_BC[static::NETWORK_ID];
$pk->position = $this->asVector3();
$pk->motion = $this->getMotion();
$pk->yaw = $this->yaw;
@ -1927,7 +1934,12 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
public function spawnTo(Player $player) : void{
if(!isset($this->hasSpawned[$player->getLoaderId()]) and $this->chunk !== null and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])){
if(
!isset($this->hasSpawned[$player->getLoaderId()]) and
$this->chunk !== null and
isset($player->usedChunks[$chunkHash = Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())]) and
$player->usedChunks[$chunkHash] === true
){
$this->hasSpawned[$player->getLoaderId()] = $player;
$this->sendSpawnPacket($player);

View File

@ -835,7 +835,11 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$pk->headYaw = $this->yaw;
$pk->mode = $teleport ? MovePlayerPacket::MODE_TELEPORT : MovePlayerPacket::MODE_NORMAL;
$this->level->addChunkPacket($this->getFloorX() >> 4, $this->getFloorZ() >> 4, $pk);
//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{

View File

@ -191,7 +191,7 @@ abstract class Living extends Entity implements Damageable{
public function hasLineOfSight(Entity $entity) : bool{
//TODO: head height
return true;
//return $this->getLevel()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null;
//return $this->getLevelNonNull()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null;
}
/**
@ -436,6 +436,12 @@ abstract class Living extends Entity implements Damageable{
* to effects or armour.
*/
public function applyDamageModifiers(EntityDamageEvent $source) : void{
if($this->lastDamageCause !== null and $this->attackTime > 0){
if($this->lastDamageCause->getBaseDamage() >= $source->getBaseDamage()){
$source->setCancelled();
}
$source->setModifier(-$this->lastDamageCause->getBaseDamage(), EntityDamageEvent::MODIFIER_PREVIOUS_DAMAGE_COOLDOWN);
}
if($source->canBeReducedByArmor()){
//MCPE uses the same system as PC did pre-1.9
$source->setModifier(-$source->getFinalDamage() * $this->getArmorPoints() * 0.04, EntityDamageEvent::MODIFIER_ARMOR);
@ -514,11 +520,6 @@ abstract class Living extends Entity implements Damageable{
public function attack(EntityDamageEvent $source) : void{
if($this->noDamageTicks > 0){
$source->setCancelled();
}elseif($this->attackTime > 0){
$lastCause = $this->getLastDamageCause();
if($lastCause !== null and $lastCause->getBaseDamage() >= $source->getBaseDamage()){
$source->setCancelled();
}
}
if($this->hasEffect(Effect::FIRE_RESISTANCE) and (
@ -550,20 +551,15 @@ abstract class Living extends Entity implements Damageable{
$this->attackTime = $source->getAttackCooldown();
if($source instanceof EntityDamageByEntityEvent){
$e = $source->getDamager();
if($source instanceof EntityDamageByChildEntityEvent){
$e = $source->getChild();
}
if($source instanceof EntityDamageByChildEntityEvent){
$e = $source->getChild();
if($e !== null){
$motion = $e->getMotion();
$this->knockBack($e, $source->getBaseDamage(), $motion->x, $motion->z, $source->getKnockBack());
}
}elseif($source instanceof EntityDamageByEntityEvent){
$e = $source->getDamager();
if($e !== null){
if((
$source->getCause() === EntityDamageEvent::CAUSE_PROJECTILE or
$source->getCause() === EntityDamageEvent::CAUSE_ENTITY_ATTACK
) and $e->isOnFire()){
$this->setOnFire(2 * $this->level->getDifficulty());
}
$deltaX = $this->x - $e->x;
$deltaZ = $this->z - $e->z;
$this->knockBack($e, $source->getBaseDamage(), $deltaX, $deltaZ, $source->getKnockBack());
@ -612,15 +608,14 @@ abstract class Living extends Entity implements Damageable{
}
protected function onDeath() : void{
$ev = new EntityDeathEvent($this, $this->getDrops());
$ev = new EntityDeathEvent($this, $this->getDrops(), $this->getXpDropAmount());
$ev->call();
foreach($ev->getDrops() as $item){
$this->getLevel()->dropItem($this, $item);
$this->getLevelNonNull()->dropItem($this, $item);
}
//TODO: check death conditions (must have been damaged by player < 5 seconds from death)
//TODO: allow this number to be manipulated during EntityDeathEvent
$this->level->dropExperience($this, $this->getXpDropAmount());
$this->level->dropExperience($this, $ev->getXpDropAmount());
}
protected function onDeathUpdate(int $tickDiff) : bool{

View File

@ -36,14 +36,10 @@ class ExperienceOrb extends Entity{
public const TAG_VALUE_PC = "Value"; //short
public const TAG_VALUE_PE = "experience value"; //int (WTF?)
/**
* Max distance an orb will follow a player across.
*/
/** Max distance an orb will follow a player across. */
public const MAX_TARGET_DISTANCE = 8.0;
/**
* Split sizes used for dropping experience orbs.
*/
/** Split sizes used for dropping experience orbs. */
public const ORB_SPLIT_SIZES = [2477, 1237, 617, 307, 149, 73, 37, 17, 7, 3, 1]; //This is indexed biggest to smallest so that we can return as soon as we found the biggest value.
/**

View File

@ -98,7 +98,7 @@ class FallingBlock extends Entity{
$hasUpdate = parent::entityBaseTick($tickDiff);
if(!$this->isFlaggedForDespawn()){
$pos = Position::fromObject($this->add(-$this->width / 2, $this->height, -$this->width / 2)->floor(), $this->getLevel());
$pos = Position::fromObject($this->add(-$this->width / 2, $this->height, -$this->width / 2)->floor(), $this->getLevelNonNull());
$this->block->position($pos);
@ -111,14 +111,14 @@ class FallingBlock extends Entity{
$this->flagForDespawn();
$block = $this->level->getBlock($pos);
if(($block->isTransparent() and !$block->canBeReplaced()) or ($this->onGround and abs($this->y - $this->getFloorY()) > 0.001)){
if(!$block->canBeReplaced() or ($this->onGround and abs($this->y - $this->getFloorY()) > 0.001)){
//FIXME: anvils are supposed to destroy torches
$this->getLevel()->dropItem($this, ItemFactory::get($this->getBlock(), $this->getDamage()));
$this->getLevelNonNull()->dropItem($this, ItemFactory::get($this->getBlock(), $this->getDamage()));
}else{
$ev = new EntityBlockChangeEvent($this, $block, $blockTarget ?? $this->block);
$ev->call();
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($pos, $ev->getTo(), true);
$this->getLevelNonNull()->setBlock($pos, $ev->getTo(), true);
}
}
$hasUpdate = true;

View File

@ -44,6 +44,6 @@ class EntityDamageByChildEntityEvent extends EntityDamageByEntityEvent{
* Returns the entity which caused the damage, or null if the entity has been killed or closed.
*/
public function getChild() : ?Entity{
return $this->getEntity()->getLevel()->getServer()->findEntity($this->childEntityEid);
return $this->getEntity()->getLevelNonNull()->getServer()->findEntity($this->childEntityEid);
}
}

View File

@ -62,7 +62,7 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{
* Returns the attacking entity, or null if the attacker has been killed or closed.
*/
public function getDamager() : ?Entity{
return $this->getEntity()->getLevel()->getServer()->findEntity($this->damagerEntityId);
return $this->getEntity()->getLevelNonNull()->getServer()->findEntity($this->damagerEntityId);
}
public function getKnockBack() : float{

View File

@ -26,6 +26,7 @@ namespace pocketmine\event\entity;
use pocketmine\entity\Entity;
use pocketmine\event\Cancellable;
use function array_sum;
use function max;
/**
* Called when an entity takes damage.
@ -40,6 +41,7 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{
public const MODIFIER_CRITICAL = 7;
public const MODIFIER_TOTEM = 8;
public const MODIFIER_WEAPON_ENCHANTMENTS = 9;
public const MODIFIER_PREVIOUS_DAMAGE_COOLDOWN = 10;
public const CAUSE_CONTACT = 0;
public const CAUSE_ENTITY_ATTACK = 1;
@ -143,7 +145,7 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{
}
public function getFinalDamage() : float{
return $this->baseDamage + array_sum($this->modifiers);
return max(0, $this->baseDamage + array_sum($this->modifiers));
}
/**

View File

@ -29,13 +29,16 @@ use pocketmine\item\Item;
class EntityDeathEvent extends EntityEvent{
/** @var Item[] */
private $drops = [];
/** @var int */
private $xp;
/**
* @param Item[] $drops
*/
public function __construct(Living $entity, array $drops = []){
public function __construct(Living $entity, array $drops = [], int $xp = 0){
$this->entity = $entity;
$this->drops = $drops;
$this->xp = $xp;
}
/**
@ -58,4 +61,21 @@ class EntityDeathEvent extends EntityEvent{
public function setDrops(array $drops) : void{
$this->drops = $drops;
}
/**
* Returns how much experience is dropped due to this entity's death.
*/
public function getXpDropAmount() : int{
return $this->xp;
}
/**
* @throws \InvalidArgumentException
*/
public function setXpDropAmount(int $xp) : void{
if($xp < 0){
throw new \InvalidArgumentException("XP drop amount must not be negative");
}
$this->xp = $xp;
}
}

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