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

than coreUI buttons permission

Discussion in 'Plugin Help' started by WylSmart, May 13, 2020.

  1. WylSmart

    WylSmart Slime

    Messages:
    93
    how to add permissions to each case, so that each buttons is highlighted in red or green, depending on the permission?

    sorry for my bad learne english

    PHP:
    class Main extends PluginBase implements Listener {
        
        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);   
            
    $this->getLogger()->info(TextFormat::GREEN "CoreUI Enable");
        }
        public function 
    onDisable() {
            
    $this->getLogger()->info(TextFormat::RED "CoreUI Disable");
        }
        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool {
            switch(
    $cmd->getName()){                   
                case 
    "coreui":
                    if (
    $sender->hasPermission("coreui.command")){
                         
    $this->Menu($sender);
                    }else{     
                         
    $sender->sendMessage(TextFormat::RED "You dont have permission!");
                         return 
    true;
                    }     
                break;         
                
             } 
            return 
    true;                         
        }
      
        public function 
    Menu($sender){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $senderint $data null) {
                
    $result $data;
                if(
    $result === null){
                    return 
    true;
                }             
                switch(
    $result){
                    case 
    0:
                
    $sender->sendMessage(TextFormat::LIGHT_PURPLE."(CORE) "TextFormat::YELLOW "Enabled flight mode!");
                
    $sender->setAllowFlight(true);
                    break;
                    case 
    1:
                
    $sender->sendMessage(TextFormat::LIGHT_PURPLE."(CORE) "TextFormat::YELLOW "Disabled flight mode!");
                
    $sender->setAllowFlight(false);
                    break;               
                    case 
    2:
                
    $sender->setHealth(20);
                
    $sender->sendMessage(TextFormat::LIGHT_PURPLE."(CORE) "TextFormat::YELLOW "Your has ben Healed");
                    break; 
                    case 
    3:
                
    $sender->setFood(20);
                
    $sender->sendMessage(TextFormat::LIGHT_PURPLE."(CORE) "TextFormat::YELLOW "You have been feed!");
                    break; 
                    case 
    4:
                
    $sender->setGameMode(1);
                
    $sender->sendMessage(TextFormat::LIGHT_PURPLE."(CORE) "TextFormat::YELLOW "GameMode changed to §9Creative");
                    break;
                    case 
    5:
                
    $sender->setGameMode(2);
                
    $sender->sendMessage(TextFormat::LIGHT_PURPLE."(CORE) "TextFormat::YELLOW "GameMode changed to §9Adventure");
                    break;
                    case 
    6:
                
    $sender->setGameMode(3);
                
    $sender->sendMessage(TextFormat::LIGHT_PURPLE."(CORE) "TextFormat::YELLOW "GameMode changed to §9Spectator");
                    break;           
            case 
    7:
                
    $sender->addEffect(new EffectInstance(Effect::getEffect(Effect::INVISIBILITY), 999999990false));
                
    $sender->addTitle(TextFormat::LIGHT_PURPLE."(CORE) "TextFormat::YELLOW "Vanish Enabled");
                    break;           
            case 
    8:
                
    $sender->removeEffect(Effect::INVISIBILITY);
                
    $sender->addTitle(TextFormat::LIGHT_PURPLE."(CORE) "TextFormat::YELLOW "Vanish Disabled");
            break;       
            case 
    9:
                
    $command "pl" ;
                
    $this->getServer()->getCommandMap()->dispatch($sender$command);
            break;         
                    case 
    10:
                
    $sender->sendMessage(TextFormat::LIGHT_PURPLE."(CORE) "TextFormat::YELLOW "CoreUI Closed");
                    break;               
                }
                
                
                });
                    
    $form->setTitle(TextFormat::BOLDTextFormat::LIGHT_PURPLE."CORE");
            
    $form->setContent(TextFormat::GRAY."Author: DaRealAqua\n".TextFormat::GRAY."Version: 0.0.2");
                    
    $form->addButton(TextFormat::GRAY."Enable Fly\n".TextFormat::LIGHT_PURPLE."Tap for Activate Fly");
            
    $form->addButton(TextFormat::GRAY."Dezactive Fly\n".TextFormat::LIGHT_PURPLE."Tap for Disable Fly");
            
    $form->addButton(TextFormat::GRAY."Heal\n".TextFormat::LIGHT_PURPLE."Tap for Heal");
            
    $form->addButton(TextFormat::GRAY."Feed\n".TextFormat::LIGHT_PURPLE."Tap for Eat");
            
    $form->addButton(TextFormat::GRAY."Creative\n".TextFormat::LIGHT_PURPLE."Tap to change GM");
            
    $form->addButton(TextFormat::GRAY."Adventure\n".TextFormat::LIGHT_PURPLE."Tap to change GM");
            
    $form->addButton(TextFormat::GRAY."Spectator\n".TextFormat::LIGHT_PURPLE."Tap to change GM");
                 
    $form->addButton(TextFormat::GRAY."Vanish on\n".TextFormat::LIGHT_PURPLE."Press for Activate Vanish");
                
    $form->addButton(TextFormat::GRAY."Vanish off\n".TextFormat::LIGHT_PURPLE."Press for Disable Vanish");
                
    $form->addButton(TextFormat::GRAY."Plugins\n".TextFormat::LIGHT_PURPLE."Show Server plugins");   
                    
    $form->addButton(TextFormat::RED."Close");
                    
    $form->sendToPlayer($sender);
                return 
    $form;                                           
        }
     
                                                                                                                                                                                                                                                                                              
    }
     
  2. Rim

    Rim Spider Jockey

    Messages:
    28
    GitHub:
    boomyourbang
    Change your button definitions to something like this. I've done the first one for you:
    PHP:
    $form->addButton(($sender->hasPermission("your.permission") ? TextFormat::GREEN TextFormat::RED) . "Enable Fly\nTap for Activate Fly");
    This is the ternary operator in PHP, and it works a lot like an "if/else" statement. If the first operand is true, evaluate as the second, otherwise evaluate as the last. :)
     
    Last edited: May 13, 2020
  3. WylSmart

    WylSmart Slime

    Messages:
    93
    Sorry, how do I add a function to GodMode ?
    immortality mode!
     
    Last edited: May 14, 2020
  4. WylSmart

    WylSmart Slime

    Messages:
    93
    How to make permission for a sender? ?
     
  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.