95 Commits

Author SHA1 Message Date
Dylan K. Taylor
2d3ce9e8b0 Remove some fully qualified function calls
PhpStorm can't see these or understand how they are being called, which is very annoying for bug hunting. Additionally, we already have the CodeOptimizer for this.
2018-06-18 12:23:19 +01:00
Dylan K. Taylor
77f3ca4d47 PluginManager: make isCompatibleApi() a bit less sub optimal 2018-06-17 11:13:48 +01:00
Dylan K. Taylor
0ff6b7b572 PluginManager: Track enabled plugins in a separate array 2018-06-13 16:54:04 +01:00
Dylan K. Taylor
fe29b89fd1 Store plugin data in <data path>/plugin_data in new installations
This will preserve the old behaviour for existing installations.
2018-06-13 12:57:41 +01:00
Dylan K. Taylor
c835c97aba Fixed phar plugins not reading resources correctly 2018-06-13 12:07:27 +01:00
Dylan K. Taylor
5a55d434ab Nuke plugin loaders from orbit
This features a near-total rewrite of PluginLoaders and some code associated with them.

Highlights:
- PluginManager->registerInterface() does not return anything, and now accepts a PluginLoader instance instead of a string.
- PluginLoader itself is drastically simplified. getPluginFilters(), enablePlugin() and disablePlugin() are now removed. loadPlugin() responsibilities are now solely confined to doing whatever is necessary to make the plugin's classes visible by the server, and does not emit log messages or check for data directories.
- PluginBase->init() and PluginBase->isInitialized() have been removed.
- Plugin interface now declares a signature for the constructor which implementations must comply with.
- Plugin interface now declares setEnabled().
2018-06-12 10:23:49 +01:00
Dylan K. Taylor
19d2d6b91c PluginManager: use null coalesce in getPermission() 2018-06-11 16:38:27 +01:00
Dylan K. Taylor
dce8ed9dd1 Eliminate more hard dependencies on MainLogger 2018-06-04 16:52:03 +01:00
Dylan K. Taylor
15270f8329 Fixed plugin schedulers crashing after disable/reenable 2018-05-31 12:34:22 +01:00
Dylan K. Taylor
51f43fb375 Removed global ServerScheduler - plugins now get their own isolated schedulers
This change breaks pretty much all API pertaining to synchronous task scheduling.

Significant changes:
- Server->getScheduler() has been removed
- Plugin->getScheduler() has been added - every plugin now has its own scheduler
- Because schedulers are now per-plugin, it is now unnecessary for PluginTask to exist because stopping plugin tasks on plugin disable is as simple as destroying the plugin's scheduler. Therefore PluginTask has now been removed and it is expected for things to now use the base Task class instead.

