How I can solve this error: PHP: 2021-04-05 [07:47:58] [Server thread/INFO]: Enabling CustomCrafting v1.0.02021-04-05 [07:47:58] [Server thread/CRITICAL]: ErrorException: "Undefined property: thurm64\CustomCrafting\CustomCrafting::$config" (EXCEPTION) in "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 $c, string $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 += 9 * $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
CustomCrafting::$config is undefined, so you have to define it... Spoiler: Example PHP: class CustomCrafting extends PluginBase implements Listener { public $example; public function onEnable(): void { $this->example = $this->getConfig(); }}
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 $c, string $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 += 9 * $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; }}
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.
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?
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 $c, string $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 += 9 * $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]