Skip to content

Commit e3c7bbe

Browse files
committed
Update RoseChat filters and API
1 parent 0277041 commit e3c7bbe

3 files changed

Lines changed: 122 additions & 114 deletions

File tree

docs/RoseChat/configuration-files.md

Lines changed: 88 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -75,60 +75,81 @@ The `shout` format is used with the `shout-commands` setting, and a message is s
7575
The `broadcast` format is used when a message is sent the channel from `/broadcast`.<br/>
7676
The `join-message` format is the message sent to a player when they join the channel.<br/>
7777

78-
## replacements.yml
79-
The replacements file is used for replacing messages with other content. This can be used for fun, or to filter a message. For example, the default replacements file replaces `<3` with `❤️`. These are extremely configurable, and allow for things like emojis and tags.
78+
## Filters
79+
The filters folder allows organising multiple files with filters defined inside them.<br/>
80+
Filters can edit or block messages, such as blocking swear words, censoring them, or adding emojis and colours.<br/>
81+
The default file `colors.yml` defines tag-based colours like `<red>` to make text red, `fun.yml` defines some fun and useful features like emojis or `@Player` tags, and `swears.yml` shows how to block or censor a word.
8082

81-
A replacement must first start with an ID and has two sections, `input` which contains settings for inputting a replacement, and `output` which contains settings for the output of a replacement. These can be seen as what the player types and what the player sees.
83+
A filter must first start with one or more `matches`, which tells the plugin what to search for in a message. They may optionally also contain a `replacement`, which tells the plugin what to replace the matched word with.
8284

83-
This basic replacement replaces the input of `:example:` to `\uE000`, which will be an emoji.<br>
85+
This basic filter replaces the input of `:example:` to `\uE000`, which represents an emoji.<br/>
8486
The `can-toggle` setting allows the /toggleemoji command to be used, this allows players to not format specific replacements, like not converting `<3` to `❤️`.<br>
8587
These emojis can have icons when using a [Resource Pack](resource-packs.md).
8688
```yaml
8789
example:
88-
input:
89-
text: ':example:'
90-
can-toggle: true
91-
output:
92-
text: "\uE000"
90+
matches:
91+
- ":example:"
92+
can-toggle: true
93+
replacement: "\uE000"
9394
```
9495

95-
There are many configuration options for replacements.
96+
There are many configuration options for filters.
9697
```yaml
9798
example:
98-
input:
99-
text: ':example:'
100-
is-emoji: true
101-
output:
102-
text: "\uE000"
103-
hover: '&b&o:rosewood:'
99+
matches:
100+
- ":example:"
101+
can-toggle: true
102+
hover: "&b&o:rosewood:"
103+
replacement: "\uE000"
104104
```
105-
The `hover` option allows a replacement to be hovered over.<br>
105+
The `hover` option allows a filter to be hovered over.<br>
106106
You can also use a custom placeholder here.
107107
```yaml
108-
output:
109-
text: "{your-placeholder}"
108+
replacement: "{your-placeholder}"
109+
```
110+
111+
There are two ways to use permissions in filters, a `use` permission and a `bypass` permission.
112+
The player also needs `rosechat.filters.<location>` to send replacements in a specific location.<br>
113+
These are formatted like so:
114+
```yaml
115+
replaceable-words:
116+
matches:
117+
- 'crap'
118+
replacement: 'cr*p'
119+
permission:
120+
bypass: "rosechat.admin"
110121
```
122+
This `bypass` permission ensures the filter will **not** be applied for that player.
123+
124+
```yaml
125+
star:
126+
matches:
127+
- ':star:'
128+
replacement: "✸"
129+
permission:
130+
use: rosechat.filter.star
131+
```
132+
This `use` permission ensures that the player must have this permission to use the filter.<br/>
111133

112134
```yaml
113135
rainbow:
114-
input:
115-
text: '&h'
116-
output:
117-
text: '<r:0.5>'
118-
color-retention: true
136+
matches:
137+
- "&h"
138+
replacement: "<r:0.5>"
139+
color-retention: true
119140
```
120141
The `color-retention` option allows the color specified in the output text to continue along the message.
121142

