Check if message contains a message in a List.

Discussion in 'Plugin Development' started by bwfcwalshy, Aug 24, 2014.

Thread Status:
Not open for further replies.
  1. Not sure if you got it from the title probably not. What I want is where it checks a list and if it contains at least one then work.
    I want to use this in a asyncPlayerChatEvent.
    1. if(e.getMessage().contians(//List here)){
  2. Offline


    1. list.size() > 0
    Is this what you mean?'

    Edit: Actually I think I get what you mean.
    Loop through your list and check.
    Gerov likes this.
  3. teej107 Mind giving a little example?
  4. Offline


    bwfcwalshy This is basic Java which you are supposed to know :/
    Rocoty likes this.
  5. Offline


    Not every person on bukkit knows Java, or remembers it, He may of also forgot how to do the certain tasks.
  6. fireblast709 Thank you for saying a useless comment. This is a sub forum for help not to criticize.
    TheTrueReality likes this.
  7. Offline


    True. Not every person on these forums knows Java. Which is a shame, really. Seeing as making Bukkit plugins assumes basic Java knowledge at least. It seems OP's problem is a strictly Java problem and they should be getting help elsewhere.

    bwfcwalshy If you want better understanding of the Java language I suggest you read through Oracle's tutorials, and maybe buy a book. Head First Java is a good book for beginners. I hope you take this as advice and not an insult, because I simply can't stress the importance of this quite enough.
    Zupsub and teej107 like this.
  8. Offline


    Here is an example
    1. @EventHandler
    2. public void onChat(AsyncPlayerChatEvent e){
    3. Player p = e.getPlayer();
    4. ArrayList list = new ArrayList();
    5. for(int i = 0; i < list.size(); i++){
    6. if(e.getMessage().contains(list.get(i).toString())){
    7. //do stuff
    8. }
    9. }
    10. }
    bwfcwalshy likes this.
  9. Offline


    I've known some people that are learning java from the bukkit api, using youtube tutorials, and they know quiet a bit on certain aspects of development of plugins. I've been doing Java for 8 years, and bukkit for awhile now, yet i still forget some basic stuff that i haven't needed to use in ages.
  10. Offline


    TheTrueReality Yes, well I can see that. But something as simple as checking if a List isn't empty...that's simply not something one should come to the Bukkit forums for help with. I'm not trying to bash down on anyone, but a simple Google search would have gotten OP the answer much quicker than this. In fact, knowing how to solve your own problems and how to do research in hope of finding a solution is essential to any kind of software development. One has to be able to act independently!

    EDIT: For instance, I did a quick Google search and found this Which contains all methods of the type List. Scroll a bit down and you find the method isEmpty. Which essentially does what the OP is looking for.

    FYI, the Oracle docs are very handy for this kind of problems.
  11. Offline


    Very True. Good words.
  12. Offline


    bwfcwalshy For loops are a fundamental part of the language. And since they are included in the language basics from the Oracle tutorial, I assume that it is a true fact.
    TheTrueReality ^
    Yekllurt Spoonfeeding :\
  13. Rocoty I did Google it and I couldn't find anything that checks the List for a sentence. Also I am not checking if it is empty it is simple to check if it is empty or not. I am checking it and looking in chat for that.
  14. Offline


    A: Yes i know that this is the basic's of java what he is asking for.
    B: He may not be able to find anything via google.
    C: He is asking for help here, Not asking for you people to say go learn java, when i know he has.
    bwfcwalshy likes this.
  15. Offline


    bwfcwalshy Then I'm afraid both your thread title and OP are frankly misleading. You might want to change that to "check if a String contains at least one element from a List", or something along those lines. As I assume that is what you want...?
  16. Rocoty I couldn't think of a good title. I guess that didn't make sense for everyone so I apologise.

    EDIT: That better?
  17. Offline


    Except he never did bother learning basic Java.
    Knowing how objects, for loops, methods and collections are stuff that should've been known BEFORE you try to access any kind of API.

    You don't know a specific method of a Java object? Sure, there's Java javadocs just for you. Can't understand them? You need to learn what you are reading.
  18. Offline


    • "Java List empty", at least 6/10 relevant hits that will tell you exactly what to do for the empty List check
    • "Java loop List", 10/10 relevant
    Sorry but that's not what I see when I google...
    C: When you lack basics, you need to learn basics. These basics form the fundament for the rest of the time you will spend programming. He might not be asking for it, he might not like it, but it is an honest reply indended to show him that he lacks some part of these basics. Hence I suggested that he should revisit some tutorials to go over them in order to properly understand these basics.
Thread Status:
Not open for further replies.

Share This Page