Solved Command usage error

Discussion in 'Development' started by MrDevCat, Feb 9, 2019.

  1. MrDevCat

    MrDevCat Spider Jockey

    Messages:
    28
    GitHub:
    elementalminecraftgaming
    I've created a load of commands for my plugin but one of them keeps showing the set error message with the correct usage and I don't know what the problem is because no error shows in the console and i typed in everything that is required to run.
    I don't understand why this is showing up when I type /pwarp la
    (la is my warp name)

    This is the code:
    PHP:
    if (strtolower($command->getName()) == "pwarp") {
                        if (
    $sender->hasPermission("pemerald.warp")) {
                            if (
    $sender instanceof Player) {
                                if (isset(
    $args[0])) {
                                    
    $warp $args[0];
                                    
    $configgp = new Config($this->getDataFolder() . "paywarps.yml"Config::YAML);
                                    
    $data $configgp->get($args[0]);
                                    if (
    is_array($data)) {
                                        
    $pay $data[0];
                                        
    $land $data[1];
                                        
    $x $data[2];
                                        
    $y $data[3];
                                        
    $z $data[4];
                                    }
                                    
    EconomyAPI::getInstance()->takeMoney($sender->getName(), (int) $pay);
                                    
    $sender->sendMessage(TextFormat::GOLD "Warping $warp at $land$x$y$z this warp was not free it cost you $pay!");
                                    
    $sender->teleport(new Position($x$y$z$this->getServer()->getLevelByName($land)));
                                    return 
    true;
                                } else {
                                    
    $sender->sendMessage(TextFormat::RED "Warp failed!");
                                }
                            } else {
                                
    $sender->sendMessage(TextFormat::RED "Warp  failed! ");
                            }
                        } else {
                            
    $sender->sendMessage(TextFormat::RED "Warp  failed! ");
                        }
                    } else {
                        
    $sender->sendMessage(TextFormat::RED "Warp  failed! ");
                    }
                } else {
                    
    $sender->sendMessage(TextFormat::RED "failed!");
                }
            } else {
                
    $sender->sendMessage(TextFormat::RED "failed!");
                return 
    false;
            }

            
    Does anyone know what is wrong?
     
  2. wolfdale

    wolfdale Zombie

    Messages:
    327
    I recommend not using the same error message for every error, you wont know which part is the one that failed, try to describe the error (etc you do not have permission, it does not exists)
    Do you have the permission pemerald.warp?
    Did you use pocketmine\Player; ?
    Does the warp "la" exist?

    It should be put like this
    PHP:
    if (is_array($data)) {
        
    $pay $data[0];
        
    $land $data[1];
        
    $x $data[2];
        
    $y $data[3];
        
    $z $data[4];
        
    EconomyAPI::getInstance()->takeMoney($sender->getName(), (int) $pay);
        
    $sender->sendMessage(TextFormat::GOLD "Warping $warp at $land$x$y$z this warp was not free it cost you $pay!");
        
    $sender->teleport(new Position($x$y$z$this->getServer()->getLevelByName($land)));
        return 
    true;
    }else 
    $sender->sendMessage("Does not exist or corrupted");
     
  3. MrDevCat

    MrDevCat Spider Jockey

    Messages:
    28
    GitHub:
    elementalminecraftgaming
    No change at all.
     
  4. wolfdale

    wolfdale Zombie

    Messages:
    327
    Just changing what i provided wont change anything..
    Do you have the permission pemerald.warp?
    Did you use pocketmine\Player; ?
    Does the warp "la" exist?
    Make all the error messages unique
     
  5. MrDevCat

    MrDevCat Spider Jockey

    Messages:
    28
    GitHub:
    elementalminecraftgaming
    Yes, Yes and yes
    Code:
    name: EmeraldWarp
    main: ElementalMinecraftGaming\EmeraldWarp\Main
    version: 1.0.0
    api: [3.5.5]
    load: POSTWORLD
    author: ElementalMinecraftGaming
    description: Set warps and use them!
    
    commands:
     setwarp:
      description: Set a warp!
      usage: "/setwarp {warp}"
      permission: emerald.setwarp
      aliases: [esw]
     warp:
      description: Warp!
      usage: "/warp {warp}"
      permission: emerald.warp
      aliases: [ew]
     listwarps:
      description: List Warps!
      usage: "/listwarps"
      permission: emerald.listw
      aliases: [elw]
     delwarp:
      description: delete Warps!
      usage: "/delwarp"
      permission: emerald.delwarp
      aliases: [edw]
     psetwarp:
      description: Set a warp!
      usage: "/psetwarp {warp}"
      permission: pemerald.setwarp
      aliases: [esw]
     pwarp:
      description: Warp!
      usage: "/pwarp {warp}"
      permission: pemerald.warp
      aliases: [epw]
     pdelwarp:
      description: delete Warps!
      usage: "/pdelwarp"
      permission: pemerald.delwarp
      aliases: [epdw]
    
    
    permissions:
      emerald.setwarp:
        default: op
        description: Let's you use /esw {warp}
      emerald.warp:
        default: true
        description: Let's you use /ew {warp}
      emerald.listw:
        default: true
        description: Let's you use /elw
      emerald.delwarp:
        default: op
        description: Let's you use /edw
      pemerald.setwarp:
        default: op
        description: Let's you use /esw {warp}
      pemerald.warp:
        default: true
        description: Let's you use /epw {warp}
      pemerald.delwarp:
        default: op
        description: Let's you use /edw
    Code:
    ---
    la:
    - 5
    - world
    - -9.357600
    - 71.000000
    - -15.206800
    ...
    
     
    Last edited: Feb 9, 2019
  6. KielKing

    KielKing Zombie

    Messages:
    251
    GitHub:
    kielking
    var_dump(); each if statement and see which ones doesn't output
     
  7. MrDevCat

    MrDevCat Spider Jockey

    Messages:
    28
    GitHub:
    elementalminecraftgaming
    Umm, if this is meant to show up in the console it didn't...for any.
    PHP:
    if (strtolower($command->getName()) == "pwarp") {
                        
    var_dump();
                        if (
    $sender->hasPermission("pemerald.warp")) {
                            
    var_dump();
                            if (
    $sender instanceof Player) {
                                
    var_dump();
                                if (isset(
    $args[0])) {
                                    
    var_dump();
                                    
    $warp $args[0];
                                    
    $configgp = new Config($this->getDataFolder() . "paywarps.yml"Config::YAML);
                                    
    $data $configgp->get($args[0]);
                                    if (
    is_array($data)) {
                                        
    var_dump();
                                        
    $pay $data[0];
                                        
    $land $data[1];
                                        
    $x $data[2];
                                        
    $y $data[3];
                                        
    $z $data[4];
                                        
    EconomyAPI::getInstance()->takeMoney($sender->getName(), (int) $pay);
                                        
    $sender->sendMessage(TextFormat::GOLD "Warping $warp at $land$x$y$z this warp was not free it cost you $pay!");
                                        
    $sender->teleport(new Position($x$y$z$this->getServer()->getLevelByName($land)));
                                        return 
    true;
                                    } else {
                                        
    $sender->sendMessage("Does not exist or corrupted");
                                    }
                                } else {
                                    
    $sender->sendMessage(TextFormat::RED "Warp  failed 2! ");
                                }
                            } else {
                                
    $sender->sendMessage(TextFormat::RED "Warp  failed 3! ");
                            }
                        } else {
                            
    $sender->sendMessage(TextFormat::RED "Warp  failed 4! ");
                        }
                    } else {
                        
    $sender->sendMessage(TextFormat::RED "failed 5!");
                    }
                } else {
                    
    $sender->sendMessage(TextFormat::RED "failed 6!");
                }
            } else {
                
    $sender->sendMessage(TextFormat::RED "failed 7!");
                return 
    false;
            }
    None outputted anything but the error that is showing is from the 7th else
     
  8. MrDevCat

    MrDevCat Spider Jockey

    Messages:
    28
    GitHub:
    elementalminecraftgaming
    Fixed it.
    2 things were wrong:
    1. Too many else statements because of how I set the last command
    2. The take money line is wrong
     
  9. KielKing

    KielKing Zombie

    Messages:
    251
    GitHub:
    kielking
    you're supposed to put a string so that you can identify where it runs up to, for example var_dump("test1"); then the next one var_dump("test2"); and so on
     

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.