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

How to solve undifined property $config

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

  1. Ayush

    Ayush Witch

    Messages:
    62
    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 Witch

    Messages:
    62
  3. Ayush

    Ayush Witch

    Messages:
    62
  4. DavyCraft648

    DavyCraft648 Spider Jockey

    Messages:
    40
    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 Witch

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

    Ayush Witch

    Messages:
    62
    U didn't help.me?
     
  9. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Stop expecting for free help. No one will be willing to help you if your attitude is just "OMG HELP, IF U DONT HELP YOU BAD"

    Perhaps try to figure out the error yourself? Or most importantly...learn PHP so you know what arrays and strings are?
    You don't even have the basic knowledge in PHP, yet you're trying so less(asking for help for every possible question)

    And doing that is just the same thing with saying "make me a plugin"

    So please, take your time. Don't think that you can make things until you have at least some what of knowledge on the language first.
     
    NTT, Primus, Axon and 1 other person like this.
  10. Ayush

    Ayush Witch

    Messages:
    62
    Bro that was not my plugin and I'm trying to fix because I need to use this on my server and because this plugin is public I want to contact after fixing and I have him to publish new fixed version of this plugin. So, people can use.
    Plugin help:
    1. Is that compleseary to use unserialize.
    2. Is this line is correct : $this->getConfig()->getAll() as $recipe
    3. I think getAll() is not correct.
    My questions and answers :

    I'm learning php.
    I need help cuz I need and I say don't expect for help then why plugin help forums here?
     
  11. Mcbeany

    Mcbeany Spider Jockey

    Messages:
    33
    GitHub:
    mcbeany
    ask the author of the plugin to fix lol
     
    Ayush and minijaham like this.
  12. Ayush

    Ayush Witch

    Messages:
    62
    That's great idea lol
     
  13. WolfZeroStar

    WolfZeroStar Creeper

    Messages:
    2
    GitHub:
    Lu-a-png
    Try it that way



    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);
            }
            
    $this->config $this->getConfig();
            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;
        }
    }[/
    B]
     
  14. KygekDev

    KygekDev Witch

    Messages:
    72
    GitHub:
    KygekDev
    I hope this can solve the error:
    https://php.net/unserialize
     
  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.