Windowy is a temporary inventory generator and manager, focused on item transactions, for PocketMine-MP.
Functional as a Plugin and Library, for multiple different tasks.
# Do the following function in your PluginBase to activate it (WindowyLibrary).
if(Windowy::hasHolder() === false){
Windowy::setHolder($this);
}
use DayKoala\inventory\WindowIds;
$id = WindowIds::CHEST;
$id = WindowIds::DOUBLE_CHEST;
$id = WindowIds::FURNACE;
$id = WindowIds::HOPPER;
use DayKoala\inventory\WindowFactory;
/**
*
* @param String $id
* @param String|null $name
* @return SimpleWindow|null
*
*/
$window = WindowFactory::getInstance()->get($id, $name);
use DayKoala\Windowy;
$window = Windowy::getWindow($id, $name);
not mandatory
for you to fill in the name
of the inventory, if you do not fill it or leave it in null
, the result will be the name of the inventory selected by the id
.SimpleWindow extension
, otherwise it won't work. Register your inventory
like this:
use DayKoala\block\BlockEntityMetadata;
use pocketmine\network\mcpe\protocol\types\inventory\WindowTypes;
use pocketmine\block\tile\Tile;
use pocketmine\block\BlockLegacyIds;
/**
*
* @param Int $network
* @param Int $size
* @param BlockEntityMetadata $metadata
*
*/
$window = new MyWindow(WindowTypes::CONTAINER, 27, new BlockEntityMetadata(Tile::class, BlockLegacyIds::Block));
/**
*
* @param String $id
* @param SimpleWindow $inventory
* @param boolean $override
*
*/
WindowFactory::register('MyWindow', $window, $override);
added before or after
registration, as well as items and derivatives. You can add a specific action
to your inventory using:
use DayKoala\inventory\action\WindowTransaction;
$callback = function(WindowTransaction $action){
$player = $action->getPlayer();
$player->sendMessage("I won't let you take this item haha!");
$action->cancel();
};
/**
*
* @param Closure $callback
* @return self
*
*/
$window->setTransaction($callback);
a certain item
to have some action
in the inventory, you can use:
$window->setItem($slot, $item, $callback);
or
/**
*
* @param Item $item
* @param Closure $callback
* @return self
*
*/
$window->setItemCallback($item, $callback);
transaction is not canceled
and the item moved from its defined slot, the item's action will be removed
.closing a window
with a different action can help you, so you can add an action
when closing it using:
use DayKoala\inventory\action\WindowAction;
$callback = function(WindowAction $action){
$player = $action->getPlayer();
$player->sendMessage("Closing...");
};
/**
*
* @param Closure $callback
* @return self
*
*/
$window->setCloseCallback($callback);