How to solve undifined property $config

Discussion in 'Plugin Help' started by Ayush, Apr 5, 2021.

  1. Ayush

    Ayush Spider Jockey

    Messages:
    28
    How I can solve this error:
    PHP:
    2021-04-05 [07:47:58] [Server thread/INFO]: Enabling CustomCrafting v1.0.0
    2021
    -04-05 [07:47:58] [Server thread/CRITICAL]: ErrorException"Undefined property: thurm64\CustomCrafting\CustomCrafting::$config(EXCEPTIONin "plugins/CustomCrafting by aot.phar/src/thurm64/CustomCrafting/CustomCrafting" at line 45 


    and the code is


    PHP:
    class CustomCrafting extends PluginBase implements Listener {
       
        
    /** @var Config $config */
        
    public $config;
       
        public function 
    log($str) {
            
    $this->getLogger()->info("[CustomCrafts]" $str);
        }

        public function 
    onEnable() {
           
            
    $this->saveDefaultConfig();
            if(!
    InvMenuHandler::isRegistered()){
                
    InvMenuHandler::register($this);
            }
            foreach(
    $this->config->getAll() as $recipe){
                
    $this->getServer()->getCraftingManager()->registerRecipe(unserialize($recipe));
            }
        }
       
        public function 
    onCommand(\pocketmine\command\CommandSender $player, \pocketmine\command\Command $cstring $l, array $a) : bool {
            if(
    $player instanceof Player && $player->hasPermission("customcrafting.command")) {

                if(
    $c->getName() == "ccrename" && count($a) == 1) {
                    
    $player->getInventory()->setItemInHand($player->getInventory()->getItemInHand()->setCustomName($a[0]));
                    return 
    true;
                } else if(
    $c->getName() == "ccrelore" && count($a) == 1) {
                    
    $player->getInventory()->setItemInHand($player->getInventory()->getItemInHand()->setLore([str_replace("{line}","\n"$a[0])]));
                    return 
    true;
                } else if(
    $c->getName() == "ccglowify" && count($a) == 0) {
                    
    $item $player->getInventory()->getItemInHand();
                    
    $item->setNamedTagEntry(new ListTag("ench"));
                    
    $player->getInventory()->setItemInHand($item);
                    return 
    true;
                } else if(
    $c->getName() == "ccrecolor" && count($a) == 3) {
                    
    $item $player->getInventory()->getItemInHand();
                    if(
    $item instanceof Armor) {
                    
    $item->setCustomColor(new Color(intval($a[0]),intval($a[1]),intval($a[2])));
                    
    $player->getInventory()->setItemInHand($item);
                    return 
    true;
                    } else {

                    }
                } else if(
    $c->getName() == "customcrafts") {
                    
    $menu InvMenu::create(InvMenu::TYPE_CHEST);
                    
    $jason Item::get(BlockIds::INVISIBLE_BEDROCK);
                    
    $a Item::get(Item::AIR);
                    
    //1,2,3
                    //10, 11, 12
                    //19, 20, 21
                    
    $inv = [
                        
    $jason,$a,$a,$a,$jason,$jason,$jason,$jason,$jason,
                        
    $jason,$a,$a,$a,$jason,$jason,$jason,$a,$jason,
                        
    $jason,$a,$a,$a,$jason,$jason,$jason,$jason,$jason
                    
    ];
                    for(
    $i 0$i 27$i++) {
                        
    $item $inv[$i]; 
                        
    $menu->getInventory()->setItem($i$inv[$i]);
                    }
                    
    $menu->send($player);
                    
    $menu->setListener(function(InvMenuTransaction $transaction) : InvMenuTransactionResult{
                        if(
    $transaction->getItemClicked()->getId() == BlockIds::INVISIBLEBEDROCK){
                            return 
    $transaction->discard();
                        }

                        return 
    $transaction->continue();
                    });
                    
    $menu->setInventoryCloseListener(function($player$inventory) : void{
                        
    $recipe = [];
                        for(
    $r 0$r 3$r++) {
                            for(
    $c 0$c 3$c++) {
                                
    $slot $c 1;
                                
    $slot += $r;
                                
    $recipe[($r 3) + $c]= $inventory->getItem($slot);
                            }
                        }
                   
                        
    $yield $inventory->getItem(16);
                        if(
    $yield->getID() != 0) {
                        
    $recipe = new ShapedRecipe([
                            
    "abc",
                            
    "def",
                            
    "ghi"
                        
    ],
                        [
                            
    "a" => $recipe[0],
                            
    "b" => $recipe[1],
                            
    "c" => $recipe[2],
                            
    "d" => $recipe[3],
                            
    "e" => $recipe[4],
                            
    "f" => $recipe[5],
                            
    "g" => $recipe[6],
                            
    "h" => $recipe[7],
                            
    "i" => $recipe[8]
                           
                        ],[
    $yield]);
                   
                    
    $this->config->set("cc" uniqid("Recipe-"), serialize($recipe));
                    
    $this->config->save();
                    
    $this->getServer()->getCraftingManager()->registerRecipe($recipe);
                    }
                });
                return 
    true;
                }
                }
            return 
    false;
        }
    }

    Try fast
     
  2. Ayush

    Ayush Spider Jockey

    Messages:
    28
  3. Ayush

    Ayush Spider Jockey

    Messages:
    28
  4. DavyCraft648

    DavyCraft648 Silverfish

    Messages:
    22
    GitHub:
    DavyCraft648
    CustomCrafting::$config is undefined, so you have to define it...

    PHP:
    class CustomCrafting extends PluginBase implements Listener {

        public 
    $example;

        public function 
    onEnable(): void {
            
    $this->example $this->getConfig();
         }
    }
     
    Primus and Ayush like this.
  5. mmm545

    mmm545 Baby Zombie

    Messages:
    152
    GitHub:
    mmm545
    Primus, Ayush and minijaham like this.
  6. Ayzrix

    Ayzrix Witch

    Messages:
    66
    GitHub:
    Ayzrix
    PHP:
    class CustomCrafting extends PluginBase implements Listener {

        public function 
    log($str) {
            
    $this->getLogger()->info("[CustomCrafts]" $str);
        }

        public function 
    onEnable() {
          
            
    $this->saveDefaultConfig();
            if(!
    InvMenuHandler::isRegistered()){
                
    InvMenuHandler::register($this);
            }
            foreach(
    $this->getConfig()->getAll() as $recipe){
                
    $this->getServer()->getCraftingManager()->registerRecipe(unserialize($recipe));
            }
        }
      
        public function 
    onCommand(\pocketmine\command\CommandSender $player, \pocketmine\command\Command $cstring $l, array $a) : bool {
            if(
    $player instanceof Player && $player->hasPermission("customcrafting.command")) {

                if(
    $c->getName() == "ccrename" && count($a) == 1) {
                    
    $player->getInventory()->setItemInHand($player->getInventory()->getItemInHand()->setCustomName($a[0]));
                    return 
    true;
                } else if(
    $c->getName() == "ccrelore" && count($a) == 1) {
                    
    $player->getInventory()->setItemInHand($player->getInventory()->getItemInHand()->setLore([str_replace("{line}","\n"$a[0])]));
                    return 
    true;
                } else if(
    $c->getName() == "ccglowify" && count($a) == 0) {
                    
    $item $player->getInventory()->getItemInHand();
                    
    $item->setNamedTagEntry(new ListTag("ench"));
                    
    $player->getInventory()->setItemInHand($item);
                    return 
    true;
                } else if(
    $c->getName() == "ccrecolor" && count($a) == 3) {
                    
    $item $player->getInventory()->getItemInHand();
                    if(
    $item instanceof Armor) {
                    
    $item->setCustomColor(new Color(intval($a[0]),intval($a[1]),intval($a[2])));
                    
    $player->getInventory()->setItemInHand($item);
                    return 
    true;
                    } else {

                    }
                } else if(
    $c->getName() == "customcrafts") {
                    
    $menu InvMenu::create(InvMenu::TYPE_CHEST);
                    
    $jason Item::get(BlockIds::INVISIBLE_BEDROCK);
                    
    $a Item::get(Item::AIR);
                    
    //1,2,3
                    //10, 11, 12
                    //19, 20, 21
                    
    $inv = [
                        
    $jason,$a,$a,$a,$jason,$jason,$jason,$jason,$jason,
                        
    $jason,$a,$a,$a,$jason,$jason,$jason,$a,$jason,
                        
    $jason,$a,$a,$a,$jason,$jason,$jason,$jason,$jason
                    
    ];
                    for(
    $i 0$i 27$i++) {
                        
    $item $inv[$i];
                        
    $menu->getInventory()->setItem($i$inv[$i]);
                    }
                    
    $menu->send($player);
                    
    $menu->setListener(function(InvMenuTransaction $transaction) : InvMenuTransactionResult{
                        if(
    $transaction->getItemClicked()->getId() == BlockIds::INVISIBLEBEDROCK){
                            return 
    $transaction->discard();
                        }

                        return 
    $transaction->continue();
                    });
                    
    $menu->setInventoryCloseListener(function($player$inventory) : void{
                        
    $recipe = [];
                        for(
    $r 0$r 3$r++) {
                            for(
    $c 0$c 3$c++) {
                                
    $slot $c 1;
                                
    $slot += $r;
                                
    $recipe[($r 3) + $c]= $inventory->getItem($slot);
                            }
                        }
                  
                        
    $yield $inventory->getItem(16);
                        if(
    $yield->getID() != 0) {
                        
    $recipe = new ShapedRecipe([
                            
    "abc",
                            
    "def",
                            
    "ghi"
                        
    ],
                        [
                            
    "a" => $recipe[0],
                            
    "b" => $recipe[1],
                            
    "c" => $recipe[2],
                            
    "d" => $recipe[3],
                            
    "e" => $recipe[4],
                            
    "f" => $recipe[5],
                            
    "g" => $recipe[6],
                            
    "h" => $recipe[7],
                            
    "i" => $recipe[8]
                          
                        ],[
    $yield]);
                  
                    
    $this->getConfig()->set("cc" uniqid("Recipe-"), serialize($recipe));
                    
    $this->getConfig()->save();
                    
    $this->getServer()->getCraftingManager()->registerRecipe($recipe);
                    }
                });
                return 
    true;
                }
                }
            return 
    false;
        }
    }
     
    Ayush likes this.
  7. Ayush

    Ayush Spider Jockey

    Messages:
    28
    I'm getting a error
    PHP:
    unserialize() expects parameter 1 to be string, array given
     

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.