122143
```yaml
123-
regex-example-url:
124-
input:
125-
text: '(?:http(?:s){0,1}://){0,1}[-a-zA-Z0-9@:%._\+~#=]{2,32}\.[a-zA-Z0-9()]{2,16}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&//=]*)'
126-
is-regex: true
127-
output:
128-
text: '{url}'
144+
regex-url:
145+
# Regex matches can also be used.
146+
matches:
147+
- '(?:http(?:s){0,1}://){0,1}[-a-zA-Z0-9@:%._\+~#=]{2,32}\.[a-zA-Z0-9()]{2,16}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&//=]*)'
148+
use-regex: true
149+
replacement: "{url}"
129150
```
130-
The `is-regex` option allows the `text` value to be seen as regex, and replacements will be matched against it.<br>
131-
For replacements that use regex, there are placeholders for regex groups. These can be used in linked custom placeholders, or in the `text` option itself.<br>
151+
The `use-regex` option allows the `text` value to be seen as regex, and replacements will be matched against it.<br>
152+
For filters that use regex, there are placeholders for regex groups. These can be used in linked custom placeholders, or in the `text` option itself.<br>
132153
```yaml
133154
spoiler-tag:
134155
text:
@@ -137,22 +158,20 @@ spoiler-tag:
137158
default:
138159
- "%input_1%"
139160
```
140-
This replacement uses `%input_1%` to get the text inside the spoiler tags. These can also be used in inline replacements.<br>
161+
This filter uses `%input_1%` to get the text inside the spoiler tags. These can also be used in inline .<br>
141162
The `input` placeholder allows grabbing a regex group while also checking a player's permission. Using `%group_1%` would return the first group and also parse the message without checking permissions, applying colours even if the player does not have permission to use colours in chat.
142163

143-
### Prefixed Replacements
164+
### Prefixed Filters
144165

145166
```yaml
146167
spoiler:
147-
input:
148-
prefix: '<spoiler>'
149-
suffix: '</spoiler>'
150-
output:
151-
text: '{spoiler-tag}'
152-
match-length: true
168+
prefix: "<spoiler>"
169+
suffix: "</spoiler>"
170+
replacement: "{spoiler-tag}"
171+
match-length: true
153172
```
154173

155-
Replacements can also have `prefix` and `suffix`. This example will match this text: `<spoiler>Hello</spoiler>` and replace it with the custom placeholder `{spoiler-tag}`.<br>
174+
Filters can also have a `prefix` and a `suffix`. This example will match this text: `<spoiler>Hello</spoiler>` and replace it with the custom placeholder `{spoiler-tag}`.<br>
156175
The `match-length` option is useful as the `{spoiler-tag}` setting contains one character, `match-length` will repeat this character 5 times as `Hello` has 5 characters.<br>
157176
`prefix` and `suffix` can also contain regex if `is-regex` is enabled.
158177

