Help! Check if an player exist in an arraylist and deny a command.

Discussion in 'Spigot Plugin Development' started by DaddyJGG, Apr 29, 2017.

  1. Hello, i have this problem:

    The event is that if a player contains the arraylist "freezer" and the sender execute the "/ ban" command, you can't use the command.

    Sorry for my english, and thanks for reading.
  2. I think it would be easier for you if you change the ban command.
    • Agree Agree x 1
  3. Yeah this is and better idea! Let your class implement "CommandExecutor" and do it like this:
    Code (Text):
    public class BanCommand implements CommandExecutor{

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (sender instanceof Player) {
                Player p = (Player) sender;
                if (cmd.getName().equalsIgnoreCase("ban")) {
                    if (freezer.contains(p.getName())) {
                        p.sendMessage(Utils.prefix + ChatColor.RED + "You don't have permissions to execute this command.");
            return false;
    You also have to register the command in you main class in your onEnable():
    Code (Text):
    getCommand("ban").setExecutor(new BanCommand(), this);
  4. Use not if cmd contains /ban, use if cmd startsWith
  5. Use UUIDs instead of names.
  6. Try debugging your arraylist by printing it to the console to check if the player's name is in the arraylist to begin with.