Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<name>ChatSentinel</name>
<description>Advanced chat management plugin</description>
<version>1.0.2</version>
<version>1.1.0</version>
<url>https://builtbybit.com/resources/23698/</url>

<properties>
Expand All @@ -29,6 +29,10 @@
<id>velocity-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -48,9 +52,14 @@
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.4.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.micartey</groupId>
<artifactId>webhookly</artifactId>
<version>master</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -90,6 +99,36 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>me.micartey.webhookly</pattern>
<shadedPattern>dev._2lstudios.chatsentinel.libs.webhookly</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>com.github.micartey:webhookly</artifact>
<excludes>
<exclude>META-INF/*.MF</exclude>
</excludes>
</filter>
</filters>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev._2lstudios.chatsentinel.bukkit;

import dev._2lstudios.chatsentinel.shared.chat.ChatNotificationManager;
import dev._2lstudios.chatsentinel.shared.modules.*;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.ConsoleCommandSender;
Expand All @@ -18,11 +19,6 @@
import dev._2lstudios.chatsentinel.shared.chat.ChatEventResult;
import dev._2lstudios.chatsentinel.shared.chat.ChatPlayer;
import dev._2lstudios.chatsentinel.shared.chat.ChatPlayerManager;
import dev._2lstudios.chatsentinel.shared.modules.CooldownModerationModule;
import dev._2lstudios.chatsentinel.shared.modules.GeneralModule;
import dev._2lstudios.chatsentinel.shared.modules.MessagesModule;
import dev._2lstudios.chatsentinel.shared.modules.ModerationModule;
import dev._2lstudios.chatsentinel.shared.modules.SyntaxModerationModule;

public class ChatSentinel extends JavaPlugin {
// Static instance
Expand Down Expand Up @@ -102,13 +98,14 @@ public void dispatchNotification(ModerationModule moderationModule, String[][] p

public String[][] getPlaceholders(Player player, ChatPlayer chatPlayer, ModerationModule moderationModule, String message) {
String playerName = player.getName();
String customModuleName = moderationModule.getCustomName();
int warns = chatPlayer.getWarns(moderationModule);
int maxWarns = moderationModule.getMaxWarns();
float remainingTime = moduleManager.getCooldownModule().getRemainingTime(chatPlayer, message);

return new String[][] {
{ "%player%", "%message%", "%warns%", "%maxwarns%", "%cooldown%" },
{ playerName, message, String.valueOf(warns), String.valueOf(maxWarns), String.valueOf(remainingTime) }
{ "%player%", "%module%", "%message%", "%warns%", "%maxwarns%", "%cooldown%" },
{ playerName, customModuleName, message, String.valueOf(warns), String.valueOf(maxWarns), String.valueOf(remainingTime) }
};
}

Expand Down Expand Up @@ -176,6 +173,11 @@ public ChatEventResult processEvent(ChatPlayer chatPlayer, Player player, String
// Send admin notification
ChatSentinel.getInstance().dispatchNotification(moderationModule, placeholders, chatNotificationManager);

// Send discord webhook notification
Server server = getServer();
DiscordWebhookModule discordWebhookModule = moduleManager.getDiscordWebhookModule();
server.getScheduler().runTaskAsynchronously(this, () -> discordWebhookModule.dispatchWebhookNotification(moderationModule, placeholders));

// Update message
finalResult.setMessage(result.getMessage());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ public void reloadData() {
locales.put(lang, messages);
}

getCapsModule().loadData(configYml.getBoolean("caps.enabled"), configYml.getBoolean("caps.replace"),
getCapsModule().loadData(configYml.getBoolean("caps.enabled"), configYml.getString("caps.custom-module-name"), configYml.getBoolean("caps.replace"),
configYml.getInt("caps.max"), configYml.getInt("caps.warn.max"),
configYml.getString("caps.warn.notification"),
configYml.getBoolean("caps.warn.webhook-notification"),
configYml.getStringList("caps.punishments").toArray(new String[0]));
getCooldownModule().loadData(configYml.getBoolean("cooldown.enabled"),
configYml.getInt("cooldown.time.repeat-global"), configYml.getInt("cooldown.time.repeat"),
configYml.getInt("cooldown.time.normal"), configYml.getInt("cooldown.time.command"));
getFloodModule().loadData(configYml.getBoolean("flood.enabled"), configYml.getBoolean("flood.replace"),
getFloodModule().loadData(configYml.getBoolean("flood.enabled"), configYml.getString("flood.custom-module-name"), configYml.getBoolean("flood.replace"),
configYml.getInt("flood.warn.max"), configYml.getString("flood.pattern"),
configYml.getString("flood.warn.notification"),
configYml.getBoolean("flood.warn.webhook-notification"),
configYml.getStringList("flood.punishments").toArray(new String[0]));
getMessagesModule().loadData(messagesYml.getString("default"), locales);
getGeneralModule().loadData(configYml.getBoolean("general.sanitize", true),
Expand All @@ -64,15 +66,31 @@ public void reloadData() {
whitelistYml.getStringList("expressions").toArray(new String[0]));
boolean censorshipEnabled = configYml.getBoolean("blacklist.censorship.enabled", false);
String censorshipReplacement = configYml.getString("blacklist.censorship.replacement", "***");
getBlacklistModule().loadData(configYml.getBoolean("blacklist.enabled"),
getBlacklistModule().loadData(configYml.getBoolean("blacklist.enabled"), configYml.getString("blacklist.custom-module-name"),
configYml.getBoolean("blacklist.fake_message"), censorshipEnabled, censorshipReplacement,
configYml.getInt("blacklist.warn.max"), configYml.getString("blacklist.warn.notification"),
configYml.getBoolean("blacklist.warn.webhook-notification"),
configYml.getStringList("blacklist.punishments").toArray(new String[0]),
blacklistYml.getStringList("expressions").toArray(new String[0]),
configYml.getBoolean("blacklist.block_raw_message"));
getSyntaxModule().loadData(configYml.getBoolean("syntax.enabled"), configYml.getInt("syntax.warn.max"),
getSyntaxModule().loadData(configYml.getBoolean("syntax.enabled"), configYml.getString("syntax.custom-module-name"), configYml.getInt("syntax.warn.max"),
configYml.getString("syntax.warn.notification"),
configYml.getBoolean("syntax.warn.webhook-notification"),
configYml.getStringList("syntax.whitelist").toArray(new String[0]),
configYml.getStringList("syntax.punishments").toArray(new String[0]));
getDiscordWebhookModule().loadData(configYml.getBoolean("discord-webhook.enabled"), configYml.getString("discord-webhook.webhook-url"),
configYml.getString("discord-webhook.warn.max"),
configYml.getString("discord-webhook.sender.avatar-url"),
configYml.getString("discord-webhook.sender.username"),
configYml.getString("discord-webhook.author.name"),
configYml.getString("discord-webhook.author.url"),
configYml.getString("discord-webhook.title"),
configYml.getString("discord-webhook.color"),
configYml.getString("discord-webhook.description"),
configYml.getString("discord-webhook.field-names.message"),
configYml.getString("discord-webhook.field-names.server"),
configYml.getString("discord-webhook.footer.text"),
configYml.getString("discord-webhook.footer.icon-url"),
configYml.getString("discord-webhook.thumbnail-url"));
}
}
18 changes: 10 additions & 8 deletions src/main/java/dev/_2lstudios/chatsentinel/bungee/ChatSentinel.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
import dev._2lstudios.chatsentinel.shared.chat.ChatNotificationManager;
import dev._2lstudios.chatsentinel.shared.chat.ChatPlayer;
import dev._2lstudios.chatsentinel.shared.chat.ChatPlayerManager;
import dev._2lstudios.chatsentinel.shared.modules.CooldownModerationModule;
import dev._2lstudios.chatsentinel.shared.modules.GeneralModule;
import dev._2lstudios.chatsentinel.shared.modules.MessagesModule;
import dev._2lstudios.chatsentinel.shared.modules.ModerationModule;
import dev._2lstudios.chatsentinel.shared.modules.SyntaxModerationModule;
import dev._2lstudios.chatsentinel.shared.modules.*;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
Expand Down Expand Up @@ -61,7 +57,7 @@ public void onEnable() {
ChatNotificationManager chatNotificationManager = new ChatNotificationManager();
PluginManager pluginManager = server.getPluginManager();

pluginManager.registerListener(this, new ChatListener(chatPlayerManager, chatNotificationManager));
pluginManager.registerListener(this, new ChatListener(moduleManager.getWhitelistModule(), chatPlayerManager, chatNotificationManager));
pluginManager.registerListener(this, new PlayerDisconnectListener(generalModule, chatPlayerManager, chatNotificationManager));
pluginManager.registerListener(this, new PostLoginListener(generalModule, chatPlayerManager, chatNotificationManager));

Expand Down Expand Up @@ -106,15 +102,16 @@ public void dispatchNotification(ModerationModule moderationModule, String[][] p

public String[][] getPlaceholders(ProxiedPlayer player, ChatPlayer chatPlayer, ModerationModule moderationModule, String message) {
String playerName = player.getName();
String customModuleName = moderationModule.getCustomName();
int warns = chatPlayer.getWarns(moderationModule);
int maxWarns = moderationModule.getMaxWarns();
float remainingTime = moduleManager.getCooldownModule().getRemainingTime(chatPlayer, message);
Server server = player.getServer();
String serverName = server != null ? server.getInfo().getName() : "";

return new String[][] {
{ "%player%", "%message%", "%warns%", "%maxwarns%", "%cooldown%", "%server_name%" },
{ playerName, message, String.valueOf(warns), String.valueOf(maxWarns), String.valueOf(remainingTime), serverName }
{ "%player%", "%module%", "%message%", "%warns%", "%maxwarns%", "%cooldown%", "%server_name%" },
{ playerName, customModuleName, message, String.valueOf(warns), String.valueOf(maxWarns), String.valueOf(remainingTime), serverName }
};
}

Expand Down Expand Up @@ -182,6 +179,11 @@ public ChatEventResult processEvent(ChatPlayer chatPlayer, ProxiedPlayer player,
// Send admin notification
ChatSentinel.getInstance().dispatchNotification(moderationModule, placeholders, chatNotificationManager);

// Send discord webhook notification
ProxyServer server = getProxy();
DiscordWebhookModule discordWebhookModule = moduleManager.getDiscordWebhookModule();
server.getScheduler().runAsync(this, () -> discordWebhookModule.dispatchWebhookNotification(moderationModule, placeholders));

// Update message
finalResult.setMessage(result.getMessage());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev._2lstudios.chatsentinel.shared.chat.ChatNotificationManager;
import dev._2lstudios.chatsentinel.shared.chat.ChatPlayer;
import dev._2lstudios.chatsentinel.shared.chat.ChatPlayerManager;
import dev._2lstudios.chatsentinel.shared.modules.WhitelistModule;
import net.md_5.bungee.api.connection.Connection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent;
Expand All @@ -13,10 +14,12 @@
import net.md_5.bungee.event.EventPriority;

public class ChatListener implements Listener {
private WhitelistModule whitelistModule;
private ChatPlayerManager chatPlayerManager;
private ChatNotificationManager chatNotificationManager;

public ChatListener(ChatPlayerManager chatPlayerManager, ChatNotificationManager chatNotificationManager) {
public ChatListener(WhitelistModule whitelistModule, ChatPlayerManager chatPlayerManager, ChatNotificationManager chatNotificationManager) {
this.whitelistModule = whitelistModule;
this.chatPlayerManager = chatPlayerManager;
this.chatNotificationManager = chatNotificationManager;
}
Expand All @@ -37,6 +40,14 @@ public void onChatEvent(ChatEvent event) {
// Get player
ProxiedPlayer player = (ProxiedPlayer) sender;

// Check if the player's current server is on the whitelist
if (player.getServer() != null) {
String playerCurrentServer = player.getServer().getInfo().getName();
if (whitelistModule.getWhitelistedServers().contains(playerCurrentServer)) {
return;
}
}

// Check if player has bypass
if (player.hasPermission("chatsentinel.bypass")) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,54 @@ public void reloadData() {
locales.put(lang, messages);
}

getCapsModule().loadData(configYml.getBoolean("caps.enabled"), configYml.getBoolean("caps.replace"),
getCapsModule().loadData(configYml.getBoolean("caps.enabled"), configYml.getString("caps.custom-module-name"), configYml.getBoolean("caps.replace"),
configYml.getInt("caps.max"), configYml.getInt("caps.warn.max"),
configYml.getString("caps.warn.notification"),
configYml.getBoolean("caps.warn.webhook-notification"),
configYml.getStringList("caps.punishments").toArray(new String[0]));
getCooldownModule().loadData(configYml.getBoolean("cooldown.enabled"),
configYml.getInt("cooldown.time.repeat-global"), configYml.getInt("cooldown.time.repeat"),
configYml.getInt("cooldown.time.normal"), configYml.getInt("cooldown.time.command"));
getFloodModule().loadData(configYml.getBoolean("flood.enabled"), configYml.getBoolean("flood.replace"),
getFloodModule().loadData(configYml.getBoolean("flood.enabled"), configYml.getString("flood.custom-module-name"), configYml.getBoolean("flood.replace"),
configYml.getInt("flood.warn.max"), configYml.getString("flood.pattern"),
configYml.getString("flood.warn.notification"),
configYml.getBoolean("flood.warn.webhook-notification"),
configYml.getStringList("flood.punishments").toArray(new String[0]));
getMessagesModule().loadData(messagesYml.getString("default"), locales);
getGeneralModule().loadData(configYml.getBoolean("general.sanitize", true),
configYml.getBoolean("general.sanitize-names", true),
configYml.getBoolean("general.filter-other", false),
configYml.getStringList("general.commands"));
getWhitelistModule().loadData(configYml.getBoolean("whitelist.enabled"),
whitelistYml.getStringList("servers"),
whitelistYml.getStringList("expressions").toArray(new String[0]));
boolean censorshipEnabled = configYml.getBoolean("blacklist.censorship.enabled", false);
String censorshipReplacement = configYml.getString("blacklist.censorship.replacement", "***");
getBlacklistModule().loadData(configYml.getBoolean("blacklist.enabled"),
getBlacklistModule().loadData(configYml.getBoolean("blacklist.enabled"), configYml.getString("blacklist.custom-module-name"),
configYml.getBoolean("blacklist.fake_message"), censorshipEnabled, censorshipReplacement,
configYml.getInt("blacklist.warn.max"), configYml.getString("blacklist.warn.notification"),
configYml.getBoolean("blacklist.warn.webhook-notification"),
configYml.getStringList("blacklist.punishments").toArray(new String[0]),
blacklistYml.getStringList("expressions").toArray(new String[0]),
configYml.getBoolean("blacklist.block_raw_message"));
getSyntaxModule().loadData(configYml.getBoolean("syntax.enabled"), configYml.getInt("syntax.warn.max"),
getSyntaxModule().loadData(configYml.getBoolean("syntax.enabled"), configYml.getString("syntax.custom-module-name"), configYml.getInt("syntax.warn.max"),
configYml.getString("syntax.warn.notification"),
configYml.getBoolean("syntax.warn.webhook-notification"),
configYml.getStringList("syntax.whitelist").toArray(new String[0]),
configYml.getStringList("syntax.punishments").toArray(new String[0]));
getDiscordWebhookModule().loadData(configYml.getBoolean("discord-webhook.enabled"), configYml.getString("discord-webhook.webhook-url"),
configYml.getString("discord-webhook.warn.max"),
configYml.getString("discord-webhook.sender.avatar-url"),
configYml.getString("discord-webhook.sender.username"),
configYml.getString("discord-webhook.author.name"),
configYml.getString("discord-webhook.author.url"),
configYml.getString("discord-webhook.title"),
configYml.getString("discord-webhook.color"),
configYml.getString("discord-webhook.description"),
configYml.getString("discord-webhook.field-names.message"),
configYml.getString("discord-webhook.field-names.server"),
configYml.getString("discord-webhook.footer.text"),
configYml.getString("discord-webhook.footer.icon-url"),
configYml.getString("discord-webhook.thumbnail-url"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public BlacklistModerationModule(ModuleManager moduleManager) {
this.moduleManager = moduleManager;
}

public void loadData(boolean enabled, boolean fakeMessage, boolean censorshipEnabled, String censorshipReplacement, int maxWarns,
String warnNotification, String[] commands, String[] patterns, boolean blockRawMessage) {
public void loadData(boolean enabled, String customName, boolean fakeMessage, boolean censorshipEnabled, String censorshipReplacement, int maxWarns,
String warnNotification, boolean webhookEnabled, String[] commands, String[] patterns, boolean blockRawMessage) {
setEnabled(enabled);
setMaxWarns(maxWarns);
setWarnNotification(warnNotification);
setWebhookEnabled(webhookEnabled);
setCommands(commands);
setCustomName(customName);
this.fakeMessage = fakeMessage;
this.censorshipEnabled = censorshipEnabled;
this.censorshipReplacement = censorshipReplacement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ public class CapsModerationModule extends ModerationModule {
private boolean replace;
private int maxCaps;

public void loadData(boolean enabled, boolean replace, int max, int maxWarns,
String warnNotification, String[] commands) {
public void loadData(boolean enabled, String customName, boolean replace, int max, int maxWarns,
String warnNotification, boolean webhookEnabled, String[] commands) {
setEnabled(enabled);
setMaxWarns(maxWarns);
setWarnNotification(warnNotification);
setWebhookEnabled(webhookEnabled);
setCommands(commands);
setCustomName(customName);
this.replace = replace;
this.maxCaps = max;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public String getName() {
return "Cooldown";
}

@Override
public String getCustomName() {
return getName();
}

@Override
public String getWarnNotification(String[][] placeholders) {
return null;
Expand Down
Loading