mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Begin (broken) modularization
This commit is contained in:
1 parent
b3a0d71ba8
commit
ad8089855c
56 files changed
+553
-369
No files matched your search
+24
@@ -0,0 +1,24 @@
|
||||
package net.draycia.simplechatmoderation;
|
||||
|
||||
import net.draycia.simplechat.SimpleChat;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class SimpleChatModeration extends JavaPlugin {
|
||||
|
||||
private SimpleChat simpleChat;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
simpleChat = (SimpleChat)Bukkit.getPluginManager().getPlugin("SimpleChat");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
public SimpleChat getSimpleChat() {
|
||||
return simpleChat;
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package net.draycia.simplechatmoderation.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import net.draycia.simplechat.SimpleChat;
|
||||
import net.draycia.simplechatmoderation.SimpleChatModeration;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandAlias("clearchat|cc")
|
||||
@CommandPermission("simplechat.clearchat.clear")
|
||||
public class ClearChatCommand extends BaseCommand {
|
||||
|
||||
private SimpleChatModeration moderation;
|
||||
|
||||
public ClearChatCommand(SimpleChatModeration moderation) {
|
||||
this.moderation = moderation;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void baseCommand(CommandIssuer issuer) {
|
||||
String format = moderation.getConfig().getString("clear-chat.message", "");
|
||||
Component component = MiniMessage.get().parse(format, "br", "\n");
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (player.hasPermission("simplechat.clearchat.exempt")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Audience audience = moderation.getSimpleChat().getAudiences().player(player);
|
||||
|
||||
for (int i = 0; i < moderation.getConfig().getInt("clear-chat.message-count", 100); i++) {
|
||||
audience.sendMessage(component);
|
||||
}
|
||||
|
||||
String name = issuer.isPlayer() ? ((Player)issuer).getName() : "Console";
|
||||
|
||||
if (player.hasPermission("simplechat.clearchat.notify")) {
|
||||
String message = moderation.getConfig().getString("language.clear-notify");
|
||||
audience.sendMessage(MiniMessage.get().parse(message, "player", name));
|
||||
}
|
||||
|
||||
if (player.hasPermission("simplechat.clearchat.exempt")) {
|
||||
String message = moderation.getConfig().getString("language.clear-exempt");
|
||||
audience.sendMessage(MiniMessage.get().parse(message, "player", name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package net.draycia.simplechatmoderation.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import net.draycia.simplechat.SimpleChat;
|
||||
import net.draycia.simplechat.storage.ChatUser;
|
||||
import net.draycia.simplechatmoderation.SimpleChatModeration;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandAlias("mute")
|
||||
@CommandPermission("simplechat.mute")
|
||||
public class MuteCommand extends BaseCommand {
|
||||
|
||||
private SimpleChatModeration moderation;
|
||||
|
||||
public MuteCommand(SimpleChatModeration moderation) {
|
||||
this.moderation = moderation;
|
||||
}
|
||||
|
||||
@Default
|
||||
@CommandCompletion("@players")
|
||||
public void baseCommand(CommandSender sender, ChatUser targetUser) {
|
||||
String format;
|
||||
|
||||
if (targetUser.isMuted()) {
|
||||
targetUser.setMuted(true);
|
||||
format = moderation.getConfig().getString("language.no-longer-muted");
|
||||
} else {
|
||||
targetUser.setMuted(false);
|
||||
format = moderation.getConfig().getString("language.is-now-muted");
|
||||
}
|
||||
|
||||
Component message = MiniMessage.get().parse(format, "br", "\n",
|
||||
"user", targetUser.asOfflinePlayer().getName());
|
||||
|
||||
moderation.getSimpleChat().getAudiences().audience(sender).sendMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package net.draycia.simplechatmoderation.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import net.draycia.simplechat.storage.ChatUser;
|
||||
import net.draycia.simplechatmoderation.SimpleChatModeration;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandAlias("shadowmute|sm|smute")
|
||||
@CommandPermission("simplechat.shadowmute")
|
||||
public class ShadowMuteCommand extends BaseCommand {
|
||||
|
||||
private SimpleChatModeration moderation;
|
||||
|
||||
public ShadowMuteCommand(SimpleChatModeration moderation) {
|
||||
this.moderation = moderation;
|
||||
}
|
||||
|
||||
@Default
|
||||
@CommandCompletion("@players")
|
||||
public void baseCommand(CommandSender sender, ChatUser targetUser) {
|
||||
String format;
|
||||
|
||||
if (targetUser.isShadowMuted()) {
|
||||
targetUser.setShadowMuted(false);
|
||||
format = moderation.getConfig().getString("language.no-longer-shadow-muted");
|
||||
} else {
|
||||
targetUser.setShadowMuted(true);
|
||||
format = moderation.getConfig().getString("language.is-now-shadow-muted");
|
||||
}
|
||||
|
||||
Component message = MiniMessage.get().parse(format, "br", "\n",
|
||||
"user", targetUser.asOfflinePlayer().getName());
|
||||
|
||||
moderation.getSimpleChat().getAudiences().audience(sender).sendMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package net.draycia.simplechatmoderation.listeners;
|
||||
|
||||
import net.draycia.simplechat.events.ChatFormatEvent;
|
||||
import net.draycia.simplechatmoderation.SimpleChatModeration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class CapsHandler implements Listener {
|
||||
|
||||
private SimpleChatModeration moderation;
|
||||
|
||||
public CapsHandler(SimpleChatModeration moderation) {
|
||||
this.moderation = moderation;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onMessage(ChatFormatEvent event) {
|
||||
if (!moderation.getConfig().getBoolean("caps-protection.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getMessage().length() >= moderation.getConfig().getInt("caps-protection.minimum-length"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
int amountOfCaps = 0;
|
||||
|
||||
for (char letter : event.getMessage().toCharArray()) {
|
||||
if (Character.isUpperCase(letter)) {
|
||||
amountOfCaps++;
|
||||
}
|
||||
}
|
||||
|
||||
double capsPercentage = (amountOfCaps * 100.0) / event.getMessage().length();
|
||||
|
||||
if (!(capsPercentage >= moderation.getConfig().getDouble("caps-protection.percent-caps"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (moderation.getConfig().getBoolean("block-message")) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
event.setMessage(event.getMessage().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package net.draycia.simplechatmoderation.listeners;
|
||||
|
||||
import net.draycia.simplechat.channels.ChatChannel;
|
||||
import net.draycia.simplechat.events.ChatFormatEvent;
|
||||
import net.draycia.simplechatmoderation.SimpleChatModeration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FilterHandler implements Listener {
|
||||
|
||||
private SimpleChatModeration moderation;
|
||||
|
||||
public FilterHandler(SimpleChatModeration moderation) {
|
||||
this.moderation = moderation;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onFilter(ChatFormatEvent event) {
|
||||
if (!moderation.getConfig().getBoolean("filters.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String filterText = moderation.getConfig().getString("filters.filter-text", "****");
|
||||
|
||||
if (channelUsesFilter(event.getChatChannel())) {
|
||||
for (String entry : moderation.getConfig().getStringList("filters.filtered-words")) {
|
||||
event.setMessage(event.getMessage().replaceAll(entry, filterText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean channelUsesFilter(ChatChannel chatChannel) {
|
||||
List<String> channels = moderation.getConfig().getStringList("filters.channels");
|
||||
|
||||
return channels.contains("*") || channels.contains(chatChannel.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
caps-protection:
|
||||
enabled: true
|
||||
minimum-length: 10
|
||||
percent-caps: 80
|
||||
block-message: false
|
||||
|
||||
filters:
|
||||
enabled: true
|
||||
filter-text: '****'
|
||||
filtered-words:
|
||||
- 'lag'
|
||||
- 'la[g]+'
|
||||
channels:
|
||||
- '*' # Use '*' to mean all channels
|
||||
|
||||
clear-chat:
|
||||
# The message sent to clear chat, you probably want to leave this blank
|
||||
message: ""
|
||||
# How many messages will be sent in order to clear chat
|
||||
message-count: 100
|
||||
|
||||
language:
|
||||
is-now-shadow-muted: '<yellow>User <user> is now shadow muted!'
|
||||
no-longer-shadow-muted: '<yellow>User <user> is no longer shadow muted!'
|
||||
is-now-muted: '<yellow>User <user> is now muted!'
|
||||
no-longer-muted: '<yellow>User <user> is no longer muted!'
|
||||
reloaded: '<yellow>ChatModeration config has been reloaded!'
|
||||
clear-notify: '<yellow>Chat has been cleared by <player>.'
|
||||
clear-exempt: '<yellow>You were exempt from the clear due to your permissions!'
|
||||
@@ -0,0 +1,5 @@
|
||||
name: SimpleChatModeration
|
||||
version: ${project.version}
|
||||
main: net.draycia.simplechatmoderation.SimpleChatModeration
|
||||
api-version: 1.16
|
||||
depend: [SimpleChat]
|
||||
Reference in new issue
Block a user