Permissions?

Discussion in 'Spigot Plugin Help' 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. Replace your command code with:
    Code (Text):
    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.");
                }
            }
    I think the issue is the ';' after '(p.hasPermission("intercube.afk"))'.
    I removed it
     
  3. Wow it seems to be a good plugin ;)
     
  4. Thank you! :) It works.



    Haha, it's just a simple /afk plugin :)