Else Problem and Help me finding errors

Discussion in 'Development' started by ZackyVN, Nov 21, 2018.

  1. ZackyVN

    ZackyVN Silverfish

    Messages:
    24
    PHP:
    <?php

    namespace HyperGames;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\event\Listener;

    class 
    Main extends PluginBase implements Listener{

    public function 
    onEnable() : void{
    $this->getLogger()->info("§9§l>§aRankShop Enable");
    }

    public function 
    onDisable() : void{
    $this->getLogger()->info("§9§l>§cRankShop Disable");
    }

    public function 
    onCommand(CommandSender $sender,Command $cmdstring $commandLabel, array $args) : bool{
    switch(
    $command->getName()){
    case 
    "buy":
    if(
    $sender instanceof Player);
    if(isset(
    $args[0])){
    switch(
    $args[0]){
    case 
    "vip1":
    if(isset(
    $args[0])){
    $nguoimua $sender->getName();
    $socoin $this->getServer()->getPluginManager()->getPlugin("Coins")->getMoney($nguoimua);
    if(
    $socoin 20){
    $sender->sendMessage("§cBạn không đủ số lượng coins!");
    }
    }else
    $this->plugin->getServer()->getCommandMap()->dispatch(new ConsoleCommandSender(), "setgroup $nguoimua vip1");
    $this->getServer()->broadcastMessage("§b>§eNgười chơi $nguoimua §ađã mua gói§e VIP-I");
    $sender->sendMessage("§a§lThành công!§r§a Bạn đã mua gói§e VIP-I");
    }
    }else
    $sender->sendMessage("§eGhi§6 /buy vip1§a để mua gói§eVIP-I");
    }
    }else
    $sender->sendMessage("§e/buy vip1 -§a Mua Gói§e VIP-I");
    }
    }else
    $sender->sendMessage("§cJoin§e hypergamesvn.tk to enable this shop!");
    }
    }
    return 
    true;
    }
    }
    }
    When i started the server, it showed this
    Code:
    2018-11-21 [14:56:17] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected 'else' (T_ELSE), expecting function (T_FUNCTION) or const (T_CONST)" (EXCEPTION) in "HG-BuySystem/src/HyperGames/Main" at line 44
    2018-11-21 [14:56:17] [Server thread/DEBUG]: #0 (): BaseClassLoader->loadClass(string HyperGames\Main)
    2018-11-21 [14:56:17] [Server thread/DEBUG]: #1 (): spl_autoload_call(string HyperGames\Main)
    2018-11-21 [14:56:17] [Server thread/DEBUG]: #2 src/pocketmine/plugin/PluginManager(159): class_exists(string HyperGames\Main, boolean 1)
    2018-11-21 [14:56:17] [Server thread/DEBUG]: #3 src/pocketmine/plugin/PluginManager(324): pocketmine\plugin\PluginManager->loadPlugin(string /storage/emulated/0/PocketMine-MP/plugins/HG-BuySystem, array Array())
    2018-11-21 [14:56:17] [Server thread/DEBUG]: #4 PocketMine-DevTools.phar/src/DevTools/DevTools(49): pocketmine\plugin\PluginManager->loadPlugins(string /storage/emulated/0/PocketMine-MP/plugins/, array Array())
    2018-11-21 [14:56:17] [Server thread/DEBUG]: #5 src/pocketmine/plugin/PluginBase(108): DevTools\DevTools->onEnable()
    2018-11-21 [14:56:17] [Server thread/DEBUG]: #6 src/pocketmine/plugin/PluginManager(568): pocketmine\plugin\PluginBase->setEnabled(boolean 1)
    2018-11-21 [14:56:17] [Server thread/DEBUG]: #7 src/pocketmine/Server(1919): pocketmine\plugin\PluginManager->enablePlugin(DevTools\DevTools object)
    2018-11-21 [14:56:17] [Server thread/DEBUG]: #8 src/pocketmine/Server(1905): pocketmine\Server->enablePlugin(DevTools\DevTools object)
    2018-11-21 [14:56:17] [Server thread/DEBUG]: #9 src/pocketmine/Server(1640): pocketmine\Server->enablePlugins(integer 0)
    2018-11-21 [14:56:17] [Server thread/DEBUG]: #10 src/pocketmine/PocketMine(249): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string /storage/emulated/0/PocketMine-MP/, string /storage/emulated/0/PocketMine-MP/plugins/)
    2018-11-21 [14:56:17] [Server thread/DEBUG]: #11 /storage/emulated/0/PocketMine-MP/PocketMine-MP.phar(1): require(string phar:///storage/emulated/0/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php)[/PHP]
     
  2. Astro

    Astro Witch

    Messages:
    50
    GitHub:
    RealAstro
    try this
    PHP:
    <?php

    namespace HyperGames;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\event\Listener;

    class 
    Main extends PluginBase implements Listener{

        public function 
    onEnable() {
            
    $this->getLogger()->info("§9§l>§aRankShop Enable");
        }

        public function 
    onDisable() {
            
    $this->getLogger()->info("§9§l>§cRankShop Disable");
        }

        public function 
    onCommand(CommandSender $sender,Command $cmdstring $commandLabel, array $args) : bool{
            if(
    $sender instanceof Player) {
                if(isset(
    $args[0])){
                    switch(
    $cmd->getName()){
                    case 
    "buy":
                        if (
    count($args) < ) {
                            
    $sender->sendMessage("§e/buy vip1 -§a Mua Gói§e VIP-I");
                            return 
    true;
                        }
                        switch(
    $args[1]){
                            case 
    "vip1":
                                if(isset(
    $args[1])){
                                    
    $nguoimua $sender->getName();
                                    
    $socoin $this->getServer()->getPluginManager()->getPlugin("Coins")->getMoney($nguoimua);
                                    if(
    $socoin 20){
                                    
    $sender->sendMessage("§cBạn không đủ số lượng coins!");
                                    } else {
                                    
    $this->plugin->getServer()->getCommandMap()->dispatch(new ConsoleCommandSender(), "setgroup $nguoimua vip1");
                                    
    $this->getServer()->broadcastMessage("§b>§eNgười chơi $nguoimua §ađã mua gói§e VIP-I");
                                    
    $sender->sendMessage("§a§lThành công!§r§a Bạn đã mua gói§e VIP-I");
                                    }
                                } else {
                                
    $sender->sendMessage("§eGhi§6 /buy vip1§a để mua gói§eVIP-I");
                            }
                        }
                    }
                }
            } else {
                
    $sender->sendMessage("§cJoin§e hypergamesvn.tk to enable this shop!");
            }
        }
    }
     
  3. ZackyVN

    ZackyVN Silverfish

    Messages:
    24
    PHP:
    $socoin $this->getServer()->getPluginManager()->getPlugin("Coins")->getMoney($sender);
    Code:
     
    2018-11-22 [04:33:14] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected '$this' (T_VARIABLE)" (EXCEPTION) in "HG-BuySystem/src/HyperGames/Main" at line 37
    2018-11-22 [04:33:14] [Server thread/DEBUG]: #0 (): BaseClassLoader->loadClass(string HyperGames\Main)
    2018-11-22 [04:33:14] [Server thread/DEBUG]: #1 (): spl_autoload_call(string HyperGames\Main)
    2018-11-22 [04:33:14] [Server thread/DEBUG]: #2 src/pocketmine/plugin/PluginManager(159): class_exists(string HyperGames\Main, boolean 1)
    2018-11-22 [04:33:14] [Server thread/DEBUG]: #3 src/pocketmine/plugin/PluginManager(324): pocketmine\plugin\PluginManager->loadPlugin(string /storage/emulated/0/PocketMine-MP/plugins/HG-BuySystem, array Array())
    2018-11-22 [04:33:14] [Server thread/DEBUG]: #4 PocketMine-DevTools.phar/src/DevTools/DevTools(49): pocketmine\plugin\PluginManager->loadPlugins(string /storage/emulated/0/PocketMine-MP/plugins/, array Array())
    2018-11-22 [04:33:14] [Server thread/DEBUG]: #5 src/pocketmine/plugin/PluginBase(108): DevTools\DevTools->onEnable()
    2018-11-22 [04:33:14] [Server thread/DEBUG]: #6 src/pocketmine/plugin/PluginManager(568): pocketmine\plugin\PluginBase->setEnabled(boolean 1)
    2018-11-22 [04:33:14] [Server thread/DEBUG]: #7 src/pocketmine/Server(1919): pocketmine\plugin\PluginManager->enablePlugin(DevTools\DevTools object)
    2018-11-22 [04:33:14] [Server thread/DEBUG]: #8 src/pocketmine/Server(1905): pocketmine\Server->enablePlugin(DevTools\DevTools object)
    2018-11-22 [04:33:14] [Server thread/DEBUG]: #9 src/pocketmine/Server(1640): pocketmine\Server->enablePlugins(integer 0)
    2018-11-22 [04:33:14] [Server thread/DEBUG]: #10 src/pocketmine/PocketMine(249): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string /storage/emulated/0/PocketMine-MP/, string /storage/emulated/0/PocketMine-MP/plugins/)
    2018-11-22 [04:33:14] [Server thread/DEBUG]: #11 /storage/emulated/0/PocketMine-MP/PocketMine-MP.phar(1): require(string phar:///storage/emulated/0/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
    Uhhh
     
  4. ZackyVN

    ZackyVN Silverfish

    Messages:
    24
    PHP:
    <?php

    namespace HyperGames;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\{PlayerServer};
    use 
    pocketmine\command\{CommandCommandSenderConsoleCommandSender};

    Class 
    Main extends PluginBase{

    public function 
    onEnable() : void{
    $this->getLogger()->info("§l§9>§r§eRankShop§a Enable");
    }

    public function 
    onDisable() : void{
    $this->getLogger()->info("§l§9>§eRankShop§c Disable");
    }

    public function 
    onCommand(CommandSender $senderCommand $cmdstring $commandLabel, array $args) : bool {
    if(
    $sender instanceof Player){
    if(isset(
    $args[0])){
    switch(
    $cmd->getName()){
    case 
    "buy":
    if(
    count($args) < 1){
    $sender->sendMessage("§e/buy vip1 -§a Mua Gói§f VIP-I");
    $sender->sendMessage("§e/buy vip2 -§a Mua Gói§e VIP-II");
    $sender->sendMessage("§e/buy vip3 -§a Mua Gói§b VIP-III");
    $sender->sendMessage("§e/buy vip4 -§a Mua Gói§a VIP-IV");
    $sender->sendMessage("§e/buy vip5 -§a Mua Gói§5 VIP-V");
    return 
    true;
    }
    switch(
    $args[1]){
    case 
    "vip1":
    if(isset(
    $args[1])){
    if(
    $this->plugin->getServer()->getPluginManager()->getPlugin("Coins")->getMoney($sender) < 20){
    $sender->sendMessage("§cBạn không đủ số lượng coins!");
    }else{
    $this->plugin->getServer()->getCommandMap()->dispatch(new ConsoleCommandSender(), "setgroup $sender vip1");
    $this->getServer()->broadcastMessage("§b>§eNgười chơi $sender §ađã mua gói§e VIP-I");
    $sender->sendMessage("§a§lThành công!§r§a Bạn đã mua gói§e VIP-I");
    }
    }else{
    $sender->sendMessage("§eGhi§6 /buy vip1§a để mua gói§eVIP-I");
    }
    }
    }
    }
    }else{
    $sender->sendMessage("§cJoin§e hypergamesvn.tk to enable this shop!");
    }
    return 
    false;
    }
    }
    When i typed the command, it didnt show anything Help
     
  5. KielKing

    KielKing Creeper

    Messages:
    3
    GitHub:
    kielking
    I think you should see an example plugin that has a simple command and study it, you're checking the command's name inside the if statement that checks if argument 0 is set
     
  6. Astro

    Astro Witch

    Messages:
    50
    GitHub:
    RealAstro
    i don't think that's the correct way of using that coin plugin, check its api first
     
  7. Kkora

    Kkora Slime

    Messages:
    91
    GitHub:
    kkora2k3
    xem api của "Coin" đi. Edit từ EconomyAPI à?
    Check the API of your "Coin" plugin.
    Edited from EconomyAPI, right?
     

Share This Page

  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.