1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How Can I place a chest and open it via command?

Discussion in 'Development' started by Atomization, Oct 10, 2017.

  1. Atomization

    Atomization Spider

    Messages:
    12
    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
    }
     
  2. Mystic30

    Mystic30 Spider Jockey

    Messages:
    49
    GitHub:
    Mystic30
  3. Atomization

    Atomization Spider

    Messages:
    12
    I have looked at other plugins including that one... here is my code so far:
    PHP:
    public function onCommand(CommandSender $senderCommand $commandstring $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?
     
  4. Kyd

    Kyd Zombie

    Messages:
    362
    function sendInventory is not defined
     
    Levi and iiFlamiinBlaze like this.
  5. Atomization

    Atomization Spider

    Messages:
    12
    That doesn't help much... can any of you help me fix it? how can i get "function sendInventory" defined?
     
  6. QuiverlyRivalry

    QuiverlyRivalry Zombie

    Messages:
    236
    GitHub:
    quiverlyrivalry
    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?
     
  7. jasonwynn10

    jasonwynn10 Wither Skeleton Verified

    Messages:
    1,093
    GitHub:
    jasonwynn10
    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!
    The error is where it says
    PHP:
    $this->sendInventory();
    Your error is
    Code:
    "Call to undefined method Atomization\shop\main::sendInventory()"
    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
    }
    Notice there is no step 4... :p
     
    Last edited: Oct 11, 2017
    iiFlamiinBlaze, Muqsit and Mystic30 like this.
  8. Kyd

    Kyd Zombie

    Messages:
    362
    Wtf this if not php learn forum :v Go to stackoverflow If you don't know how to define function
     
    jasonwynn10 and iiFlamiinBlaze like this.
  9. Atomization

    Atomization Spider

    Messages:
    12
    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 $senderCommand $commandstring $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
     
    Last edited: Oct 11, 2017
  10. jasonwynn10

    jasonwynn10 Wither Skeleton Verified

    Messages:
    1,093
    GitHub:
    jasonwynn10
     
  11. Aviv

    Aviv Baby Zombie

    Messages:
    139
    return value
    PHP:
    return "value";
    must be the type of boolean
    boolean = true/false
    http://php.net/manual/en/function.return.php

    Just type 'return true;' at the end of the onCommand function if you are lazy
     
  12. Karanpatel567

    Karanpatel567 Spider Jockey

    Messages:
    42
    GitHub:
    Karanpatel567
    What about if I told you that you have to create a tile. :)
     
  13. Atomization

    Atomization Spider

    Messages:
    12
    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
     
  14. jasonwynn10

    jasonwynn10 Wither Skeleton Verified

    Messages:
    1,093
    GitHub:
    jasonwynn10
    This is off topic from the original question. Search for it yourself using the search bar here on the forums.
     
    Kyd likes this.

Share This Page