Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Velocity placeholder %server_name% for warns, server whitelist option, Discord webhooks integration #48

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4c4d38b
Velocity placeholder %server_name% for warns
MemencioPerez Oct 17, 2024
2a6dbfa
Server whitelist option
MemencioPerez Oct 17, 2024
ec83f89
1.0.4
MemencioPerez Oct 17, 2024
7dfa021
Custom names for moderation modules
MemencioPerez Oct 18, 2024
8c358e4
Remove duplicate data loading for the caps moderation module in Velocity
MemencioPerez Oct 18, 2024
4ea71b6
Fix custom names for moderation modules for Bukkit and Bungeecord
MemencioPerez Oct 18, 2024
3665468
Discord webhook integration for Velocity
MemencioPerez Oct 18, 2024
6fd6cdb
Fix custom names for moderation modules for Bukkit and Bungeecord again
MemencioPerez Oct 18, 2024
b5a2e15
Discord webhook integration for Bukkit and Bungeecord
MemencioPerez Oct 18, 2024
169cab7
Fix some typos
MemencioPerez Oct 18, 2024
ee76877
Update Discord webhooks library
MemencioPerez Oct 18, 2024
9823866
Little cleanup
MemencioPerez Oct 18, 2024
8049abf
Change default Discord webhook color to Aqua
MemencioPerez Oct 18, 2024
b16ec68
Move custom module name to a temporary variable for easier reading an…
MemencioPerez Oct 18, 2024
b1b0307
Discord webhook notification toggle per module (partially reverts com…
MemencioPerez Oct 18, 2024
a9ccd60
Remove unused custom module name option for Cooldown module
MemencioPerez Oct 18, 2024
881d690
Make Discord webhook disabled by default
MemencioPerez Oct 18, 2024
4f0bfb1
Dispatch Discord Webhook notification asynchronously
MemencioPerez Nov 4, 2024
bfcbe84
Clear Discord webhook embeds list after execution
MemencioPerez Nov 4, 2024
e025ebd
Update Discord webhooks library
MemencioPerez Nov 5, 2024
1af4f81
Update DiscordWebhook setTimestamp method usage in Discord webhook mo…
MemencioPerez Nov 5, 2024
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
41 changes: 40 additions & 1 deletion 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.0.4</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 @@ -51,6 +55,11 @@
<version>3.3.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.memencioperez</groupId>
<artifactId>webhookly</artifactId>
<version>master-SNAPSHOT</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.memencioperez: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
@@ -1,7 +1,6 @@
package dev._2lstudios.chatsentinel.bukkit.modules;

import java.util.HashMap;
import java.util.Map;
import java.util.*;

import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -44,35 +43,53 @@ 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"),
getWhitelistModule().loadData(configYml.getBoolean("whitelist.enabled"), new HashSet<>(),
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 @@ -9,6 +9,8 @@
public class BlacklistModerationModule extends ModerationModule {
private ModuleManager moduleManager;

private String customName;

private boolean fakeMessage;
private boolean blockRawMessage;
private Pattern pattern;
Expand All @@ -20,12 +22,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);
this.customName = customName;
this.fakeMessage = fakeMessage;
this.censorshipEnabled = censorshipEnabled;
this.censorshipReplacement = censorshipReplacement;
Expand Down Expand Up @@ -107,4 +111,9 @@ public ChatEventResult processEvent(ChatPlayer chatPlayer, MessagesModule messag
public String getName() {
return "Blacklist";
}

@Override
public String getCustomName() {
return customName;
}
}
Loading