Commit Graph

273 Commits

Author SHA1 Message Date
c47ecb55c0 Sign: Do not allow edits by any player except the one who placed it, and only while that player is online
signs now become finalized if:
- the player quits and rejoins (because the entity runtime ID of the player will not be the same)
- the chunk is unloaded and reloaded (because the tagged entity runtime ID is not saved).

closes #4198
2021-05-02 13:22:31 +01:00
dd2c3db285 Fixed a bucket of lava disappearing when used in a furnace (#3973)
fixes #2385
2020-12-17 23:57:34 +00:00
e30b1ee2c7 Clean up entity and tile saveID handling
we only ever need the first entry, so there's no point storing all of them. In addition, the field is private, which guarantees that nothing else needs the array either.
This also fixes phpstan/phpstan@c50650c5dd.
2020-11-12 21:49:12 +00:00
3e09ff5350 EnchantTable: fix formatting issue [ci skip] 2020-06-10 10:54:22 +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
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
fa82cb26d8 added native types to closures (phpstan-strict-rules) 2020-02-05 16:35:10 +00:00
799183e13e make use of phpstan class-string in some areas 2020-01-30 22:23:11 +00:00
260ac47588 add some phpstan array types 2020-01-30 22:23:11 +00:00
92a752053d populate missing array value types in tile namespace 2020-01-30 21:20:42 +00:00
f624871b3f strip extra blank lines (php-cs-fixer) 2020-01-22 14:50:29 +00:00
c4793241f5 Mass removal of useless @param/@return PHPDoc annotations, pass 1 2020-01-21 15:10:18 +00:00
8776b71d63 tile: populate missing return type information 2020-01-19 17:08:40 +00:00
494660102e Replace empty() usages with count() 2019-12-18 11:23:24 +00:00
cc3285c8fe Chest: fixed type doc of doubleChestInventory field 2019-10-22 10:25:24 +01:00
c58a1bf9b7 Protocol changes for 1.12.0.28 2019-07-12 19:00:15 +01:00
389e7767d1 Sign: apply a very stupid limit on text size
this is necessary because of the epidemic of server attacks going around lately.
2019-04-14 19:30:28 +01:00
44697e784a Sign: add validity checks on text encoding, scrub invalid UTF-8 on load
this works around a bug where corrupted text on preexisting signs can mess up the client. This also prevents corrupted text getting onto signs in the future by having them scrubbed and validated before applying them.
2019-02-14 15:16:51 +00:00
480a513f30 Sign: fixed asserts on loading NBT, closes #2636 2019-01-19 16:42:22 +00:00
4b9a142a5d Import global functions and constants for enhanced performance
This is better for performance because these then don't need to be reevaluated every time they are called.

When encountering an unqualified function or constant reference, PHP will first try to locate a symbol in the current namespace by that name, and then fall back to the global namespace.
This short-circuits the check, which has substantial performance effects in some cases - in particular, ord(), chr() and strlen() show ~1500x faster calls when they are fully qualified.

However, this doesn't mean that PM is getting a massive amount faster. In real world terms, this translates to about 10-15% performance improvement.
But before anyone gets excited, you should know that the CodeOptimizer in the PreProcessor repo has been applying fully-qualified symbol optimizations to Jenkins builds for years, which is one of the reasons why Jenkins builds have better performance than home-built or source installations.
We're choosing to do this for the sake of future SafePHP integration and also to be able to get rid of the buggy CodeOptimizer, so that phar and source are more consistent.
2019-01-04 20:43:15 +00:00
d71a543d10 Fixed a bunch of things PHPStan finds unpalatable
close #2614, fix a bunch of docs bugs, fix sendCreativeContents() crash on Human holders, move some inline variable declarations
2019-01-04 00:23:09 +00:00
a71af952ba Sign: simplify network data reading, ensure text is always 4 lines, closes #2610 2018-12-26 22:57:42 +00:00
98f903783c Chest: remove pairx and pairz on blockpick, fixes #2612 2018-12-26 22:26:17 +00:00
c143834632 Merge branch 'release/3.3' into release/3.4 2018-10-30 15:43:06 +00:00
31ceafa111 Chest: keep inventory better in sync when paired
should fix #2502
2018-10-30 15:42:44 +00:00
2a40c0d82c Make use of isInLoadedTerrain() 2018-10-20 19:13:34 +01:00
d563b9e31b Level: Added API method broadcastPacketToViewers()
This supersedes addChunkPacket() in most cases, and has a more clear name. It broadcasts the given packet to every player who has the target position within their chunk load radius.
2018-10-20 15:14:41 +01:00
1dd6591ac1 Migrate a bunch of PluginManager->callEvent() usages to Event->call
This has the triple bonus effect of a) making a lot of code easier to read, b) reducing Server::getInstance() usages, and c) removing a whole bunch of Server dependencies.

