Compare commits

..

No commits in common. "cb0bda8d5bd07fdb58dc73f5a174deb18db5b763" and "f1b8af6136cfa2d9efae7a9f300dc4d7249632b1" have entirely different histories.

11 changed files with 34 additions and 92 deletions

View File

@ -15,9 +15,9 @@ public abstract interface ChatAPI {
DatabaseConnection getDataBase();
void reloadConfig();
void ReloadConfig();
void reloadChatFilters();
void ReloadChatFilters();
HashMap<String, String> getPrefixes();

View File

@ -5,12 +5,15 @@ 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{
@ -23,7 +26,7 @@ public class ChatImplementation implements ChatAPI{
public ChatImplementation() {
instance = this;
reloadConfig();
ReloadConfig();
luckPerms = getLuckPerms();
databaseConnection = getDataBase();
@ -54,13 +57,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();
}

View File

@ -12,6 +12,7 @@ public class CustomChannel extends Channel {
this.format = format;
this.servers = servers;
this.proxy = proxy;
channels.put(channelName.toLowerCase(), this);
}
public List<String> getServers() {
return servers;

View File

@ -12,16 +12,13 @@ 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 {
@ -41,7 +38,7 @@ public class ChatPlugin extends JavaPlugin {
chatAPI = new ChatImplementation();
chatHandler = new ChatHandler();
DatabaseConnection.initialize();
serverConfig = new ServerConfig(ServerName.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) {
@ -60,9 +57,7 @@ public class ChatPlugin extends JavaPlugin {
registerCommand("p", new PartyChat());
registerCommand("emotes", new Emotes());
for (Channel channel : Channel.getChannels()) {
if (!(channel instanceof CustomChannel customChannel)) {
continue;
}
if (!(channel instanceof CustomChannel customChannel)) continue;
this.getServer().getCommandMap().register(channel.getChannelName().toLowerCase(), new ChatChannel(customChannel));
}
@ -121,10 +116,10 @@ public class ChatPlugin extends JavaPlugin {
serverConfig.MUTED = !serverConfig.MUTED;
}
public void reloadConfig() {
chatAPI.reloadConfig();
chatAPI.reloadChatFilters();
serverConfig = new ServerConfig(ServerName.getServerName());
public void ReloadConfig() {
chatAPI.ReloadConfig();
chatAPI.ReloadChatFilters();
serverConfig = new ServerConfig(Bukkit.getServer().getName());
Bukkit.broadcast(Utility.parseMiniMessage("Reloaded ChatPlugin Config."), "command.chat.reloadchat");
ALogger.info("Reloaded ChatPlugin config.");
}

View File

@ -8,9 +8,7 @@ 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;
@ -28,7 +26,6 @@ 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 {
@ -129,11 +126,12 @@ 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", ServerName.getServerName())
Placeholder.parsed("server", Bukkit.getServer().getName())
);
Component component = Utility.parseMiniMessage(Config.GCFORMAT, placeholders);
@ -159,10 +157,7 @@ public class ChatHandler {
return;
}
if (isMuted(player, message, "[" + channel.getChannelName() + " Muted] ")) {
ALogger.info("Refusing to send message by muted user");
return;
}
if (isMuted(player, message, "[" + channel.getChannelName() + " Muted] ")) return;
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
Component senderName = user.getDisplayName();
@ -170,7 +165,7 @@ public class ChatHandler {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("sender", senderName),
Placeholder.component("message", parseMessageContent(player, message)),
Placeholder.parsed("server", ServerName.getServerName()),
Placeholder.parsed("server", Bukkit.getServer().getName()),
Placeholder.parsed("channel", channel.getChannelName())
);
Component component = Utility.parseMiniMessage(channel.getFormat(), placeholders);
@ -181,8 +176,7 @@ public class ChatHandler {
player,
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
"");
ALogger.info("Refusing to send blocked chat message");
return;
return; // the message was blocked
}
component = modifiableString.component();
@ -244,17 +238,12 @@ public class ChatHandler {
}
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, Component component) {
Player player = Bukkit.getPlayer(uuid);
if (player == null) {
ALogger.warn("Failed to send chat message from non existent player");
if (!chatChannel.getServers().contains(Bukkit.getServer().getName())) {
return;
}
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()));
Player player = Bukkit.getPlayer(uuid);
if (player == null) {
return;
}

View File

@ -9,7 +9,6 @@ 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;
@ -107,7 +106,7 @@ public class ChatListener implements Listener {
GalaxyUtility.sendBlockedNotification("Language", player,
modifiableString.component(),
"");
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), PlainTextComponentSerializer.plainText().serialize(input), true);
chatLogHandler.addChatLog(uuid, player.getServer().getName(), PlainTextComponentSerializer.plainText().serialize(input), true);
return; // the message was blocked
}
@ -130,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(uuid, ServerName.getServerName(), modifiableString.string(), false);
chatLogHandler.addChatLog(uuid, player.getServer().getName(), modifiableString.string(), false);
ALogger.info(PlainTextComponentSerializer.plainText().serialize(input));
}

View File

@ -11,7 +11,6 @@ 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;
@ -165,7 +164,7 @@ public class PluginMessage implements PluginMessageListener {
break;
}
case "reloadconfig":
ChatPlugin.getInstance().reloadConfig();
ChatPlugin.getInstance().ReloadConfig();
break;
case "chatpunishments":
UUID uuid = UUID.fromString(in.readUTF());
@ -195,7 +194,7 @@ public class PluginMessage implements PluginMessageListener {
ALogger.warn("Received ChatChannel message for non existent channel.");
return;
}
if (!chatChannel.getServers().contains(ServerName.getServerName())) {
if (!chatChannel.getServers().contains(Bukkit.getServer().getName())) {
ALogger.warn("Received ChatChannel message for the wrong server.");
return;
}

View File

@ -1,41 +0,0 @@
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;
}
}

View File

@ -24,6 +24,7 @@ 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;
@ -82,9 +83,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");

View File

@ -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();

View File

@ -205,10 +205,6 @@ 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;