Generalized user interface framework for PocketMine plugins.

Related tags

Frameworks ActionApi
Overview

ActionApi

Generalized user interface framework for PocketMine plugins.

How does this work?

ActionApi introduces the following concepts:

Action

Action is an interface implemented by plugins to represent something that a user can do.

Each action type implements a new subclass of Action. A new instance of Action is created for every execution. An Action subclass holds the arguments required for the action.

Arg

Arg is an argument that the user provides to customize the action. They can be inferred from the Hook (action trigger), or separately requested from the user.

Implementations provided by ActionApi:

Type Command line support Form UI support Inference from Hook
StringArg Yes (single argument or space implosion) Yes (CustomForm Input) None
StringEnumArg Yes (single argument) Yes (CustomForm Dropdown, or CustomForm StepSlider, or MenuForm) None
StringEnumSetArg Yes (last argument only, or if delimiter is provided) Yes (CustomForm Toggles) None
IntArg Yes Yes (CustomForm Slider, or CustomForm Input) None
FloatArg Yes Yes (CustomForm Slider, or CustomForm Input) None
BoolArg Yes Yes (CustomForm Toggle, or ModalForm) None
GenericListArg Yes if element type supports (rearranged as last argument, variadic) Yes if element type supports (interactive loop) If element type is inferrable, singleton list
PlayerArg (online players only) Yes (by name prefix or full name) Yes (CustomForm Dropdown, or MenuForm) If hook is clicking on a player
PlayerSetArg (online players only) Yes (comma-separated) Yes (CustomForm Toggles) None
EntityArg No Yes (click on entity in world) If hook is clicking on an entity
BlockTypeArg Yes (by name, with variant colon-separated) Yes (interactive selector with search button) If hook is clicking on a block
ItemArg Yes (by name, with damage and count colon-separated) Yes (interactive selector with search button) If hook is clicking on air, a block or entity (default value is currently held item)
ItemTypeArg Yes (by name, with damage colon-separated) Yes (interactive selector with search button) If hook is clicking on air, a block or entity (default value is currently held item)
PositionArg Yes (by typing x y z world-name) Yes (CustomForm Dropdown to select current position, CustomForm Input, current crosshair target or next-click position) If hook is clicking on a block or entity (otherwise)
WorldArg Yes (world name) Yes (CustomForm Dropdown, or MenuForm) None (default value is player current world)
WorldSetArg Yes (last argument only) Yes (CustomForm Toggles) None
YawArg Yes (in degrees, not recommended) Yes (CustomForm Slider) Player current orientation
PitchArg Yes (in degrees, not recommended) Yes (CustomForm Slider) Player current orientation
DateTimeArg Yes (ISO 8601, or + + duration) Yes (CustomForm Sliders for YMDhmsZ) None
DurationArg Yes (single argument, e.g. 1w2d3h4m5s) Yes (interactive loop with CustomForm Input + Dropdown for unit) None

Inference from Hook may be suppressed as the default value instead of silently selected by an extra flag from the constructor call in the Action implementation.

Hook

Hook is the method that the user used to trigger the initiation of this action. It stores data related to the trigger.

Implementations provided by ActionApi:

  • command
  • block click
  • air click
  • entity click
  • item selection
  • hotbar switch
  • action menu (a navigation index for actions defined in config.yml)

Example Action implementation

final class AddWarpAction implements Action {
	private DataProvider $db;

	private ?string $name = null;
	private ?Position $pos = null;
	private ?bool $open = null;

	public function __construct(DataProvider $db) {
		$this->db = $db;
	}

	public function isMissingArg() : bool {
		return $this->name === null || $this->pos === null || $this->open === null;
	}

	public function getArguments() : iterable {
		yield StringArg::new("Warp name", $this->name);
		yield PositionArg::new("Warp position", $this->pos);
		yield BoolArg::new("Open to public?", $this->open)->default(true);
	}

	public function run(CommandSender $sender) : void {
		$this->db->addWarp($this->name, $this->pos->getX(), $this->pos->getY(), $this->pos->getZ(),
				$this->pos->getWorld()->getFolderName(), $this->open);
		$sender->sendMessage("Warp \"$this->name\" created at $this->pos");
	}
}

Implementing Arg and Hook

If the existing arguments are not sufficient, other plugins can implement additional Arg types. Plugins that want to trigger actions from other methods can also implement their own Hook types.

