1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Inventory problem !

Discussion in 'Development' started by TrixZSlow, Nov 20, 2016.

  1. TrixZSlow

    TrixZSlow Spider Ban Evader

    Messages:
    9
    When I click the inventory appears and then disappears how to fix it please ?
    File 1
    PHP:
        public function onTouchh(PlayerInteractEvent $event) {
             
    $Player $event->getPlayer();
                                    
    $Level $Player->getLevel();
     
                                            
    $Type = ($Level->getFolderName() == $this->plugin->lobby_name) ? 0;
                                            
    $X round($Player->getX() - 0.5);
                                            
    $Z round($Player->getZ() - 0.5);
                                            if (
    $Level->getBlockIdAt($X,0,$Z) != 54)
                                                {
                                                    
    $Level->setBlock(new Vector3($X,0,$Z),Block::get(54),true,true);
                                                    
                                            
    $nbt = new CompoundTag("", [
                new 
    ListTag("Items", []),
                new 
    StringTag("id"Tile::CHEST),
                
    $this->plugin
            
    ]);
            
    $nbt->Items->setTagType(NBT::TAG_Compound);
            
    $tile Tile::createTile("Chest"$Level->getChunk($X >> 4,$Z >> 4), $nbt);           

                                                    
    //$chest = new Chest($Level->getChunk($X >> 4,$Z >> 4,true),new CompoundTag(false,array( new IntTag("x",$X), new IntTag("y",0), new IntTag("z",$Z), new StringTag("id",Tile::CHEST))),$this->plugin);
                                                    
    $Level->addTile($tile);
                                                    
                                                }
                                                else 
    $chest $Level->getTile(new Vector3($X,0,$Z));
                                                if (
    $Level->getBlockIdAt($X,1,$Z) != 54)
                                                    
    $Level->setBlock(new Vector3($X,1,$Z),Block::get(0),true,true);
                                                
    $chest = new BuyingInventory($Level->getTile(new Vector3($X,0,$Z)),$Player);
                                                
                                                
    $contents = [];
                                                switch (
    $Type)
                                                {
                                                    case 
    0: foreach ($this->plugin->Buys_Values as $Buy_Value)
                                                    
    $contents []= Item::get($Buy_Value[0],0,1);
                                                    break;
                                                    case 
    1: if ($this->plugin->Status == 0)
                                                        {
                                                            foreach (
    $this->plugin->MapsList as $Map)
                                                            
    $contents []= Item::get(35,$Map[0],($Map[4] == 0) ? 99 $Map[4]);
                                                            } else {
                                                                
    $contents []= Item::get(345,0,1);
                                                                foreach (
    $this->plugin->game->Teams as $Name => $Team)
                                                                
    $contents []= Item::get(35,$this->plugin->getTeamDataByName($Name),(count($Team->Players) == 0) ? 99 count($Team->Players));
                                                            }
                                                            break;
                                                    }
                                                
    $chest->setContents($contents);
                                                
    $this->plugin->setState("buying_chest",$Player,$chest);
                                                
    $this->plugin->setState("buying_type",$Player,$Type);
                                                
    $this->plugin->setState("buying_menu",$Player,-1);
                                                
    $Player->addWindow($chest);
                                                
    $event->setCancelled(true);
            
                            
                          
    $Level $Player->getLevel();
                        if ((!
    $this->plugin->game) || ($this->plugin->game->level_name != $Level->getFolderName()))
                            return;
                        
    $X $Player->getFloorX();
                        
    $Y $Player->getFloorY() - 1;
                        
    $Z $Player->getFloorZ();
                        
    $Block $Level->getBlock(new Vector3($X,$Y,$Z));
                        if (
    $Block->getId() == 133)
                            {
                                
    $event->setCancelled(true);
                            }
                       }
    File 2
    PHP:
    class BuyingInventory extends CustomInventory{
         protected 
    $client;
         protected 
    $holder;

             public function 
    __construct($holder,$client){
             
    $this->client $client;
             
    parent::__construct($holder,InventoryType::get(InventoryType::CHEST),[],null,"");
         }
     

    Attached Files:

  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Is holder null?
     
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    would help if you copy the FULL ERROR and not just screen shot things
     
    SOFe and HimbeersaftLP like this.
  4. Michael

    Michael Baby Zombie

    Messages:
    113
    GitHub:
    michaelm04
    The inventory holder is 'null' due to not being done correctly, you forgot the x,y,z in the compound tag:
    PHP:
    new IntTag("x"$player->getX()),
    new 
    IntTag("y"$player->getY()),
    new 
    IntTag("z"$player->getZ())
    Also you forgot the types in the BuyingInventory Class:
    PHP:
    public function __construct(Chest $holderPlayer $client){
    I'm assuming those were the types you were using, feel free to correct them.
     
  5. TrixZSlow

    TrixZSlow Spider Ban Evader

    Messages:
    9
  6. TrixZSlow

    TrixZSlow Spider Ban Evader

    Messages:
    9
    It's the full screen please stop answer for like
     
  7. TrixZSlow

    TrixZSlow Spider Ban Evader

    Messages:
    9
     
  8. TrixZSlow

    TrixZSlow Spider Ban Evader

    Messages:
    9
    No... please why $player->getX() , $player->getY() etc. ? I have already defined -_-
     
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    ofcourse you can edit it to whatever you have defined he just want to make it simpler for other to understand
     
    HimbeersaftLP likes this.
  10. TrixZSlow

    TrixZSlow Spider Ban Evader

    Messages:
    9
    But the problem is when I click the inventory appears and then disappears idk why :(
     
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Then type the error out. If you know it is hard to read it from your console, it is even harder to read it from an image on a forum.
     
    HimbeersaftLP likes this.
  12. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Or just copy it?
     
    Thunder33345 likes this.
  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.