How to make this checker?

Discussion in 'Plugin Development' started by TitaniuMark, Oct 21, 2019.

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

    TitaniuMark

    Well, I am stuck on making a checker!

    For an string of words that are not splitted, like "doeveryunderstandingthings" i need to check if that string contains words from a predefined list.
    Explaining: I have a "setup.yml" that contains an string list "words" and I need to check if a given string is containing any of the words defined previously, on my "setup.yml" , "words"
    if I do like this:
    for(String v : o){
    if(b.contains(v){
    }
    }

    //asumming that "v" is a word that belongs to our list "words" ;"o" is our previously mentioned list, and "b" is our given string
    it will only check if "b",in it's complete form is present on "words"

    Think I need to split the given string at the first letter from every word in the list
    for example: string - "doeveryunderstandingthings" ; list: "- ever", "- thing", "- standing" ; split at "e", "t", "s", but I need to do it based on my list, like getting first letter of every word on my list and splitting at it.
    Explaining: get the word "- thing" present on my list -> split the given wort at letter "t" because it is the first letter of the word that i have in list , but I don't know how do i make this exactly
     
  2. I would loop over the chars of the String and check if any String in the list starts with this letter. Then check if there is indeed the whole word at this point
     
  3. Offline

    TitaniuMark

    Tryed like this:
    List<String> a = this.ns.getcfg().getStringList("List.a");
    //make a list "a" wich contains all words that starts with letter "a" on my config
    then check if list "a" is containing word that is present in my string wich starts with "a"

    if (a.contains(b.split("a").toString())) {
    }

    but it isn't working ... :(
    //asuming that b is the whole string that i need to check
     
  4. Offline

    Strahan

    I hope you aren't actually using those variable names in production. That said, assuming you make the case consistent what is wrong with your example? That should work fine.

    Like if I wanted to prevent religious speech in a chat message, I could do:
    Code:
    String[] blockedWords = new String[]{"jesus","budda","allah","god","etcetc"};
    
    chat event {
      for (String word : blockedWords) {
        if (!word.toLowerCase().contains(word.toLowerCase())) continue;
        e.getPlayer().sendMessage("Bad!");
        e.setCancelled(true);
        return;
      }
    }
    ...though of course this whole idea is flawed as one can easily bypass it.
     
  5. Offline

    TitaniuMark

    I need it to get the words from an external setup ( setup.yml )
     
  6. Offline

    KarimAKL

    @TitaniuMark Just get the list from that file; if you need help with that, ask.
     
  7. Offline

    TitaniuMark

    You mean, for example, replacing:
    String[] blockedWords = new String[]{"jesus","budda","allah","god","etcetc"};
    to
    String[] blockedWords = new String[]{this.ns.getcfg().getStringList("List.a")};
     
  8. Offline

    KarimAKL

  9. Offline

    TitaniuMark

    Already did it:
    List<String> a = this.ns.getcfg().getStringList("List.a");
    but the problem is here, i think:
    if (a.contains(b.split("a").toString())) {
    }
    mentioning that "b" is the whole word that i need to check
    i've tried those ways:
    my "b" is , for exemple "childattackedhim"
    1. added "attack" on list "a" and checked if my whole word, splitted at "a" is returning the word "attack" and then do the action
    2. having "b" defined as "childattackedhim", added "ttack" to a list called "a", then splitted the word at "a" to check for word "attack"
    none worked
     
  10. Offline

    robertlit

    If you keep giving your variables names like a and b it will be tough to provide you help
     
  11. Offline

    TitaniuMark

    tried this:
    for (String word : zlist) {
    if (input.split("z").toString().startsWith(word)) {
    }

    //assuming that "input" is the variable for the whole word and "zlist" is the list of words that starts with letter "z"
    but it is not working ...
    what is wrong...
     
  12. Offline

    KarimAKL

    @TitaniuMark String#split(String) returns an array of strings, you have to loop that array, not use toString() on it.
     
Thread Status:
Not open for further replies.

Share This Page