Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help with my code.

Comments in 'Plugin Development' started by iiDeathStrokeii, Aug 13, 2015.

  1. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    Xenturio before I even try that it says that $player data is undefined in this line:
    $data = $playerdata->getAll();
    although I DID define it:
    $playerdata = new Config($this->getDataFolder()."players/".$player->getName().".json", Config::JSON);
  2. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
  3. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    try.
    PHP:
    public $item;
    $this->item = new Item($id,$damage,$ammount);
    $player->getInventory()->addItem($this->item);
  4. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    My original code saves the inventory but doesnt give it back.
    WHAT i need to figure out is how to give thr inventory back
  5. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    You want to give it back from the json file?
  6. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    yes! :)
  7. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    the inventory data saves perfectly
  8. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Do yaml like this.
    PHP:
    public $items;
    $data mkdir($this->getDataFolder() . "players/" .  strtolower($player->getName() ) . ".yml"Config::YAML);
    if(
    $data->exists("items")){
    $n 0;
    $items $data->get("items");
    $i explode(":",$items);
    $inv[$n] = new Items($items[0],$items[1],$items[2]);
    $n++;
    $p->getInventory()->setItems($items);
    }
  9. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    maybe you dont set the variable PUBLIC and used with $this->
    public $playerdata;
    ***
    onEnable
    $this->playerdata = new Config($this->getDataFolder()."players/".$player->getName().".json", Config::JSON);

    onMove(or something else)
    $data = $this->playerdata->getAll();
  10. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    like this
    PHP:
        public function PlayerJoinEvent(PlayerJoinEvent $event){
            
    $player $event->getPlayer();
            
    $ign $player->getName();
            
    $inv $player->getInventory();
            
    $datafile = ($this->getDataFolder() . "players/".$ign.".json");
                if(!
    file_exists($datafile)){
                    
    $this->playerdata = new Config($this->getDataFolder()."players/".$player->getName().".json"Config::JSON);
                }
                    if(
    file_exists($datafile)){
                            
    $data = ($this->getDataFolder()."players/".$player->getName().".json");
                            if(
    $data->exists("items")){
                            
    $n 0;
                            
    $items $data->get("items");
                            
    $i explode(":",$items);
                            
    $inv[$n] = new Items($items[0],$items[1],$items[2]);
                            
    $n++;
                            
    $player->getInventory()->setItems($items);
    }
                            }
                    }
      
     
        public function 
    PlayerQuitEvent(PlayerQuitEvent $event){
            
    $player $event->getPlayer();
            
    $inventory $player->getInventory();
            
    $items = [];
            
    $playerdata = new Config($this->getDataFolder()."players/".$player->getName().".json"Config::JSON);
            foreach(
    $inventory->getContents() as $slot => $item){
                
    $playerdata->set($slot"$item->getId():$item->getDamage():$item->count");
            }
    }
  11. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
  12. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    foreach($inventory->getContents() as $slot => $item){$this->playerdata->set($slot, "$item->getId():$item->getDamage():$item->count");
    }
  13. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  14. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    That's just wrong.
  15. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    That's just wrong.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That isn't wrong, depending on what you want to do.

Share This Page

Advertisement