Permissions For Plugins

Discussion in 'Plugin Development' started by ForsakenRealmz, Jan 2, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    ForsakenRealmz

    Hello, I just created a freeze plugin that freezes a player in place.. This being my first plugin I am happy happy.

    The last thing I am looking for are setting permissions for it.

    Any good tutorials on that or can anyone in here help me?
    I have two commands set. 'freeze' and 'unfreeze'
    The proper usage for the commands are /freeze <playername>, etc.

    The plugins name is 'MrFreeze' so I was wondering if I could set permission nodes like 'mrfreeze.freeze' and 'mrfreeze.unfreeze'.

    Thank you!
     
  2. Offline

    keelar

    You can check if a player has a permission by doing:
    Code:
    Player player (Player)sender;
     
    if(player.hasPermission("mrfreeze.freeze")){
        //freeze player code here
    }else{
        player.sendMessage("You do not have permission to do that.");
    }
    And just do the same thing for the unfreeze command except use "mrfreeze.unfreeze".

    Also, before you try to cast sender to Player you should always make sure it is a player first by doing:

    Code:
    if(sender instanceof Player){
        //sender is a player
    }
     
  3. Offline

    ForsakenRealmz

    Should this be my line?

    Code:
            if(commandLabel.equalsIgnoreCase("freeze") && player.hasPermission("mrfreeze.freeze")){
    And what about my plugin.yml?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
  4. Offline

    keelar

    What about it?
     
  5. Offline

    ForsakenRealmz

    Do I have to set the permissions in my plugin.yml?

    Currently looks like this...

    Code:
    name: MrFreeze
    main: me.ForsakenRealmz.Youtube.Youtube
    version: 1.0
    description: >
                MyFreeze Plugin.
    commands:
      freeze:
        description: Freeze a player
      unfreeze:
        description: Unfreeze a player
     
  6. Offline

    tommycake50

    nope you dont.
     
  7. Offline

    ForsakenRealmz

    Nvm it works now! :)
     
  8. just a note: registering permissions at plugin.yml is optional if you want the default settings
     
Thread Status:
Not open for further replies.

Share This Page