Instructions - grandwazir/ChatReplace GitHub Wiki

Example usage

Choosing a replacement type

ChatReplace supports two different modes of operation: substitution (replace matched patterns) and append (append replacements at either end of message which has a match). You must use one of them for the plugin do to anything but you do not have to use both. You configure which one you want to use in the config.yml.

formatters:
  append: false
  substitution: true

You add patterns to these formatters separately in their respective configuration files which is either append.yml or substitution.yml.

Creating a pattern

ChatReplace uses the full power of regular expressions to give you an many different ways to match chat messages. Regular expressions are a complex topic and beyond the scope of this introduction. Because of that the examples here will be quite simplistic but suitable for most server administrators.

An excellent website to try out expressions before you put them into your configuration is Rubular which lets you try out expressions and see what will match on test messages.

To being with I am going to create a pattern which removes any mention of the word nOOb on my server; I just don't like the phrase. To do this I need to create a substitution pattern and so I go to substitution.yml.

noob-remover:
  pattern: (nOOb)
  replacements:
  - ""

The brackets around the word tell the formatter to replace any word that matches what is inside the brackets.

So far so good. However this will not work if someone decides to mix it up a bit and type n00b. This is where regular expressions come in handy. I am going to change my pattern now to catch both types of spelling.

pattern: (nOOb)|(n00b)

The line between the two sets of brackets tells the formatter to match either nOOb or n00b.

This will fail though if someone decides to type the word in capitals (a usual gambit to get around swearword filters for example). We can get around this by putting (?i) in front of our pattern which will make it case-insensitive.

pattern: (?i)(nOOb)|(n00b)

I'm now going to go one step further and instead of simply blanking the word I am going to replace it with something else instead.

noob-remover:
  pattern: (nOOb)
  replacements:
  - valued new player

Appending patterns

This works the same way as above except you need to obviously edit the append.yml instead. Append patterns also have one extra property that substitution patterns do not. In the example below I am going to append some silly words to the beginning of every chat message:

start:
  pattern: '[a-zA-Z]'
  append-location: start
  replacements:
  - Forsooth,
  - I say,
  - I sayeth,
  - Forsooth, I say
  - Forsooth, say I,
  - Hark!