Discussion in 'Spigot Plugin Development' started by Zeuss, Aug 4, 2018.

  1. I'm trying to implement a system to prevent players from divulging other servers in the chat, but I do not know how to use the regex very well so if I have someone like me send me a code that blocks everything except what I determine in a list
  2. You can use an anti spam plugin, or use an anti swear plugin - and adjust it to fight server mentions. Or unpack it and see how they use regex to catch swear words and their alternatives and spam things like *anything*.*tld*
  3. That's not what regexes are for. What you want is to enumerate your list of forbidden/allowed words, and see if the message to be chatted fails/passes the test (which i guess is "containsIgnoreCase"), and then act accordingly by maybe cancelling the chat event.

    The only reason you might need regexes here is if you want the user to block/allow certain messages based on a regex. To see if a regex matches, first compile it into an actual pattern that can be saved for later (to speed things up), then on this pattern call pattern.match(string).find(). If find() returns true, your pattern matched.
  4. Assuming that what he wants to do is block server IP addresses and he is looking for a Regex pattern for this. But, because there is no determining what domain name will be put in chat, he cannot just use an Enum (which by the way, I do not recommend for lists like this one). I also wish, as a Java Developer that containsIgnoreCase() was a thing. I am no expert in Regex, so I will not attempt this, but best of luck to the Original Poster.
  5. DavidDevelops


    *obviously not a very good java developer*
    "containsIgnoreCase(CharSequence str, CharSequence searchStr)"
    is a thing,
  6. JanTuck


    It's most likely just. String#toLowerCase#contains(otherString#toLowerCase)
  7. This is my method when I am outside of the Bukkit libraries (Bukkit has the apache commons library).