Permissions?

Discussion in 'Spigot Plugin Development' started by entelogie, Jun 17, 2017.

  1. Hi,

    I am coding an AFK Plugin for my server. I was testing it until now, and users can do /afk too. I inserted a permission... What did I do wrong?
    Code (Text):
    package intercube.commands;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class AfkCommand implements CommandExecutor{
        ArrayList<Player> check = new ArrayList<>();
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
         
            Player p = (Player)sender;
         
            if (cmd.getName().equalsIgnoreCase("afk")){
                if (args.length == 0) {
                if(p.hasPermission("intercube.afk")); {
                    if(check.contains(p)) {
                        check.remove(p);
                        Bukkit.broadcastMessage("§6Lobby §8» §6"+ p.getName() +" §7ist nicht mehr AFK.");
                        }else{
                        check.add(p);
                        Bukkit.broadcastMessage("§6Lobby §8» §6"+ p.getName() +" §7ist jetzt AFK.");}}

            }else{
                p.sendMessage("§6Lobby §8» §7Dazu hast Du keine Rechte.");
            }}
         
            return false;
        }

    }
     
    Ps: Sorry for my bad english :D
     
  2. Make sure to register the permission in your plugin.yml. You can see how to register a permission in a plugin.yml on this page: http://bukkit.gamepedia.com/Plugin_YAML
    When you do that, either set the "default:" value of the permission to "op" or "false". That way, regular users will not get this permission. Hopefully this solves your problem!
     
  3. if(p.hasPermission("intercube.afk")); <---- remove the semicolon {
     
  4. Its not required to add your permissions to the plugin.yml (im not sure if youre indicating it is) and by default users do not have the permissions you make. The text below is from the link you sent ;)
    Code (Text):
    If node does not exist the permission defaults to op
     
  5. 1. properly indent your code
    2. program against abstraction rather than implementation
    3. you have certain errors that your IDE should highlight to you. resolve them.
     
  6. I have a question too, does it matter if any of the letters are capitalized? Just asking for my future plugins
     
  7. No idea. But all plugins use lowercase letters, why would yours need capital letters.
     
  8. No, it doesn't. However, if you are asking because you want player's to specify their permissions in a config file like so:
    Code (Text):
    perms:
    - perm.perm1
    - perm.perm2
    - PeRM.PErm3
    And you are afraid that they will specify with uppercase, just call String#toLowerCase().trim() to make it lowercase and remove leading white-spaces (such as "perm.perm1 "). For readability and for safety :)
     
  9. Hi,

    Ich habe deinen Code ein wenig geändert :D Versuch das mal:

    Code (Text):
    package intercube.commands;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class AfkCommand implements CommandExecutor{
        ArrayList<Player> check = new ArrayList<>();
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName.equalsIgnoreCase("afk")) {
                if(sender instanceof Player) {
                   
                    Player p = (Player) sender;
                   
                    if(p.hasPermission("intercube.afk")) {
                   
                        if(args.length == 0) {
                       
                            if(check.contains(p)) {
                           
                                check.remove(p);
                                Bukkit.broadcastMessage("§6Lobby §8» §6"+ p.getName() +" §7ist nicht mehr AFK.");
                               
                            } else {
                               
                                check.add(p);
                                Bukkit.broadcastMessage("§6Lobby §8» §6"+ p.getName() +" §7ist jetzt AFK.");}}
                               
                            }
                        } else {
                           
                            p.sendMessage("§6Lobby §8» §6Zu viele Argumente! Nutze /afk");
                           
                        }
                    } else {
                       
                        p.sendMessage("§6Lobby §8» §7Dazu hast Du keine Rechte.");
                       
                    }
                } else {
                   
                    sender.sendMessage("§6Lobby §8» §6Dieser Befehl ist nur für Spieler");
                   
                }
            }
            return true;
        }

    }