Commit Graph

359 Commits

Author SHA1 Message Date
2559f5ec2b Moved Player-related classes to pocketmine\player namespace 2019-06-18 18:51:36 +01:00
89242543b9 Clean up Skin error handling, close #2926
Skin->__construct() now does all the validation.
2019-05-27 16:20:46 +01:00
3902a3c28c Require opting into receiving cancelled events instead of opting out (#2906)
Warning for plugin developers: This is a silent BC break. It won't raise any errors.

This alters the default behaviour of event handlers to **not** receive cancelled events by default.
It is now required to opt into receiving cancelled events by using the @handleCancelled directive (or the handleCancelled parameter where it's appropriate).

The ambiguous @ignoreCancelled directive is now ignored.

Ramifications:
- The majority of handlers with `if($event->isCancelled()) return;` no longer need such checks.
- Handlers with `@ignoreCancelled true` or `@ignoreCancelled` annotations can have them removed.
- Handlers which want to receive cancelled events need to use `@handleCancelled`.
2019-05-27 15:47:58 +01:00
b329cac3d2 Move pocketmine\tile\* to pocketmine\block\tile\* 2019-05-25 19:23:43 +01:00
dec6c9f49b Removed EntityInventoryChangeEvent and EntityArmorChangeEvent
there is nothing that these events do that can't be fulfilled by transactions. They complicate the internal implementation and produce unexpected behaviour for plugins when cancelled.

TL;DR: Use transactions. That's what they are there for.
2019-05-19 16:02:03 +01:00
64f7f558a4 Merge branch 'stable'
# Conflicts:
#	resources/vanilla
#	src/pocketmine/entity/Human.php
2019-05-17 17:43:30 +01:00
76e5ea385b Skin: improved error checking
plugin devs should find this less of a pain in the ass now.
2019-05-17 17:40:27 +01:00
cf0c0e72a9 Assume the player is online when they are, uh, assumed to be online
the checks removed here should never be hit under normal circumstances. If they were hit, they'd just conceal bugs which would cause a crash to happen later anyway.
2019-05-07 19:49:06 +01:00
00944eff72 Removed EntityWorldChangeEvent
there's nothing that can be done with this event that can't be done with EntityTeleportEvent. Having this extra event needlessly increases system complexity.
2019-05-07 17:37:10 +01:00
3cd6e12e71 Renaming "Level" -> "World" (#2907)
This has been a pain point for a long time due to the misleading nature of the name "level". It's also confusing when trying to do things like getting the XP level of the player or such, and also does not translate well to other languages.

This transition was already executed on the UI some time ago (language strings) and now it's time for the same change to occur on the API.

This will burn a lot of plugins, but they'll acclimatize. Despite the scary size of this PR, there isn't actually so many changes to make. Most of this came from renaming `Position->getLevel()` to `Position->getWorld()`, or cosmetic changes like changing variable names or doc comments.
2019-05-07 14:47:28 +01:00
e506c7f7de Call BlockTeleportEvent when dragon egg teleports (#2840) 2019-04-14 17:46:22 +01:00
42a263a9df GameMode is now an enum 2019-03-31 16:19:36 +01:00
ca22223b62 PlayerDeathEvent: fixed constructor signature, closes #2835
can we ban multi-type parameters already? this is tiresome...
2019-03-25 14:55:25 +00:00
23071d257e Extract process-related functions from Utils into a separate Process class 2019-03-24 18:57:32 +00:00
a753c1342d Clean up Query cache handling, remove useless timeouts
the timeout was entirely useless, because:
- when shorter than 25.6 seconds (512 ticks) it would cause caches to be needlessly destroyed and regenerated
- when longer than 25.6 seconds, just made outdated caches persist for longer, even after the query info was regenerated.

This now uses a mark-dirty model to deal with caches, which means that plugin modifications to the query data will be reflected immediately, regardless of when they are made. Previously, modifying the result of Server->getQueryInformation() would have inconsistent results.
2019-03-24 17:43:02 +00:00
2a3e6dcf00 Rename BlockIds -> BlockLegacyIds 2019-03-23 19:46:31 +00:00
79ef8e0803 Replace all legacy blockID references with BlockIds:: 2019-03-23 19:44:33 +00:00
034bd716c8 Clean up WritableBook hierarchy 2019-03-23 14:36:03 +00:00
433dab078b DataPacket events now use network sessions instead of players 2019-03-23 09:52:03 +00:00
b8d1eb20b0 EntityDeathEvent: add XP amount API, closes #2690 2019-03-21 19:53:14 +00:00
b9208eb1fb Merge branch '3.6' 2019-03-09 19:04:37 +00:00
8f1bc5d497 Flatten wall_banner and wall_sign into single blocks (#2798)
This comes with some problems, but the problems are more bearable than the previous code.
2019-03-08 16:37:26 +00:00
c0bed03a2a Update PlayerRespawnEvent.php (#2797)
removed obsolete comment
2019-03-05 16:28:58 +00:00
6c8fa8ae28 More nullable and void typehints 2019-03-02 10:29:11 +00:00
5cca4b5e31 Revamp Sign API, flatten API into blocks 2019-02-28 17:10:37 +00:00
c26544475e More PHP 7.1 nullables 2019-02-22 12:55:34 +00:00
646fea5a4e Effect: Introduce a bunch of static getters, change a bunch of API to use objects
This introduces static getters for every currently-known effect type. At some point in the near future, the magic number constants (which are really network IDs, by the way) will disappear.

Migrating:
- If you used constants (like any sensible person would): for the most part it's just a case of adding a () anywhere you used an Effect constant.
- If you hardcoded magic numbers: ... well, have fun fixing your code, and I reserve the right to say "I told you so" :)

This achieves multiple goals:
1) creating an EffectInstance for application is much less verbose (see diff for examples, especially the Potion class)
2) plugin devs cannot use magic numbers to apply effects anymore and are forced to use type-safe objects. :)

This is a warning shot for plugin devs who use magic numbers. More changes like this are coming in the not-too-distant future.
2019-02-20 12:05:17 +00:00
3e58708130 Add some missing @throws annotations 2019-02-04 19:50:43 +00:00
78dfcc5f2d Move Effect and EffectInstance to entity\effect namespace 2019-01-28 15:41:07 +00:00
d378371cc8 Transition to spl_object_id() 2019-01-26 15:06:38 +00:00
e341f3dce2 Level: rename getName() to getDisplayName() 2019-01-17 16:46:56 +00:00
76f1ee1827 Add restrictions on packet send directions with interfaces
This prevents plugins sending wrong packets at the compiler level (or would, if we had a compiler). It's more robust than a getter for client/server and throwing an exception since a static analysis tool can detect faults created by sending wrong packets from the server. This is also used to deny service to dodgy clients which send wrong packets to the server to attack it.
2019-01-17 12:51:24 +00:00
b82e00ffdf Extract a Packet interface from DataPacket
this is in preparation for clientbound/serverbound packet separation. I did this already on another branch, but the changeset was dependent on a massive refactor to split apart packets and binarystream which i'm still not fully happy with.
2019-01-17 12:21:56 +00:00
9c0ebb6350 Minor formatting fixes 2019-01-16 22:14:40 +00:00
38afe22b79 Move Event cancellable parts to trait 2019-01-16 22:14:25 +00:00
9c53b41851 Added PlayerInfo, Player is no longer accessible during PlayerPreLoginEvent 2019-01-13 19:32:30 +00:00
5052b75565 Separate Level management functionality from Server, clean up a bunch of mess 2019-01-12 19:11:05 +00:00
adc1069ed2 Merge branch '3.5' 2019-01-04 23:28:44 +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
7a4e2371e6 master-specific PHPStan nits 2019-01-04 00:40:09 +00:00
e1064a9e36 Merge branch '3.5' 2019-01-04 00:37:48 +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
171be946c6 Network: burn some deprecated stuff 2019-01-01 20:53:33 +00:00
c6a32ccf2a Merge branch 'release/3.5' 2019-01-01 14:08:20 +00:00
f7de6eb59f Network: Deprecate some garbage
Deprecations on a patch version breaks release protocol, but I don't care at this point. Nobody should have been using this shit anyway.
2018-12-31 22:52:39 +00:00
3b183447b0 Merge branch 'release/3.5' 2018-12-31 21:52:48 +00:00
9ed1b5ca7f Event: More detailed errors for non-cancellable events 2018-12-31 21:29:22 +00:00
9f4bb440bd Move server-full/banned/whitelisted controls into PlayerPreLoginEvent
This allows plugins to more easily control the behaviour of server-full, whitelisting and banning. A message can be assigned for each, with a plugin custom reason taking the final priority if set.

This system solves several edge case problems in the Bukkit version by allowing kick reasons to be combined, so that removing one kick reason will roll back the final reason to the next highest, instead of just allowing the player through completely.
Only one message will be shown at point of disconnection, for consistency with the old behaviour.
The message priority is as follows (for all cases, only if set):
- Plugin reason
- Server full
- Whitelist enabled
- Player is banned

This also brings us one step closer to separating Player and NetworkSession.
2018-12-26 13:46:44 +00:00
02efa93e3a PlayerPreLoginEvent: New, more elegant way to control authentication requirement
Previously the only way to deal with this was to cancel the PlayerKickEvent generated by lack of authentication. Now, plugins can decide whether auth should be required for a specific player. The default is whatever xbox-auth is set to in server.properties.

cc @Johnmacrocraft
2018-12-23 18:24:33 +00:00
f313d06070 Merge branch 'release/3.5' 2018-12-23 14:04:29 +00:00