7 Commits
Author SHA1 Message Date
auto 9e437079e4 Remove Galaxy dependency
Switched back to paper since we don't use any features from Galaxy that aren't already in paper
2025-03-21 20:34:45 +01:00
auto 45eceaf4a6 Merge branch 'main' into ignore_fix 2025-01-02 00:37:11 +01:00
auto c5eebb7e88 Merge remote-tracking branch 'origin/main' 2025-01-02 00:36:11 +01:00
auto 5e34e6e7fa Don't ignore users with bypass permission
Refactored chat logic to respect 'chat.ignorebypass' permission for both senders and receivers. This only applies to cases where a user is sending text to another user, checks for login/out messages were not fixed
2025-01-02 00:30:55 +01:00
auto c5c60d25b1 Cleanup 2025-01-02 00:22:03 +01:00
Len 804e619e8a Add workaround to display nickname when tagging a player in chat. 2024-10-06 19:29:31 +02:00
auto b3e545a0c8 Log custom messages sent in custom channels
Added a log statement to capture and log information whenever a message is sent in a custom channel. This includes the player's name, the channel name, and the message content for better monitoring and debugging.
2024-09-25 20:03:12 +02:00
13 changed files with 107 additions and 61 deletions
+4 -3
View File
@@ -3,9 +3,10 @@ plugins {
}
dependencies {
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") {
// compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") {
// exclude("net.kyori")
}
// }
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
compileOnly("net.luckperms:api:5.3") // Luckperms
}
@@ -24,4 +25,4 @@ publishing {
credentials(PasswordCredentials::class)
}
}
}
}
+3 -2
View File
@@ -5,7 +5,8 @@ plugins {
dependencies {
implementation(project(":api")) // API
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") // Galaxy
// compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") // Galaxy
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") // move to proxy
compileOnly("org.apache.commons:commons-lang3:3.12.0") // needs an alternative, already removed from upstream api and will be removed in server
compileOnly("net.luckperms:api:5.3") // Luckperms
@@ -21,4 +22,4 @@ tasks {
dependsOn(shadowJar)
}
}
}
@@ -38,7 +38,7 @@ public class ChatPlugin extends JavaPlugin {
chatAPI = new ChatImplementation();
chatHandler = new ChatHandler();
DatabaseConnection.initialize();
serverConfig = new ServerConfig(Bukkit.getServerName());
serverConfig = new ServerConfig(Bukkit.getServer().getName());
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true);
registerListener(new PlayerListener(serverConfig), new ChatListener(chatLogHandler), new BookListener(), new ShutdownListener(chatLogHandler, this));
if(serverConfig.GLOBALCHAT) {
@@ -119,7 +119,7 @@ public class ChatPlugin extends JavaPlugin {
public void ReloadConfig() {
chatAPI.ReloadConfig();
chatAPI.ReloadChatFilters();
serverConfig = new ServerConfig(Bukkit.getServerName());
serverConfig = new ServerConfig(Bukkit.getServer().getName());
Bukkit.broadcast(Utility.parseMiniMessage("Reloaded ChatPlugin Config."), "command.chat.reloadchat");
ALogger.info("Reloaded ChatPlugin config.");
}
@@ -38,7 +38,7 @@ public class ChatChannel extends BukkitCommand {
}
if(args.length == 0 && player.hasPermission(channel.getPermission())) {
player.sendMiniMessage(Config.CUSTOM_CHANNEL_TOGGLED, TagResolver.resolver(
player.sendRichMessage(Config.CUSTOM_CHANNEL_TOGGLED, TagResolver.resolver(
Placeholder.unparsed("channel", channel.getChannelName()),
Placeholder.component("status", toggleableForCustomChannel.toggle(player.getUniqueId())
? Config.TOGGLED_ON : Config.TOGGLED_OFF)));
@@ -27,7 +27,7 @@ public class PartyChat extends Toggleable implements CommandExecutor {
}
if(args.length == 0) {
player.sendMiniMessage(Config.PARTY_TOGGLED, Placeholder.component("status",
player.sendRichMessage(Config.PARTY_TOGGLED, Placeholder.component("status",
toggle(player.getUniqueId()) ? Config.TOGGLED_ON : Config.TOGGLED_OFF));
return true;
}
@@ -26,6 +26,7 @@ import org.bukkit.inventory.ItemStack;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
public class ChatHandler {
@@ -130,7 +131,7 @@ public class ChatHandler {
Placeholder.component("sender", senderName),
Placeholder.component("prefix", prefix),
Placeholder.component("message", parseMessageContent(player, message)),
Placeholder.parsed("server", Bukkit.getServerName())
Placeholder.parsed("server", Bukkit.getServer().getName())
);
Component component = Utility.parseMiniMessage(Config.GCFORMAT, placeholders);
@@ -164,7 +165,7 @@ public class ChatHandler {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("sender", senderName),
Placeholder.component("message", parseMessageContent(player, message)),
Placeholder.parsed("server", Bukkit.getServerName()),
Placeholder.parsed("server", Bukkit.getServer().getName()),
Placeholder.parsed("channel", channel.getChannelName())
);
Component component = Utility.parseMiniMessage(channel.getFormat(), placeholders);
@@ -237,12 +238,21 @@ public class ChatHandler {
}
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, Component component) {
if (!chatChannel.getServers().contains(Bukkit.getServerName())) return;
if (!chatChannel.getServers().contains(Bukkit.getServer().getName())) {
return;
}
Bukkit.getServer().getOnlinePlayers().stream()
.filter(p -> p.hasPermission(chatChannel.getPermission()))
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid))
.forEach(p -> p.sendMessage(component));
Player player = Bukkit.getPlayer(uuid);
if (player == null) {
return;
}
Stream<? extends Player> stream = Bukkit.getServer().getOnlinePlayers().stream()
.filter(p -> p.hasPermission(chatChannel.getPermission()));
if (!player.hasPermission("chat.ignorebypass")) {
stream = stream.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid) && !p.hasPermission("chat.ignorebypass"));
}
stream.forEach(p -> p.sendMessage(component));
}
private void sendPluginMessage(Player player, String channel, Component component) {
@@ -32,8 +32,10 @@ import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ChatListener implements Listener {
@@ -81,13 +83,14 @@ public class ChatListener implements Listener {
}
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
Component input = event.message().colorIfAbsent(NamedTextColor.WHITE);
ModifiableString modifiableString = new ModifiableString(input);
// todo a better way for this
if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, true, "chat", filterType -> {
if(!RegexManager.filterText(player.getName(), uuid, 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;
@@ -95,7 +98,7 @@ public class ChatListener implements Listener {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("punish");
out.writeUTF(player.getName());
out.writeUTF(player.getUniqueId().toString());
out.writeUTF(uuid.toString());
out.writeUTF(modifiableString.string());
player.sendPluginMessage(ChatPlugin.getInstance(), Config.MESSAGECHANNEL, out.toByteArray());
})) {
@@ -103,14 +106,18 @@ public class ChatListener implements Listener {
GalaxyUtility.sendBlockedNotification("Language", player,
modifiableString.component(),
"");
chatLogHandler.addChatLog(player.getUniqueId(), player.getServer().getServerName(), PlainTextComponentSerializer.plainText().serialize(input), true);
chatLogHandler.addChatLog(uuid, player.getServer().getName(), PlainTextComponentSerializer.plainText().serialize(input), true);
return; // the message was blocked
}
Set<Player> receivers = event.viewers().stream().filter(audience -> audience instanceof Player)
.map(audience -> (Player) audience)
.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId()))
.collect(Collectors.toSet());
Stream<Player> stream = event.viewers().stream().filter(audience -> audience instanceof Player)
.map(audience -> (Player) audience);
if (!player.hasPermission("chat.ignorebypass")) {
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
&& !receiver.hasPermission("chat.ignorebypass"));
}
Set<Player> receivers = stream.collect(Collectors.toSet());
Set<Player> playersToPing = new HashSet<>();
pingPlayers(playersToPing, modifiableString, player);
@@ -122,7 +129,7 @@ public class ChatListener implements Listener {
for (Player pingPlayer : playersToPing) {
pingPlayer.playSound(pingPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1);
}
chatLogHandler.addChatLog(player.getUniqueId(), player.getServer().getServerName(), modifiableString.string(), false);
chatLogHandler.addChatLog(uuid, player.getServer().getName(), modifiableString.string(), false);
ALogger.info(PlainTextComponentSerializer.plainText().serialize(input));
}
@@ -136,11 +143,12 @@ public class ChatListener implements Listener {
Pattern nickPattern = Pattern.compile("\\b(?<!\\\\)" + nickName + "\\b", Pattern.CASE_INSENSITIVE);
// Pattern escapedNickPattern = Pattern.compile("\\b\\\\" + nickName + "\\b", Pattern.CASE_INSENSITIVE);
ChatUser onlinePlayerUser = ChatUserManager.getChatUser(onlinePlayer.getUniqueId());
if (namePattern.matcher(modifiableString.string()).find()) {
modifiableString.replace(TextReplacementConfig.builder()
.once()
.match(namePattern)
.replacement(mention.append(onlinePlayer.displayName()))
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
.build());
//TODO replace all instances of \name with just name but using the match result so the capitalization doesn't change
// modifiableString.replace(TextReplacementConfig.builder()
@@ -150,15 +158,17 @@ public class ChatListener implements Listener {
// String substring = a.group().substring(1);
// return ;
// });
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId()))
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
&& !player.hasPermission("chat.ignorebypass"))
playersToPing.add(onlinePlayer);
} else if (nickPattern.matcher(modifiableString.string()).find()) {
modifiableString.replace(TextReplacementConfig.builder()
.once()
.match(nickPattern)
.replacement(mention.append(onlinePlayer.displayName()))
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
.build());
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId()))
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
&& !player.hasPermission("chat.ignorebypass"))
playersToPing.add(onlinePlayer);
}
}
@@ -209,4 +219,4 @@ public class ChatListener implements Listener {
}
}
}
@@ -15,20 +15,20 @@ import com.alttd.chat.util.Utility;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class PluginMessage implements PluginMessageListener {
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] bytes) {
public void onPluginMessageReceived(String channel, @NotNull Player ignored, byte[] bytes) {
if (!channel.equals(Config.MESSAGECHANNEL)) {
return;
}
@@ -38,35 +38,36 @@ public class PluginMessage implements PluginMessageListener {
case "privatemessagein": {
UUID uuid = UUID.fromString(in.readUTF());
String target = in.readUTF();
Player p = Bukkit.getPlayer(uuid);
Player player = Bukkit.getPlayer(uuid);
String message = in.readUTF();
UUID targetuuid = UUID.fromString(in.readUTF());
if (p != null) {
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
if (!chatUser.getIgnoredPlayers().contains(targetuuid)) {
p.sendMessage(GsonComponentSerializer.gson().deserialize(message));
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1); // todo load this from config
ChatUser user = ChatUserManager.getChatUser(uuid);
if (!user.getReplyContinueTarget().equalsIgnoreCase(target))
user.setReplyTarget(target);
}
if (player == null) {
break;
}
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
if (isTargetNotIgnored(chatUser, targetuuid)) {
player.sendMessage(GsonComponentSerializer.gson().deserialize(message));
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1); // todo load this from config
ChatUser user = ChatUserManager.getChatUser(uuid);
if (!user.getReplyContinueTarget().equalsIgnoreCase(target))
user.setReplyTarget(target);
}
break;
}
case "privatemessageout": {
UUID uuid = UUID.fromString(in.readUTF());
String target = in.readUTF();
Player p = Bukkit.getPlayer(uuid);
Player player = Bukkit.getPlayer(uuid);
String message = in.readUTF();
UUID targetuuid = UUID.fromString(in.readUTF());
if (p != null) {
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
if (!chatUser.getIgnoredPlayers().contains(targetuuid)) {
chatUser.setReplyTarget(target);
p.sendMessage(GsonComponentSerializer.gson().deserialize(message));
if (player == null) {
break;
}
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
if (isTargetNotIgnored(chatUser, targetuuid)) {
chatUser.setReplyTarget(target);
player.sendMessage(GsonComponentSerializer.gson().deserialize(message));
// ChatUser user = ChatUserManager.getChatUser(uuid);
// user.setReplyTarget(target);
}
}
break;
}
@@ -78,7 +79,7 @@ public class PluginMessage implements PluginMessageListener {
Bukkit.getOnlinePlayers().stream().filter(p -> p.hasPermission(Config.GCPERMISSION)).forEach(p -> {
ChatUser chatUser = ChatUserManager.getChatUser(p.getUniqueId());
if (!chatUser.getIgnoredPlayers().contains(uuid)) {
if (isTargetNotIgnored(chatUser, uuid)) {
p.sendMessage(GsonComponentSerializer.gson().deserialize(message));
}
});
@@ -193,7 +194,7 @@ public class PluginMessage implements PluginMessageListener {
ALogger.warn("Received ChatChannel message for non existent channel.");
return;
}
if (!chatChannel.getServers().contains(Bukkit.getServerName())) {
if (!chatChannel.getServers().contains(Bukkit.getServer().getName())) {
ALogger.warn("Received ChatChannel message for the wrong server.");
return;
}
@@ -216,4 +217,15 @@ public class PluginMessage implements PluginMessageListener {
}.runTaskAsynchronously(ChatPlugin.getInstance());
}
}
private boolean isTargetNotIgnored(ChatUser chatUser, UUID targetUUID) {
if (!chatUser.getIgnoredPlayers().contains(targetUUID)) {
return true;
}
Player target = Bukkit.getPlayer(targetUUID);
if (target == null) {
return true;
}
return target.hasPermission("chat.ignorebypass");
}
}
@@ -149,24 +149,24 @@ public class NickUtilities
public static boolean validNick(Player sender, OfflinePlayer target, String nickName) {
if (!noBlockedCodes(nickName)) {
sender.sendMiniMessage(Config.NICK_BLOCKED_COLOR_CODES, null);
sender.sendRichMessage(Config.NICK_BLOCKED_COLOR_CODES);
return false;
}
if (!Utility.checkNickBrightEnough(nickName)) {
sender.sendMiniMessage("<red>At least one color must be brighter than 30 for each color</red>", null);
sender.sendRichMessage("<red>At least one color must be brighter than 30 for each color</red>");
return false;
}
String cleanNick = NickUtilities.removeAllColors(nickName);
if (cleanNick.length() < 3 || cleanNick.length() > 16) {
sender.sendMiniMessage(Config.NICK_INVALID_LENGTH, null);
sender.sendRichMessage(Config.NICK_INVALID_LENGTH);
return false;
}
if (!cleanNick.matches("[a-zA-Z0-9_]*") || nickName.length() > 192) { //192 is if someone puts {#xxxxxx<>} in front of every letter
sender.sendMiniMessage(Config.NICK_INVALID_CHARACTERS, null);
sender.sendRichMessage(Config.NICK_INVALID_CHARACTERS);
return false;
}
@@ -183,7 +183,7 @@ public class NickUtilities
if (uniqueId.equals(uuid)){
ChatPlugin.getInstance().getLogger().info(uuid + " " + uniqueId);
}
sender.sendMiniMessage(Config.NICK_TAKEN, null);
sender.sendRichMessage(Config.NICK_TAKEN);
return false;
}
}
@@ -111,7 +111,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
Placeholder.component("nickname", chatUser.getDisplayName()),
Placeholder.parsed("currentnickname", chatUser.getNickNameString())
);
player.sendMiniMessage(Config.NICK_CURRENT, placeholders);
player.sendRichMessage(Config.NICK_CURRENT, placeholders);
}
break;
case "help":
@@ -41,6 +41,7 @@ public class ToggleableForCustomChannel extends Toggleable {
new BukkitRunnable() {
@Override
public void run() {
ALogger.info(String.format("%s sent %s message: %s", player.getName(), customChannel.getChannelName(), message));
ChatPlugin.getInstance().getChatHandler().chatChannel(player, customChannel, message);
}
}.runTaskAsynchronously(ChatPlugin.getInstance());
+12 -1
View File
@@ -4,11 +4,14 @@ include(":api")
include(":galaxy")
include(":velocity")
val nexusUser = providers.gradleProperty("alttdSnapshotUsername").get()
val nexusPass = providers.gradleProperty("alttdSnapshotPassword").get()
dependencyResolutionManagement {
repositories {
// mavenLocal()
mavenCentral()
maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
// 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://nexus.velocitypowered.com/repository/") // Velocity
@@ -16,6 +19,14 @@ dependencyResolutionManagement {
maven("https://repo.spongepowered.org/maven") // Configurate
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi
maven("https://jitpack.io")
maven {
name = "nexus"
url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
credentials {
username = nexusUser
password = nexusPass
}
}
}
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
}
+2 -2
View File
@@ -11,7 +11,7 @@ dependencies {
implementation("org.spongepowered", "configurate-yaml", "4.1.2")
compileOnly("net.kyori:adventure-text-minimessage:4.10.1")
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5")
compileOnly("com.alttd.proxydiscordlink:ProxyDiscordLink:1.0.0-BETA-SNAPSHOT")
compileOnly("com.alttd.proxydiscordlink:ProxyDiscordLink:1.0.1-SNAPSHOT")
}
tasks {
@@ -30,4 +30,4 @@ tasks {
dependsOn(shadowJar)
}
}
}