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

Unhandled exception executing command 'fakechest' in fakechest: Cannot instantiate abstract class

Discussion in 'Development' started by armagadon159753, Nov 14, 2017.

  1. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Error
    PHP:
    [13:41:00] [Server thread/CRITICAL]: Unhandled exception executing command 'fakechest' in fakechestCannot instantiate abstract class FakeChest\Inventory\WindowInventory    
    [13:41:00] [Server thread/CRITICAL]: Error"Cannot instantiate abstract class FakeChest\Inventory\WindowInventory" (EXCEPTIONin "VitualChest/src/FakeChest/Loader" at line 229


    Line
    299
    $chest 
    = new WindowInventory($player27"§8-=>[§dFake §eAChest§8]=-");
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    http://bfy.tw/F1c6
    https://stackoverflow.com/a/44219467
     
    armagadon159753 likes this.
  3. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    I must either explicitly redefine the abstract methods of the superclass or make our WindowInventory class abstract.
    But
    PHP:
    <?php

    namespace FakeChest\Inventory;

    use 
    pocketmine\block\Block;
    use 
    pocketmine\inventory\CustomInventory;
    use 
    pocketmine\Player;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\inventory\InventoryType;
    use 
    pocketmine\network\protocol\UpdateBlockPacket;
    use 
    pocketmine\nbt\tag\CompoundTag;
    use 
    pocketmine\nbt\tag\StringTag;
    use 
    pocketmine\tile\Tile;
    use 
    pocketmine\nbt\tag\IntTag;
    use 
    pocketmine\nbt\NBT;
    use 
    pocketmine\network\protocol\BlockEntityDataPacket;
    use 
    pocketmine\inventory\InventoryHolder;

    abstract  class 
    WindowInventory extends CustomInventory{

        protected 
    $customName "";
        protected 
    $tile;
        protected 
    $block;

        public function 
    __construct(Player $player$size 27$name "") {
            
    $this->tile Tile::CHEST;
            
    $this->block 54;
            
    $type InventoryType::get(InventoryType::CHEST);
            switch(
    $size){
                case 
    5:
                    
    $this->tile Tile::HOPPER;
                    
    $this->block 154;
                    
    $type InventoryType::get(InventoryType::HOPPER);
                    break;
                case 
    9:
                    
    $this->tile Block::WORKBENCH;
                    
    $this->block 58;
                    
    $type InventoryType::get(InventoryType::WORKBENCH);
                    break;
                case 
    27:
                    
    $type InventoryType::get(InventoryType::CHEST);
                    
    $this->tile Tile::CHEST;
                    
    $this->block 54;
                    break;
                case 
    2:
                    
    $type InventoryType::get(InventoryType::ENCHANT_TABLE);
                    
    $this->tile Tile::ENCHANT_TABLE;
                    
    $this->block 116;
                    break;
                case 
    3:
                    
    $type InventoryType::get(InventoryType::FURNACE);
                    
    $this->tile Tile::FURNACE;
                    
    $this->block 61;
                    break;
                case 
    1:
                    
    $type InventoryType::get(InventoryType::BREWING_STAND);
                    
    $this->tile Tile::BREWING_STAND;
                    
    $this->block 117;
                    break;
                default:
                    
    $player->getServer()->getLogger()->notice("Unknown window size. If must be one from: 1, 2, 3, 5, 9, 27, 54. Using default size(27).");
            }
            
    $this->customName $name;
            
    $holder = new WindowHolder($player->getFloorX(), $player->getFloorY() + 2$player->getFloorZ(), $this);
            
    parent::__construct($holder$type);
        }

        public function 
    onOpen(Player $who): void {
            
    $this->holder $holder = new WindowHolder($who->getFloorX(), $who->getFloorY() + 2$who->getFloorZ(), $this);
            
    $pk = new UpdateBlockPacket();
            
    $pk->$holder->x;
            
    $pk->$holder->y;
            
    $pk->$holder->z;
            
    $pk->blockId $this->block;
            
    $pk->blockData 0;
            
    $pk->flags UpdateBlockPacket::FLAG_ALL;
            
    $who->dataPacket($pk);
            
    $c = new CompoundTag("", [
                new 
    StringTag("id"$this->tile),
                new 
    IntTag("x", (int) $holder->x),
                new 
    IntTag("y", (int) $holder->y),
                new 
    IntTag("z", (int) $holder->z)
            ]);
            if(
    $this->name !== ""){
                
    $c->CustomName = new StringTag("CustomName"$this->customName);
            }
            
    $nbt = new NBT(NBT::LITTLE_ENDIAN);
            
    $nbt->setData($c);
            
    $pk = new BlockEntityDataPacket();
            
    $pk->$holder->x;
            
    $pk->$holder->y;
            
    $pk->$holder->z;
            
    $pk->namedtag $nbt->write();
            
    $who->dataPacket($pk);
            
    parent::onOpen($who);
            
    $this->sendContents($who);
        }

        public function 
    onClose(Player $who): void {
            
    $holder $this->holder;
            
    $pk = new UpdateBlockPacket();
            
    $pk->$holder->x;
            
    $pk->$holder->y;
            
    $pk->$holder->z;
            
    $pk->blockId $who->getLevel()->getBlockIdAt($holder->x$holder->y$holder->z);
            
    $pk->blockData $who->getLevel()->getBlockDataAt($holder->x$holder->y$holder->z);
            
    $pk->flags UpdateBlockPacket::FLAG_ALL;
            
    $who->dataPacket($pk);
            
    parent::onClose($who);
        }
    }
     
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    just make your class a normal class instead of it being abstract. Otherwise, you need to create another class which extends from your abstract class and is not abstract itself
     
    EdwardHamHam 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.