@@ -166,25 +185,24 @@ player:
166185
tag-online-players: true
167186
sound: minecraft:block.note_block.pling
168187
```
169-
Replacements can also have only a `prefix` option. This example will look for words starting with `@` and replace them with the output text.<br>
188+
Filters can also have only a `prefix` option. This example will look for words starting with `@` and replace them with the output text.<br>
170189
The `stop` setting is a regex string, telling the plugin where to stop looking after it finds the prefix. This example searches for `@player` and stops when it finds punctuation or a space.<br>
171190
The output option `tag-online-players` highlights the player's name, and sends them a sound, specified in the `sound` option.
172191

173-
### Inline Replacements
192+
### Inline Filters
174193

175194
```yaml
176195
url:
177-
input:
178-
prefix: '['
179-
suffix: ']'
180-
text: '(?:http(?:s){0,1}://){0,1}[-a-zA-Z0-9@:%._\+~#=]{2,32}\.[a-zA-Z0-9()]{2,16}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&//=]*)'
181-
inline-prefix: '('
182-
inline-suffix: ')'
183-
is-inline-regex: true
184-
output:
185-
text: '{url}'
196+
prefix: '['
197+
suffix: ']'
198+
inline-matches:
199+
- '(?:http(?:s){0,1}://){0,1}[-a-zA-Z0-9@:%._\+~#=]{2,32}\.[a-zA-Z0-9()]{2,16}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&//=]*)'
200+
use-regex: true
201+
inline-prefix: '('
202+
inline-suffix: ')'
203+
replacement: "{url}"
186204
```
187-
This replacement converts `[Click Here](www.example.com)` to `Click Here`, with the link `www.example.com`. <br>
205+
This filter converts `[Click Here](www.example.com)` to `Click Here`, with the link `www.example.com`. <br>
188206
The `prefix` and `suffix` values define the prefix and suffix for the content, `Click Here`.<br>
189207
The `inline-prefix` and `inline-suffix` values define the prefix and suffix for the inline, `www.example.com`<br>
190208
These can be used without regex, and without the `text` value to allow players to create their own hoverable messages. For example, `[Hover Me!](Hello)`, when configured, will create a message saying "Hover Me", and the hover says "Hello".<br>
@@ -194,40 +212,27 @@ You can also use `is-content-regex` to match text between the `prefix` and `suff
194212

195213
The `discord-output` option, requiring DiscordSRV, allows the output to be different if sent to Discord.
196214
```yaml
197-
example:
198-
input:
199-
text: ':example:'
200-
output:
201-
text: "\uE000"
202-
discord-output: ":smile:"
203-
```
204-
205-
By default, the permission to use a replacement is `rosechat.replacement.<id>`. The player also needs `rosechat.replacements.<location>` to send replacements in a specific location.<br>
206-
This can be changed using the `permission` option:
207-
```yaml
208-
example:
209-
input:
210-
text: ':example:'
211-
permission: 'your.permission'
212-
output:
213-
text: "\uE000"
215+
discord-output: ":smile:"
214216
```
215217

216-
## colors.yml
217-
The colors file serves as an extra space to add replacements that are specifically custom colors. These have `color-retention` enabled by default.
218-
By default, this file allows players used to MiniMessage formats to use colors in RoseChat.
219-
220-
This is an example of a basic color.
218+
### Swear Filters
219+
You may want to stop players from sending messages with bad words in them.
220+
The `block` option stops a message from being sent.
221221
```yaml
222-
red:
223-
input:
224-
text: "<red>"
225-
has-closing-tag: true
226-
output:
227-
text: "&c"
222+
bannable-words:
223+
matches:
224+
- damn
225+
sensitivity: 20
226+
block: true
227+
commands:
228+
server:
229+
- warn %player% Swearing
228230
```
229-
230-
The format is the same as a replacement, the player can type `<red>` and it is replaced by the `&c` color code. The `has-closing-tag` option allows the plugin to automatically create a closing tag version of the replacement. This means that the above color will also be available by typing `<red>your text</red>`, allowing for non-colored text the be placed outside of the tags.
231+
The default `bannable-words` filter in `swears.yml` blocks the message being sent if it finds "damn", it then also runs a command on the server to warn the player.<br>
232+
The `sensitivity` option provides an easy way to filter similar words without having to type them all. This filter will catch `damn`, `dámn` and other variations.
233+
A filter with a sensitivity that is too high may catch incorrect words, like `dam`, in this instance, the sensitivity can be lowered or removed entirely.
234+
There may be some instances where creating a second filter with a different sensitivity value may be more useful than editing the sensitivity of one.<br>
235+
These options may also be used in other filters.
231236

232237
## custom-placeholders.yml
233238
The placeholders file is used to define placeholders that RoseChat uses. This is probably the most useful file.