For the most part, plugins will simply need to change Plugin->getServer()->getScheduler()->... to Plugin->getScheduler()->...
Another highlight is that plugin tasks now no longer have global IDs - they are unique to each scheduler.
2018-05-30 14:11:11 +01:00
Dylan K. Taylor
34b8557094 Moved parseDocComment from PluginManager to Utils 2018-05-13 11:24:04 +01:00
Dylan K. Taylor
7565b786e7
Implemented @notHandler annotation for event handlers - skip registering any handlers with this annotation (#2164)
It is somewhat reasonable to have a function in an event handler which accepts an Event parameter, but is not a handler. For example, multiple event handlers can redirect to the same function to process an event, but this function may not want to receive called events.

There are other ways to get around this, such as making the event handler protected/private, or adding a dummy parameter, but this way is cleaner and more explicit.

Relevant old-repo PR: PocketMine/PocketMine-MP#2143
2018-05-04 21:36:58 +01:00
Dylan K. Taylor
b4068dfd2f remove unused import 2018-05-02 10:44:05 +01:00
SOFe
3293074cfc Implement @softDepend annotation for event handlers - skip registering if the event class is undefined (#2162)
This allows plugins to soft-depend on other plugins without separating their listeners into a dedicated class for listening to that plugin.

This can be utilized by adding a `@softDepend PluginName` to the event handler's annotations.
If the plugin providing the event does not exist or is not loaded, then the handler will silently not be registered.
If it does exist and the event is not found, the original behaviour applies and an exception will be thrown.

This change should be fully backwards compatible.
2018-05-01 14:33:24 +01:00
Dylan K. Taylor
5f52e00213 Fixed plugin loaders trying to load plugins they aren't able to load
closes #2125

This is an API break for things implementing the PluginLoader interface.
2018-04-09 15:54:20 +01:00
Dylan K. Taylor
eba1ca030c Fix variadic type docs ...again
PhpStorm changed its mind how it wants these documenting in 2018.1, and apparently the correct syntax follows the PHP code.
2018-04-02 12:33:24 +01:00
Johnmacrocraft
b151cb26a5 Fix deprecated event message (#2127) 2018-03-30 11:09:24 +01:00
SOFe
c19cf22ac5
Fixed #2110 2018-03-21 21:52:55 +08:00
Dylan K. Taylor
d2fb32c28a PluginManager: added event call recursion limit, closes #2109
This prevents unexplained segfaults on accidental event call recursion by limiting the max depth of event call stack to 50. If another event attempts to be called, an exception will be thrown.
2018-03-21 10:40:08 +00:00
SOFe
49fbbea7bf Implemented event handler inheritance, allow registering handlers for any valid event (#1792)
* Event handlers always handle subclass events. public static $handlerList no longer required.
* Removed $handlerList declarations
* HandlerList cleanup: Removed HandlerList->handlers and related bake methods
* Removed obsolete Event->getHandlers()
* EventPriority: Added fromString()
* PluginManager: throw exceptions on registering handlers with invalid priorities

This allows specifying a handler of `EntityDamageEvent` which will handle any instanceof it (as per current behaviour), AND also now allows specifying a handler specifically for `EntityDamageByEntityEvent`, which only handles `EntityDamageEvent`.

This was not previously possible due to limitations in the way handlers were registered.

Abstract events may not be handled unless they declare the `@allowHandle` PhpDoc tag.
2018-03-20 17:05:09 +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
7dd834bca0 Fixed API patch version being useless
Plugins will now be able to require a specific minimum patch version, in case they depend on bug fixes or whatever.
2018-02-15 21:45:46 +00:00
Dylan K. Taylor
0bf5ab76fb Remove WeakRef leftovers 2018-01-23 19:04:37 +00:00
Dylan K. Taylor
38ec5da260 Refactored API compatibility checking code into its own method (#1394)
Refactored API compatibility checking code into its own method so plugins can use it
this change was inspired by https://github.com/poggit/devirion/blob/master/src/poggit/virion/devirion/DEVirion.php#L140-L172
2017-09-24 15:00:08 +01:00
Dylan K. Taylor
d065e76a41 Fixed plugins with unknown dependencies saying they have circular dependencies, close #356 (#1342) 2017-09-04 19:41:21 +01:00
Dylan K. Taylor
c81b76cbf6 Make plugin load errors more descriptive 2017-09-01 18:52:55 +01:00
Dylan K. Taylor
506118e28f Fixed exception thrown when plugins specify API version like 3.0 instead of 3.0.0
This could only be seen in a build with a non-suffixed API version, for example 3.0.0. When attempting to load plugins which specify API like 3.0 the server would raise errors.
2017-09-01 18:13:07 +01:00
Dylan K. Taylor
6e8631347d Added capability to specify compatible protocol versions in plugin.yml (#1247)
Protocol-dependent plugins may specify the `mcpe-protocol` attribute in plugin.yml to disallow plugin loading when the protocol changes.
2017-09-01 17:57:40 +01:00
Dylan K. Taylor
5b4035253b Casting cleanup and removed some 32-bit string-int leftovers 2017-08-17 11:24:49 +01:00
Dylan K. Taylor
dbb92096e4 More typehints, documentation fixes and static analysis cleanup 2017-07-15 12:12:06 +01:00
Dylan K. Taylor
c3b8be3f60 and more typehints 2017-07-14 10:56:51 +01:00
Dylan K. Taylor
8bb0c53797 More typehints for Command stuff 2017-07-14 08:52:27 +01:00
Dylan K. Taylor
2a7b736f18 Heap of bugfixes, cleanup and PHP 7 upgrades 2017-07-13 19:18:56 +01:00
Dylan K. Taylor
51b0673b4b Bite the bullet and enable strict types on everything 2017-06-07 12:53:16 +01:00
Dylan K. Taylor
3f03d9e683 Fixed DevTools getting disabled when a plugin throws an exception during load (#1025) 2017-06-07 11:12:47 +01:00
SOFe
c7c7a40899 Added "extensions" attribute in plugin.yml with version checking (#903)
* Added "extensions" attribute in plugin.yml with version checking

* Renamed getExtensions() to getRequiredExtensions()

As per recommendation from @dktapps
2017-05-15 10:04:26 +01:00
Dylan K. Taylor
dbb8e8ad0a Improved checks for event registration 2017-05-14 12:07:15 +01:00
Dylan K. Taylor
0c35c16727 Fix some doc comments 2017-02-06 14:50:05 +00:00
Dylan K. Taylor
26fc21d56c API version suffix is now non case sensitive 2017-01-19 10:57:32 +00:00
Dylan K. Taylor
b28e38ab26 Move some exceptions out of utils into their relevant namespaces, move some Chunk methods to ChunkUtils for I/O, refactor "colour" -> "color" 2017-01-15 11:31:12 +00:00
Dylan K. Taylor
3433a931c1 Fix load order (no tolerance for mismatches with suffixes) 2016-12-19 19:30:11 +00:00
Dylan K. Taylor
71704228a9 Added support for API alpha/beta/whatever suffixes 2016-12-19 18:08:45 +00:00
SOF3
6fc435da0e
Imports rearrangement 2016-10-03 00:43:46 +08:00
PEMapModder
13d1089d30 Fixed PluginManager:: type doc 2016-03-23 23:57:02 +08:00
Shoghi Cervantes
0bcf639a98 Changed how exceptions work and are logged, throw proper exceptions on tasks 2015-09-18 12:03:24 +02:00
Shoghi Cervantes
e137ac4c56 Base PHP7 work to make it "run" - READ NEXT LINES!
All plugins will need to bump the API if they want to use this.
NOTE THAT THIS IS NOT THE FINAL API 2.0.0 AND THAT THERE WILL BE MORE CHANGES.
To start updating, you might also want to read https://secure.php.net/manual/en/migration70.php and specifically https://secure.php.net/manual/en/migration70.incompatible.php

To compile PHP7 with some of the required dependencies, use https://gist.github.com/shoghicp/166ab26ce5cc7a390f45
ONLY LINUX IS TESTED, DO NOT ASK FOR OTHER PLATFORMS!

----- THIS VERSION IS NOT SUPPORTED -----

This version WILL crash randomly in unexpected places due to PHP7, pthreads, PocketMine or cosmic rays.

Handle with care, and store under direct sunlight for the best performance.
2015-09-10 21:29:29 +02:00
Shoghi Cervantes
34dc6ea0d6 NOTE! THIS SHOULD BE REVERTED LATER! Removed WeakRef dependency 2015-08-23 00:25:29 +02:00
Michael Yoo
ff232a9f04 Merge pull request #3332 from PEMapModder/dec
Disallow registration of events without handlerList, fixes #3330
2015-08-11 16:12:59 +09:30
PEMapModder
d5c2702908 Update PluginManager.php 2015-08-10 22:14:11 +08:00