The network and block namespaces are untouched by this commit due to potential for merge conflicts. These should be dealt with separately on master.
2018-10-05 17:30:06 +01:00
ddcb2f002a Tile: Be explicit about not calling Tile::createNBT() (#2388)
A common pitfall developers fall into with this function is that it has to be called from the scope of the tile class you're creating NBT for, but people commonly do Tile::createNBT() directly, which then results in cryptic "Tile is not registered" errors. This now throws a BadMethodCallException instead to be fully clear about this.

In the future this will be removed completely once NBT is no longer required to create a tile, but for now this is a confusing issue that should be dealt with.
2018-08-19 19:54:22 +01:00
5df601c817 Add @see docs so PhpStorm can see dynamic constructor usages
PhpStorm can't see constructor usages when the class name is dynamic. This causes maintenance problems because cross-referencing constructors called like this doesn't show up dynamic calls.
2018-08-19 16:00:15 +01:00
5dbb0d177e Fixed double chest inventory desync issues, closes #2261 (#2279)
chest pairing really needs rewriting... this code really sucks
2018-07-05 17:42:30 +01:00
f315aca4c3 Tile: make saveNBT() return a CompoundTag
I don't know why I made it take a parameter for this...
2018-06-16 17:59:41 +01:00
cfb10360ff Furnace: remove trailing whitespace 2018-06-11 13:31:05 +01:00
05af87e1d4 Strip empty lines at the end of classes 2018-06-11 13:19:23 +01:00
c4c6c58615 Added some missing typehints 2018-06-10 17:18:55 +01:00
f6481eab8f Implemented an InventoryEventProcessor, fixes #1986 (#2176)
* Implemented InventoryEventProcessor, fixes #1986
Event processors can now be registered and unregistered at will. Entity inventory/armor change events are now handled by event processors instead of the inventories themselves, which allows enabling/disabling the calling of these events at will.
This now avoids stupid things happening when initializing inventory contents, since the callers for those events are now registered _after_ the contents are initialized.
2018-06-09 17:37:10 +01:00
14914781fc Added exception throws when a closed tile or entity attempts to schedule itself for updating
I can't believe it took so long to find what was causing these stdClass bugs.
2018-06-07 12:37:26 +01:00
fe21f0e916 Spawnable: change visibility of addAdditionalSpawnData() 2018-06-03 19:58:48 +01:00
4c1d29cdf7 Tile: remove unnecessary removeTag() calls
these CompoundTags are now ephemeral, so it's not necessary to remove potential garbage from them anymore.
2018-06-03 18:31:23 +01:00
fa21cd96c5 Tiles no longer store their NBT at runtime
This is a significant breaking change for anything utilizing Tiles as they now do not store their NBT at runtime anymore.
This is another step in the process of ridding PocketMine-MP of runtime NBT.

It can be noticed that all tiles are now using class fields to store properties instead of NBT, which is much faster, uses less memory and is also more concise when written in code.

Highlights:
- Tile->namedtag has been removed.
- Tile->saveNBT() now accepts a CompoundTag() parameter. Typically it's expected that this will be fed a newly-created CompoundTag (this part may be improved in the future).
- New internal methods Tile->readSaveData() and Tile->writeSaveData() have been added. Instead of overriding __construct() and saveNBT() to load and save properties from NBT, you should now implement these methods instead.

This is not final and will see further changes before it's done.
2018-06-03 18:29:08 +01:00
a22e5616f6 Fixed tile and furnace custom names not being visible
This is caused by the Spawnable constructor calling spawnToAll() before the tile is fully initialized. I really really really hate constructors that _DO_ things by themselves.
2018-06-03 17:02:00 +01:00
b6317fa7ce Sign: remove non-standard broken bad solution for editing
this never really worked properly and is a bad idea anyway. This was the cause of many sign-going-blank bugs before it was broken (by me), and since it's broken it's now useless. I don't think there's any practical way to make this work properly, so I leave it up to plugins to decide whether or not they want to cancel sign editing in protected areas. PocketMine-MP built-in spawn protection will already block this by default anyway.
2018-06-03 16:45:26 +01:00
b1cb63ebd6 Tile: make ContainerTrait and NameableTrait non-dependent on context-retained NBT 2018-06-03 16:32:05 +01:00
7b7917939a Cleaned up Container lock handling 2018-06-03 13:42:04 +01:00
6aaaaefd2f Make tiles less dependent on runtime NBT, use properties instead
This will ultimately culminate in the complete removal of runtime NBT, so plugins should also follow these steps if they have custom data.
2018-06-03 12:50:16 +01:00
1bb0337420 Tile: Improved Nameable and NameableTrait to cut down code duplication 2018-06-02 15:17:32 +01:00
febba6e3a6 Tile: call parent constructor instead of duping code 2018-05-18 16:49:14 +01:00
396056c636 Sign: Pad exploded blob to appropriate size
I'm not sure how it's possible to get one of these blobs with less newlines than expected, but whatever I guess
closes #2152
2018-05-04 23:29:32 +01:00
e03d2b23f7 Sign: add some typehints where it wasn't previously possible 2018-05-01 14:00:23 +01:00
e565cdeea4 Tile: remove unnecessary createAdditionalNBT() things
these things are filled in by the tiles' constructors anyway.
2018-04-13 11:50:04 +01:00