docs/RoseChat/features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
![PlaceholderAPI Placeholders](https://user-images.githubusercontent.com/46502463/158833118-20fbd662-dd90-47db-9147-33099c374473.png)
2222
* Supports RoseChat Placeholders<br/>
2323
![RoseChat Placeholders](https://user-images.githubusercontent.com/46502463/158834078-c2fc3d40-b42e-4fdf-ba47-8457feb6ef4d.png)
24-
* Chat Replacements
24+
* Chat Replacements and Filters
2525
* Replace words in chat
2626
* Supports Regex Replacements and RoseChat Formatting<br/>
2727
![Chat Replacements](https://user-images.githubusercontent.com/46502463/158837535-2829e7f1-7a13-4a4c-8197-45f4a67c7e50.png)

docs/RoseChat/parsing-messages.md

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ There are a few variations of this function:<br><br>
77

88
This method simply parses the message.
99
```java
10-
BaseComponent[] parse(RosePlayer sender, RosePlayer viewer, String message)
10+
MessageContents parse(RosePlayer sender, RosePlayer viewer, String message)
1111
```
1212

1313
This method allows you to use placeholders in the message.
1414
```java
15-
BaseComponent[] parse(RosePlayer sender, RosePlayer viewer, String message, StringPlaceholders placeholders)
15+
MessageContents parse(RosePlayer sender, RosePlayer viewer, String message, StringPlaceholders placeholders)
1616
```
1717

18-
This method allows using a [MessageLocation](https://github.com/Rosewood-Development/RoseChat/blob/master/src/main/java/dev/rosewood/rosechat/message/MessageLocation.java) to check for permissions.
18+
This method allows using a [PermissionArea](https://github.com/Rosewood-Development/RoseChat/blob/master/src/main/java/dev/rosewood/rosechat/message/PermissionArea.java) to check for permissions.
1919
```java
20-
BaseComponent[] parse(RosePlayer sender, RosePlayerviewer, String message, MessageLocation location)
20+
MessageContents parse(RosePlayer sender, RosePlayerviewer, String message, MessageLocation location)
2121
```
22+
<br>
23+
The [MessageContents](https://github.com/Rosewood-Development/RoseChat/blob/master/src/main/java/dev/rosewood/rosechat/message/contents/MessageContents.java) class provides an abstracted way to handle the output of a message, abstracted from whichever platform you are using.
24+
2225

2326
#### RosePlayer
2427
The [RosePlayer](https://github.com/Rosewood-Development/RoseChat/blob/master/src/main/java/dev/rosewood/rosechat/message/RosePlayer.java) object is used by RoseChat to give more information to a Player object. When you need to use a RosePlayer, you can just create a `new RosePlayer()`. This object has a few different constructors, but passing a Player object through is the most common.
@@ -31,8 +34,9 @@ public void onPlayerJoin(PlayerJoinEvent event) {
3134
Player player = event.getPlayer();
3235
RosePlayer rosePlayer = new RosePlayer(player);
3336

34-
BaseComponent[] message = rosechat.parse(rosePlayer, rosePlayer, "<r:0.5>Hi %player_name% &r:rosewood:");
35-
Bukkit.spigot().broadcast(message);
37+
MessageContents message = rosechat.parse(rosePlayer, rosePlayer, "<r:0.5>Hi %player_name% &r:rosewood:");
38+
BaseComponent[] components = message.buildComponents();
39+
Bukkit.spigot().broadcast(components);
3640
}
3741
```
3842

@@ -45,27 +49,26 @@ Creating a new `RoseMessage` object for each player allows each player to receiv
4549
#### Rose Messages
4650
The preferred way to send a message to multiple players is by using `RoseMessage.forChannel(RosePlayer, Channel)` or `RoseMessage.forLocation(RosePlayer, MessageLocation).<br>
4751

48-
An example of this is used in the RoseChatChannel class:
52+
An simple example of this can be seen below:
4953
```java
54+
55+
RoseMessage message = RoseMessage.forChannel(sender, this);
56+
MessageRules rules = new MessageRules().applyAllFilters();
57+
MessageRules.RuleOutputs outputs = rules.apply(message, input);
58+
59+
// Check if the message is allowed to be sent.
60+
if (outputs.isBlocked()) {
61+
if (outputs.getWarning() != null)
62+
outputs.getWarning().send(sender);
63+
return;
64+
}
5065

51-
RoseMessage roseMessage = RoseMessage.forChannel(sender, this);
52-
53-
// Create the rules for this message.
54-
MessageRules rules = new MessageRules().applyAllFilters();
55-
MessageRules.RuleOutputs outputs = rules.apply(roseMessage, message);
56-
57-
// Check if the message is allowed to be sent.
58-
if (outputs.isBlocked()) {
59-
if (outputs.getWarning() != null)
60-
outputs.getWarning().send(sender);
61-
return;
62-
}
63-
64-
roseMessage.setPlayerInput(outputs.getFilteredMessage());
66+
roseMessage.setPlayerInput(outputs.getFilteredMessage());
6567

66-
MessageTokenizerResults<BaseComponent[]> components = roseMessage.parse(receiver, format);
67-
MessageOutputs messageOutputs = components.outputs();
68+
MessageContents contents = message.parse(receiver, format);
6869

70+
// Sending the message to a player:
71+
receiver.send(contents);
6972
```
7073

7174
This creates a new `MessageRules` object, which defines the rules of the message, and if a message should be filtered based on the permissions of the sender. It also applies the sender's chat colour.<br>
@@ -80,34 +83,34 @@ A format is not needed, and `null` can be passed.<br>
8083
There are several `parse` functions in the `RoseMessage` class.<br>
8184
The first simply parses the message as it should be seen in-game.
8285
```java
83-
BaseComponent[] parse(RosePlayer viewer, String format)
86+
MessageContents parse(RosePlayer viewer, String format)
8487
```
8588

8689
The second treats the message as if it was sent from Discord, converting Discord formatting to Minecraft. A discord id can be passed to allow messages to be deleted in Discord.
8790
```java
88-
BaseComponent[] parseMessageFromDiscord(RosePlayer viewer, String format, String discordId)
91+
MessageContents parseMessageFromDiscord(RosePlayer viewer, String format, String discordId)
8992
```
9093

9194
The third treats the message as if it was sent to Discord, converting Minecraft formatting to Discord.
9295
```java
93-
BaseComponent[] parseMessageToDiscord(RosePlayer viewer, String format)
96+
MessageContents parseMessageToDiscord(RosePlayer viewer, String format)
9497
```
9598

9699
The fourth treats the message as if it was going to be sent to a Bungee server.
97100
```java
98-
BaseComponent[] parseBungeeMessage(RosePlayer viewer, String format)
101+
MessageContents parseBungeeMessage(RosePlayer viewer, String format)
99102
```
100103

101-
The final method allows a MessageParser to be specified, and a discord id too, if needed..
104+
The final method allows a MessageParser to be specified, and a discord id too, if needed.
102105
```java
103-
BaseComponent[] parse(MessageParser parser, RosePlayer viewer, String format, String discordId)
106+
MessageContents parse(MessageParser parser, RosePlayer viewer, String format, String discordId)
104107
```
105108

106109
Now that the message is parsed, functions such as `getTaggedPlayers()` becomes available to use from the MessageOuputs class.
107110

108111
### Message Parsers
109112
A message parser is a way of deciding what to do with a message when it is parsed.<br>
110-
Typically, this consists of combining multiple [tokenizers]() to create a final message.<br>
113+
Typically, this consists of combining multiple [tokenizers](tokens-%26-tokenizers.md) to create a final message.<br>
111114
An example of a MessageParser can be seen [here](https://github.com/Rosewood-Development/RoseChat/blob/master/src/main/java/dev/rosewood/rosechat/message/parser/RoseChatParser.java).<br>
112115
This MessageParser mainly decides what tokenizers to use for the message.<br>
113116
A MessageParser is simply called when the message is parsed, so anything can be done to the message.

0 commit comments

Comments
 (0)