Merge branch 4.9

This commit is contained in:
destro174
2022-03-14 16:48:35 +01:00
21 changed files with 258 additions and 177 deletions
+1 -4
View File
@@ -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
}
@@ -185,6 +185,7 @@ public final class Config {
public static String MESSAGESENDER = "<hover:show_text:Click to reply><click:suggest_command:/msg <receivername> ><light_purple>(Me -> <gray><receiver></gray>)</hover> <message>";
public static String MESSAGERECIEVER = "<hover:show_text:Click to reply><click:suggest_command:/msg <sendername> ><light_purple>(<gray><sender></gray> on <server> -> Me)</hover> <message>";
public static String MESSAGESPY = "<gray>(<gray><sendername></gray> -> <receivername>) <message>";
public static String RECEIVER_DOES_NOT_EXIST = "<red><player> is not a valid player.</red>";
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 = "<white><light_purple><prefix></light_purple> <gray><sender></gray> <hover:show_text:on <server>><yellow>to Global</yellow></hover><gray>: <message>";
@@ -271,6 +273,7 @@ public final class Config {
public static String REMOVED_USER_FROM_PARTY = "<green>You removed <player> from the chat party!</green>";
public static String NOT_A_PARTY_MEMBER = "<red><player> is not a member of your party!</red>";
public static String ALREADY_IN_PARTY = "<red>You're already in a party!</red>";
public static String ALREADY_IN_THIS_PARTY = "<red>You're already in <party>!</red>";
public static String SENT_PARTY_INV = "<green>You send a chat party invite to <player>!</green>";
public static String JOIN_PARTY_CLICK_MESSAGE = "<click:run_command:'/party join <party> <party_password>'>" +
"<dark_aqua>You received an invite to join <party>, click this message to accept.</dark_aqua></click>";
@@ -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 = "<gold>ChatParty help:\n<commands></gold>";
@@ -410,4 +414,26 @@ public final class Config {
mailSent = getString("settings.mail.mail-sent", mailSent);
}
public static HashMap<String, Long> serverChannelId = new HashMap<>();
public static String REPORT_SENT = "<green>Your report was sent, staff will contact you asap to help resolve your issue!</green>";
private static void loadChannelIds() {
serverChannelId.clear();
serverChannelId.put("general", getLong("discord-channel-id.general", (long) -1));
ConfigurationNode node = config.node("discord-channel-id");
Map<Object, ? extends ConfigurationNode> 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 = "<red>/report <message></red>";
private static void loadMessages() {
HELP_REPORT = getString("settings.mail.mail-sent", HELP_REPORT);
}
}
@@ -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;
}
}
@@ -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(), "<gold>" + matcher.group() + "</gold>"));
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;
}
}
@@ -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;
}
}