All Projects → Muqsit → Invmenu

Muqsit / Invmenu

Licence: gpl-3.0
A PocketMine-MP virion to create and manage virtual inventories!

Projects that are alternatives of or similar to Invmenu

Smartinvs
Advanced Inventory API for your Minecraft Bukkit plugins.
Stars: ✭ 132 (+26.92%)
Mutual labels:  inventory, gui
Pytkgen
Create Tkinter GUIs from JSON definition files.
Stars: ✭ 100 (-3.85%)
Mutual labels:  gui
Inventorymanagementsystem
A software developed using Java SE which provides as easy way to track the products, suppliers, customers as well as purchase and sales information. It also records the stock currently available in the store.
Stars: ✭ 94 (-9.62%)
Mutual labels:  inventory
Mgui
Python module for cleaner maya GUI layout syntax
Stars: ✭ 99 (-4.81%)
Mutual labels:  gui
Spamsms
SPAM SMS (-UPDATE 2020!-)
Stars: ✭ 94 (-9.62%)
Mutual labels:  gui
Polished Map
A map and tileset editor for pokecrystal, pokered, and hacks based on them like Polished Crystal. Written in C++ with FLTK.
Stars: ✭ 100 (-3.85%)
Mutual labels:  gui
Nodegui Starter
A starter repo for NodeGui projects
Stars: ✭ 93 (-10.58%)
Mutual labels:  gui
Easyfxml
A collection of tools and libraries for easier development on the JavaFX platform!
Stars: ✭ 102 (-1.92%)
Mutual labels:  gui
Windowsagent
OCS Inventory NG Agent for Windows
Stars: ✭ 100 (-3.85%)
Mutual labels:  inventory
Kflash gui
Cross platform GUI wrapper for kflash.py (download(/burn) tool for k210)
Stars: ✭ 99 (-4.81%)
Mutual labels:  gui
Blender Toolbox Qt
Attempt to recreate a blender like toolbox in Qt
Stars: ✭ 98 (-5.77%)
Mutual labels:  gui
Nordpy
A gui application to connect automatically to the recommended NordVPN server
Stars: ✭ 95 (-8.65%)
Mutual labels:  gui
Ansible Proxmox Inventory
Proxmox dynamic inventory for Ansible
Stars: ✭ 100 (-3.85%)
Mutual labels:  inventory
Bups
Simple GUI for Bup, a very efficient backup system.
Stars: ✭ 94 (-9.62%)
Mutual labels:  gui
Ahk Rare
My collection of rare and maybe very useful functions
Stars: ✭ 101 (-2.88%)
Mutual labels:  gui
Qt Client
This repository contains the source code for the Desktop client. The Desktop client is built using the Qt framework for C++. The client can be extended or customized using JavaScript. This client is used by all editions of xTuple ERP.
Stars: ✭ 93 (-10.58%)
Mutual labels:  inventory
Dockdash
Docker dashboard using Termui
Stars: ✭ 96 (-7.69%)
Mutual labels:  gui
Cata Msx Deadpeopletileset
Tileset for cataclysm dda for use with hair mods.
Stars: ✭ 100 (-3.85%)
Mutual labels:  gui
Whatsappbot
Send messages to any person in any time how much you want.
Stars: ✭ 104 (+0%)
Mutual labels:  gui
Python Examples
Python examples from my answers on Stackoverflow and other short scripts.
Stars: ✭ 101 (-2.88%)
Mutual labels:  gui

InvMenu

InvMenu is a PocketMine-MP virion that eases creating and managing fake inventories!

Installation

You can get the compiled .phar file on poggit by clicking here.

Usage

NOTE: You MUST register InvMenuHandler during plugin enable before you can begin creating InvMenu instances.

if(!InvMenuHandler::isRegistered()){
	InvMenuHandler::register($this);
}

Creating an InvMenu instance

InvMenu::create($identifier) creates a new instance of InvMenu. $identifier must be an identifier of a registered MenuMedata object. InvMenu comes with 3 pre-registered MenuMetadata identifiers by default: InvMenu::TYPE_CHEST, InvMenu::TYPE_DOUBLE_CHEST and InvMenu::TYPE_HOPPER.

$menu = InvMenu::create(InvMenu::TYPE_CHEST);

To access this menu's inventory, you can use:

$inventory = $menu->getInventory();

The $inventory extends pocketmine's Inventory class, so you can use all the fancy pocketmine inventory methods.

$menu->getInventory()->setContents([
	Item::get(Item::DIAMOND_SWORD),
	Item::get(Item::DIAMOND_PICKAXE)
]);
$menu->getInventory()->addItem(Item::get(Item::DIAMOND_AXE));
$menu->getInventory()->setItem(3, Item::get(Item::GOLD_INGOT));

To send the menu to a player, use:

/** @var Player $player */
$menu->send($player);

Yup, that's it. It's that simple.

Specifying a custom name to the menu

To set a custom name to a menu, use

$menu->setName("Custom Name");

You can also specify a different menu name for each player separately during InvMenu::send().

/** @var Player $player */
$menu->send($player, "Greetings, " . $player->getName());

Verifying whether the menu was sent to the player

Not a common occurrence but it's possible for plugins to disallow players from opening inventories. This can also occur as an attempt to drop garbage InvMenu::send() requests (if you send two menus simultaneously without any delay in betweeen, the first menu request may be regarded as garbage).

