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

Plugin Error

Discussion in 'Facepalm' started by Defications2po, May 14, 2017.

  1. Defications2po

    Defications2po Witch

    Messages:
    51
    so ive been making this plugin for a server and i need help i got some erros but fixed them by myself .
    Heres my code
    PHP:
    <?php

    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */

    use pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pockemine\plugin\{PluginBasePlugin};
    use 
    pocketmine\command\{CommandCommandSender};
    use 
    pocketmine\utils\TextFormat as C;
    use 
    pocketmine\item\Item;

    class 
    Main extends PluginBase{
       
        public function 
    onCommand(CommandSender $sendercommand $command$label, array $args){
            if (
    $command->getName() == "Mask"){
                if (!isset(
    $args[0])){
                    
    $sender->sendMessage(C::DARK_RED."Usage ".C::DARK_GRAY."/Mask (mask name) (player) (amount)");
                    return;
                }
                switch (
    strtolower($args[0])){
                    case 
    "Zombie"
                        
    if(!$sender->hasPermission("Mask.zombie")){
                            
    $amount $amount = ((int) $args[1]);
                            
    $item Item::get(3970$amount);
                            
    $item->setCustomName("§7Name:§eZombie Mask\n§7Desc:§ePut On for effects\n§7Status:\n§eUNLOCKED");
                            
    $player->getInventory()->addItem($item);
                            
    $sender->sendMessage("§eLatenci §7>> You just recieved a Zombie Mask");
                            return;
                       
                }
               
                else{
    $sender->sendMessage("§4YOU DONT HAVE PERMISSION SMH STOPPPP");
                return;
                        }
                }
            }
        }
    }
    heres the errors
    Code:
    [CONSOLE: Reload complete.]
    2017-05-14 [mcpeplugin] > [CONSOLE: Reloading server...]
    2017-05-14 [mcpeplugin] > Saving levels...
    2017-05-14 [mcpeplugin] > Disabling OpSlimeBall v0.1
    2017-05-14 [mcpeplugin] > Reloading properties...
    2017-05-14 [mcpeplugin] > Loading plugin: Masks v0.1
    2017-05-14 [mcpeplugin] > An unknown error occurred while attempting to perform this command
    2017-05-14 [mcpeplugin] > Unhandled exception executing command 'reload' in reload: syntax error, unexpected 'if' (T_IF)
    2017-05-14 [mcpeplugin] > ParseError: "syntax error, unexpected 'if' (T_IF)" (EXCEPTION) in "/Masks/src/Masks/Main" at line 27
    2017-05-14 [mcpeplugin] > [CONSOLE: Reloading server...]
    2017-05-14 [mcpeplugin] > Saving levels...
    2017-05-14 [mcpeplugin] > Reloading properties...
    2017-05-14 [mcpeplugin] > Loading plugin: Masks v0.1
    2017-05-14 [mcpeplugin] > An unknown error occurred while attempting to perform this command
    2017-05-14 [mcpeplugin] > Unhandled exception executing command 'reload' in reload: syntax error, unexpected variable (T_VARIABLE)
    2017-05-14 [mcpeplugin] > ParseError: "syntax error, unexpected variable (T_VARIABLE)" (EXCEPTION) in "/Masks/src/Masks/Main" at line 27
    2017-05-14 [mcpeplugin] > TTOp left the game
    2017-05-14 [mcpeplugin] > TTOp[/10.0.0.149:19132] logged out due to client disconnect
    
    Helping me will be highly appreciated thx
     
  2. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    show me where line 25 - 30 is
     
  3. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    oh i have it you forgot a ":" :D It should be:
    PHP:
    case "Zombie":
     
  4. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    I don't see how a string to lower could possibly have the first letter uppercase either :facepalm:
     
    HimbeersaftLP and corytortoise like this.
  5. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    yes, you are right :D
     
  6. Defications2po

    Defications2po Witch

    Messages:
    51
    Srry i i have been coding for like 3 hours my brain is dead
     
  7. Defications2po

    Defications2po Witch

    Messages:
    51
    Now it comes with this what to do now i know i have fixed a error similar to this but i cant fix this ik its ez but cant remember
    Code:
    [mcpeplugin] > Loading plugin: Masks v0.1
    2017-05-14 [mcpeplugin] > An unknown error occurred while attempting to perform this command
    2017-05-14 [mcpeplugin] > Unhandled exception executing command 'reload' in reload: syntax error, unexpected '}', expecting end of file
    2017-05-14 [mcpeplugin] > ParseError: "syntax error, unexpected '}', expecting end of file" (EXCEPTION) in "/Masks/src/Masks/Main" at line 41
    2017-05-14 [mcpeplugin] > DarkStray : :/
    
    PHP:
    <?php

    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    namespace Masks;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pockemine\plugin\{PluginBasePlugin};
    use 
    pocketmine\command\{CommandCommandSender};
    use 
    pocketmine\utils\TextFormat as C;
    use 
    pocketmine\item\Item;

    class 
    Main extends PluginBase{
       
        public function 
    onCommand(CommandSender $sendercommand $command$label, array $args){
            if (
    $command->getName() == "Mask"){
                if (!isset(
    $args[0])){
                    
    $sender->sendMessage(C::DARK_RED."Usage ".C::DARK_GRAY."/Mask (mask name) (player) (amount)");
                    return;
                }
                switch (
    strtolower($args[0])){
                    case 
    "Zombie":
                            
    $amount $amount = ((int) $args[1]);
                            
    $item Item::get(3970$amount);
                            
    $item->setCustomName("§7Name:§eZombie Mask\n§7Desc:§ePut On for effects\n§7Status:\n§eUNLOCKED");
                            
    $player->getInventory()->addItem($item);
                            
    $sender->sendMessage("§eLatenci §7>> You just recieved a Zombie Mask");
                            return;
                        }
                }
               
                else{
    $sender->sendMessage("§4YOU DONT HAVE PERMISSION SMH STOPPPP");
                return;
                        }
                }
            }
        }
     
  8. Defications2po

    Defications2po Witch

    Messages:
    51
  9. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    PHP:
    <?php

    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    namespace Masks;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pockemine\plugin\{PluginBasePlugin};
    use 
    pocketmine\command\{CommandCommandSender};
    use 
    pocketmine\utils\TextFormat as C;
    use 
    pocketmine\item\Item;

    class 
    Main extends PluginBase{
     
        public function 
    onCommand(CommandSender $sendercommand $command$label, array $args){
            if (
    $command->getName() == "Mask"){
                if (!isset(
    $args[0])){
                    
    $sender->sendMessage(C::DARK_RED."Usage ".C::DARK_GRAY."/Mask (mask name) (player) (amount)");
                    return;
                }
                switch (
    strtolower($args[0])){
                    case 
    "zombie":
                        if(
    $sender->hasPermission("mask.zombie")){
                            
    $amount $amount = ((int) $args[1]);
                            
    $item Item::get(3970$amount);
                            
    $item->setCustomName("§7Name:§eZombie Mask\n§7Desc:§ePut On for effects\n§7Status:\n§eUNLOCKED");
                            
    $player->getInventory()->addItem($item);
                            
    $sender->sendMessage("§eLatenci §7>> You just recieved a Zombie Mask");
                            return 
    true;
                        } else {
                            
    $sender->sendMessage("§4YOU DONT HAVE PERMISSION SMH STOPPPP");
                            return 
    true;
                        }
                }
            }
        }
    }
    If you reformat your code better it's a whole lot easier to work with.
     
    corytortoise likes this.
  10. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    I don't see the namespace?
     
  11. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    in the messages after that, the code has an namespace :D
     
  12. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    <?php

    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */

    use pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pockemine\plugin\{PluginBasePlugin};
    use 
    pocketmine\command\{CommandCommandSender};
    use 
    pocketmine\utils\TextFormat as C;
    use 
    pocketmine\item\Item;

    class 
    Main extends PluginBase
    {
        public function 
    onCommand(CommandSender $sendercommand $command$label, array $args){
            if (
    strtolower($command->getName()) == "mask"){
                if (!isset(
    $args[0])){
                    
    $sender->sendMessage(C::DARK_RED."Usage ".C::DARK_GRAY."/Mask (mask name) (player) (amount)");
                    return 
    false// must return a bool
                
    }
                switch (
    strtolower($args[0])){
                    case 
    "zombie"// must be lowercase and have a : after the string
                        
    if(!$sender->hasPermission("mask.zombie")){
                            
    $amount $amount = ((int) $args[1]);
                            
    $item Item::get(3970$amount);
                            
    $item->setCustomName("§7Name:§eZombie Mask\n§7Desc:§ePut On for effects\n§7Status:\n§eUNLOCKED");
                            
    $player->getInventory()->addItem($item);
                            
    $sender->sendMessage("§eLatenci §7>> You just recieved a Zombie Mask");
                            return 
    true// must return a bool
                        
    }else{
                            
    $sender->sendMessage("§4YOU DONT HAVE PERMISSION SMH STOPPPP");
                            return 
    true// must return a bool
                        
    }
                default: 
    // argument switches must have a default
                    
    return false// must return a bool
                
    }
            }
        }
    }
     
  13. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Doesn't return false show the no permission message?
     
  14. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    returning false shows the command's usage
     
  15. Defications2po

    Defications2po Witch

    Messages:
    51
    Oh sorry i dont need that anymore i fixed all my code but thx for helping
     
  16. Lowkey

    Lowkey Slime

    Messages:
    94
    Wow... Syntax errors in the development section. There should really be a punishment for this. Online php syntax checkers are out there people!
     
    jasonwynn10 and Sandertv like this.
  17. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Please don't put syntax errors here, we keep syntax errors where only some see them in the facepalm section for a reason and useful questions in this section. It's just for future developers to find helpful content, not cause we dislike beginners.
     
    SOFe and jasonwynn10 like this.
  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.