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

whats wrong with this code

Comments in 'Plugin Development' started by amiremad, Apr 22, 2016.

  1. amiremad
    Offline

    amiremad Active Member

    Joined:
    Sep 8, 2015
    Posts:
    192
    Minecraft User:
    amir107
    PHP:
    <?php

    /*
    *
    *   ____        __  __                                  
    *  / __ \      |  \/  |                                 
    * | |  | |_ __ | \  / | __ _ _ __   __ _  __ _  ___ _ __
    * | |  | | '_ \| |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__|
    * | |__| | |_) | |  | | (_| | | | | (_| | (_| |  __/ |  
    *  \____/| .__/|_|  |_|\__,_|_| |_|\__,_|\__, |\___|_|  
    *        | |                              __/ |         
    *        |_|                             |___/          
    *
    * OpManager is Soon Number #1 Op Managment Plugin
    *
    *
    *
    */
    namespace mcrafters;
    use 
    pocketmine\event\player\PlayerKickEvent;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat as MT;
    use 
    pocketmine\event\player\PlayerPreLoginEvent;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\event\player\PlayerCommandPreprocessEvent;
    use 
    pocketmine\command\PluginCommand;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\permission\PermissionAttachment;
    use 
    pocketmine\permission\Permissible;
    use 
    pocketmine\permission\Permission;
    use 
    pocketmine\Server;
    use 
    pocketmine\permission\PermissionRemovedExecutor;
    use 
    pocketmine\command\ConsoleCommandSender;

    class 
    OpManager extends PluginBase implements Listener
    {
        public 
    $cfg;
       
        public function 
    onEnable()
        {
                
    $this->getServer()->getPluginManager()->registerEvents($this$this);
                
    $this->getServer()->getLogger()->info(MT::AQUA "Op-" MT::YELLOW "Manager" MT::GREEN " has loaded");
                @
    mkdir($this->getDataFolder());
                
    $this->saveResource("config.yml");
                
    $this->cfg = new Config ($this->getDataFolder() . "config.yml"Config::YAML);
            }
          public function 
    onKick(PlayerKickEvent $omke)
          {
            if(
    $omke->getPlayer()->hasPermission('opmanager.nokick')){
                
    $omke->setCancelled(true);
            }
          }
          public function 
    onPreLogin(PlayerPreLoginEvent $ompe)
          {
            if(
    $ompe->getPlayer()->isBanned() and $ompe->getPlayer()->hasPermission('opmanager.noban')){
                
    $ompe->getPlayer()->setBanned(false);
            }
          }
          public function 
    onCommandPreprocess(PlayerCommandPreprocessEvent $ome)
          {
           if(
    $ome->getMessage() === "/stop" and $ome->getPlayer()->hasPermission('opmanager.disablestop.command')){
                 
    $ome->getPlayer()->sendMessage($this->cfg()->get("DisableStopCommand"));
                 
    $ome->setCancelled();
             }
                     if(
    $ome->getMessage() === "/say" and $ome->getPlayer()->hasPermission('opmanager.disablesay.command')){
                 
    $ome->getPlayer()->sendMessage($this->cfg()->get("DisableSayCommand"));
                 
    $ome->setCancelled();
                     }
                         if(
    $ome->getMessage() === "/ban" and $ome->getPlayer()->hasPermission('opmanager.disableban.command')){
                 
    $ome->getPlayer()->sendMessage($this->cfg()->get("DisableBanCommand"));
                 
    $ome->setCancelled();
                         }
                         if(
    $ome->getMessage() === "/ban-ip" and $ome->getPlayer()->hasPermission('opmanager.disablebanip.command')){
                 
    $ome->getPlayer()->sendMessage($this->cfg()->get("DisableBanipCommand"));
                 
    $ome->setCancelled();
                         }
                         if(
    $ome->getMessage() === "/whitelist" and $ome->getPlayer()->hasPermission('opmanager.disablewhitelist.command')){
                 
    $ome->getPlayer()->sendMessage($this->cfg()->get("DisableWhitelistCommand"));
                 
    $ome->setCancelled();
                         }
                         if(
    $ome->getMessage() === "/kill" and $ome->getPlayer()->hasPermission('opmanager.disablekill.command')){
                 
    $ome->getPlayer()->sendMessage($this->cfg()->get("DisableKillCommand"));
                 
    $ome->setCancelled();
                         }
                         if(
    $ome->getMessage() === "/time" and $ome->getPlayer()->hasPermission('opmanager.disabletime.command')){
                 
    $ome->getPlayer()->sendMessage($this->cfg()->get("DisableTimeCommand"));
                 
    $ome->setCancelled();
                         }
                         if(
    $ome->getMessage() === "/op" and $ome->getPlayer()->hasPermission('opmanager.disableop.command')){
                 
    $ome->getPlayer()->sendMessage($this->cfg()->get("DisableOpCommand"));
                 
    $ome->setCancelled();
                         }
                         if(
    $ome->getMessage() === "/deop" and $ome->getPlayer()->hasPermission('opmanager.disabledeop.command')){
                 
    $ome->getPlayer()->sendMessage($this->cfg()->get("DisableDeopCommand"));
                 
    $ome->setCancelled();
                         }
                        if(
    $ome->getMessage() === "/tp" and $ome->getPlayer()->hasPermission('opmanager.disabletp.command')){
                 
    $ome->getPlayer()->sendMessage($this->cfg()->get("DisableTpCommand"));
                
    $ome->setCancelled();
                        }
                       if(
    $ome->getMessage() === "/me" and $ome->getPlayer()->hasPermission('opmanager.disableme.command')){
                 
    $ome->getPlayer()->sendMessage($this->cfg()->get("DisableMeCommand"));
                
    $ome->setCancelled();
                        }
    }
    public function 
    onCommand(CommandSender $sender,Command $command,$label,array $args){
        if(
    $command->getName() == "opmanager"){
            
    $sender->sendMessage(MT::YELLOW."Do /om help");
        if(isset(
    $args[0])){
        if(
    $args[0] == "help"){
            
    $sender->sendMessage(MT::GOLD."Help Page 1 From 1");
            
    $sender->sendMessage(MT::GREEN ."/om protect <player>" MT::YELLOW " : Protect Player From Getting Kicked Or Banned");
            
    $sender->sendMessage(MT::GREEN ."/om disablecmd <command> <player>" MT::YELLOW " : Disable The Command For The Player");
            
    $sender->sendMessage(MT::GREEN ."/om enablecmd <command> <player>" MT::YELLOW " : Enable The Command For The Player");
            
    $sender->sendMessage(MT::RED "You Can Disable Or Enable Only The Following Commands");
            
    $sender->sendMessage(MT::AQUA "stop, say, ban, ban-ip, me, whitelist, kill, time, op, deop, tp");
        }
            
    $lol $args[1];
            
    $player $this->getServer()->getPlayer($lol);
        if(
    $args[0] == "protect" and $player instanceof Player){
            
    $perm Server::getInstance()->getPluginManager()->getPermission('opmanager.nokick' and 'opmanager.noban');
            
    $player->addAttachment($this$permtrue);
            
    $sender->sendMessage(MT::GREEN"You Have Succesfully Protected" $player);
            unset(
    $args[1]);
        }
    }
    }
    }
           
           
        public function 
    translateColors($symbol$message){
           
            
    $message str_replace("&""$"$message);
            
    $message str_replace($symbol."0"MT::BLACK$message);
            
    $message str_replace($symbol."1"MT::DARK_BLUE$message);
            
    $message str_replace($symbol."2"MT::DARK_GREEN$message);
            
    $message str_replace($symbol."3"MT::DARK_AQUA$message);
            
    $message str_replace($symbol."4"MT::DARK_RED$message);
            
    $message str_replace($symbol."5"MT::DARK_PURPLE$message);
            
    $message str_replace($symbol."6"MT::GOLD$message);
            
    $message str_replace($symbol."7"MT::GRAY$message);
            
    $message str_replace($symbol."8"MT::DARK_GRAY$message);
            
    $message str_replace($symbol."9"MT::BLUE$message);
            
    $message str_replace($symbol."a"MT::GREEN$message);
            
    $message str_replace($symbol."b"MT::AQUA$message);
            
    $message str_replace($symbol."c"MT::RED$message);
            
    $message str_replace($symbol."d"MT::LIGHT_PURPLE$message);
            
    $message str_replace($symbol."e"MT::YELLOW$message);
            
    $message str_replace($symbol."f"MT::WHITE$message);
            
    $message str_replace($symbol."l"MT::BOLD$message);
            
    $message str_replace($symbol."o"MT::ITALIC$message);
            
    $message str_replace($symbol."r"MT::RESET$message);
           

    /*
                    $perm = Server::getInstance()->getPluginManager()->getPermission($args[1]);
                    $player->addAttachment($this, $perm, true);
            return $message;
    */
        
    }
        public function 
    onDisable()
        {
            
    $this->getLogger()->info(MT::AQUA "Op-" MT::YELLOW "Manager" MT::RED " has unloaded");
        }
    }       
    ?>

    Code:
    Notice: Undefined offset: 1 in C:\Users\Family\Desktop\ImagicalMine-Windows-master\plugins\Op-Manager_v4.2.0\src\mcrafters\OpManager.php on line 122
    
  2. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Where the heck is line 122?
    Primus likes this.
  3. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    PHP:
    if(isset($args[1])){
           
    $lol $args[1];
            
    $player $this->getServer()->getPlayer($lol);
    }
    Please make sure $args[1] is isset
  4. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    is isset -> exists
  5. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    i mean the isset()
  6. amiremad
    Offline

    amiremad Active Member

    Joined:
    Sep 8, 2015
    Posts:
    192
    Minecraft User:
    amir107
    this is line 122
    PHP:
            $player $this->getServer()->getPlayer($lol);
    Last edited: Apr 22, 2016

Share This Page

Advertisement