Phpcraft
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
Phpcraft\Plugin Class Reference

Public Member Functions

 __construct (string $folder, string $name)
 
 fire (Event $event)
 

Public Attributes

 $name
 
 $event_handlers = []
 

Protected Member Functions

 on (Closure $function, int $priority=Event::PRIORITY_NORMAL)
 
 registerCommand ($names, callable $function, ?string $required_permission=null)
 
 unregister ()
 

Constructor & Destructor Documentation

◆ __construct()

Phpcraft\Plugin::__construct ( string  $folder,
string  $name 
)

Don't call this unless you know what you're doing.

Parameters
string$folderThe path of the folder the plugin was loaded from.
string$nameThe name of the plugin.
See also
PluginManager::loadPlugins()

Member Function Documentation

◆ fire()

Phpcraft\Plugin::fire ( Event  $event)

Fires the event handler for the given event with its data as parameter.

Parameters
Event$event
Returns
boolean True if the event was cancelled.

◆ on()

Phpcraft\Plugin::on ( Closure  $function,
int  $priority = Event::PRIORITY_NORMAL 
)
protected

Defines a function to be called to handle the given event.

Parameters
Closure$functionThe function. The first parameter should explicitly declare its type to be a decendant of Event.
int$priorityThe priority of the event handler. The higher the priority, the earlier it will be executed. Use a high value if you plan to cancel the event.
Returns
Plugin $this

@noinspection PhpDeprecationInspection

◆ registerCommand()

Phpcraft\Plugin::registerCommand (   $names,
callable  $function,
?string  $required_permission = null 
)
protected

Registers a command.

Parameters
string|array<string>$names One or more names without the / prefix. So, if you want a "/gamemode" comand, you provide "gamemode", and if you want a "//wand" command, you provide "/wand".
callable$functionThe function called when the command is executed. The first argument will be the CommandSender but if type-hinted to be ClientConnection or Server it will be exclusive to players or the server, respectively. Further arguments determine the command's arguments, e.g. ->registerCommand("gamemode", function(ClientConnection &$con, int $gamemode){...}) would result in the player-exclusive command /gamemode <gamemode> where the gamemode argument only allows integers.
string | null$required_permissionThe permission required to use this command or null if not applicable.
Returns
Plugin $this

◆ unregister()

Phpcraft\Plugin::unregister ( )
protected

Unregisters the plugin, including its event handlers and its commands. Make sure your plugin has no statements other than return; after this.

Returns
void

Member Data Documentation

◆ $event_handlers

array< array{function:Closure, priority:int}> Phpcraft\Plugin::$event_handlers = []

◆ $name

string Phpcraft\Plugin::$name

The name of the plugin.