ArrayList Error Help

Discussion in 'Plugin Development' started by eli.musgrove9, Jan 17, 2015.

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

    eli.musgrove9

    I am getting an error whenever I try to do this, and have had this problem for a while. Anybody help??

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("warn")) {
                if (args.length == 0) {
                    sender.sendMessage(ChatColor.DARK_RED + "Please specify a player.");
                    return true;
                }
                Player target = Bukkit.getServer().getPlayer(args[0]);
                if (target == null) {
                    sender.sendMessage(ChatColor.DARK_RED + "The player " + args[0] + " is not on the server.");
                }
                if (!warned1.contains(target.getName())) {
                    target.sendMessage(ChatColor.RED + "You have recieved a warning from " + sender.getName() + "\n" + args[1]);
                    warned1.add(target.getName());
                    return true;
                }
            }
            return true;
        }   
    }
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    InkzzzMC

    Tag me in with the error, you post.
     
  4. Offline

    teej107

    Failure to post the error?

    I would use UUIDs rather than player names. Players can just evade warnings by changing their name with your code. I would also use a Set rather than a List. Sets don't allow duplicates which will negate the need for you to do such things like this:
    Code:
    if (!warned1.contains(target.getName()))
     
Thread Status:
Not open for further replies.

Share This Page