259 Commits

Author SHA1 Message Date
Dylan K. Taylor
cc3285c8fe Chest: fixed type doc of doubleChestInventory field 2019-10-22 10:25:24 +01:00
Dylan K. Taylor
c58a1bf9b7 Protocol changes for 1.12.0.28 2019-07-12 19:00:15 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
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
Dylan K. Taylor
480a513f30 Sign: fixed asserts on loading NBT, closes #2636 2019-01-19 16:42:22 +00:00
Dylan K. Taylor
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
Dylan K. Taylor
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
Dylan K. Taylor
a71af952ba Sign: simplify network data reading, ensure text is always 4 lines, closes #2610 2018-12-26 22:57:42 +00:00
Dylan K. Taylor
98f903783c Chest: remove pairx and pairz on blockpick, fixes #2612 2018-12-26 22:26:17 +00:00
Dylan K. Taylor
c143834632 Merge branch 'release/3.3' into release/3.4 2018-10-30 15:43:06 +00:00
Dylan K. Taylor
31ceafa111 Chest: keep inventory better in sync when paired
should fix #2502
2018-10-30 15:42:44 +00:00
Dylan K. Taylor
2a40c0d82c Make use of isInLoadedTerrain() 2018-10-20 19:13:34 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
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
Dylan K. Taylor
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
Dylan K. Taylor
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
Dylan K. Taylor
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
Dylan K. Taylor
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
Dylan K. Taylor
cfb10360ff Furnace: remove trailing whitespace 2018-06-11 13:31:05 +01:00
Dylan K. Taylor
05af87e1d4 Strip empty lines at the end of classes 2018-06-11 13:19:23 +01:00
Dylan K. Taylor
c4c6c58615 Added some missing typehints 2018-06-10 17:18:55 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
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
Dylan K. Taylor
fe21f0e916 Spawnable: change visibility of addAdditionalSpawnData() 2018-06-03 19:58:48 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
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
Dylan K. Taylor
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
Dylan K. Taylor
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
Dylan K. Taylor
b1cb63ebd6 Tile: make ContainerTrait and NameableTrait non-dependent on context-retained NBT 2018-06-03 16:32:05 +01:00
Dylan K. Taylor
7b7917939a Cleaned up Container lock handling 2018-06-03 13:42:04 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
1bb0337420 Tile: Improved Nameable and NameableTrait to cut down code duplication 2018-06-02 15:17:32 +01:00
Dylan K. Taylor
febba6e3a6 Tile: call parent constructor instead of duping code 2018-05-18 16:49:14 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
e03d2b23f7 Sign: add some typehints where it wasn't previously possible 2018-05-01 14:00:23 +01:00
Dylan K. Taylor
e565cdeea4 Tile: remove unnecessary createAdditionalNBT() things
these things are filled in by the tiles' constructors anyway.
2018-04-13 11:50:04 +01:00
Dylan K. Taylor
556a465c05 Container tiles: remove unnecessary ListTag Items creation
the existence of this tag is checked for anyway.
2018-04-13 11:27:11 +01:00
Dylan K. Taylor
280f2b7259 always loose imports... 2018-04-13 11:25:52 +01:00
Dylan K. Taylor
933b0e8b41 Furnace: cleanup, stop abusing NBT, stop spamming packets 2018-04-13 11:22:47 +01:00
Dylan K. Taylor
1648fff916 Replaced Position->getLevel() null checks with isValid() 2018-03-20 11:10:36 +00:00
Dylan K. Taylor
73e09392b6 Timings: Clean up some terrible code, move namespaces 2018-03-19 19:05:51 +00:00
Dylan K. Taylor
ac5a91b67e Cleaned up bool comparison mess 2018-03-19 14:10:55 +00:00
Dylan K. Taylor
596c8a7b4f Tile: Removed cyclic dependence on Chunks
Chunks were used by tiles for a couple of things:
- 1. for coordinates - which can be gotten using bitshifts
- 2. setChanged() - which is unnecessary as seen in the previous commit

Removing this circular dependency was actually remarkably easy to do.
2018-03-15 10:21:42 +00:00
Dylan K. Taylor
9c598d1345 Spawnable: don't mark chunk as changed onChanged()
this is unnecessary because a chunk is considered "changed" if it has tiles on it anyway.
2018-03-15 09:48:28 +00:00
Dylan K. Taylor
28e601bbb9 Tile: added handling for PC 1.11 save IDs 2018-02-28 19:58:18 +00:00
Dylan K. Taylor
0ad8ea6e92 Remove unused imports 2018-02-24 19:01:09 +00:00
Dylan K. Taylor
093cb5b39e Updated PocketMine-NBT dependency 2018-02-17 14:29:20 +00:00
Dylan K. Taylor
ce4e0bf69c Tile: fixed copying of custom block data 2018-02-15 11:47:12 +00:00
Dylan K. Taylor
dc84484c2b ContainerTrait: Add PhpDoc for ListTag iteration 2018-02-15 11:45:13 +00:00
Dylan K. Taylor
9abfd54cc1 Updated with ListTag changes from PocketMine-NBT 2018-02-13 16:50:49 +00:00