Each Arg supports command line and form UI interface. However, if an Arg additionally infers arguments from a Hook, the logic is implemented under a separate Inferrer interface. Plugins may register an Inferrer instance that supports a specific type of Arg and a specific type of Hook. An example implementation for inferring EntityArg from an EntityClickHook:

final class EntityClickItemInferrer implements Inferrer {
	public function infer(Hook $hook) {
		assert($hook instanceof EntityClickHook); // this is true if you registered the inferrer for the correct class
		return $hook->getClickedEntity();
	}
}
You might also like...
Framework X – the simple and fast micro framework for building reactive web applications that run anywhere.

Framework X Framework X – the simple and fast micro framework for building reactive web applications that run anywhere. Quickstart Documentation Tests

Framework X is a simple and fast micro framework based on PHP
Framework X is a simple and fast micro framework based on PHP

Framework X is a simple and fast micro framework based on PHP. I've created a simple CRUD application to understand how it works. I used twig and I created a custom middleware to handle PUT, DELETE methods.

Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components
Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components

Spiral HTTP Application Skeleton Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components.

Sunhill Framework is a simple, fast, and powerful PHP App Development Framework

Sunhill Framework is a simple, fast, and powerful PHP App Development Framework that enables you to develop more modern applications by using MVC (Model - View - Controller) pattern.

A PHP framework for web artisans.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

The Symfony PHP framework

Symfony is a PHP framework for web and console applications and a set of reusable PHP components. Symfony is used by thousands of web applications (in

Open Source PHP Framework (originally from EllisLab)

What is CodeIgniter CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Its goal is to enable

Yii 2: The Fast, Secure and Professional PHP Framework
Yii 2: The Fast, Secure and Professional PHP Framework

Yii 2 is a modern framework designed to be a solid foundation for your PHP application. It is fast, secure and efficient and works right out of the bo

CakePHP: The Rapid Development Framework for PHP - Official Repository

CakePHP is a rapid development framework for PHP which uses commonly known design patterns like Associative Data Mapping, Front Controller, and MVC. O

Owner
Jonathan Chan Kwan Yin
a.k.a. SOFe, @chankyin, @PEMapModder
Jonathan Chan Kwan Yin
A Yii2 module for embedding social plugins and widgets.

yii2-social Module that enables access to social plugins for Yii Framework 2.0. It includes support for embedding plugins from the following networks

Kartik Visweswaran 92 May 29, 2022
Adapters for PHP framework containers to an interoperable interface

Get Acclimated! Use any third-party dependency injection containers and service locators in your code by adapting them to a common container interface.

Acclimate Container 215 Dec 16, 2022
FreeSWITCH's Event Socket Layer is a TCP control interface enabling the development of complex dynamic dialplans/workflows

Asynchronous Event Socket Layer library for PHP Quickstart FreeSWITCH's Event Socket Layer is a TCP control interface enabling the development of comp

rtckit 3 Oct 11, 2022
"Static" interface for various Slim features

SlimFacades SlimFacades is a collection of facades for Slim PHP microframework, providing simple "static" interface for various Slim features. For exa

its 74 May 12, 2022
Laravel 8 Project Restrict User Access From IP Addresses. prevent other ip address that want to access over secure api or urls.

block-ip-address-laravel Laravel 8 Project Restrict User Access From IP Addresses. prevent other ip address that want to access over secure api or url

Hasmukh Dharajiya 2 Mar 24, 2022
A pocketmine-mp server that we develop live on Twitch every Saturday from 8pm to 10pm (FR)

Server A pocketmine-mp server that we develop live on Twitch every Saturday from 8pm to 10pm (FR) Contributing Pull requests are welcome. For major ch

Gaëtan H 11 Oct 9, 2022
CleverStyle Framework is simple, scalable, fast and secure full-stack PHP framework

CleverStyle Framework is simple, scalable, fast and secure full-stack PHP framework. It is free, Open Source and is distributed under Free Public Lice

Nazar Mokrynskyi 150 Apr 12, 2022
I made my own simple php framework inspired from laravel framework.

Simple MVC About Since 2019, I started learning the php programming language and have worked on many projects using the php framework. Laravel is one

null 14 Aug 14, 2022
PHPR or PHP Array Framework is a framework highly dependent to an array structure.

this is new repository for php-framework Introduction PHPR or PHP Array Framework is a framework highly dependent to an array structure. PHPR Framewor

Agung Zon Blade 2 Feb 12, 2022
I made my own simple php framework inspired from laravel framework.

Simple MVC About Since 2019, I started learning the php programming language and have worked on many projects using the php framework. Laravel is one

Rizky Alamsyah 14 Aug 14, 2022