How do I add permissions to my Bukkit plugin.

Discussion in 'Plugin Development' started by MichaelDoesPlugins, Jun 1, 2014.

Thread Status:
Not open for further replies.
  1. Hello! My name is Michael and I am wondering how to add permissions to my Bukkit plugin. It is called Spawn2Hub and I already have the config created. I have looked all over YouTube but have no success please help me. (I'm not a pro at coding :p)
     
  2. Offline

    Mrawesomecookie

  3. Yeah but those videos are outdated. I'm on 1.7.9 and I don't know what verison they're running
     
  4. Offline

    Mrawesomecookie

  5. Offline

    iiHeroo


    Linking to TheBCBroz is the worst idea as they teach bad coding habits.
     
  6. Offline

    Mrawesomecookie

    MichaelDoesPlugins iiHeroo
    I know, but at least it has the basics.
    Just because you don't have the same minecraft version doesn't mean the same method won't work.
     
  7. Mrawesomecookie I believe that outdated verisons won't work on the newer verisons
     
  8. Offline

    iiHeroo


    Your beliefs are somewhat run.

    NMS breaks each update, pretty sure Pogo and BCBroz don't use it that much so it won't make a big impact. Some methods get deprecated, but usually there's another method to replace it.
     
  9. Offline

    Mrawesomecookie

    iiHeroo
    I wasn't talking about CraftBukkit. The question is "How do I add permissions to my bukkit plugin".
     
  10. iiHeroo I was trying to look for a UPDATED verison of one. Also Pogo has a MAC and I use a PC and I think that MAC verison is different from PC

    Mrawesomecookie If you want me to I'll add my code.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
  11. Offline

    Mrawesomecookie

    MichaelDoesPlugins
    Ok, you can add your code, but I would rather not spoofeed you. There isn't a different version of bukkit based on operating system.
     
  12. Offline

    iiHeroo


    I think there's over 1500 versions of Bukkit...

    http://horrgs.org/img/8lfO.png
     
  13. Offline

    Mrawesomecookie

  14. Offline

    iiHeroo


    Sure, but all you need to do for example:

    //Runs command "fly"
    //Has Permission "fly.fly"
    //Allow player to fly
    //Else
    //No perm

    To check if a player has that permission is Player#hasPermission(String)
     
  15. Offline

    Gater12

  16. Mrawesomecookie package me.XxMarioPlaysxX.Spawn2Hub;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Main extends JavaPlugin{

    public void onEnable() {
    getLogger().info("Spawn2Hub has been Enabled!");
    }

    public void onDisable() {
    getLogger().info("Spawn2Hub has been Disabled!");
    }

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if(sender instanceof Player) {
    Player player = (Player) sender;
    if(cmd.getName().equalsIgnoreCase("hub")){
    String hub = "spawn " + player.getName();
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), hub);
    player.sendMessage(ChatColor.DARK_AQUA + "Returning back to Spawn!");

    }
    }
    return false;
    }
    }

    Gater12 I just posted my code :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
  17. Offline

    Mrawesomecookie

  18. Offline

    Gater12

    MichaelDoesPlugins
    I do not see a way you are incorporating permission checking in your code.

    A much more easier built-in permission checking would be to register permission nodes in the plugin.yml, and assign the permission node to the command.

    Refer to this page: http://wiki.bukkit.org/Plugin_YAML
     
  19. Offline

    Mrawesomecookie

    Gater12
    True, but that doesn't work if you have multiple subcommands in a command.
     
  20. Offline

    Gater12

    Mrawesomecookie
    In this case, it is for just a base command.
    hasPermission is used for that purpose to check permissions for subcommands, other events, etc.

    MichaelDoesPlugins
    Example plugin.yml:
    Code:
    name: Test
    main: me.gater12.testplugin.Main
    version 0.6.9
    commands:
      fly:
        description: Fly command!
        permission: test.fly
        permission-message: You do not have permission
    permissions:
      test.fly:
        description: Permission node to fly
        default: op
     
  21. Offline

    Mrawesomecookie

    Gater12
    Yeah, he could have figured it out for himself though. I don't like to spoonfeed people code.
     
    Gater12 likes this.
  22. Gater12 Do I need to put that in my plugin.yml
     
  23. Offline

    mactown21

    MichaelDoesPlugins yes you need to put that in your plugin.yml.. Also for permissions have you tried doing

    Code:
    Player player = (Player)sender;
    if(player.hasPermission("hub.use")
    {
      if(cmd.getName().equalsIgnoreCase("hub")
      {
        String hub = "Spawn " + player.getName();
        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), hub);
        player.sendMessage(ChatColor.DARK_AQUA + "Returning back to Spawn!");
    and maybe you should trying use UUID's instead. Since i havnt made a plugin for 1.7.9 yet i have no clue if things actually changed from previous versions(1.6, ... 1.7.2, 1.7.4, 1.7.5)
     
  24. Offline

    Gater12

    mactown21
    Where would UUID be present for permission checking?
     
  25. Offline

    MrZoraman

    MichaelDoesPlugins
    First off,
    Code:java
    1. public void onEnable() {
    2. getLogger().info("Spawn2Hub has been Enabled!");
    3. }
    4.  
    5. public void onDisable() {
    6. getLogger().info("Spawn2Hub has been Disabled!");
    7. }
    8.  

    This is unecessary. Bukkit nowadays automatically writes those messages.

    You only need to register your command under the commands section of the plugin.yml. You are not required to put your permissions there.

    I suggest you read about the CommandSender in the documentation. I guarantee you that it's not out of date.
    http://jd.bukkit.org/beta/doxygen/dd/dd4/interfaceorg_1_1bukkit_1_1command_1_1CommandSender.html.

    Also, (sorry I can't edit my above message for some reason...),
    You can use the plugin.yml to handle your permissions for you, but that hinders the amount of control you have over your plugin, so I tend to avoid that (but that's just me...)

    Also, I guess this is an anti-spoon feeding bandwagon, but that's ok. You can have the extensive bukkit plugin tutorial spoon feed it for you (http://wiki.bukkit.org/Plugin_Tutorial#Permissions).

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
  26. Offline

    es359

Thread Status:
Not open for further replies.

Share This Page