/** @var string|null $name */
$menu->send($player, $name, function(bool $sent) : void{
	if($sent){
		// do something
	}
});

Handling menu item transactions

To handle item transactions happening to and from the menu's inventory, you may specify a Closure handler that gets triggered by InvMenu every time a transaction occurs. You may allow, cancel and do other things within this handler. To register a transaction handler to a menu, use:

/** @var Closure $listener */
$menu->setListener($listener);

What's $listener?

/**
 * @param InvMenuTransaction $transaction
 *
 * Must return an InvMenuTransactionResult instance.
 * Return $transaction->continue() to continue the transaction.
 * Return $transaction->discard() to cancel the transaction.
 * @return InvMenuTransactionResult
 */
Closure(InvMenuTransaction $transaction) : InvMenuTransactionResult;

InvMenuTransaction holds all the item transction data.
InvMenuTransaction::getPlayer() returns the Player that triggered the transaction.
InvMenuTransaction::getItemClicked() returns the Item the player clicked in the menu.
InvMenuTransaction::getItemClickedWith() returns the Item the player had in their hand when clicking an item.
InvMenuTransaction::getAction() returns a SlotChangeAction instance, to get the slot index of the item clicked from the menu's inventory.
InvMenuTransaction::getTransaction() returns the complete InventoryTransaction instance.

$menu->setListener(function(InvMenuTransaction $transaction) : InvMenuTransactionResult{
	$player = $transaction->getPlayer();
	$itemClicked = $transaction->getItemClicked();
	$itemClickedWith = $transaction->getItemClickedWith();
	$action = $transaction->getAction();
	$inv_transaction = $transaction->getTransaction();
	return $transaction->continue();
});

A handler that doesn't allow players to take out apples from the menu's inventory:

$menu->setListener(function(InvMenuTransaction $transaction) : InvMenuTransactionResult{
	if($transaction->getItemClicked()->getId() === ItemIds::APPLE){
		$player->sendMessage("You cannot take apples out of that inventory.");
		return $transaction->discard();
	}
	return $transaction->continue();
});

Preventing inventory from being changed by players

There are two ways you can go with to prevent players from modifying the inventory contents of a menu.

Method #1: Calling InvMenuTransaction::discard()

$menu->setListener(function(InvMenuTransaction $transaction) : InvMenuTransactionResult{
	// do something
	return $transaction->discard();
});

Method #2: Using InvMenu::readonly()

$menu->setListener(InvMenu::readonly());
$menu->setListener(InvMenu::readonly(function(DeterministicInvMenuTransaction $transaction) : void{
	// do something
}));

Based on your use-case, you may find one better than the other. While Method #1 gives you full control over a transaction (you can conditionally cancel a transaction, f.e based on whether player has permission, or player is in a specific area etc), Method #2 reduces boilerplate InvMenuTransactionResult imports and calls to InvMenutransaction::discard().

Executing a task post-transaction

A few actions are impossible to be done at the time a player is viewing an inventory, such as sending a form — a player won't be able to view a form while viewing an inventory. To do this, you will need to close the menu inventory and make sure they've closed it by waiting for a response from their side. You can do this by supplying a callback to InvMenuTransactionResult::then().

$menu->setListener(function(InvMenuTransaction $transaction) : InvMenuTransactionResult{
	$transaction->getPlayer()->removeWindow($transaction->getAction()->getInventory());
	return $transaction->discard()->then(function(Player $player) : void{ // $player === $transaction->getPlayer()
		// assert($player->isOnline());
		$player->sendForm(new Form());
	});
});
$menu->setListener(InvMenu::readonly(function(DeterministicInvMenuTransaction $transaction) : void{
	$transaction->getPlayer()->removeWindow($transaction->getAction()->getInventory());
	$transaction->then(function(Player $player) : void{
		$player->sendForm(new Form());
	});
}));

Listening players closing or no longer viewing the inventory

To listen inventory close triggers, specify the inventory close Closure using:

/** @var Closure $listener */
$menu->setInventoryCloseListener($listener);

What's $listener?

/**
 * @param Player $player the player who closed the inventory.
 *
 * @param Inventory $inventory the inventory instance closed by the player.
 */
Closure(Player $player, Inventory $inventory) : void;

To forcefully close or remove the menu from a player, you can use

/** @var InvMenuTransaction $transaction */
$transaction->getPlayer()->removeWindow($transaction->getAction()->getInventory());

Writing a custom inventory class

So let's say you'd like to send players a dispenser inventory. Sadly, InvMenu doesn't ship with a InvMenu::TYPE_DISPENSER. You can still create a dispenser InvMenu by registering a MenuMetadata object with the information about what a dispenser inventory looks like.

public const TYPE_DISPENSER = "myplugin:dispenser";

public function registerCustomMenuTypes() : void{
	$type = new SingleBlockMenuMetadata(
		self::TYPE_DISPENSER, // identifier
		9, // number of slots
		WindowTypes::DISPENSER, // mcpe window type id
		BlockFactory::get(Block::DISPENSER), // Block
		"Dispenser" // block entity identifier
	);
	InvMenuHandler::registerMenuType($type);
}

$this->registerCustomMenuTypes();

Sweet! Now you can create a dispenser menu using

$menu = InvMenu::create(self::TYPE_DISPENSER);

InvMenu Wiki

Applications, examples, tutorials and featured projects using InvMenu can be found on the InvMenu Wiki.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].