Skip to content

Commit 9e04ec0

Browse files
committed
Changed whitelist method and better management of commands
1 parent dd97202 commit 9e04ec0

26 files changed

+1316
-1124
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/server/

LICENSE.md

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2021, Jochyoua
4-
All rights reserved.
3+
Copyright (c) 2021, Jochyoua All rights reserved.
54

6-
Redistribution and use in source and binary forms, with or without
7-
modification, are permitted provided that the following conditions are met:
5+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6+
following conditions are met:
87

9-
1. Redistributions of source code must retain the above copyright notice, this
10-
list of conditions and the following disclaimer.
8+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
9+
disclaimer.
1110

12-
2. Redistributions in binary form must reproduce the above copyright notice,
13-
this list of conditions and the following disclaimer in the documentation
14-
and/or other materials provided with the distribution.
11+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
12+
disclaimer in the documentation and/or other materials provided with the distribution.
1513

16-
3. Neither the name of the copyright holder nor the names of its
17-
contributors may be used to endorse or promote products derived from
18-
this software without specific prior written permission.
14+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
15+
derived from this software without specific prior written permission.
1916

2017
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 86 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,103 @@
11
# MCSF
22

3-
This repo is a plugin for Minecraft, and I'm going to keep it updated for as long as possible. Currently, this plugin has been tested with Minecraft Java edition versions 1.8.8 through 1.16.4.
3+
This repo is a plugin for Minecraft, and I'm going to keep it updated for as long as possible. Currently, this plugin
4+
has been tested with Minecraft Java edition versions 1.8.8 through 1.16.4.
45

56
Download the latest version from [SpigotMC.org](https://www.spigotmc.org/resources/54115/)
67

7-
MCSF is a swear filter that enables your server to let users personally toggle their filter status. That means users who feel like they don't need to have a swear filter could toggle it on/off whenever they please.
8+
MCSF is a swear filter that enables your server to let users personally toggle their filter status. That means users who
9+
feel like they don't need to have a swear filter could toggle it on/off whenever they please.
10+
811
# FEATURES:
12+
913
* **Per player toggling**:
10-
* Giving players the option to disable or enable the swear filter whenever they wish
11-
* **DiscordSRV support**:
12-
* This allows you to filter discord messages along with server chat messages.
13-
* Optionally you may surround blacklisted words with spoilers.
14-
* **Punishments**:
15-
* This allows you to punish players if they swear by executing commands.
16-
* **Whitelists**:
17-
* This is optional but will enable you to remove words from being filtered.
18-
* **Custom regex support**:
19-
* This allows you to add custom regex.
20-
* By default, an IP and a domain regex would remove any matches and enable it through the config!
21-
* **UTF-8 support**:
22-
* This allows you to use special characters in your blacklist so that the filter could also filter languages like Chinese!
23-
* **MySQL support**:
24-
* MySQL, if enabled, would save both the swears and whitelist values into the database of choice along with user information.
25-
* **Customizability**:
26-
* This is probably one of the most important, but you may modify every message seen by the player!
27-
* **Multiple languages files**:
28-
* MCSF supports multiple languages!
29-
* You can find language files in MCSF/locales/; you may choose which one you'd like to use by changing settings.language to the file name of the language that you'd like to use :)
30-
* **RGB support**:
31-
* Any message sent by MCSF may have RGB using this format: &#RRGGBB
32-
* **Cooldowns**:
33-
* By default, all MCSF messages have a time delay of 5 seconds.
34-
* A 5 second delay would mean players can only use MCSF commands every 5 seconds
35-
* You can disable this with the permission MCSF.bypass or set the cooldown to 0.
36-
* **Global blocking**:
37-
* This allows you to block specific words for everyone even if the player's filter is disabled.
14+
* Giving players the option to disable or enable the swear filter whenever they wish
15+
* **DiscordSRV support**:
16+
* This allows you to filter discord messages along with server chat messages.
17+
* Optionally you may surround blacklisted words with spoilers.
18+
* **Punishments**:
19+
* This allows you to punish players if they swear by executing commands.
20+
* **Whitelists**:
21+
* This is optional but will enable you to remove words from being filtered.
22+
* **Custom regex support**:
23+
* This allows you to add custom regex.
24+
* If you wish to use this, please read the bottom of this page!
25+
* **UTF-8 support**:
26+
* This allows you to use special characters in your blacklist so that the filter could also filter languages like
27+
Chinese!
28+
* **MySQL support**:
29+
* MySQL, if enabled, would save both the swears and whitelist values into the database of choice along with user
30+
information.
31+
* **Customizability**:
32+
* This is probably one of the most important, but you may modify every message seen by the player!
33+
* **Multiple languages files**:
34+
* MCSF supports multiple languages!
35+
* MCSF supports multiple languages!
36+
* You can find language files in MCSF/locales/; you may choose which one you'd like to use by changing
37+
settings.language to the file name of the language that you'd like to use :)
38+
* **RGB support**:
39+
* Any message sent by MCSF may have RGB using this format: &#RRGGBB
40+
* **Cooldowns**:
41+
* By default, all MCSF messages have a time delay of 5 seconds.
42+
* A 5 second delay would mean players can only use MCSF commands every 5 seconds
43+
* You can disable this with the permission MCSF.bypass or set the cooldown to 0.
44+
* **Global blocking**:
45+
* This allows you to block specific words for everyone even if the player's filter is disabled.
3846

