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

Permission Related [PHP]

Comments in 'Plugin Development' started by deot, Oct 13, 2015.

  1. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    I wanted to achieve that is anyone has capslimit.exception permission, it will do not run THE CODE
    So, is this correct? or return false?
    PHP:
            if($player->hasPermission("capslimit.exception")){
                return 
    true;
            }else{
                  
    //THE CODE
            
    }
  2. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    so you would like the person with the permission "caplimit.exception" to use Caps?
  3. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Yep, :)
    I was thinking if "else" is necessary?
  4. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Can you please post the full code, so it can be a little more understanding, and to find more efficient ways of doing this. :)

    EDIT: as "else" can be used before, where you coded to limit the Caps
  5. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Hello!
    No need the else. There is a thing called '!' :)
    PHP:
    if(!$player->hasPermission("capslimit.exception")){
        
    //Executes this code when the player does NOT have the permission
    }
  7. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    PHP:
      
    public function onChat(PlayerChatEvent $event){
    $player $event->getPlayer();
    if(!
    $player->hasPermission("capslimit.exception")){
    $message $event->getMessage();
    $strlen strlen($message);
    $asciiA ord("A");
    $asciiZ ord("Z");
    $count 0;
    for(
    $i 0$i $strlen$i++){
    $char $message[$i];
    $ascii ord($char);
    if(
    $asciiA <= $ascii and $ascii <= $asciiZ){
    $count++;
    }
    }
          

    you can add it before you start the code
    EDIT: fixed the code, Srry I was in a rush
    Last edited: Oct 13, 2015
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    `return` is basically to stop executing that function. You can imagine it as skipping the rest of the function and directly going to the end of the function.
    Since you skipped the code, you don't need to use else to prevent executing the code.
    PHP:
    if($condition){
      return;
    }
    // these will only be run if $condition is not true.
    We are talking about control flow, not about how to detect caps... Please don't post if you don't know what is going on.

Share This Page

Advertisement