Stripping a string of a color code? (Bukkit)
Posted: Fri May 25, 2012 11:22 am
I'm in the middle of writing a plugin to filter the chat (for personal use atm, since the other chat filter plugins just seem to suck). At the moment, it's working wonderfully, but it seems you can completely bypass the filter by putting a color code or some text before the word that needs to be filtered. So &ftest wouldn't be detected. I have a small bit of regex to detect it and any other text before the word. I've tried:
I intended for this to catch any color codes or various text (this is concatenated at the beginning of the regex string before it is compiled), but this isn't working. I tried it with and without escaping the & and § symbol, but no luck. I know the rest of the regex works fine, it's just this bit. I figure the color code is converted to another datatype before my plugin gets to it, and so the conventional &X won't catch it, but I'm just looking for a way to strip the color code off before it gets to the regex or some regex to detect whatever it uses to format the colors so that it doesn't bypass the filter. I guess most servers don't let people use color codes freely, but I still don't want this little gap here >.<
-- Edit --
Random thought, would a regex or something work if I jack up the event priority? I'm half-asleep right now and perhaps that's a dumb idea, but it's a thought.
- (([&|§])?([a-z0-9]?)*
(([\\&|\\§][a-fk-o0-9])?[a-z0-9]?)*
(([&|§][a-fk-o0-9])?[a-z0-9]?)*
I intended for this to catch any color codes or various text (this is concatenated at the beginning of the regex string before it is compiled), but this isn't working. I tried it with and without escaping the & and § symbol, but no luck. I know the rest of the regex works fine, it's just this bit. I figure the color code is converted to another datatype before my plugin gets to it, and so the conventional &X won't catch it, but I'm just looking for a way to strip the color code off before it gets to the regex or some regex to detect whatever it uses to format the colors so that it doesn't bypass the filter. I guess most servers don't let people use color codes freely, but I still don't want this little gap here >.<
-- Edit --
Random thought, would a regex or something work if I jack up the event priority? I'm half-asleep right now and perhaps that's a dumb idea, but it's a thought.