-
Notifications
You must be signed in to change notification settings - Fork 2
Code Environment
Unless otherwise specified, the API for plugin development questions is assumed to be the latest commit on the PocketMine repository, on the master branch or any branch that is considerably dominant in development (such as the core-rewrite or mcpe-0.12 branches in the past), at the time of posting, as well as that on any other repositories of dependency plugins specified.
If no context is given, any code put in [PHP] tags is assumed to be in the context of (a non-static class method in) a plugin's main class, run in the main thread. A context only refers to where the code is put at, not when the code is run (i.e. the stack is not relevant, e.g. in a task, in an event handler, in a command handler, doesn't matter). In simple words, this context should only affect the values of $this, self:: and static::. (parent:: is assumed to be equivalent to PluginBase::).
Here are some variables that are common sense under some contexts:
-
$this: see above -
$cmd: abbreviation of$command, instance of\pocketmine\command\Command -
$ev,$evt: abbreviation of$event, instance of\pocketmine\event\Event -
$inv: abbreviation of$inventory, instance of\pocketmine\inventory\Inventory -
$levelrefers to an instance of\pocketmine\level\Level -
$blockrefers to an instance of\pocketmine\block\Block -
$itemrefers to an instance of\pocketmine\item\Item -
$serverrefers to the singleton instance of the server (e.g. accessible from\pocketmine\plugin\Plugin::getServer()) -
$mainor$pluginrefers to the singleton instance of the main class of the plugin (the one that you can get from\pocketmine\plugin\PluginManager::getPlugin(), in case there is discussion about multiple instances of the main class) -
$taskcan refer to an instance of\pocketmine\scheduler\Taskor\pocketmine\scheduler\AsyncTask. Forum members are encouraged to emphasize thatAsyncTaskis not a subclass ofTask, and to emphasize if you are using anAsyncTaskrather than aTask. - Variables that are lowercase of (the last word of) simple class names (e.g.
$playerforPlayer,$schedulerforServerScheduler): the singleton instance, or should-be-given values appropriate in that context, of the named class. For example,$playerrefers to an appropriate instance ofPlayer(if the question is asking about how to do things on a player), and$eventrefers to the current event in event handlers (the event in the nearest stack level if an event is fired within another). - In addition to the above rule, the plural form of these words, such as
$players, refers to an array or aTraversableor instances of that type.
If a variable contains values provided in the question or other places, the type of the variable should be specified (the class of an object variable, the type of a resource variable, or the scalar type of a scalar variable).
As mentioned above, the context of a method is assumed to be in the main class if not specified, and therefore methods like onEnable, onCommand are assumed to override/implement their parent implementations.
Exceptionally, the method onRun($t) (the parameter name doesn't matter) refers to an implementation of a PluginTask.
A public method that accepts only one parameter that is an event is assumed to be a registered event handler function.
A class may be referred to with its simple name (namespace removed). However, some names exist with the same name in different namespaces in PocketMine, so here lists some assumptions of what they refer to. Here also lists some commonly-used aliases.
-
Item: We usually assume it to bepocketmine\item\Item, especially ifItem::get()is used -
DroppedItemorItemEntityis the alias forpocketmine\entity\Itemifpocketmine\item\Itemis also used in the same code snippet -
ItemItemorItemis the alias forpocketmine\item\Itemifpocketmine\entity\Itemis also used in the same code snippet -
ProtocolInfoforpocketmine\network\protocol\Info -
TallGrassis assumed to bepocketmine\block\TallGrass -
TallGrassPopulatorforpocketmine\level\generator\populator\TallGrass -
TallGrassObjectforpocketmine\level\generator\object\TallGrass -
ObjectOreforpocketmine\level\generator\object\Ore -
ObjectTreeforpocketmine\level\generator\object\Tree -
Chestis assumed to bepocketmine\tile\Chest -
TileChestforpocketmine\tile\Chest -
ChestBlockforpocketmine\block\Chest
To be completed.
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to http://unlicense.org
-
FAQ
-
PHP
- 🌐 Syntax errors
- [[ClassNotFoundException: Class
a class in your pluginnot found|PocketMine Plugin Development FAQ#classnotfoundexception class a class in your plugin not found]]
- Command API
- Event API
-
Scheduler API & Threading
- Cancelling tasks
- [[Difference between
schedule***Task|PocketMine Plugin Development FAQ#what is different between scheduledelayedtask, schedulerepeatingtask, scheduledelayedrepeatingtask and scheduleasynctask]] - What is threading? Does it make the server faster?
- AsyncTask: An analogy of a restaurant
- What can be done in AsyncTasks
- Data Saving
- The Virions framework
-
PHP