Compare commits
29
Commits
ignore_fix
...
e74361a7b7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e74361a7b7 | ||
|
|
769859a617 | ||
|
|
cb0bda8d5b | ||
|
|
5212954946 | ||
|
|
f1b8af6136 | ||
|
|
bfc9af69d0 | ||
|
|
ea705c879f | ||
|
|
f5c0a0676c | ||
|
|
9bd9e21321 | ||
|
|
1c570fd524 | ||
|
|
131ea6da9d | ||
|
|
3275db13d0 | ||
|
|
a908e32d0b | ||
|
|
8393d12c6d | ||
|
|
782c7df4ef | ||
|
|
a876a9f77b | ||
|
|
f3147b3256 | ||
|
|
65503a02f3 | ||
|
|
7140a0cd78 | ||
|
|
187f71d6c3 | ||
|
|
3b2aa84164 | ||
|
|
0fb497c2f1 | ||
|
|
192fca3a89 | ||
|
|
d6135f2456 | ||
|
|
c057c69653 | ||
|
|
c25767e473 | ||
|
|
37aa9fdf4c | ||
|
|
ed2ba74772 | ||
|
|
44d6e994cc |
@@ -15,9 +15,9 @@ public abstract interface ChatAPI {
|
||||
|
||||
DatabaseConnection getDataBase();
|
||||
|
||||
void ReloadConfig();
|
||||
void reloadConfig();
|
||||
|
||||
void ReloadChatFilters();
|
||||
void reloadChatFilters();
|
||||
|
||||
HashMap<String, String> getPrefixes();
|
||||
|
||||
|
||||
@@ -5,15 +5,12 @@ import com.alttd.chat.config.PrefixConfig;
|
||||
import com.alttd.chat.database.DatabaseConnection;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChatImplementation implements ChatAPI{
|
||||
|
||||
@@ -26,7 +23,7 @@ public class ChatImplementation implements ChatAPI{
|
||||
|
||||
public ChatImplementation() {
|
||||
instance = this;
|
||||
ReloadConfig();
|
||||
reloadConfig();
|
||||
|
||||
luckPerms = getLuckPerms();
|
||||
databaseConnection = getDataBase();
|
||||
@@ -57,13 +54,13 @@ public class ChatImplementation implements ChatAPI{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ReloadConfig() {
|
||||
public void reloadConfig() {
|
||||
Config.init();
|
||||
loadPrefixes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ReloadChatFilters() {
|
||||
public void reloadChatFilters() {
|
||||
RegexManager.initialize();
|
||||
}
|
||||
|
||||
|
||||
@@ -368,6 +368,8 @@ public final class Config {
|
||||
public static String CUSTOM_CHANNEL_TOGGLED = "<yellow>Toggled <channel> <status>.</yellow>";
|
||||
public static Component TOGGLED_ON = null;
|
||||
public static Component TOGGLED_OFF = null;
|
||||
public static double LOCAL_DISTANCE;
|
||||
public static String CHANNEL_SPY = "<i><gray>SPY:</gray> <dark_gray>(<dark_gray><sender> → <channel>) <message></dark_gray>";
|
||||
private static void chatChannels() {
|
||||
ConfigurationNode node = getNode("chat-channels");
|
||||
if (node.empty()) {
|
||||
@@ -383,12 +385,16 @@ public final class Config {
|
||||
new CustomChannel(channelName,
|
||||
getString(key + "format", ""),
|
||||
getList(key + "servers", Collections.EMPTY_LIST),
|
||||
getBoolean(key + "proxy", false));
|
||||
getBoolean(key + "proxy", false),
|
||||
getBoolean(key + "local", false)
|
||||
);
|
||||
}
|
||||
|
||||
CUSTOM_CHANNEL_TOGGLED = getString("chat-channels-messages.channel-toggled", CUSTOM_CHANNEL_TOGGLED);
|
||||
TOGGLED_ON = Utility.parseMiniMessage(getString("chat-channels-messages.channel-on", "<green>on</green><gray>"));
|
||||
TOGGLED_OFF = Utility.parseMiniMessage(getString("chat-channels-messages.channel-off", "<red>off</red><gray>"));
|
||||
LOCAL_DISTANCE = getDouble("chat-channels-messages.local-distance", 200.0);
|
||||
CHANNEL_SPY = getString("chat-channels-messages.spy", CHANNEL_SPY);
|
||||
}
|
||||
|
||||
public static String SERVERMUTEPERMISSION = "chat.command.mute-server";
|
||||
@@ -424,6 +430,7 @@ public final class Config {
|
||||
public static String mailUnread = "<green><click:run_command:/mail list unread>You have <amount> unread mail, click to view it.</click></green>";
|
||||
public static String mailSent = "<green>Successfully send mail to <player_name></green>: <#2e8b57><message></#2e8b57>";
|
||||
public static List<String> mailCommandAlias = new ArrayList<>();
|
||||
public static int mailDisplayDelay = 5;
|
||||
private static void mailSettings() {
|
||||
mailHeader = getString("settings.mail.header", mailHeader);
|
||||
mailBody = getString("settings.mail.message", mailBody);
|
||||
@@ -432,6 +439,7 @@ public final class Config {
|
||||
mailReceived = getString("settings.mail.mail-received", mailReceived);
|
||||
mailUnread = getString("settings.mail.mail-unread", mailUnread);
|
||||
mailSent = getString("settings.mail.mail-sent", mailSent);
|
||||
mailDisplayDelay = getInt("settings.mail.delay", mailDisplayDelay);
|
||||
}
|
||||
|
||||
public static HashMap<String, Long> serverChannelId = new HashMap<>();
|
||||
@@ -503,7 +511,7 @@ public final class Config {
|
||||
public static String NICK_TOO_SOON = "<red>Please wait <time><red> until requesting a new nickname";
|
||||
public static String NICK_REQUEST_PLACED = "<green>Replaced your previous request <oldrequestednick><green> with <newrequestednick><green>.";
|
||||
public static String NICK_REQUEST_NEW = "<green>New nickname request by <player><green>!";
|
||||
public static String NICK_TRYOUT = "<white><prefix><white> <nick><gray>: <white>Hi, this is what my new nickname could look like!";
|
||||
public static String NICK_TRYOUT = "<white><prefix><white> <nick><gray>: <white><click:suggest_command:/nick request <nickrequest>>Hi, this is what my new nickname could look like! Click this message to request.";
|
||||
public static String NICK_REQUESTED = "<green>Your requested to be nicknamed <nick><green> has been received. Staff will accept or deny this request asap!";
|
||||
public static String NICK_REVIEW_WAITING = "<green>There are <amount> nicknames waiting for review!";
|
||||
public static String NICK_TAKEN = "<red>Someone else already has this nickname, or has this name as their username.";
|
||||
|
||||
@@ -10,12 +10,14 @@ public class Channel {
|
||||
protected String channelName;
|
||||
protected String format;
|
||||
protected boolean proxy;
|
||||
protected boolean local;
|
||||
|
||||
public Channel(String channelName, String format, boolean proxy) {
|
||||
public Channel(String channelName, String format, boolean proxy, boolean local) {
|
||||
this.permission = "chat.channel." + channelName.toLowerCase();
|
||||
this.channelName = channelName;
|
||||
this.format = format;
|
||||
this.proxy = proxy;
|
||||
this.local = local;
|
||||
channels.put(channelName.toLowerCase(), this);
|
||||
}
|
||||
|
||||
@@ -39,6 +41,10 @@ public class Channel {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
public boolean isLocal() {
|
||||
return local;
|
||||
}
|
||||
|
||||
public static Channel getChatChannel(String channelName) {
|
||||
return channels.get(channelName.toLowerCase());
|
||||
}
|
||||
|
||||
@@ -5,14 +5,13 @@ import java.util.*;
|
||||
public class CustomChannel extends Channel {
|
||||
private final List<String> servers;
|
||||
|
||||
public CustomChannel(String channelName, String format, List<String> servers, boolean proxy) {
|
||||
super(channelName, format, proxy);
|
||||
public CustomChannel(String channelName, String format, List<String> servers, boolean proxy, boolean local) {
|
||||
super(channelName, format, proxy, local);
|
||||
this.permission = "chat.channel." + channelName.toLowerCase();
|
||||
this.channelName = channelName;
|
||||
this.format = format;
|
||||
this.servers = servers;
|
||||
this.proxy = proxy;
|
||||
channels.put(channelName.toLowerCase(), this);
|
||||
}
|
||||
public List<String> getServers() {
|
||||
return servers;
|
||||
|
||||
@@ -2,6 +2,6 @@ package com.alttd.chat.objects.channels;
|
||||
|
||||
public abstract class DefaultChannel extends Channel{
|
||||
public DefaultChannel(String channelName, String format, boolean proxy) {
|
||||
super(channelName, format, proxy);
|
||||
super(channelName, format, proxy, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class Utility {
|
||||
|
||||
private static final List<String> EMPTY_LIST = new ArrayList<>();
|
||||
static final Pattern DEFAULT_URL_PATTERN = Pattern.compile("(?:(https?)://)?([-\\w_.]+\\.\\w{2,})(/\\S*)?");
|
||||
static final Pattern URL_SCHEME_PATTERN = Pattern.compile("^[a-z][a-z0-9+\\-.]*:");
|
||||
|
||||
private static MiniMessage miniMessage = null;
|
||||
|
||||
@@ -307,6 +308,9 @@ public class Utility {
|
||||
String url = matcher.group();
|
||||
String clickUrl = url;
|
||||
String urlFormat = Config.URLFORMAT;
|
||||
// if (!URL_SCHEME_PATTERN.matcher(clickUrl).find()) {
|
||||
// clickUrl = "http://" + clickUrl;
|
||||
// }
|
||||
message = message.replace(url, urlFormat.replaceAll("<url>", url).replaceAll("<clickurl>", clickUrl));
|
||||
}
|
||||
return message;
|
||||
|
||||
@@ -12,13 +12,16 @@ import com.alttd.chat.objects.channels.Channel;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.ServerName;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class ChatPlugin extends JavaPlugin {
|
||||
@@ -38,7 +41,7 @@ public class ChatPlugin extends JavaPlugin {
|
||||
chatAPI = new ChatImplementation();
|
||||
chatHandler = new ChatHandler();
|
||||
DatabaseConnection.initialize();
|
||||
serverConfig = new ServerConfig(Bukkit.getServer().getName());
|
||||
serverConfig = new ServerConfig(ServerName.getServerName());
|
||||
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true);
|
||||
registerListener(new PlayerListener(serverConfig), new ChatListener(chatLogHandler), new BookListener(), new ShutdownListener(chatLogHandler, this));
|
||||
if(serverConfig.GLOBALCHAT) {
|
||||
@@ -57,8 +60,10 @@ public class ChatPlugin extends JavaPlugin {
|
||||
registerCommand("p", new PartyChat());
|
||||
registerCommand("emotes", new Emotes());
|
||||
for (Channel channel : Channel.getChannels()) {
|
||||
if (!(channel instanceof CustomChannel customChannel)) continue;
|
||||
this.getServer().getCommandMap().register(channel.getChannelName().toLowerCase(), new ChatChannel(customChannel));
|
||||
if (!(channel instanceof CustomChannel customChannel)) {
|
||||
continue;
|
||||
}
|
||||
this.getServer().getCommandMap().register(channel.getChannelName().toLowerCase(), new ChatChannel(customChannel));
|
||||
}
|
||||
|
||||
messageChannel = Config.MESSAGECHANNEL;
|
||||
@@ -116,10 +121,10 @@ public class ChatPlugin extends JavaPlugin {
|
||||
serverConfig.MUTED = !serverConfig.MUTED;
|
||||
}
|
||||
|
||||
public void ReloadConfig() {
|
||||
chatAPI.ReloadConfig();
|
||||
chatAPI.ReloadChatFilters();
|
||||
serverConfig = new ServerConfig(Bukkit.getServer().getName());
|
||||
public void reloadConfig() {
|
||||
chatAPI.reloadConfig();
|
||||
chatAPI.reloadChatFilters();
|
||||
serverConfig = new ServerConfig(ServerName.getServerName());
|
||||
Bukkit.broadcast(Utility.parseMiniMessage("Reloaded ChatPlugin Config."), "command.chat.reloadchat");
|
||||
ALogger.info("Reloaded ChatPlugin config.");
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ import com.alttd.chat.objects.ChatFilter;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.ModifiableString;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.GalaxyUtility;
|
||||
import com.alttd.chat.util.ServerName;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
@@ -20,12 +22,15 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ChatHandler {
|
||||
@@ -126,12 +131,11 @@ public class ChatHandler {
|
||||
|
||||
Component senderName = user.getDisplayName();
|
||||
Component prefix = user.getPrefix();
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("sender", senderName),
|
||||
Placeholder.component("prefix", prefix),
|
||||
Placeholder.component("message", parseMessageContent(player, message)),
|
||||
Placeholder.parsed("server", Bukkit.getServer().getName())
|
||||
Placeholder.parsed("server", ServerName.getServerName())
|
||||
);
|
||||
|
||||
Component component = Utility.parseMiniMessage(Config.GCFORMAT, placeholders);
|
||||
@@ -157,7 +161,10 @@ public class ChatHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isMuted(player, message, "[" + channel.getChannelName() + " Muted] ")) return;
|
||||
if (isMuted(player, message, "[" + channel.getChannelName() + " Muted] ")) {
|
||||
ALogger.info("Refusing to send message by muted user");
|
||||
return;
|
||||
}
|
||||
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
Component senderName = user.getDisplayName();
|
||||
@@ -165,7 +172,7 @@ public class ChatHandler {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("sender", senderName),
|
||||
Placeholder.component("message", parseMessageContent(player, message)),
|
||||
Placeholder.parsed("server", Bukkit.getServer().getName()),
|
||||
Placeholder.parsed("server", ServerName.getServerName()),
|
||||
Placeholder.parsed("channel", channel.getChannelName())
|
||||
);
|
||||
Component component = Utility.parseMiniMessage(channel.getFormat(), placeholders);
|
||||
@@ -176,15 +183,16 @@ public class ChatHandler {
|
||||
player,
|
||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||
"");
|
||||
return; // the message was blocked
|
||||
ALogger.info("Refusing to send blocked chat message");
|
||||
return;
|
||||
}
|
||||
|
||||
component = modifiableString.component();
|
||||
|
||||
if (channel.isProxy()) {
|
||||
sendChatChannelMessage(player, channel.getChannelName(), "chatchannel", component);
|
||||
sendChatChannelMessage(player, channel.getChannelName(), "chatchannel", component, message);
|
||||
} else {
|
||||
sendChatChannelMessage(channel, player.getUniqueId(), component);
|
||||
sendChatChannelMessage(channel, player.getUniqueId(), component, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,22 +245,49 @@ public class ChatHandler {
|
||||
// }
|
||||
}
|
||||
|
||||
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, Component component) {
|
||||
if (!chatChannel.getServers().contains(Bukkit.getServer().getName())) {
|
||||
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, Component component, String message) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) {
|
||||
ALogger.warn("Failed to send chat message from non existent player");
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) {
|
||||
if (!chatChannel.getServers().contains(ServerName.getServerName())) {
|
||||
player.sendRichMessage("<red>Unable to send messages to <channel> in this server.</red>",
|
||||
Placeholder.parsed("channel", chatChannel.getChannelName()));
|
||||
ALogger.info(String.format("Not sending chat message due to [%s] not being in this channels config",
|
||||
ServerName.getServerName()));
|
||||
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 = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
|
||||
|| receiver.hasPermission("chat.ignorebypass"));
|
||||
}
|
||||
stream.forEach(p -> p.sendMessage(component));
|
||||
if (chatChannel.isLocal()) {
|
||||
Location location = player.getLocation();
|
||||
stream = stream.filter(receiver -> {
|
||||
Player receiverPlayer = Bukkit.getPlayer(receiver.getUniqueId());
|
||||
if (receiverPlayer == null)
|
||||
return false;
|
||||
if (!location.getWorld().getUID().equals(receiverPlayer.getLocation().getWorld().getUID()))
|
||||
return false;
|
||||
return !(receiverPlayer.getLocation().distance(location) > Config.LOCAL_DISTANCE);
|
||||
});
|
||||
}
|
||||
List<? extends Player> recipientPlayers = stream.toList();
|
||||
recipientPlayers.forEach(p -> p.sendMessage(component));
|
||||
|
||||
List<UUID> recipientUUIDs = recipientPlayers.stream().map(Entity::getUniqueId).toList();
|
||||
Bukkit.getServer().getOnlinePlayers().stream()
|
||||
.filter(onlinePlayer -> onlinePlayer.hasPermission(Config.SPYPERMISSION))
|
||||
.filter(onlinePlayer -> !recipientUUIDs.contains(onlinePlayer.getUniqueId()))
|
||||
.forEach(onlinePlayer -> onlinePlayer.sendRichMessage(Config.CHANNEL_SPY,
|
||||
Placeholder.component("sender", player.name()),
|
||||
Placeholder.parsed("channel", chatChannel.getChannelName()),
|
||||
Placeholder.parsed("message", message)));
|
||||
}
|
||||
|
||||
private void sendPluginMessage(Player player, String channel, Component component) {
|
||||
@@ -272,7 +307,7 @@ public class ChatHandler {
|
||||
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
||||
}
|
||||
|
||||
public void sendChatChannelMessage(Player player, String chatChannelName, String channel, Component component) {
|
||||
public void sendChatChannelMessage(Player player, String chatChannelName, String channel, Component component, String ignored) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF(channel);
|
||||
out.writeUTF(chatChannelName);
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.alttd.chat.objects.*;
|
||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.GalaxyUtility;
|
||||
import com.alttd.chat.util.ServerName;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
@@ -106,7 +107,7 @@ public class ChatListener implements Listener {
|
||||
GalaxyUtility.sendBlockedNotification("Language", player,
|
||||
modifiableString.component(),
|
||||
"");
|
||||
chatLogHandler.addChatLog(uuid, player.getServer().getName(), PlainTextComponentSerializer.plainText().serialize(input), true);
|
||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), PlainTextComponentSerializer.plainText().serialize(input), true);
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
@@ -115,7 +116,7 @@ public class ChatListener implements Listener {
|
||||
|
||||
if (!player.hasPermission("chat.ignorebypass")) {
|
||||
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
|
||||
&& !receiver.hasPermission("chat.ignorebypass"));
|
||||
|| receiver.hasPermission("chat.ignorebypass"));
|
||||
}
|
||||
Set<Player> receivers = stream.collect(Collectors.toSet());
|
||||
|
||||
@@ -129,7 +130,7 @@ public class ChatListener implements Listener {
|
||||
for (Player pingPlayer : playersToPing) {
|
||||
pingPlayer.playSound(pingPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1);
|
||||
}
|
||||
chatLogHandler.addChatLog(uuid, player.getServer().getName(), modifiableString.string(), false);
|
||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), modifiableString.string(), false);
|
||||
ALogger.info(PlainTextComponentSerializer.plainText().serialize(input));
|
||||
}
|
||||
|
||||
@@ -139,9 +140,9 @@ public class ChatListener implements Listener {
|
||||
String nickName = PlainTextComponentSerializer.plainText().serialize(onlinePlayer.displayName());
|
||||
|
||||
Pattern namePattern = Pattern.compile("\\b(?<!\\\\)" + name + "\\b", Pattern.CASE_INSENSITIVE);
|
||||
// Pattern escapedNamePattern = Pattern.compile("\\b\\\\" + name + "\\b", Pattern.CASE_INSENSITIVE);
|
||||
// Pattern escapedNamePattern = Pattern.compile("\\b\\\\" + name + "\\b", Pattern.CASE_INSENSITIVE);
|
||||
Pattern nickPattern = Pattern.compile("\\b(?<!\\\\)" + nickName + "\\b", Pattern.CASE_INSENSITIVE);
|
||||
// Pattern escapedNickPattern = 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()) {
|
||||
@@ -151,16 +152,18 @@ public class ChatListener implements Listener {
|
||||
.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()
|
||||
// .once()
|
||||
// .match(escapedNamePattern)
|
||||
// .replacement((a, b) -> {
|
||||
// String substring = a.group().substring(1);
|
||||
// return ;
|
||||
// });
|
||||
// modifiableString.replace(TextReplacementConfig.builder()
|
||||
// .once()
|
||||
// .match(escapedNamePattern)
|
||||
// .replacement((a, b) -> {
|
||||
// String substring = a.group().substring(1);
|
||||
// return ;
|
||||
// });
|
||||
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||
&& !player.hasPermission("chat.ignorebypass"))
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
playersToPing.add(onlinePlayer);
|
||||
}
|
||||
} else if (nickPattern.matcher(modifiableString.string()).find()) {
|
||||
modifiableString.replace(TextReplacementConfig.builder()
|
||||
.once()
|
||||
@@ -168,8 +171,9 @@ public class ChatListener implements Listener {
|
||||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||
&& !player.hasPermission("chat.ignorebypass"))
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
playersToPing.add(onlinePlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,7 +202,7 @@ public class ChatListener implements Listener {
|
||||
});
|
||||
|
||||
MiniMessage miniMessage = MiniMessage.builder().tags(tagResolver.build()).build();
|
||||
Component component = miniMessage.deserialize(rawMessage);
|
||||
Component component = miniMessage.deserialize(Utility.formatText(rawMessage));
|
||||
for(ChatFilter chatFilter : RegexManager.getEmoteFilters()) {
|
||||
component = component.replaceText(
|
||||
TextReplacementConfig.builder()
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.alttd.chat.objects.channels.Channel;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.ServerName;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
@@ -164,7 +165,7 @@ public class PluginMessage implements PluginMessageListener {
|
||||
break;
|
||||
}
|
||||
case "reloadconfig":
|
||||
ChatPlugin.getInstance().ReloadConfig();
|
||||
ChatPlugin.getInstance().reloadConfig();
|
||||
break;
|
||||
case "chatpunishments":
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
@@ -194,7 +195,7 @@ public class PluginMessage implements PluginMessageListener {
|
||||
ALogger.warn("Received ChatChannel message for non existent channel.");
|
||||
return;
|
||||
}
|
||||
if (!chatChannel.getServers().contains(Bukkit.getServer().getName())) {
|
||||
if (!chatChannel.getServers().contains(ServerName.getServerName())) {
|
||||
ALogger.warn("Received ChatChannel message for the wrong server.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,8 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
sender.sendMessage(Utility.parseMiniMessage(Config.NICK_TRYOUT,
|
||||
Placeholder.component("prefix", Utility.applyColor(api.getUserManager().getUser(player.getUniqueId())
|
||||
.getCachedData().getMetaData().getPrefix())), // TODO pull this from chatuser?
|
||||
Placeholder.component("nick", Utility.applyColor(args[1]))));
|
||||
Placeholder.component("nick", Utility.applyColor(args[1])),
|
||||
Placeholder.unparsed("nickrequest", args[1])));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Utility.parseMiniMessage(Config.NICK_NO_LUCKPERMS));
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.alttd.chat.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ServerName {
|
||||
|
||||
private static final String serverName = loadServerName();
|
||||
|
||||
private static String loadServerName() {
|
||||
String serverName = "unknown";
|
||||
try {
|
||||
File serverPropertiesFile = new File(Bukkit.getWorldContainer().getParentFile(), "server.properties");
|
||||
if (!serverPropertiesFile.exists()) {
|
||||
ALogger.warn(String.format("server.properties file not found in %s!", serverPropertiesFile.getAbsolutePath()));
|
||||
return serverName;
|
||||
}
|
||||
|
||||
Properties properties = new Properties();
|
||||
FileInputStream fis = new FileInputStream(serverPropertiesFile);
|
||||
properties.load(fis);
|
||||
fis.close();
|
||||
|
||||
serverName = properties.getProperty("server-name", serverName);
|
||||
|
||||
ALogger.info(String.format("Found server name [%s]", serverName));
|
||||
} catch (IOException e) {
|
||||
ALogger.error("Failed to read server.properties", e);
|
||||
}
|
||||
return serverName;
|
||||
}
|
||||
|
||||
public static String getServerName() {
|
||||
return serverName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Dependency;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
@@ -83,9 +82,9 @@ public class VelocityChat {
|
||||
ChatUserManager.addUser(console);
|
||||
}
|
||||
|
||||
public void ReloadConfig() {
|
||||
chatAPI.ReloadConfig();
|
||||
chatAPI.ReloadChatFilters();
|
||||
public void reloadConfig() {
|
||||
chatAPI.reloadConfig();
|
||||
chatAPI.reloadChatFilters();
|
||||
serverHandler.cleanup();
|
||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("reloadconfig");
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Reload {
|
||||
.<CommandSource>literal("reloadchat")
|
||||
.requires(ctx -> ctx.hasPermission("command.chat.reloadchat"))
|
||||
.executes(context -> {
|
||||
VelocityChat.getPlugin().ReloadConfig();
|
||||
VelocityChat.getPlugin().reloadConfig();
|
||||
return 1;
|
||||
})
|
||||
.build();
|
||||
|
||||
@@ -205,6 +205,10 @@ public class ChatHandler {
|
||||
}
|
||||
Mail mail = new Mail(targetUUID, uuid, message);
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(targetUUID);
|
||||
if (chatUser.getIgnoredPlayers().contains(uuid)) {
|
||||
commandSource.sendMessage(Utility.parseMiniMessage("<red>You cannot mail this player</red>"));
|
||||
return;
|
||||
}
|
||||
chatUser.addMail(mail);
|
||||
// TODO load from config
|
||||
String finalSenderName = senderName;
|
||||
|
||||
@@ -23,8 +23,10 @@ import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
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.title.Title;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ProxyPlayerListener {
|
||||
|
||||
@@ -68,9 +70,17 @@ public class ProxyPlayerListener {
|
||||
List<Mail> unReadMail = chatUser.getUnReadMail();
|
||||
if (unReadMail.isEmpty())
|
||||
return;
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.mailUnread,
|
||||
Placeholder.unparsed("amount", String.valueOf(unReadMail.size()))
|
||||
));
|
||||
VelocityChat plugin = VelocityChat.getPlugin();
|
||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
||||
if (!player.isActive())
|
||||
return;
|
||||
|
||||
Component message = Utility.parseMiniMessage(Config.mailUnread,
|
||||
Placeholder.unparsed("amount", String.valueOf(unReadMail.size())));
|
||||
player.sendMessage(message);
|
||||
player.showTitle(Title.title(message, Component.empty()));
|
||||
}).delay(Config.mailDisplayDelay * 50L, TimeUnit.MILLISECONDS).schedule();
|
||||
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
Reference in New Issue
Block a user