-
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
-
$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).
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 -
DroppedItem
orItemEntity
is the alias forpocketmine\entity\Item
ifpocketmine\item\Item
is also used in the same code snippet -
ItemItem
orItem
is the alias forpocketmine\item\Item
ifpocketmine\entity\Item
is also used in the same code snippet -
ProtocolInfo
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
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 plugin
not 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