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

NotWorking?

Discussion in 'Plugin Help' started by princeace, Mar 30, 2020.

  1. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    PrinceAce\ShopTest;

    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\item\enchantment\Enchantment;

    class 
    Main extends PluginBase{
        public function 
    onEnable(){
            
    /*i will use EconomyAPI*/
    $this->money $this->getServer()->getPluginManager()->getPlugin("EconomyAPI");
            
    $this->getLogger()->info("§eEnable");
        }
        public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args): bool {
            
    /*Register Function*/
            
    $money $this->money->myMoney($sender->getName());
            switch(
    $command->getName()){
                case 
    "shop":
                if(!
    $sender instanceof Player){
                    
    $sender->sendMessage("§cRun commands in game!");
                    return 
    true;
                }
                if(!isset(
    $args[0])){
                    
    $sender->sendMessage("§Commands:§6/shop list");
                    return 
    true;
                }
                if(!
    in_array($args[0],array("list, buy"))){
                    
    $sender->sendMessage("§cCommands §6/shop list");
                    return 
    true;
                }
                if(
    strtolower($args[0]) == "list"){
                    
    $sender->sendMessage("§9SHOP ITEM\n§e64 Stone - 100$\n64 Grass - 300$\nDiamond Swords - 1000$");
                    return 
    true;
                }
                if(
    strtolower($args[0]) == "buy")
                if(!isset(
    $args[1])){
                    
    $sender->sendMessage("§e/shop buy <id>");
                    return 
    true;
                }
                if(!
    in_array($args[1],array("Stone","Grass","Swords"))){
                    
    $sender->sendMessage("§cError!");
                    return 
    true;
                }
                if(
    strtolower($args[1]) == "Stone"){
                    if(
    $money >= 100){
                        
    /*Reduce Money*/
                        
    $this->money->reduceMoney($sender->getName(), 100);
                        
    $sender->getInventory()->addItem(item::get(1,0,64));
                        
    $sender->sendMessage("§aSuccess!");
                    }else{
                        
    $sender->sendMessage("§cError!");
                    }
                }
            if(
    strtolower($args[1]) == "Grass"){
                if(
    $money >= 300){
                    
    $this->money->reduceMoney($sender->getName(), 300);
                    
    $sender->getInventory()->addItem(item::get(2,0,64));
                    
    $sender->sendMessage("§aSuccess!");
                }else{
                    
    $sender->sendMessage("§cError!");
                }
            }
            if(
    strtolower($args[1]) == "Swords"){
                if(
    $money >= 1000){
                    
    $this->money->reduceMoney($sender->getName(), 1000);
                    
    $sender->sendMessage("§aSuccess!");
                    
    $item item::get(276,0,1);
                    
    $item->addEnchantment(Enchantment::getEnchantment(9)->setLevel(2));
                }else{
                    
    $sender->sendMessage("§cError!");
                }
            }
            }
        }
    }
    when i use /shop in game no result or not working i dont have a error why not working?
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Did you add the command to your plugin.yml?
     
  3. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    i already fix that thanks but when i type /shop got this error
    [12:19:26] [Server thread/CRITICAL]: TypeError: "Return value of PrincessAcesia\TestShop\Main::eek:nCommand() must be of the type bool, none returned" (EXCEPTION) in "plugins/TestShop/src/PrincessAcesia/TestShop/Main" at line 81
    this is my code
    https://pastebin.com/XHxJAubh
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    The onCommand method must always return a boolean, just add return true; to the very end of it
     
  5. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    PrinceAce\TestShop;

    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\item\enchantment\Enchantment;

    class 
    Main extends PluginBase{
        public function 
    onEnable(){
            
    /*i will use EconomyAPI*/
    $this->money $this->getServer()->getPluginManager()->getPlugin("EconomyAPI");
            
    $this->getLogger()->info("§eEnable");
        }
        public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args): bool {
            
    /*Register Function*/
            
    $money $this->money->myMoney($sender->getName());
            switch(
    $command->getName()){
                case 
    "shop":
                if(!
    $sender instanceof Player){
                    
    $sender->sendMessage("§cRun commands in game!");
                    return 
    true;
                }
                if(!isset(
    $args[0])){
                    
    $sender->sendMessage("§6Commands§f:§6/shop list");
                    return 
    true;
                }
                if(!
    in_array($args[0],array("list","buy"))){
                    
    $sender->sendMessage("§cCommands§f:§6/shop list");
                    return 
    true;
                }
                if(
    strtolower($args[0]) == "list"){
                    
    $sender->sendMessage("§9SHOP ITEM\n§e64 Stone - 100$\n64 Grass - 300$\nDiamond Swords - 1000$");
                    return 
    true;
                }
                if(
    strtolower($args[0]) == "buy")
                if(!isset(
    $args[1])){
                    
    $sender->sendMessage("§e/shop buy §7<id>");
                    return 
    true;
                }
                if(!
    in_array($args[1],array("Stone","Grass","Swords"))){
                    
    $sender->sendMessage("§cError!");
                    return 
    true;
                }
                if(
    strtolower($args[1]) == "Stone"){
                    if(
    $money >= 100){
                        
    /*Reduce Money*/
                        
    $this->money->reduceMoney($sender->getName(), 100);
                        
    $sender->getInventory()->addItem(item::get(1,0,64));
                        
    $sender->sendMessage("§aSuccess!");
                    }else{
                        
    $sender->sendMessage("§cError!");
                    }
                }
            if(
    strtolower($args[1]) == "Grass"){
                if(
    $money >= 300){
                    
    $this->money->reduceMoney($sender->getName(), 300);
                    
    $sender->getInventory()->addItem(item::get(2,0,64));
                    
    $sender->sendMessage("§aSuccess!");
                }else{
                    
    $sender->sendMessage("§cError!");
                }
            }
            if(
    strtolower($args[1]) == "Swords"){
                if(
    $money >= 1000){
                    
    $this->money->reduceMoney($sender->getName(), 1000);
                    
    $sender->sendMessage("§aSuccess!");
                    
    $item item::get(276,0,1);
                    
    $item->addEnchantment(Enchantment::getEnchantment(9)->setLevel(2));
                }else{
                    
    $sender->sendMessage("§cError!");
                }
            }
            }
            return 
    true;
        }
    }
    [14:09:16] [Server thread/CRITICAL]: TypeError: "Return value of PrinceAce\TestShop\Main::eek:nCommand() must be of the type bool, none returned" (EXCEPTION) in "plugins/TestShop/src/PrinceAce/TestShop/Main" at line 81

    not working??
     
  6. Invy55

    Invy55 Witch

    Messages:
    52
    GitHub:
    invy55
    Are you sure you have restarted NOT RELOADED?
     
    HimbeersaftLP likes this.
  7. HiToLaKhanh

    HiToLaKhanh Spider Jockey

    Messages:
    25
    GitHub:
    HiToLaKhanh
    delete the "!" dude
     
  8. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Wrong, look at the code again
     
  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.