diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index daf9307..1d7d406 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,8 +16,3 @@ jobs: run: git config --global user.email "no-reply@github.com" && git config --global user.name "Github Actions" - name: Build run: ./gradlew build --stacktrace - - name: Upload artifact - uses: actions/upload-artifact@v2 - with: - name: Chat.jar - path: build/libs/Chat*.jar \ No newline at end of file diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 92987cd..7454321 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -3,10 +3,7 @@ plugins { } dependencies { - compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT") { - exclude("net.kyori.adventure.text.minimessage") - } - compileOnly("net.kyori:adventure-text-minimessage:4.10.0-SNAPSHOT") // Minimessage + compileOnly("com.alttd:Galaxy-API:1.18.2-R0.1-SNAPSHOT") compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate compileOnly("net.luckperms:api:5.3") // Luckperms } diff --git a/api/src/main/java/com/alttd/chat/config/Config.java b/api/src/main/java/com/alttd/chat/config/Config.java index ad9914b..e94ac15 100755 --- a/api/src/main/java/com/alttd/chat/config/Config.java +++ b/api/src/main/java/com/alttd/chat/config/Config.java @@ -185,6 +185,7 @@ public final class Config { public static String MESSAGESENDER = " >(Me -> ) "; public static String MESSAGERECIEVER = " >( on -> Me) "; public static String MESSAGESPY = "( -> ) "; + public static String RECEIVER_DOES_NOT_EXIST = " is not a valid player."; private static void messageCommand() { MESSAGECOMMANDALIASES.clear(); REPLYCOMMANDALIASES.clear(); @@ -193,6 +194,7 @@ public final class Config { MESSAGESENDER = getString("commands.message.sender-message", MESSAGESENDER); MESSAGERECIEVER = getString("commands.message.reciever-message", MESSAGERECIEVER); MESSAGESPY = getString("commands.message.spy-message", MESSAGESPY); + RECEIVER_DOES_NOT_EXIST = getString("commands.message.receiver-does-not-exist", RECEIVER_DOES_NOT_EXIST); } public static String GCFORMAT = " >to Global: "; @@ -271,6 +273,7 @@ public final class Config { public static String REMOVED_USER_FROM_PARTY = "You removed from the chat party!"; public static String NOT_A_PARTY_MEMBER = " is not a member of your party!"; public static String ALREADY_IN_PARTY = "You're already in a party!"; + public static String ALREADY_IN_THIS_PARTY = "You're already in !"; public static String SENT_PARTY_INV = "You send a chat party invite to !"; public static String JOIN_PARTY_CLICK_MESSAGE = " '>" + "You received an invite to join , click this message to accept."; @@ -317,6 +320,7 @@ public final class Config { DISBAND_PARTY_CONFIRM = getString("party.messages.disband-party-confirm", DISBAND_PARTY_CONFIRM); DISBANDED_PARTY = getString("party.messages.disbanded-party", DISBANDED_PARTY); PARTY_INFO = getString("party.messages.party-info", PARTY_INFO); + ALREADY_IN_THIS_PARTY = getString("party.messages.already-in-this-party", ALREADY_IN_THIS_PARTY); } public static String PARTY_HELP_WRAPPER = "ChatParty help:\n"; @@ -410,4 +414,26 @@ public final class Config { mailSent = getString("settings.mail.mail-sent", mailSent); } + public static HashMap serverChannelId = new HashMap<>(); + public static String REPORT_SENT = "Your report was sent, staff will contact you asap to help resolve your issue!"; + private static void loadChannelIds() { + serverChannelId.clear(); + serverChannelId.put("general", getLong("discord-channel-id.general", (long) -1)); + ConfigurationNode node = config.node("discord-channel-id"); + Map objectMap = node.childrenMap(); + for (Object o : objectMap.keySet()) { + String key = (String) o; + if (key.equalsIgnoreCase("general")) + continue; + ConfigurationNode configurationNode = objectMap.get(o); + long channelId = configurationNode.getLong(); + serverChannelId.put(key.toLowerCase(), channelId); + } + REPORT_SENT = getString("messages.report-sent", REPORT_SENT); + } + + public static String HELP_REPORT = "/report "; + private static void loadMessages() { + HELP_REPORT = getString("settings.mail.mail-sent", HELP_REPORT); + } } diff --git a/api/src/main/java/com/alttd/chat/managers/RegexManager.java b/api/src/main/java/com/alttd/chat/managers/RegexManager.java index 7939560..61dac32 100755 --- a/api/src/main/java/com/alttd/chat/managers/RegexManager.java +++ b/api/src/main/java/com/alttd/chat/managers/RegexManager.java @@ -3,15 +3,14 @@ package com.alttd.chat.managers; import com.alttd.chat.ChatAPI; import com.alttd.chat.config.RegexConfig; import com.alttd.chat.objects.ChatFilter; +import com.alttd.chat.objects.ModifiableString; import com.alttd.chat.util.ALogger; -import net.luckperms.api.LuckPerms; import net.luckperms.api.cacheddata.CachedPermissionData; import net.luckperms.api.model.user.User; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexManager { @@ -29,15 +28,15 @@ public class RegexManager { chatFilters.add(filter); } - public static String replaceText(String playerName, UUID uuid, String text) { // TODO loop all objects in the list and check if they violate based on the MATCHER - return replaceText(playerName, uuid, text, true); + public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, String channel) { // TODO loop all objects in the list and check if they violate based on the MATCHER + return filterText(playerName, uuid, modifiableString, true, channel); } - public static String replaceText(String playerName, UUID uuid, String text, boolean matcher) { + public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, boolean matcher, String channel) { User user = ChatAPI.get().getLuckPerms().getUserManager().getUser(uuid); if (user == null) { ALogger.warn("Tried to check chat filters for a user who doesn't exist in LuckPerms"); - return null; + return false; } CachedPermissionData permissionData = user.getCachedData().getPermissionData(); for(ChatFilter chatFilter : chatFilters) { @@ -45,22 +44,24 @@ public class RegexManager { case CHAT: break; case REPLACE: - text = chatFilter.replaceText(text); + chatFilter.replaceText(modifiableString); break; case BLOCK: - if(chatFilter.matches(text) && !permissionData.checkPermission("chat.bypass-filter." + chatFilter.getName()).asBoolean()) { // todo find a better way to do this? + if(!permissionData.checkPermission("chat.bypass-filter-channel." + channel).asBoolean() && + !permissionData.checkPermission("chat.bypass-filter." + chatFilter.getName()).asBoolean() && + chatFilter.matches(modifiableString)) { // todo find a better way to do this? ALogger.info(playerName + " triggered the chat filter for " + chatFilter.getName() + "."); - return null; + return false; } break; case REPLACEMATCHER: if(matcher) { - text = chatFilter.replaceMatcher(text); + chatFilter.replaceMatcher(modifiableString); } break; } } - return text; + return true; } } diff --git a/api/src/main/java/com/alttd/chat/objects/ChatFilter.java b/api/src/main/java/com/alttd/chat/objects/ChatFilter.java index 352ff79..33f5953 100755 --- a/api/src/main/java/com/alttd/chat/objects/ChatFilter.java +++ b/api/src/main/java/com/alttd/chat/objects/ChatFilter.java @@ -42,34 +42,57 @@ public class ChatFilter { return this.exclusions; } - public boolean matches(String input) { + public boolean matches(ModifiableString filterableString) { + String input = filterableString.string(); Matcher matcher = pattern.matcher(input); - return (matcher.find() || matcher.matches()); + while (matcher.find()) + if (!isException(input, matcher.start())) { + filterableString.string(filterableString.string().replaceFirst(matcher.group(), "" + matcher.group() + "")); + return true; + } + return matcher.matches(); } - public String replaceText(String input) { + public boolean isException(String string, int start) + { + char[] chars = string.toCharArray(); + if (start != 0) { //go to start of word if not at start of string + while (chars[start] != ' ' && start > 0) + start--; + start += 1; //go past the space + } + + String match = string.substring(start); + for (String s : getExclusions()) { + if (match.toLowerCase().startsWith(s.toLowerCase())) + return true; + } + return false; + } + + public void replaceText(ModifiableString modifiableString) { + String input = modifiableString.string(); Matcher matcher = pattern.matcher(input); while (matcher.find()) { String group = matcher.group(); // todo debug - if(getExclusions().stream().noneMatch(s -> s.equalsIgnoreCase(group))) { // idk how heavy this is:/ - input = input.replace(group, getReplacement()); + if (getExclusions().stream().noneMatch(s -> s.equalsIgnoreCase(group))) { // idk how heavy this is:/ + modifiableString.string(input.replace(group, getReplacement())); } } - return input; } - public String replaceMatcher(String input) { - int lenght; + public void replaceMatcher(ModifiableString modifiableString) { + String input = modifiableString.string(); + int length; try { - lenght = Integer.parseInt(replacement); + length = Integer.parseInt(replacement); } catch (NumberFormatException e) { - lenght = 3; // could load this from config and make it cleaner + length = 3; // could load this from config and make it cleaner } Matcher matcher = pattern.matcher(input); while (matcher.find()) { String group = matcher.group(); - input = input.replace(group, group.substring(0, lenght)); + modifiableString.string(input.replace(group, group.substring(0, length))); } - return input; } } diff --git a/api/src/main/java/com/alttd/chat/objects/ModifiableString.java b/api/src/main/java/com/alttd/chat/objects/ModifiableString.java new file mode 100644 index 0000000..6324148 --- /dev/null +++ b/api/src/main/java/com/alttd/chat/objects/ModifiableString.java @@ -0,0 +1,17 @@ +package com.alttd.chat.objects; + +public class ModifiableString { + private String string; + + public ModifiableString(String string) { + this.string = string; + } + + public void string(String string) { + this.string = string; + } + + public String string() { + return string; + } +} diff --git a/build.gradle.kts b/build.gradle.kts index e05b27e..6c465bb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,18 +8,18 @@ allprojects { version = "1.0.0-SNAPSHOT" description = "All in one minecraft chat plugin" - repositories { - mavenCentral() - maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy - maven("https://oss.sonatype.org/content/groups/public/") // Adventure - maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage - maven("https://oss.sonatype.org/content/repositories/") // Minimessage - maven("https://nexus.velocitypowered.com/repository/") // Velocity - maven("https://nexus.velocitypowered.com/repository/maven-public/") // Velocity - maven("https://repo.spongepowered.org/maven") // Configurate - maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi - maven("https://jitpack.io") - } +// repositories { +// mavenCentral() +// maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy +// maven("https://oss.sonatype.org/content/groups/public/") // Adventure +// maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage +// maven("https://oss.sonatype.org/content/repositories/") // Minimessage +// maven("https://nexus.velocitypowered.com/repository/") // Velocity +// maven("https://nexus.velocitypowered.com/repository/maven-public/") // Velocity +// maven("https://repo.spongepowered.org/maven") // Configurate +// maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi +// maven("https://jitpack.io") +// } } subprojects { diff --git a/galaxy/build.gradle.kts b/galaxy/build.gradle.kts index f2cd3d6..4bb1ff6 100644 --- a/galaxy/build.gradle.kts +++ b/galaxy/build.gradle.kts @@ -5,10 +5,7 @@ plugins { dependencies { implementation(project(":api")) // API - compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT") { // Galaxy - exclude("net.kyori.adventure.text.minimessage") - } - compileOnly("net.kyori:adventure-text-minimessage:4.10.0-SNAPSHOT") // Minimessage + compileOnly("com.alttd:Galaxy-API:1.18.2-R0.1-SNAPSHOT") // Galaxy compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") // move to proxy } diff --git a/galaxy/src/main/java/com/alttd/chat/commands/ChatClear.java b/galaxy/src/main/java/com/alttd/chat/commands/ChatClear.java index e07c113..ab5d90e 100644 --- a/galaxy/src/main/java/com/alttd/chat/commands/ChatClear.java +++ b/galaxy/src/main/java/com/alttd/chat/commands/ChatClear.java @@ -24,6 +24,7 @@ public class ChatClear implements CommandExecutor { for (Player player : Bukkit.getOnlinePlayers()) if (!player.hasPermission("chat.clear-bypass")) player.sendMessage(component); + Bukkit.getServer().sendMessage(miniMessage.deserialize( " cleared chat.", Placeholder.component("player",sender.name())) diff --git a/galaxy/src/main/java/com/alttd/chat/handler/ChatHandler.java b/galaxy/src/main/java/com/alttd/chat/handler/ChatHandler.java index 4073cae..b14998e 100755 --- a/galaxy/src/main/java/com/alttd/chat/handler/ChatHandler.java +++ b/galaxy/src/main/java/com/alttd/chat/handler/ChatHandler.java @@ -5,6 +5,7 @@ import com.alttd.chat.config.Config; import com.alttd.chat.managers.ChatUserManager; import com.alttd.chat.managers.RegexManager; import com.alttd.chat.objects.ChatUser; +import com.alttd.chat.objects.ModifiableString; import com.alttd.chat.objects.channels.CustomChannel; import com.alttd.chat.util.GalaxyUtility; import com.alttd.chat.util.Utility; @@ -37,11 +38,16 @@ public class ChatHandler { public void privateMessage(Player player, String target, String message) { // ChatUser user = ChatUserManager.getChatUser(player.getUniqueId()); // user.setReplyTarget(target); - String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message); // todo a better way for this - if(updatedMessage == null) { - GalaxyUtility.sendBlockedNotification("DM Language", player, message, target); + ModifiableString modifiableString = new ModifiableString(message); + // todo a better way for this + if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "privatemessage")) { + GalaxyUtility.sendBlockedNotification("DM Language", + player, + Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())), + target); return; // the message was blocked } + String updatedMessage = modifiableString.string(); if(!player.hasPermission("chat.format")) { updatedMessage = Utility.stripTokens(updatedMessage); @@ -92,12 +98,17 @@ public class ChatHandler { Component senderName = user.getDisplayName(); Component prefix = user.getPrefix(); - String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message); // todo a better way for this - if(updatedMessage == null) { - GalaxyUtility.sendBlockedNotification("GC Language", player, message, ""); + ModifiableString modifiableString = new ModifiableString(message); + // todo a better way for this + if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "globalchat")) { + GalaxyUtility.sendBlockedNotification("GC Language", + player, + Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())), + ""); return; // the message was blocked } + String updatedMessage = modifiableString.string(); if(!player.hasPermission("chat.format")) { updatedMessage = Utility.stripTokens(updatedMessage); } else { @@ -132,12 +143,16 @@ public class ChatHandler { ChatUser user = ChatUserManager.getChatUser(player.getUniqueId()); Component senderName = user.getDisplayName(); - String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message); - if(updatedMessage == null) { - GalaxyUtility.sendBlockedNotification(channel.getChannelName() + " Language", player, message, ""); + ModifiableString modifiableString = new ModifiableString(message); + if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, channel.getChannelName())) { + GalaxyUtility.sendBlockedNotification(channel.getChannelName() + " Language", + player, + Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())), + ""); return; // the message was blocked } + String updatedMessage = modifiableString.string(); if(!player.hasPermission("chat.format")) { updatedMessage = Utility.stripTokens(updatedMessage); } @@ -192,7 +207,7 @@ public class ChatHandler { // // updatedMessage = Utility.formatText(updatedMessage); // -// List