Skip to content

A PocketMine-MP plugin to easily save inventories in a database.

License

Notifications You must be signed in to change notification settings

Nathan459770/InventoryManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

InventoryManager 


A PocketMine-MP plugin to easily save inventories in a database.

Usage

  • Download this plugin
  • You can put it on your server or put the api in the src of your plugin
  • To use it you'll have to import DatabaseManager object and the InventoryManager object.

Be careful !

If you have put the api in your folder, you need to run these lines of code in the onEnable function of your main file

    $db = DatabaseManager::getInstance();
       
    if(!$db->isEnabled()){
        $db->init();
    }

Basic Usage

Import the classes

You'll need to import these classes in order to easily use it within our code.

<?php
use Nathan45\Inventories\DatabaseManager;
use Nathan45\Inventories\InventoryManager;

Access to managers

DO NOT use new !
YOU MUST USE getInstance() function as shown below.

$db = DatabaseManager::getInstance();
$api = InventoryManager::getInstance();

Functions

There are 7 main functions which are all in the InventoryManager class

  • getAllData() > it returns an array with all existing player inventories, it follows this pattern: $array[$player][$id] = [item1, item2, etc].
  • setAllData(array $inventories) > It replaces all existing player inventories by the given array.
  • getInventoriesFor(Player|string $player) > This function returns all inventories of the given player in the order.
  • getInventoryFor(Player|string $player, string|int $inventoryId) > This function returns the player's inventory corresponding to the given id.
  • setInventoriesFor(Player|string $player, array $inventories) > This function sets all ths inventories of the given player in the order.
  • setInventoryFor(Player|string $player, string|int $id, array $inventories) > This function sets the player's inventory corresponding to the given id.
  • updateDataFor(string $player) > This function stores the player's inventories in the database.

##Here is a basic example with an event

public function onUseItem(PlayerItemUseEvent $event): void{

        $api = InventoryManager::getInstance();
        $player = $event->getPlayer();

        switch ($event->getItem()->getId()){
            case ItemIds::GOLD_INGOT:
                $api->setInventoryFor($player, "gold_inventory", $player->getInventory()->getContents()); // You can also put an int as id.
                break;

            case ItemIds::GOLD_BLOCK:
                $player->getInventory()->setContents($api->getInventoryFor($player, "gold_inventory"));
                break;
        }
    }

About

A PocketMine-MP plugin to easily save inventories in a database.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages