Inventory

Discussion in 'Development' started by GamakCZ, Mar 16, 2017.

  1. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    567
    GitHub:
    GamakCZ
    How I can backup player s inventory?
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,570
    GitHub:
    muqsit
    PHP:
    /** @var Player $player */
    $inventory $player->getInventory();
    $items = [];
    foreach (
    $inventory->getContents() as $slot => $item) {
        
    $items[$slot] = $item->nbtSerialize(-1"Item");
    }
    file_put_contents($this->getDataFolder().'config.sl'serialize($items));
    PHP:
    $inventory unserialize(file_get_contents($this->getDataFolder().'config.sl'));
    $items = [];
    foreach (
    $inventory as $slot => $item) {
        
    $items[$slot] = $item->nbtDeserialize();
    }
    $player->getInventory()->setContents($items);
     
  3. kaliiks

    kaliiks Zombie

    Messages:
    250
    Yep, Muqsits method is good save items to serialize file then add to player
     
    GamakCZ likes this.
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    567
    GitHub:
    GamakCZ
    Thanks it works.
     
  5. CV71-codes

    CV71-codes Spider

    Messages:
    7
    GitHub:
    craveyou-newcoder
    How D
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.