Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94484593f1 | ||
|
|
de04c6b80a |
@@ -8,9 +8,6 @@ dependencies {
|
||||
}
|
||||
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
|
||||
compileOnly("net.luckperms:api:5.3") // Luckperms
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
|
||||
testImplementation("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
publishing {
|
||||
@@ -28,7 +25,3 @@ publishing {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
@@ -543,9 +543,4 @@ public final class Config {
|
||||
NICK_ALLOWED_COLOR_CODESLIST = getList("nicknames.allowed-color-codes", List.of("&0", "&1", "&2", "&3", "&4", "&5", "&6", "&7", "&8", "&9", "&a", "&b", "&c", "&d", "&e", "&f", "&r"));
|
||||
NICK_CURRENT = getString("nicknames.messages.nick-current", NICK_CURRENT);
|
||||
}
|
||||
|
||||
public static String APRIL_FOOLS_RESET = "esrever";
|
||||
private static void aprilFools() {
|
||||
APRIL_FOOLS_RESET = getString("april-fools.reset", APRIL_FOOLS_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,18 +178,13 @@ public final class RegexConfig {
|
||||
String regex = entry.getValue().node("regex").getString();
|
||||
String replacement = entry.getValue().node("replacement").getString();
|
||||
List<String> exclusions = entry.getValue().node("exclusions").getList(io.leangen.geantyref.TypeToken.get(String.class), new ArrayList<>());
|
||||
boolean disableInPrivate = false;
|
||||
ConfigurationNode node = entry.getValue().node("disable-in-private");
|
||||
if (node != null) {
|
||||
disableInPrivate = node.getBoolean();
|
||||
}
|
||||
if (type == null || type.isEmpty() || regex == null || regex.isEmpty()) {
|
||||
ALogger.warn("Filter: " + name + " was set up incorrectly");
|
||||
} else {
|
||||
if (replacement == null || replacement.isEmpty()) {
|
||||
replacement = name;
|
||||
}
|
||||
ChatFilter chatFilter = new ChatFilter(name, type, regex, replacement, exclusions, disableInPrivate);
|
||||
ChatFilter chatFilter = new ChatFilter(name, type, regex, replacement, exclusions);
|
||||
RegexManager.addFilter(chatFilter);
|
||||
}
|
||||
} catch(SerializationException ex) {
|
||||
|
||||
@@ -8,13 +8,10 @@ import com.alttd.chat.objects.ModifiableString;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import net.luckperms.api.cacheddata.CachedPermissionData;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RegexManager {
|
||||
@@ -46,24 +43,17 @@ public class RegexManager {
|
||||
}
|
||||
|
||||
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, null);
|
||||
return filterText(playerName, uuid, modifiableString, true, channel);
|
||||
}
|
||||
|
||||
public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, boolean matcher, String channel) {
|
||||
return filterText(playerName, uuid, modifiableString, matcher, channel, null);
|
||||
}
|
||||
|
||||
public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, boolean matcher, String channel, Consumer<FilterType> filterAction) {
|
||||
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 false;
|
||||
}
|
||||
CachedPermissionData permissionData = user.getCachedData().getPermissionData();
|
||||
boolean isPrivate = channel.equals("party");
|
||||
for(ChatFilter chatFilter : chatFilters) {
|
||||
if (isPrivate && chatFilter.isDisabledInPrivate())
|
||||
continue;
|
||||
switch (chatFilter.getType()) {
|
||||
case CHAT:
|
||||
break;
|
||||
@@ -84,25 +74,6 @@ public class RegexManager {
|
||||
chatFilter.replaceMatcher(modifiableString);
|
||||
}
|
||||
break;
|
||||
case PUNISH:
|
||||
if (permissionData.checkPermission("chat.bypass-punish").asBoolean())
|
||||
break;
|
||||
if (chatFilter.matches(modifiableString)) {
|
||||
ALogger.info(playerName + " triggered the punish filter for " + chatFilter.getName()
|
||||
+ " with: " + modifiableString.string() + ".");
|
||||
|
||||
if (filterAction == null){
|
||||
ALogger.info("No filterAction was provided, not doing anything");
|
||||
return false;
|
||||
}
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) {
|
||||
ALogger.warn("Tried to punish a player who triggered the filter, but the player is offline.");
|
||||
return false;
|
||||
}
|
||||
filterAction.accept(FilterType.PUNISH);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -17,16 +17,14 @@ public class ChatFilter {
|
||||
private final Pattern pattern;
|
||||
private final String replacement;
|
||||
private final List<String> exclusions;
|
||||
private final boolean disableInPrivate;
|
||||
|
||||
public ChatFilter(String name, String type, String regex, String replacement, List<String> exclusions, boolean disableInPrivate) {
|
||||
public ChatFilter(String name, String type, String regex, String replacement, List<String> exclusions) {
|
||||
this.name = name;
|
||||
this.filterType = FilterType.getType(type);
|
||||
this.regex = regex;
|
||||
this.pattern = Pattern.compile(getRegex(), Pattern.CASE_INSENSITIVE);
|
||||
this.replacement = replacement;
|
||||
this.exclusions = exclusions;
|
||||
this.disableInPrivate = disableInPrivate;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -49,10 +47,6 @@ public class ChatFilter {
|
||||
return this.exclusions;
|
||||
}
|
||||
|
||||
public boolean isDisabledInPrivate() {
|
||||
return disableInPrivate;
|
||||
}
|
||||
|
||||
public boolean matches(ModifiableString filterableString) {
|
||||
String input = filterableString.string();
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
|
||||
@@ -5,8 +5,7 @@ public enum FilterType {
|
||||
EMOTE("emote"),
|
||||
CHAT("chat"),
|
||||
REPLACEMATCHER("replacematcher"),
|
||||
BLOCK("block"),
|
||||
PUNISH("punish");
|
||||
BLOCK("block");
|
||||
|
||||
private final String name;
|
||||
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package com.alttd.chat.objects;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.intellij.lang.annotations.RegExp;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.RegEx;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ModifiableString {
|
||||
private Component text;
|
||||
@@ -32,37 +30,4 @@ public class ModifiableString {
|
||||
public Component component() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void reverse() {
|
||||
text = reverseComponent(text);
|
||||
}
|
||||
|
||||
public Component reverseComponent(Component component) {
|
||||
if (!(component instanceof TextComponent textComponent)) {
|
||||
return Component.text("")
|
||||
.append(Component.join(JoinConfiguration.noSeparators(), reverseChildren(component.children())));
|
||||
}
|
||||
|
||||
String content = textComponent.content();
|
||||
String reversedContent = new StringBuilder(content).reverse().toString();
|
||||
|
||||
List<Component> reversedChildren = reverseChildren(component.children());
|
||||
|
||||
return Component.text("")
|
||||
.append(Component.join(JoinConfiguration.noSeparators(), reversedChildren)
|
||||
.append(Component.text(reversedContent, component.style())));
|
||||
}
|
||||
|
||||
public List<Component> reverseChildren(List<Component> children) {
|
||||
return children.stream()
|
||||
.map(this::reverseComponent)
|
||||
.collect(Collectors.collectingAndThen(Collectors.toList(), list -> {
|
||||
Collections.reverse(list);
|
||||
return list;
|
||||
}));
|
||||
}
|
||||
|
||||
public void removeStringAtStart(String s) {
|
||||
text = text.replaceText(TextReplacementConfig.builder().match("^" + s).replacement("").build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.objects.ModifiableString;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
public class ReverseTest {
|
||||
|
||||
@Test
|
||||
public void testReverseString() {
|
||||
String input = "Hello how are you doing today?";
|
||||
String expectedOutput = new StringBuilder(input).reverse().toString();
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
ModifiableString modifiableString = new ModifiableString(miniMessage.deserialize(input));
|
||||
modifiableString.reverse();
|
||||
assertEquals(expectedOutput, modifiableString.string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveKeyword() {
|
||||
String input = "Hello how are you doing today?";
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(miniMessage.deserialize(Config.APRIL_FOOLS_RESET + " " + input));
|
||||
modifiableString.removeStringAtStart(Config.APRIL_FOOLS_RESET + " ");
|
||||
|
||||
assertEquals(input, modifiableString.string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveKeywordWithTags() {
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
String input = "<blue>" + Config.APRIL_FOOLS_RESET + " <red>Hello how are</red> you <blue>doing today</blue>?</blue>";
|
||||
String expectedOutput = "Hello how are you doing today?";
|
||||
Component deserialize = miniMessage.deserialize(input);
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(deserialize);
|
||||
modifiableString.removeStringAtStart(Config.APRIL_FOOLS_RESET + " ");
|
||||
|
||||
assertEquals(expectedOutput, modifiableString.string());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReverseStringWithTags() {
|
||||
String input = "<red>Hello how are</red> you <blue>doing today</blue>?";
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
Component deserialize = miniMessage.deserialize(input);
|
||||
ModifiableString modifiableString = new ModifiableString(deserialize);
|
||||
String expectedOutput = new StringBuilder(PlainTextComponentSerializer.plainText().serialize(deserialize)).reverse().toString();
|
||||
modifiableString.reverse();
|
||||
assertEquals(expectedOutput, modifiableString.string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void complexTestReverseStringWithTags() {
|
||||
String input = "<green><red>Hello <b>how</b> are</red> you <blue>doing today</blue><gold>?</gold></green>";
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
Component deserialize = miniMessage.deserialize(input);
|
||||
ModifiableString modifiableString = new ModifiableString(deserialize);
|
||||
String expectedOutput = new StringBuilder(PlainTextComponentSerializer.plainText().serialize(deserialize)).reverse().toString();
|
||||
modifiableString.reverse();
|
||||
assertEquals(expectedOutput, modifiableString.string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extraComplexTestReverseStringWithTags() {
|
||||
String input = "<gold>This <red>is</red> longer<green> <name> <red>Hello <b>how</b> are</red> you <test> <blue>doing <name> today</blue><gold>?</gold></green></gold>";
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
Component deserialize = miniMessage.deserialize(input, TagResolver.resolver(
|
||||
Placeholder.component("name", miniMessage.deserialize("<red>Cool<blue><rainbow>_player_</rainbow>name</red>")),
|
||||
Placeholder.parsed("test", "test replacement")
|
||||
));
|
||||
ModifiableString modifiableString = new ModifiableString(deserialize);
|
||||
String expectedOutput = new StringBuilder(PlainTextComponentSerializer.plainText().serialize(deserialize)).reverse().toString();
|
||||
modifiableString.reverse();
|
||||
System.out.println(expectedOutput);
|
||||
assertEquals(expectedOutput, modifiableString.string());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import com.alttd.chat.nicknames.Nicknames;
|
||||
import com.alttd.chat.nicknames.NicknamesEvents;
|
||||
import com.alttd.chat.objects.channels.Channel;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import com.alttd.chat.requests.RequestHandler;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -29,6 +30,7 @@ public class ChatPlugin extends JavaPlugin {
|
||||
|
||||
private ChatAPI chatAPI;
|
||||
private ChatHandler chatHandler;
|
||||
private RequestHandler requestHandler;
|
||||
|
||||
private String messageChannel;
|
||||
private ServerConfig serverConfig;
|
||||
@@ -40,6 +42,8 @@ public class ChatPlugin extends JavaPlugin {
|
||||
chatAPI = new ChatImplementation();
|
||||
chatHandler = new ChatHandler();
|
||||
DatabaseConnection.initialize();
|
||||
requestHandler = new RequestHandler();
|
||||
requestHandler.loadRequests();
|
||||
serverConfig = new ServerConfig(Bukkit.getServerName());
|
||||
registerListener(new PlayerListener(serverConfig), new ChatListener(), new BookListener());
|
||||
if(serverConfig.GLOBALCHAT) {
|
||||
@@ -105,6 +109,10 @@ public class ChatPlugin extends JavaPlugin {
|
||||
return chatHandler;
|
||||
}
|
||||
|
||||
public RequestHandler getRequestHandler() {
|
||||
return requestHandler;
|
||||
}
|
||||
|
||||
public boolean serverGlobalChatEnabled() {
|
||||
return serverConfig.GLOBALCHAT;
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@ import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.handler.ChatHandler;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.*;
|
||||
import com.alttd.chat.objects.ChatFilter;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.ModifiableString;
|
||||
import com.alttd.chat.objects.Toggleable;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.GalaxyUtility;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
@@ -29,7 +30,6 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -87,18 +87,7 @@ public class ChatListener implements Listener {
|
||||
ModifiableString modifiableString = new ModifiableString(input);
|
||||
|
||||
// todo a better way for this
|
||||
if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, true, "chat", filterType -> {
|
||||
if (!filterType.equals(FilterType.PUNISH)) {
|
||||
ALogger.warn("Received another FilterType than punish when filtering chat and executing a filter action");
|
||||
return;
|
||||
}
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("punish");
|
||||
out.writeUTF(player.getName());
|
||||
out.writeUTF(player.getUniqueId().toString());
|
||||
out.writeUTF(modifiableString.string());
|
||||
player.sendPluginMessage(ChatPlugin.getInstance(), Config.MESSAGECHANNEL, out.toByteArray());
|
||||
})) {
|
||||
if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "chat")) {
|
||||
event.setCancelled(true);
|
||||
GalaxyUtility.sendBlockedNotification("Language", player,
|
||||
modifiableString.component(),
|
||||
@@ -108,14 +97,7 @@ public class ChatListener implements Listener {
|
||||
|
||||
Set<Player> playersToPing = new HashSet<>();
|
||||
pingPlayers(playersToPing, modifiableString, player);
|
||||
LocalDate now = LocalDate.now();
|
||||
if (now.getMonth().equals(Month.APRIL) && now.getDayOfMonth() == 1) {
|
||||
if (modifiableString.string().startsWith(Config.APRIL_FOOLS_RESET + " ")) {
|
||||
modifiableString.removeStringAtStart(Config.APRIL_FOOLS_RESET + " ");
|
||||
} else {
|
||||
modifiableString.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
input = render(player, modifiableString.component());
|
||||
for (Player receiver : receivers) {
|
||||
receiver.sendMessage(input);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.alttd.chat.requests;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NickNameRequest extends Request {
|
||||
|
||||
public NickNameRequest(UUID requester, String request) {
|
||||
super(requester, request);
|
||||
|
||||
this.requestType = RequestType.NICKNAME;
|
||||
}
|
||||
|
||||
public NickNameRequest(UUID requester, String request, boolean completed, UUID completedBy, long dateRequested, long dateCompleted) {
|
||||
super(requester, request, completed, completedBy, dateRequested, dateCompleted);
|
||||
|
||||
this.requestType = RequestType.NICKNAME;
|
||||
}
|
||||
@Override
|
||||
public boolean processRequest(UUID processor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.alttd.chat.requests;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PrefixRequest extends Request{
|
||||
|
||||
public PrefixRequest(UUID requester, String request) {
|
||||
super(requester, request);
|
||||
|
||||
this.requestType = RequestType.PREFIX;
|
||||
}
|
||||
|
||||
public PrefixRequest(UUID requester, String request, boolean completed, UUID completedBy, long dateRequested, long dateCompleted) {
|
||||
super(requester, request, completed, completedBy, dateRequested, dateCompleted);
|
||||
|
||||
this.requestType = RequestType.NICKNAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processRequest(UUID processor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.alttd.chat.requests;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class Request {
|
||||
|
||||
protected UUID requester;
|
||||
protected RequestType requestType;
|
||||
protected String serverName;
|
||||
protected String request;
|
||||
protected boolean completed;
|
||||
protected UUID completedBy;
|
||||
protected long dateRequested;
|
||||
protected long dateCompleted;
|
||||
|
||||
Request(UUID requester, String request) {
|
||||
this.requester = requester;
|
||||
this.request = request;
|
||||
this.serverName = Bukkit.getServerName();
|
||||
this.dateRequested = new Date().getTime();
|
||||
saveRequest();
|
||||
}
|
||||
|
||||
Request(UUID requester, String request, boolean completed, UUID completedBy, long dateRequested, long dateCompleted) {
|
||||
this.requester = requester;
|
||||
this.request = request;
|
||||
this.completed = completed;
|
||||
this.completedBy = completedBy;
|
||||
this.dateRequested = dateRequested;
|
||||
this.dateCompleted = dateCompleted;
|
||||
}
|
||||
|
||||
public static Request of(UUID requester, RequestType requestType, String request) {
|
||||
return switch (requestType) {
|
||||
case PREFIX -> new PrefixRequest(requester, request);
|
||||
case NICKNAME -> new NickNameRequest(requester, request);
|
||||
};
|
||||
}
|
||||
|
||||
public static Request load(UUID requester, RequestType requestType, String request, boolean completed, UUID completedBy, long dateRequested, long dateCompleted) {
|
||||
return switch (requestType) {
|
||||
case PREFIX -> new PrefixRequest(requester, request, completed, completedBy, dateRequested, dateCompleted);
|
||||
case NICKNAME -> new NickNameRequest(requester, request, completed, completedBy, dateRequested, dateCompleted);
|
||||
};
|
||||
}
|
||||
|
||||
public boolean processRequest(UUID completedBy) {
|
||||
completeRequest(completedBy);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isCompleted() {
|
||||
return completed;
|
||||
}
|
||||
|
||||
void completeRequest(UUID completedBy) {
|
||||
this.completed = true;
|
||||
this.completedBy = completedBy;
|
||||
this.dateCompleted = new Date().getTime();
|
||||
saveRequest();
|
||||
}
|
||||
|
||||
public void saveRequest() {
|
||||
// upsert into database
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.alttd.chat.requests;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.DatabaseConnection;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RequestHandler {
|
||||
|
||||
private final List<Request> requests;
|
||||
|
||||
public RequestHandler() {
|
||||
requests = new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean addRequest(Request request) {
|
||||
return requests.add(request);
|
||||
}
|
||||
|
||||
public boolean removeRequest(Request request) {
|
||||
return requests.remove(request);
|
||||
}
|
||||
|
||||
public List<Request> getRequests() {
|
||||
return requests;
|
||||
}
|
||||
|
||||
public void loadRequests() {
|
||||
long time = new Date().getTime() - Config.NICK_WAIT_TIME;
|
||||
// Load all requests that have not been completed yet
|
||||
String query = "SELECT * FROM requests WHERE completed=false and (datechanged = 0 or datechanged > " + time + ")";
|
||||
|
||||
try {
|
||||
Connection connection = DatabaseConnection.getConnection();
|
||||
ResultSet resultSet = connection.prepareStatement(query).executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
UUID requester = UUID.fromString(resultSet.getString("requester"));
|
||||
RequestType requestType = RequestType.valueOf(resultSet.getString("requesttype"));
|
||||
String requestString = resultSet.getString("request");
|
||||
boolean completed = resultSet.getBoolean("completed");
|
||||
UUID completedby = UUID.fromString(resultSet.getString("completedby"));
|
||||
long dateRequested = resultSet.getLong("daterequested");
|
||||
long dateCompleted = resultSet.getLong("datecompleted");
|
||||
|
||||
Request request = Request.load(requester, requestType, requestString, completed, completedby, dateRequested, dateCompleted);
|
||||
addRequest(request);
|
||||
}
|
||||
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.alttd.chat.requests;
|
||||
|
||||
public enum RequestType {
|
||||
|
||||
NICKNAME,
|
||||
PREFIX
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.alttd.chat.requests;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RequestsGui implements InventoryHolder {
|
||||
|
||||
private final Inventory inventory;
|
||||
private final int inventorySize = 54;
|
||||
|
||||
RequestsGui() {
|
||||
inventory = Bukkit.createInventory(this, inventorySize, "A title");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,14 +4,11 @@ import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.proxydiscordlink.DiscordLink;
|
||||
import com.alttd.proxydiscordlink.lib.net.dv8tion.jda.api.EmbedBuilder;
|
||||
import com.alttd.velocitychat.VelocityChat;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
@@ -19,10 +16,8 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PluginMessageListener {
|
||||
@@ -98,20 +93,6 @@ public class PluginMessageListener {
|
||||
proxy.getAllServers().forEach(registeredServer ->
|
||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData()));
|
||||
}
|
||||
case "punish" -> {
|
||||
String playerName = in.readUTF();
|
||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||
ConsoleCommandSource consoleCommandSource = proxy.getConsoleCommandSource();
|
||||
proxy.getCommandManager().executeAsync(consoleCommandSource, String.format("ban %s Automatic ban, please appeal if you feel review is needed.", playerName));
|
||||
ALogger.info(String.format("Auto banned %s due to violating the `punish` filter.", playerName));
|
||||
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setTitle("Automatic ban through the chat filter");
|
||||
embedBuilder.setAuthor(playerName, null, "https://crafatar.com/avatars/" + in.readUTF() + "?overlay");
|
||||
embedBuilder.setDescription(String.format("`%s`\n\n Auto permanent ban\n\n Auto banned for violating the `punish` chat filter. This could be a false positive! Their message was\n||%s||", playerName, in.readUTF()));
|
||||
embedBuilder.setColor(Color.RED);
|
||||
DiscordLink.getPlugin().getBot().sendEmbedToDiscord(514922317923614728L, embedBuilder, -1);
|
||||
}
|
||||
default -> {
|
||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||
|
||||
Reference in New Issue
Block a user