Code Environment - SOF3/pmmp-wilderness GitHub Wiki
Code API (a.k.a. library, SDK)
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.
Code context
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::
).
Variable names
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
$level
refers to an instance of\pocketmine\level\Level
$block
refers to an instance of\pocketmine\block\Block
$item
refers to an instance of\pocketmine\item\Item
$server
refers to the singleton instance of the server (e.g. accessible from\pocketmine\plugin\Plugin::getServer()
)$main
or$plugin
refers 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)$task
can refer to an instance of\pocketmine\scheduler\Task
or\pocketmine\scheduler\AsyncTask
. Forum members are encouraged to emphasize thatAsyncTask
is not a subclass ofTask
, and to emphasize if you are using anAsyncTask
rather than aTask
.- Variables that are lowercase of (the last word of) simple class names (e.g.
$player
forPlayer
,$scheduler
forServerScheduler
): the singleton instance, or should-be-given values appropriate in that context, of the named class. For example,$player
refers to an appropriate instance ofPlayer
(if the question is asking about how to do things on a player), and$event
refers 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 aTraversable
or 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).
Method names
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.
Class names
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 usedDroppedItem
orItemEntity
is the alias forpocketmine\entity\Item
ifpocketmine\item\Item
is also used in the same code snippetItemItem
orItem
is the alias forpocketmine\item\Item
ifpocketmine\entity\Item
is also used in the same code snippetProtocolInfo
forpocketmine\network\protocol\Info
TallGrass
is assumed to bepocketmine\block\TallGrass
TallGrassPopulator
forpocketmine\level\generator\populator\TallGrass
TallGrassObject
forpocketmine\level\generator\object\TallGrass
ObjectOre
forpocketmine\level\generator\object\Ore
ObjectTree
forpocketmine\level\generator\object\Tree
Chest
is assumed to bepocketmine\tile\Chest
TileChest
forpocketmine\tile\Chest
ChestBlock
forpocketmine\block\Chest
Example code/Pseudocode
To be completed.