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

how to make the plugin set a permission

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
    how to make my plugin set a permission to a player
  2. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
  3. amiremad
    Offline

    amiremad Active Member

    Joined:
    Sep 8, 2015
    Posts:
    192
    Minecraft User:
    amir107
    my code :

    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"){
    if(
    $this->cfg->get("ServerOwner") != $sender->getName()){
        
    $sender->sendMessage(MT::AQUA "You Cant Use This Command");
    }
        if(
    $this->cfg->get("ServerOwner") == $sender->getName()){
        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");
        }
        if(isset(
    $args[1])){
        
    $player $this->getServer()->getPlayer($args[1]);
        if(
    $args[0] == "protect"){
            
    $lololo Server::getInstance()->getPluginManager()->getPermission('opmanager.nokick');
            
    $lololol Server::getInstance()->getPluginManager()->getPermission('opmanager.noban');
            
    $this->setPermission($player$lololo$lololol);
            
    $sender->sendMessage(MT::GREEN"You Have Succesfully Protected" $player);
        }
    }
    }
    }
    }   
    }   
           
        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");
        }
    }       
    ?>

    My Error :

    Code:
    [18:54:35] [Server thread/CRITICAL]: Unhandled exception executing command 'om protect amir107' in opmanager: Call to undefined method mcrafters\OpManager::setPermission()
    [18:54:35] [Server thread/CRITICAL]: Error: "Call to undefined method mcrafters\OpManager::setPermission()" (EXCEPTION) in "/Op-Manager_v4.2.0/src/mcrafters/OpManager" at line 130
    
  4. amiremad
    Offline

    amiremad Active Member

    Joined:
    Sep 8, 2015
    Posts:
    192
    Minecraft User:
    amir107
    i know how already to set a permission from my plugin but each time i try this i get that error

    i know how to do it but i dont know how to fix the error
  5. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    When you call setPermission(), that function doesn't exist in your plugin object at start.
    That function belongs to the UserDataManager class in PurePerms, so you have to get an instance of that class, then call the setPermission() method from the UserDataManager instance.

    Example:
    PHP:
    // $pureperms is the PurePerm class.
    $usrdmg $pureperms->getUserDataMgr();
    $usrdmg->setPermission($player$permission);

Share This Page

Advertisement