Solved Command argues black list

Discussion in 'Plugin Development' started by galaipa, Dec 18, 2014.

Thread Status:
Not open for further replies.
  1. Hi,
    I need help to detect blacklisted words in the arguments of a command. I have created a arraylist in the config file.
    Thank you

    This is everything I have :(
    Code:
    List<String> ex = getConfig().getStringList("Blacklist");
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  2. Offline

    CraftCreeper6

    @galaipa
    Check for ChatEvent, loop through the list using a for loop. If the message contains a word from the list. Cancel the event and do whatever...

    EDIT: Sorry, mis-read. You would need to use args[].
     
  3. @CraftCreeper6 Sorry, I didn't understand you very well. So do I have to use the ChatEvent?
     
  4. Offline

    CraftCreeper6

    @galaipa
    I edited, I mis-read your OP.
     
  5. Offline

    Lammazz

    @galaipa
    Code:
    for (String s : args) {
        if (ex.contains(s)) {
            // Found a disallowed argument
        }
    }
    This help?
     
  6. @Lammazz Thank you, but it dosn't work
    I have tryed this:
    Code:
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < args.length; i++){
                sb.append(args[i]).append(" ");
                }String allArgs = sb.toString().trim();
    and then
    Code:
    if (ex.contains(allArgs)) { 
                     sender.sendMessage(ChatColor.RED +(getTranslation("14")));
                     return true;
    }
    It only works if there is only one arg.

    @Lammazz Sorry, your code is working! I was using it incorrectly. Thank you very much.
    Now a little noob question. When whil this loop stop searching?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  7. Offline

    mythbusterma

    @galaipa

    When it's done iterating...?
     
Thread Status:
Not open for further replies.

Share This Page