3947
# REQUIRMENTS:
4048

4149
(Optional: for global filtering) ProtocolLib
4250
Java 8+
51+
4352
# COMMANDS:
4453

45-
* **/MCSF toggle [player]** *(Permission: MCSF.use.toggle & MCSF.modify.others if toggling other users)*
46-
* This command toggles a users's swear filter.
47-
* **/MCSF reload** *(Permission: MCSF.modify.reload)*
48-
* This command reloads the configuration files
49-
* **/MCSF status [player]** *(Permission: MCSF.modify.others if viewing the status of other users)*
50-
* This command views the status of a user's swear filter status
51-
* **/MCSF add/remove [word]** *(Permission:MCSF.modify.add and MCSF.modify.remove)*
52-
* Modifies the blacklist
53-
* **/MCSF unset [player/uuid]** *(Permission:MCSF.modify.unset)*
54-
* Removes remove specific users from the database
55-
* **/MCSF whitelist [word]** *(Permission:MCSF.modify.whitelist)*
56-
* Adds/Removes word from the whitelist (Requires settings.whitelist to be true)
57-
* **/MCSF global [word]** *(Permission:MCSF.modify.global)*
58-
* Adds/Removes word from the global list (Requires settings.global blacklist to be true)
59-
* **/MCSF reload [confirm]** *(Permission:MCSF.modify.reload)*
60-
* Reloads the configuration files, and the database (can be dangerous)
54+
* **/MCSF toggle [player]** *(Permission: MCSF.use.toggle & MCSF.modify.others if toggling other users)*
55+
* This command toggles a users's swear filter.
56+
* **/MCSF reload** *(Permission: MCSF.modify.reload)*
57+
* This command reloads the configuration files
58+
* **/MCSF status [player]** *(Permission: MCSF.modify.others if viewing the status of other users)*
59+
* This command views the status of a user's swear filter status
60+
* **/MCSF add/remove [word]** *(Permission:MCSF.modify.add and MCSF.modify.remove)*
61+
* Modifies the blacklist
62+
* **/MCSF unset [player/uuid]** *(Permission:MCSF.modify.unset)*
63+
* Removes remove specific users from the database
64+
* **/MCSF whitelist [word]** *(Permission:MCSF.modify.whitelist)*
65+
* Adds/Removes word from the whitelist (Requires settings.whitelist to be true)
66+
* **/MCSF global [word]** *(Permission:MCSF.modify.global)*
67+
* Adds/Removes word from the global list (Requires settings.global blacklist to be true)
68+
* **/MCSF reload [confirm]** *(Permission:MCSF.modify.reload)*
69+
* Reloads the configuration files, and the database (can be dangerous)
6170

6271
# PLACEHOLDERS:
72+
6373
*These placeholders are only valid for plugin messages if applicable*
6474

65-
* **{prefix}**:
66-
* Returns the current prefix
75+
* **{prefix}**:
76+
* Returns the current prefix
6777
* **{player}**:
68-
* Returns the user's name according to MCSF
78+
* Returns the user's name according to MCSF
6979
* **{message}**:
70-
* Returns the failure/success value if applicable
80+
* Returns the failure/success value if applicable
7181
* **{current}**:
72-
* Returns the current version of the plugin
82+
* Returns the current version of the plugin
7383
* **{version}**:
74-
* Returns the latest plugin version according to SpigotMC
84+
* Returns the latest plugin version according to SpigotMC
7585
* **{serverversion}**:
76-
* Returns the current version of the server
77-
* **{swearcount}**:
78-
* Returns the amount of blacklisted words
86+
* Returns the current version of the server
7987
* **{wordcount}**:
80-
* Returns the amount of swear words in the config
81-
88+
* Returns the amount of swear words in the config
89+
8290
### PlacholderAPI placeholders:
91+
8392
* **%mcsf_player_name%**:
84-
* Returns the player's username according to MCSF (Returns player's username)
93+
* Returns the player's username according to MCSF (Returns player's username)
8594
* **%mcsf_player_flags%**:
86-
* Returns the flags of the user (Returns integer as String)
95+
* Returns the flags of the user (Returns integer as String)
8796
* **%mcsf_player_status%**:
88-
* Returns the flags of the user (Returns "enabled" or "disabled")
89-
* **%mcsf_swearcount%**:
90-
* Returns the amount of swears filtered (Returns integer as String)
97+
* Returns the flags of the user (Returns "enabled" or "disabled")
9198
* **%mcsf_version%**:
92-
* Returns the current version of this plugin (Returns double as String)
93-
99+
* Returns the current version of this plugin (Returns double as String)
100+
94101
# NOTES:
95102

