ArrayLists and ChatEvent.

Discussion in 'Plugin Development' started by TheGamesHawk2001, Nov 29, 2014.

Thread Status:
Not open for further replies.
  1. Hello, How would I make it so if a player chats and their message contains another player who is online and is in an arraylist. It would do something.

    Here's my code so far.
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("afk")) {
    2. Player p = (Player) sender;
    3. if (afk.contains(p)) {
    4. afk.remove(p);
    5. sender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "SUCCESS" + ChatColor.GRAY + ": You are no longer AFK!");
    6. }else{
    7. afk.add(p);
    8. sender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "SUCCESS" + ChatColor.GRAY + ": You are now AFK!");
    9. }
    10. }
    11. }
    12. return true;
    13. }
    14. }
     
  2. Offline

    Forge_User_45064837 Retired Staff

    TheGamesHawk2001 For the chat, make an AsyncPlayerChatEvent method and check if they are in the list, if they are make them no longer afk.
     
  3. Offline

    fireblast709

    Use a HashSet as it's more efficient than a List.
     
  4. bwfcwalshy U got the wrong idea. I want is so if a player called bob123 is in afk array list. and max543 says "hello bob123" it would recognise that bob123 is in the arraylist and would send max543 a message etc.
     
  5. Offline

    Forge_User_45064837 Retired Staff

    TheGamesHawk2001 Check if the message contains a players name (check with for statement) then if the list contains the player send the other player the message saying he is afk.
     
  6. Offline

    JordyPwner

    that is for the PlayerChat event >.< just get the player's message check if he is in the list if not just ignore else you know what to do

    EDIT: Just got Ninjad by bwfcwalshy
     
  7. Offline

    ChipDev

    If(event.getMessage().contains(" bob123"))
    Use a loop for checking, not checking for bob123
    (Loop of afk players)
     
  8. Offline

    teej107

    Splitting the message by whitespaces would be the way to go. Then compare each String in the array to see if it matches a player name.

    The problem with ChipDev solution is that somebody's IGN could be "bob123456" for example.
     
  9. Offline

    ChipDev

    The
    oh! right.. You could check if it ends with a ?, !, or . , otherwise, continue
     
Thread Status:
Not open for further replies.

Share This Page