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

Switch error

Comments in 'Plugin Development' started by JonsMC, Jul 29, 2016.

  1. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Hi, im making a plugin but the console always return me this error when i load the plugin:

    Code:
    Server thread/CRITICAL ParseError: "syntax error, unexpected 'switch' (T_SWITCH)" (EXCEPTION) in "/OpBlock/src/opblock/Main" at line 36
    PHP:
    <?php

    namespace opblock;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\utils\Config;

    class 
    Main extends PluginBase implements Listerner{
    private 
    $plogged;

         public function 
    onLoad() {
             
    $this->getLogger->info(TextFormat::RED."[OpBlock] loading... ");
         }
         public function 
    onEnable() {
                
    $this->cfg = new Config($this->getDataFolder()."config.yml"Config::YAML);
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger->info(TextFormat::GREEN."[OpBlock] OpBlock loaded!");
            
    $this->list $this->getConfig()->get('list');
        }
        
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args) {
       
        
    $allias = array("ob""opblock""opb""oblock");
       
        if(
    $command->getName() == $allias and $sender->hasPermission("opblock.command"){
       
            switch(
    strtolower($args[0])) {
            
    // add and remove player from bypass list
                 
    case "add":
                        if (
    $sender->hasPermission("opblock.command.add") {
                           if (isset(
    $args[1])) {
                                
    $this->addPlayerConfig($args[1]);
                                
    $sender->sendMessage("Added ".$args[1] ."to Bypass list");
                            } else {
                               
    $sender->sendMessage("Usage: /opblock add <player>");
                               }
                               
    $sender->sendMessage(TextFormat::RED."You Don't have permission to use this command");
                               }
                               break;
                              
                   case 
    "remove":
                   case 
    "rm":
                           if(
    $sender->hasPermission("opblock.command.rm"){
                              if (isset(
    $args[1]) {
                                   
    $this->removePlayerConfig($args[1]);
                                   
    $sender->sendMessage("Removed ".$args[1] ."out of Bypass list");
                                   }else{
                                   
    $sender->sendMessage("Usage: /opblock remove <name>");
                                }
                             }   else {
                                
    $sender->sendMessage(TextFormat::RED."You don't have permission to use this command");
                                }
                              break;
                           
                              default:
                                  
    $sender->sendMessage("Usage: /opblock <add/remove> or <password>");
                                  break;
                               }
                              
                               
    $password $this->getConfig()->get('password');
                               if (
    $sender instanceof Player) {
                                  if (isset(
    $args[0]) {
                                     if (
    $args[0] == $password) {
                                        
    $this->plogged[$event->getPlayer()->getName] == true
                                       $sender
    ->sendMessage(TextFormat::GREEN."Password Accepted!");
                                     } else {
                                     
    $sender->sendMessage(TextFomat::RED."Wrong Password!");
                                     }
                                     } else {
                                     
    $sender->sendMessage("Usage: /opblock <add/remove> or <password>");
                                     }
                                     else {
                                     
    $sender->sendMessage("This command is only avaliable for ingame player");
                                     }
                                }
                           }
                                                                                                      
        public function 
    onBlockBreak(BlockBreakEvent$event)
        
    $p $event->getPlayer();
             if (
    $p->isOp()) {
                  if(!
    $this->plogged[$event->getPlayer()->getName] == true){
                      
    $p->sendMessage(TextFormat::RED."Please input Password for OP before you continute");
                            
    $event->setCancelled;
                            }
                           
                            public function 
    onTap(PlayerInteractEvent$event) {
                            
    $p $event->getPlayer();
                            if (
    $p->isOp()) {
                  if(!isset(
    $this->plogged[$event->getPlayer()->getName] == true){
                      
    $p->sendMessage(TextFormat::RED."Please input Password for OP before you continute");
                            
    $event->setCancelled;
                            }
                           
                       private function 
    addPlayerConfig($event) {
                       
    $playerName $event->getPlayer()->getName();
               
                      
    $list $this->getConfig()->get('list');
                      
    $new_list $list;
                      
    $new_list[] = $playerName;
                      
    $this->getConfig()->set('list'$new_list);
                      
    $this->getConfig()->save();
                      
    $this->getConfig()->reload();
                      }
                     
                      private function 
    removePlayerConfig($event) {
                      
    $playerName $event->getPlayer()->getName();
                 
    $list $this->getConfig()->get('list');
                 
    $for_remove $playerName;
                 
    $new_list = [];
                            foreach(
    $list as $value) {
        if(
    $value != $for_remove) {
            
    $new_list[] = $value;
        }
    }
           
    $this->getConfig()->set('list'$new_list);
           
    $this->getConfig()->save();
           
    $this->getConfig()->reload();
            
             public function 
    onJoin(PlayerJoinEvent$event) {
             
    $player $event->getPlayer-();
             if (
    $player->isOp()){
            if (
    $this->list->exits($player->getName())) {
                 
    $this->plogged[$player->getName] == true;
                 }
                 if(!
    $this->plogged[$player->getName] == true) {
                  
    $player->sendMessage(TextFormat::RED."Please input password for OP before you continute");
                  }
                }
             }
          }
    Crashdump:
    Code:
    Genisys Crash Dump Thu Jul 28 21:30:15 PDT 2016
    
    Error: syntax error, unexpected 'switch' (T_SWITCH)
    File: /OpBlock/src/opblock/Main
    Line: 36
    Type: notice
    
    THIS CRASH WAS CAUSED BY A PLUGIN
    
    Code:
    [27]         $this->list = $this->getConfig()->get('list');
    [28]     }
    [29]      
    [30]     public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
    [31]    
    [32]     $allias = array("ob", "opblock", "opb", "oblock");
    [33]    
    [34]     if($command->getName() == $allias and $sender->hasPermission("opblock.command"){
    [35]    
    [36]        switch(strtolower($args[0])) {
    [37]        // add and remove player from bypass list
    [38]             case "add":
    [39]                    if ($sender->hasPermission("opblock.command.add") {
    [40]                       if (isset($args[1])) {
    [41]                            $this->addPlayerConfig($args[1]);
    [42]                            $sender->sendMessage("Added ".$args[1] ."to Bypass list");
    [43]                        } else {
    [44]                           $sender->sendMessage("Usage: /opblock add <player>");
    [45]                           }
    [46]                           $sender->sendMessage(TextFormat::RED."You Don't have permission to use this command");
    
    Backtrace:
    #0 (): spl_autoload_call(string opblock\Main)
    #1 /src/pocketmine/plugin/FolderPluginLoader(48): class_exists(string opblock\Main, boolean 1)
    #2 /src/pocketmine/plugin/PluginManager(155): pocketmine\plugin\FolderPluginLoader->loadPlugin(string /home/minecraft/multicraft/servers/server20/plugins/OpBlock)
    #3 /src/pocketmine/plugin/PluginManager(333): pocketmine\plugin\PluginManager->loadPlugin(string /home/minecraft/multicraft/servers/server20/plugins/OpBlock, array Array())
    #4 /src/pocketmine/Server(2031): pocketmine\plugin\PluginManager->loadPlugins(string /home/minecraft/multicraft/servers/server20/plugins/)
    #5 /src/pocketmine/PocketMine(467): pocketmine\Server->__construct(pocketmine\CompatibleClassLoader object, pocketmine\utils\MainLogger object, string phar:///home/minecraft/multicraft/jar/genisys.phar/, string /home/minecraft/multicraft/servers/server20/, string /home/minecraft/multicraft/servers/server20/plugins/, string unknown)
    #6 (1): require_once(string phar:///home/minecraft/multicraft/jar/genisys.phar/src/pocketmine/PocketMine.php)
    
    Genisys version: 0909f533a4652606107c420de530bfd46a848d70 [Protocol 81; API 2.0.0]
    uname -a: Linux voltage.nether.co 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64
    PHP version: 7.0.3
    Zend version: 3.0.0
    OS : Linux, linux
    
    Server uptime: 0 seconds
    Number of loaded worlds: 0
    Players online: 0/10
    
    Loaded plugins:
    What is wrong, please help me!
  2. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Are you sure that $command->getName () == $allias works? I think you must do foreach ($allias as $a) and do if ($command->getName () == $a
    SOFe likes this.
  3. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Line 34 has a missing closing parenthesis.
    Try exploring more about the error message yourself next time ;) The error is not always exactly on the line you made the mistake, but usually on that line or the (functional, not empty or comment) line before it.
    Or in_array().

    In conclusion, change line 34 to:
    PHP:
    if(in_array($command->getName(), $allias) and $sender->hasPermission("opblock.command")){
    CraftYourBukkit likes this.
  4. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Yeah the 2 methods work its not important which he uses
  5. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    It is quite wrong to do what that function does while there exists a function that does the exactly same thing. It is very ugly to write a foreach loop every time you can use in_array() to get it done.

    What is your purpose of posting this anyway? Trying to pick a fight?
    CraftYourBukkit likes this.
  6. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Be quiet Samanta xD
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Good one but stick to new forum standards in order to avoid punishment.
    Survingo likes this.

Share This Page

Advertisement