96103
If you have this plugin on your server, please let me know so I can add it here.
@@ -100,18 +107,26 @@ MCSF is a swear filter that enables your server to let users personally toggle t
100107

101108
Download this plugin into your server's plugin folder
102109

103-
**(OPTIONAL):** If you wish all messages to be filtered, you must install [ProtocolLib](https://www.spigotmc.org/resources/1997/) as-well!
110+
**(OPTIONAL):** If you wish all messages to be filtered, you must
111+
install [ProtocolLib](https://www.spigotmc.org/resources/1997/) as-well!
104112

105-
**(OPTIONAL):** If you plan on using [DiscordSRV](https://www.spigotmc.org/resources/18494/), you must first download the plugin and then add them to your server and then restart the server.
113+
**(OPTIONAL):** If you plan on using [DiscordSRV](https://www.spigotmc.org/resources/18494/), you must first download
114+
the plugin and then add them to your server and then restart the server.
106115

107116
## Example Regex Test:
117+
108118
https://regex101.com/r/pvMY0o/1
109119

110120
# CUSTOM REGEX:
111-
You can add custom regex for both global and normal filtering by adding them as normal swears.
112-
For a string to be recognised as regex, it must be valid for Java and have the prefix regex:
121+
122+
You can add custom regex for both global and normal filtering by adding them as normal swears. For a string to be
123+
recognised as regex, it must be valid for Java and have the prefix regex:
113124
This is a valid example:
114-
### IP Addresses:
115-
* (Per Player) /mcsf add regex:\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])(\.|,|-)){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b
116-
* (Globally) /mcsf global regex:\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])(\.|,|-)){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b
125+
126+
### IP Addresses:
127+
128+
* (Per Player) /mcsf add regex:\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])(\.|,|-)){3}(?:(?:2([0-4][0-9]|5[0-5])
129+
|[0-1]?[0-9]?[0-9]))\b
130+
* (Globally) /mcsf global regex:\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])(\.|,|-)){3}(?:(?:2([0-4][0-9]|5[0-5])
131+
|[0-1]?[0-9]?[0-9]))\b
117132
* This will match IP Addresses.

src/main/java/io/github/jochyoua/mychristianswearfilter/MCSF.java

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package io.github.jochyoua.mychristianswearfilter;
22

