ArrayLists checking words in a sentence

Discussion in 'Spigot Plugin Development' started by RegionFlag, Jun 20, 2015.

  1. Hey, I'm trying use for loops to check if a persons sentence contains one word from all 3 arraylists, so for example; I'm making it so when a player asks how to buy a plot, it checks 3 different array lists which I made containing different words with the same meaning, such as (get, buy, obtain etc) here is the main class containing the for loops: none of my debug messages appear, I'm fairly new to bukkit/spigot API so I might just be making a stupid mistake but I'd really appreciate some help! Thanks
  2. Why not just check if the msg contains the words you want...
    Code (Text):
        public void onSpeak(AsyncPlayerChatEvent event) {
            String msg = event.getMessage().toLowerCase();
            if (msg.contains("get")){
                  //Do stuff with get
            else if (msg.contains("buy")){
                  //Do stuff with buy
            else if (msg.contains("obtain")){
                  //Do stuff with obtain
  3. But that would be separate sentences, so every time a player would say "get" it would send the title. Meaning a player could be like "Can you go get some wood" and it would send a title referring to buying a vault. I started doing it this way, but the fact of it, is that is extremely long winded and messy
  4. Add them to a List then loop through them and break it once a match is found
  5. You can use:
    for(String s : arraylist) {
    if(s.equalsignorecase(xxx)) {
    do something