I would like to know if any of you know how You can place a chest with custom name and open it via command. here is an example: PHP: switch($command->getName()) { case "shop": Open Chest}
I have looked at other plugins including that one... here is my code so far: PHP: public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{ if(strtolower($command->getName()) == "shop"){ if($sender->hasPermission("shop.cmd")){ $sender->sendMessage(c::GOLD. "Opening Shop!"); $this->sendInventory($sender); } } } and the error message when i type the command into chat: Code: [Server thread/CRITICAL]: Unhandled exception executing command 'shop' in shop: Call to undefined method Atomization\shop\main::sendInventory() [11:17:22] [Server thread/CRITICAL]: Error: "Call to undefined method Atomization\shop\main::sendInventory()" (EXCEPTION) in "shop/src/Atomization/shop/Main" at line 50 So i have asked already, how can i open a chest via command?
That doesn't help much... can any of you help me fix it? how can i get "function sendInventory" defined?
Okay lmao I'm a nooby code I can't even get my plugin to work but would it be like $sender = $player? Or something saying sender is player?
Debugging 101 Step 1: Look at your code and find what line the error occurs according to the error given. Step 2: Pay attention to the type of error you are given (in your case it is a missing function). Step 3: If you have not created the function within the called class, create the function. Step 5: Profit! Spoiler: Hints Spoiler: Hint 1 The error is where it says PHP: $this->sendInventory(); Spoiler: Hint 2 Your error is Code: "Call to undefined method Atomization\shop\main::sendInventory()" Spoiler: Hint 3 Create the following function and implement it to do what you need it to in your main class PHP: public function sendInventory(Player $player) { //TODO} Spoiler: Hint 4 Notice there is no step 4...
That helped somewhat, I looked back and saw that it was defined, it was just misspelled, however, I have an other error which i don't understand. Code: [10:48:47] [Server thread/CRITICAL]: Unhandled exception executing command 'addshop' in addshop: Return value of Atomization\shop\main::onCommand() must be of the type boolean, none returned [10:48:47] [Server thread/CRITICAL]: TypeError: "Return value of Atomization\shop\main::onCommand() must be of the type boolean, none returned" (EXCEPTION) in "shop/src/Atomization/shop/Main" at line 75 And here is what it says in the function onCommand... begins on line 57 PHP: public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{ if(strtolower($command->getName()) == "addshop"){ if($sender->hasPermission("addshop.cmd")){ for($this->time = 3; $this->time >= 1; $this->time--){ $sender->sendMessage("§2Loading..§c $this->time"); if($this->time==1){ $this->sendInventory($sender); } } }else{ $sender->sendMessage(c::RED. "You cannot perform this action, for staff only"); } } } Any help is appreciated, I know that I may seem like a person that doesn't know anything, however, this is how I learn, from people who know how better than I do
return value PHP: return "value"; must be the type of boolean boolean = true/false http://php.net/manual/en/function.return.php Spoiler: READ return MANUAL FIRST Just type 'return true;' at the end of the onCommand function if you are lazy
Thank you for helping me understand what boolean values are, But I have one more question to ask before I mark this thread as Solved... This is not an error question but rather seeking some assistance on how to achieve a task. I was trying to make a countdown of 3 sec. before opening the shop, it will send a title saying, "Loding... 3, 2, 1" and then open the shop, I have made a for loop looping the loading title, but how do I make it last for 3 or more sec.? PHP: for($this->time = 3; $this->time >= 1; $this->time--){ $sender->sendMessage("§2Loading..§c $this->time"); if($this->time==1){ $this->sendInventory($sender); } } "Anyone who helped me fixed any errors or help me add features to my plugin will be given credit
This is off topic from the original question. Search for it yourself using the search bar here on the forums.