3+
import io.github.jochyoua.mychristianswearfilter.commands.McsfCommand;
34
import io.github.jochyoua.mychristianswearfilter.dependencies.configapi.ConfigAPI;
45
import io.github.jochyoua.mychristianswearfilter.dependencies.configapi.Settings;
5-
import io.github.jochyoua.mychristianswearfilter.events.CommandEvents;
66
import io.github.jochyoua.mychristianswearfilter.events.PlayerEvents;
77
import io.github.jochyoua.mychristianswearfilter.events.PunishmentEvents;
88
import io.github.jochyoua.mychristianswearfilter.shared.Manager;
@@ -43,13 +43,7 @@ public class MCSF extends JavaPlugin {
4343
@Override
4444
public void onEnable() {
4545

46-
// Sets the default configuration with header
47-
getConfig().options().header(
48-
"MCSF (My Christian Swear Filter) v" + getDescription().getVersion() + " by Jochyoua\n"
49-
+ "This is a toggleable swear filter for your players\n"
50-
+ "Resource: https://www.spigotmc.org/resources/54115/\n"
51-
+ "Github: https://www.github.com/Jochyoua/MCSF/\n"
52-
+ "Wiki: https://github.com/Jochyoua/MCSF/wiki");
46+
// Sets the default configuration
5347
getConfig().options().copyDefaults(true);
5448
saveDefaultConfig();
5549

@@ -65,7 +59,7 @@ public void onEnable() {
6559
}
6660
Manager.FileManager.saveFile(this, sql, "sql");
6761
this.getConfig().set("mysql", null);
68-
this.saveConfig();
62+
Manager.FileManager.saveFile(this, getConfig(), "config");
6963
}
7064
FileConfiguration local = Manager.FileManager.getFile(this, "data/swears");
7165
if (!this.getConfig().getStringList("swears").isEmpty()) {
@@ -81,11 +75,11 @@ public void onEnable() {
8175
}
8276
}
8377
getConfig().set("swears", null);
84-
saveConfig();
78+
Manager.FileManager.saveFile(this, getConfig(), "config");
8579
}
8680
local = Manager.FileManager.getFile(this, "data/whitelist");
8781
if (!getConfig().getStringList("whitelist").isEmpty()) {
88-
getLogger().info("(CONFIG) Setting path `global` into `data/whitelist.yml`");
82+
getLogger().info("(CONFIG) Setting path `whitelist` into `data/whitelist.yml`");
8983
if (local.isSet("whitelist")) {
9084
if (!local.getStringList("whitelist").isEmpty()) {
9185
Set<String> local1 = new HashSet<>(local.getStringList("whitelist"));
@@ -97,7 +91,7 @@ public void onEnable() {
9791
}
9892
}
9993
this.getConfig().set("whitelist", null);
100-
this.saveConfig();
94+
Manager.FileManager.saveFile(this, getConfig(), "config");
10195
}
10296
local = Manager.FileManager.getFile(this, "data/global");
10397
if (!this.getConfig().getStringList("global").isEmpty()) {
@@ -113,7 +107,7 @@ public void onEnable() {
113107
}
114108
}
115109
this.getConfig().set("global", null);
116-
this.saveConfig();
110+
Manager.FileManager.saveFile(this, getConfig(), "config");
117111
}
118112

119113
// Loads MySQL data if mysql is enabled
@@ -134,6 +128,7 @@ else if (!connector.isWorking())
134128
}
135129
}
136130
manager = new Manager(this, connector);
131+
137132
// Sets the correct data for tables
138133
if (getHikariCP().isEnabled())
139134
try {
@@ -152,7 +147,7 @@ else if (!connector.isWorking())
152147
}
153148
}
154149
getConfig().set("users", null);
155-
saveConfig();
150+
Manager.FileManager.saveFile(this, getConfig(), "config");
156151
}
157152

158153
// Loop through each language file that isn't the selected one and add it to /locales/ folder
@@ -169,7 +164,7 @@ else if (!connector.isWorking())
169164
manager.reload();
170165

171166
// Loads the MCSF commands with aliases
172-
new CommandEvents(manager);
167+
new McsfCommand(this);
173168

174169
// Loads all the player related events
175170
new PlayerEvents(manager);
@@ -193,14 +188,16 @@ else if (!connector.isWorking())
193188
}
194189

195190
// Debugs and checks to make sure that strings are correctly being filtered
196-
final List<String> swears = Manager.FileManager.getFile(this, "data/swears").getStringList("swears");
197-
if (!swears.isEmpty()) {
198-
final String test = swears.get((new SecureRandom()).nextInt(swears.size()));
199-
String clean = manager.clean(test, true, false, manager.reloadPattern(Types.Filters.BOTH), Types.Filters.DEBUG);
200-
manager.debug("Running filter test for `" + test + "`; returns as: `" + clean + "`");
201-
} else {
202-
manager.debug("Uh-oh! Swears seems to be empty.");
203-
}
191+
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
192+
final List<String> swears = Manager.FileManager.getFile(this, "data/swears").getStringList("swears");
193+
if (!swears.isEmpty()) {
194+
final String test = swears.get((new SecureRandom()).nextInt(swears.size()));
195+
String clean = manager.clean(test, true, false, manager.reloadPattern(Types.Filters.BOTH), Types.Filters.DEBUG);
196+
manager.debug("Running filter test for `" + test + "`; returns as: `" + clean + "`");
197+
} else {
198+
manager.debug("Uh-oh! Swears seems to be empty.");
199+
}
200+
});
204201

205202
// Basic metrics data, includes currently set language
206203
final Metrics metrics = new Metrics(this, 4345);
@@ -226,7 +223,7 @@ else if (!connector.isWorking())
226223

227224
@Override
228225
public void onDisable() {
229-
// Closes pre-existing mysql and sqlite connections
226+
// Closes pre-existing mysql and sqlite connectionsman
230227
manager.shutDown();
231228

232229
// Terminates all pre-existing tasks that are still running

0 commit comments

Comments
 (0)