Merge branch 4.9

This commit is contained in:
destro174 2022-03-14 16:48:35 +01:00
commit e6dfd19b84
21 changed files with 258 additions and 177 deletions

View File

@ -16,8 +16,3 @@ jobs:
run: git config --global user.email "no-reply@github.com" && git config --global user.name "Github Actions" run: git config --global user.email "no-reply@github.com" && git config --global user.name "Github Actions"
- name: Build - name: Build
run: ./gradlew build --stacktrace run: ./gradlew build --stacktrace
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: Chat.jar
path: build/libs/Chat*.jar

View File

@ -3,10 +3,7 @@ plugins {
} }
dependencies { dependencies {
compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT") { compileOnly("com.alttd:Galaxy-API:1.18.2-R0.1-SNAPSHOT")
exclude("net.kyori.adventure.text.minimessage")
}
compileOnly("net.kyori:adventure-text-minimessage:4.10.0-SNAPSHOT") // Minimessage
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
compileOnly("net.luckperms:api:5.3") // Luckperms compileOnly("net.luckperms:api:5.3") // Luckperms
} }

View File

@ -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 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 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 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() { private static void messageCommand() {
MESSAGECOMMANDALIASES.clear(); MESSAGECOMMANDALIASES.clear();
REPLYCOMMANDALIASES.clear(); REPLYCOMMANDALIASES.clear();
@ -193,6 +194,7 @@ public final class Config {
MESSAGESENDER = getString("commands.message.sender-message", MESSAGESENDER); MESSAGESENDER = getString("commands.message.sender-message", MESSAGESENDER);
MESSAGERECIEVER = getString("commands.message.reciever-message", MESSAGERECIEVER); MESSAGERECIEVER = getString("commands.message.reciever-message", MESSAGERECIEVER);
MESSAGESPY = getString("commands.message.spy-message", MESSAGESPY); 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>"; 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 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 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_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 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>'>" + 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>"; "<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); DISBAND_PARTY_CONFIRM = getString("party.messages.disband-party-confirm", DISBAND_PARTY_CONFIRM);
DISBANDED_PARTY = getString("party.messages.disbanded-party", DISBANDED_PARTY); DISBANDED_PARTY = getString("party.messages.disbanded-party", DISBANDED_PARTY);
PARTY_INFO = getString("party.messages.party-info", PARTY_INFO); 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>"; 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); 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);
}
} }

View File

@ -3,15 +3,14 @@ package com.alttd.chat.managers;
import com.alttd.chat.ChatAPI; import com.alttd.chat.ChatAPI;
import com.alttd.chat.config.RegexConfig; import com.alttd.chat.config.RegexConfig;
import com.alttd.chat.objects.ChatFilter; import com.alttd.chat.objects.ChatFilter;
import com.alttd.chat.objects.ModifiableString;
import com.alttd.chat.util.ALogger; import com.alttd.chat.util.ALogger;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.cacheddata.CachedPermissionData; import net.luckperms.api.cacheddata.CachedPermissionData;
import net.luckperms.api.model.user.User; import net.luckperms.api.model.user.User;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class RegexManager { public class RegexManager {
@ -29,15 +28,15 @@ public class RegexManager {
chatFilters.add(filter); 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 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 replaceText(playerName, uuid, text, true); 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); User user = ChatAPI.get().getLuckPerms().getUserManager().getUser(uuid);
if (user == null) { if (user == null) {
ALogger.warn("Tried to check chat filters for a user who doesn't exist in LuckPerms"); 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(); CachedPermissionData permissionData = user.getCachedData().getPermissionData();
for(ChatFilter chatFilter : chatFilters) { for(ChatFilter chatFilter : chatFilters) {
@ -45,22 +44,24 @@ public class RegexManager {
case CHAT: case CHAT:
break; break;
case REPLACE: case REPLACE:
text = chatFilter.replaceText(text); chatFilter.replaceText(modifiableString);
break; break;
case BLOCK: 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() + "."); ALogger.info(playerName + " triggered the chat filter for " + chatFilter.getName() + ".");
return null; return false;
} }
break; break;
case REPLACEMATCHER: case REPLACEMATCHER:
if(matcher) { if(matcher) {
text = chatFilter.replaceMatcher(text); chatFilter.replaceMatcher(modifiableString);
} }
break; break;
} }
} }
return text; return true;
} }
} }

View File

@ -42,34 +42,57 @@ public class ChatFilter {
return this.exclusions; return this.exclusions;
} }
public boolean matches(String input) { public boolean matches(ModifiableString filterableString) {
String input = filterableString.string();
Matcher matcher = pattern.matcher(input); 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); Matcher matcher = pattern.matcher(input);
while (matcher.find()) { while (matcher.find()) {
String group = matcher.group(); // todo debug String group = matcher.group(); // todo debug
if(getExclusions().stream().noneMatch(s -> s.equalsIgnoreCase(group))) { // idk how heavy this is:/ if (getExclusions().stream().noneMatch(s -> s.equalsIgnoreCase(group))) { // idk how heavy this is:/
input = input.replace(group, getReplacement()); modifiableString.string(input.replace(group, getReplacement()));
} }
} }
return input;
} }
public String replaceMatcher(String input) { public void replaceMatcher(ModifiableString modifiableString) {
int lenght; String input = modifiableString.string();
int length;
try { try {
lenght = Integer.parseInt(replacement); length = Integer.parseInt(replacement);
} catch (NumberFormatException e) { } 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); Matcher matcher = pattern.matcher(input);
while (matcher.find()) { while (matcher.find()) {
String group = matcher.group(); String group = matcher.group();
input = input.replace(group, group.substring(0, lenght)); modifiableString.string(input.replace(group, group.substring(0, length)));
} }
return input;
} }
} }

View File

@ -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;
}
}

View File

@ -8,18 +8,18 @@ allprojects {
version = "1.0.0-SNAPSHOT" version = "1.0.0-SNAPSHOT"
description = "All in one minecraft chat plugin" description = "All in one minecraft chat plugin"
repositories { // repositories {
mavenCentral() // 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/groups/public/") // Adventure
maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage // maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage
maven("https://oss.sonatype.org/content/repositories/") // Minimessage // maven("https://oss.sonatype.org/content/repositories/") // Minimessage
maven("https://nexus.velocitypowered.com/repository/") // Velocity // maven("https://nexus.velocitypowered.com/repository/") // Velocity
maven("https://nexus.velocitypowered.com/repository/maven-public/") // Velocity // maven("https://nexus.velocitypowered.com/repository/maven-public/") // Velocity
maven("https://repo.spongepowered.org/maven") // Configurate // maven("https://repo.spongepowered.org/maven") // Configurate
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi // maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi
maven("https://jitpack.io") // maven("https://jitpack.io")
} // }
} }
subprojects { subprojects {

View File

@ -5,10 +5,7 @@ plugins {
dependencies { dependencies {
implementation(project(":api")) // API implementation(project(":api")) // API
compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT") { // Galaxy compileOnly("com.alttd:Galaxy-API:1.18.2-R0.1-SNAPSHOT") // Galaxy
exclude("net.kyori.adventure.text.minimessage")
}
compileOnly("net.kyori:adventure-text-minimessage:4.10.0-SNAPSHOT") // Minimessage
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") // move to proxy compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") // move to proxy
} }

View File

@ -24,6 +24,7 @@ public class ChatClear implements CommandExecutor {
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
if (!player.hasPermission("chat.clear-bypass")) if (!player.hasPermission("chat.clear-bypass"))
player.sendMessage(component); player.sendMessage(component);
Bukkit.getServer().sendMessage(miniMessage.deserialize( Bukkit.getServer().sendMessage(miniMessage.deserialize(
"<gold><player> cleared chat.</gold>", "<gold><player> cleared chat.</gold>",
Placeholder.component("player",sender.name())) Placeholder.component("player",sender.name()))

View File

@ -5,6 +5,7 @@ import com.alttd.chat.config.Config;
import com.alttd.chat.managers.ChatUserManager; import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager; import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser; import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.objects.ModifiableString;
import com.alttd.chat.objects.channels.CustomChannel; import com.alttd.chat.objects.channels.CustomChannel;
import com.alttd.chat.util.GalaxyUtility; import com.alttd.chat.util.GalaxyUtility;
import com.alttd.chat.util.Utility; import com.alttd.chat.util.Utility;
@ -37,11 +38,16 @@ public class ChatHandler {
public void privateMessage(Player player, String target, String message) { public void privateMessage(Player player, String target, String message) {
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId()); // ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
// user.setReplyTarget(target); // user.setReplyTarget(target);
String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message); // todo a better way for this ModifiableString modifiableString = new ModifiableString(message);
if(updatedMessage == null) { // todo a better way for this
GalaxyUtility.sendBlockedNotification("DM Language", player, message, target); if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "privatemessage")) {
GalaxyUtility.sendBlockedNotification("DM Language",
player,
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
target);
return; // the message was blocked return; // the message was blocked
} }
String updatedMessage = modifiableString.string();
if(!player.hasPermission("chat.format")) { if(!player.hasPermission("chat.format")) {
updatedMessage = Utility.stripTokens(updatedMessage); updatedMessage = Utility.stripTokens(updatedMessage);
@ -92,12 +98,17 @@ public class ChatHandler {
Component senderName = user.getDisplayName(); Component senderName = user.getDisplayName();
Component prefix = user.getPrefix(); Component prefix = user.getPrefix();
String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message); // todo a better way for this ModifiableString modifiableString = new ModifiableString(message);
if(updatedMessage == null) { // todo a better way for this
GalaxyUtility.sendBlockedNotification("GC Language", player, message, ""); if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "globalchat")) {
GalaxyUtility.sendBlockedNotification("GC Language",
player,
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
"");
return; // the message was blocked return; // the message was blocked
} }
String updatedMessage = modifiableString.string();
if(!player.hasPermission("chat.format")) { if(!player.hasPermission("chat.format")) {
updatedMessage = Utility.stripTokens(updatedMessage); updatedMessage = Utility.stripTokens(updatedMessage);
} else { } else {
@ -132,12 +143,16 @@ public class ChatHandler {
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId()); ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
Component senderName = user.getDisplayName(); Component senderName = user.getDisplayName();
String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message); ModifiableString modifiableString = new ModifiableString(message);
if(updatedMessage == null) { if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, channel.getChannelName())) {
GalaxyUtility.sendBlockedNotification(channel.getChannelName() + " Language", player, message, ""); GalaxyUtility.sendBlockedNotification(channel.getChannelName() + " Language",
player,
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
"");
return; // the message was blocked return; // the message was blocked
} }
String updatedMessage = modifiableString.string();
if(!player.hasPermission("chat.format")) { if(!player.hasPermission("chat.format")) {
updatedMessage = Utility.stripTokens(updatedMessage); updatedMessage = Utility.stripTokens(updatedMessage);
} }
@ -192,7 +207,7 @@ public class ChatHandler {
// //
// updatedMessage = Utility.formatText(updatedMessage); // updatedMessage = Utility.formatText(updatedMessage);
// //
// List<Template> templates = new ArrayList<>(List.of( // List<Placeholder> Placeholders = new ArrayList<>(List.of(
// Placeholder.miniMessage("sender", senderName), // Placeholder.miniMessage("sender", senderName),
// Placeholder.miniMessage("sendername", senderName), // Placeholder.miniMessage("sendername", senderName),
// Placeholder.miniMessage("partyname", party.getPartyName()), // Placeholder.miniMessage("partyname", party.getPartyName()),
@ -200,10 +215,10 @@ public class ChatHandler {
// Placeholder.miniMessage("server", Bukkit.getServerName()), // Placeholder.miniMessage("server", Bukkit.getServerName()),
// Placeholder.miniMessage("[i]", itemComponent(player.getInventory().getItemInMainHand())))); // Placeholder.miniMessage("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
// //
// Component component = Utility.parseMiniMessage(Config.PARTY_FORMAT, templates); // Component component = Utility.parseMiniMessage(Config.PARTY_FORMAT, Placeholders);
//// sendPartyMessage(player, party.getPartyId(), component); //// sendPartyMessage(player, party.getPartyId(), component);
// //
// Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, templates); // Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, Placeholders);
// for(Player pl : Bukkit.getOnlinePlayers()) { // for(Player pl : Bukkit.getOnlinePlayers()) {
// if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) { // if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
// pl.sendMessage(spyMessage); // pl.sendMessage(spyMessage);
@ -253,7 +268,7 @@ public class ChatHandler {
if (user == null) return false; if (user == null) return false;
if (user.isMuted() || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) { if (user.isMuted() || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) {
// if (Database.get().isPlayerMuted(player.getUniqueId(), null) || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) { // if (Database.get().isPlayerMuted(player.getUniqueId(), null) || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) {
GalaxyUtility.sendBlockedNotification(prefix, player, message, ""); GalaxyUtility.sendBlockedNotification(prefix, player, Utility.parseMiniMessage(Utility.stripTokens(message)), "");
return true; return true;
} }
return false; return false;

View File

@ -6,6 +6,7 @@ import com.alttd.chat.handler.ChatHandler;
import com.alttd.chat.managers.ChatUserManager; import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager; import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser; import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.objects.ModifiableString;
import com.alttd.chat.util.GalaxyUtility; import com.alttd.chat.util.GalaxyUtility;
import com.alttd.chat.util.Utility; import com.alttd.chat.util.Utility;
import io.papermc.paper.chat.ChatRenderer; import io.papermc.paper.chat.ChatRenderer;
@ -43,14 +44,16 @@ public class ChatListener implements Listener, ChatRenderer {
Component input = event.message(); Component input = event.message();
String message = PlainTextComponentSerializer.plainText().serialize(input); String message = PlainTextComponentSerializer.plainText().serialize(input);
ModifiableString modifiableString = new ModifiableString(message);
message = RegexManager.replaceText(player.getName(), player.getUniqueId(), message); // todo a better way for this // todo a better way for this
if(message == null) { if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "chat")) {
event.setCancelled(true); event.setCancelled(true);
GalaxyUtility.sendBlockedNotification("Language", player, input, ""); GalaxyUtility.sendBlockedNotification("Language", player,
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
"");
return; // the message was blocked return; // the message was blocked
} }
message = modifiableString.string();
if(!player.hasPermission("chat.format")) { if(!player.hasPermission("chat.format")) {
message = Utility.stripTokens(message); message = Utility.stripTokens(message);
} else { } else {
@ -62,7 +65,7 @@ public class ChatListener implements Listener, ChatRenderer {
message = Utility.formatText(message); message = Utility.formatText(message);
TagResolver placeholders = TagResolver.resolver( TagResolver placeholders = TagResolver.resolver(
Placeholder.parsed("message", message), Placeholder.unparsed("message", message), // needs to be unparsed because of the placeholders repeating bug
Placeholder.component("[i]]", ChatHandler.itemComponent(player.getInventory().getItemInMainHand())) Placeholder.component("[i]]", ChatHandler.itemComponent(player.getInventory().getItemInMainHand()))
); );

View File

@ -4,10 +4,10 @@ import com.alttd.chat.database.Queries;
import com.alttd.chat.managers.ChatUserManager; import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager; import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser; import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.objects.ModifiableString;
import com.alttd.chat.util.GalaxyUtility; import com.alttd.chat.util.GalaxyUtility;
import com.alttd.chat.util.Utility; import com.alttd.chat.util.Utility;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -48,12 +48,18 @@ public class PlayerListener implements Listener {
Component component = event.line(i); Component component = event.line(i);
if (component != null) { if (component != null) {
String message = PlainTextComponentSerializer.plainText().serialize(component); String message = PlainTextComponentSerializer.plainText().serialize(component);
Player player = event.getPlayer(); ModifiableString modifiableString = new ModifiableString(message);
message = RegexManager.replaceText(player.getName(), player.getUniqueId(), message, false); // todo a better way for this
if (message == null) { Player player = event.getPlayer();
GalaxyUtility.sendBlockedNotification("Sign Language" , player, PlainTextComponentSerializer.plainText().serialize(component), "");
// todo a better way for this
if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, false, "sign")) {
GalaxyUtility.sendBlockedNotification("Sign Language",
player,
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
"");
} }
message = modifiableString.string();
component = message == null ? Component.empty() : Component.text(message); component = message == null ? Component.empty() : Component.text(message);

View File

@ -9,6 +9,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class GalaxyUtility { public class GalaxyUtility {
public static void sendBlockedNotification(String prefix, Player player, String input, String target) { public static void sendBlockedNotification(String prefix, Player player, String input, String target) {
TagResolver placeholders = TagResolver.resolver( TagResolver placeholders = TagResolver.resolver(
Placeholder.parsed("prefix", prefix), Placeholder.parsed("prefix", prefix),
@ -30,4 +31,5 @@ public class GalaxyUtility {
public static void sendBlockedNotification(String prefix, Player player, Component input, String target) { public static void sendBlockedNotification(String prefix, Player player, Component input, String target) {
sendBlockedNotification(prefix, player, PlainTextComponentSerializer.plainText().serialize(input), target); sendBlockedNotification(prefix, player, PlainTextComponentSerializer.plainText().serialize(input), target);
} }
} }

View File

@ -4,21 +4,21 @@ include(":api")
include(":galaxy") include(":galaxy")
include(":velocity") include(":velocity")
//dependencyResolutionManagement { dependencyResolutionManagement {
// repositories { repositories {
// mavenLocal() // mavenLocal()
// mavenCentral() 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/groups/public/") // Adventure
// maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage
// maven("https://nexus.velocitypowered.com/repository/") // Velocity maven("https://nexus.velocitypowered.com/repository/") // Velocity
// maven("https://nexus.velocitypowered.com/repository/maven-public/") // Velocity maven("https://nexus.velocitypowered.com/repository/maven-public/") // Velocity
// maven("https://repo.spongepowered.org/maven") // Configurate maven("https://repo.spongepowered.org/maven") // Configurate
// maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi
// maven("https://jitpack.io") maven("https://jitpack.io")
// } }
// repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
//} }
pluginManagement { pluginManagement {
repositories { repositories {

View File

@ -5,15 +5,11 @@ plugins {
dependencies { dependencies {
implementation(project(":api")) // API implementation(project(":api")) // API
compileOnly("com.velocitypowered:velocity-api:3.0.1") // Velocity compileOnly("com.velocitypowered:velocity-api:3.1.0") // Velocity
annotationProcessor("com.velocitypowered:velocity-api:3.0.1") annotationProcessor("com.velocitypowered:velocity-api:3.1.0")
// compileOnly("com.velocitypowered:velocity-brigadier:1.0.0-SNAPSHOT")
implementation("mysql:mysql-connector-java:8.0.27") // mysql implementation("mysql:mysql-connector-java:8.0.27") // mysql
implementation("org.spongepowered", "configurate-yaml", "4.1.2") implementation("org.spongepowered", "configurate-yaml", "4.1.2")
implementation("net.kyori", "adventure-text-minimessage", "4.10.0-SNAPSHOT") { implementation("net.kyori:adventure-text-minimessage:4.10.1")
exclude("net.kyori")
exclude("net.kyori.examination")
}
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") 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.0-BETA-SNAPSHOT")
} }

View File

@ -5,10 +5,7 @@ import com.alttd.chat.ChatImplementation;
import com.alttd.chat.managers.ChatUserManager; import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.PartyManager; import com.alttd.chat.managers.PartyManager;
import com.alttd.chat.objects.ChatUser; import com.alttd.chat.objects.ChatUser;
import com.alttd.velocitychat.commands.GlobalAdminChat; import com.alttd.velocitychat.commands.*;
import com.alttd.velocitychat.commands.MailCommand;
import com.alttd.velocitychat.commands.PartyCommand;
import com.alttd.velocitychat.commands.Reload;
import com.alttd.chat.config.Config; import com.alttd.chat.config.Config;
import com.alttd.chat.database.DatabaseConnection; import com.alttd.chat.database.DatabaseConnection;
import com.alttd.velocitychat.handlers.ChatHandler; import com.alttd.velocitychat.handlers.ChatHandler;
@ -37,7 +34,7 @@ import java.nio.file.Path;
@Plugin(id = "chatplugin", name = "ChatPlugin", version = "1.0.0", @Plugin(id = "chatplugin", name = "ChatPlugin", version = "1.0.0",
description = "A chat plugin for Altitude Minecraft Server", description = "A chat plugin for Altitude Minecraft Server",
authors = {"destro174", "teri"}, authors = {"destro174", "teri"},
dependencies = {@Dependency(id = "luckperms"), @Dependency(id = "litebans")} dependencies = {@Dependency(id = "luckperms"), @Dependency(id = "litebans"), @Dependency(id = "proxydiscordlink")}
) )
public class VelocityChat { public class VelocityChat {
@ -114,6 +111,7 @@ public class VelocityChat {
new GlobalAdminChat(server); new GlobalAdminChat(server);
new Reload(server); new Reload(server);
new MailCommand(server); new MailCommand(server);
new Report(server);
server.getCommandManager().register("party", new PartyCommand()); server.getCommandManager().register("party", new PartyCommand());
// all (proxy)commands go here // all (proxy)commands go here
} }

View File

@ -93,7 +93,7 @@ public class PartyCommand implements SimpleCommand {
List<String> finalValues = new ArrayList<>(); List<String> finalValues = new ArrayList<>();
for (String str : possibleValues) { for (String str : possibleValues) {
if (str.toLowerCase().startsWith(remaining)) { if (str.toLowerCase().startsWith(remaining.toLowerCase())) {
finalValues.add(StringArgumentType.escapeIfRequired(str)); finalValues.add(StringArgumentType.escapeIfRequired(str));
} }
} }

View File

@ -2,11 +2,15 @@ package com.alttd.velocitychat.commands;
import com.alttd.chat.config.Config; import com.alttd.chat.config.Config;
import com.alttd.chat.util.Utility; import com.alttd.chat.util.Utility;
import com.alttd.velocitychat.VelocityChat;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.Suggestions;
import com.alttd.proxydiscordlink.DiscordLink;
import com.alttd.proxydiscordlink.lib.net.dv8tion.jda.api.EmbedBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.BrigadierCommand; import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandMeta; import com.velocitypowered.api.command.CommandMeta;
@ -16,8 +20,12 @@ import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.ServerConnection;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.awt.*;
import java.util.Optional; import java.util.Optional;
public class Report { public class Report {
@ -26,40 +34,43 @@ public class Report {
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
.<CommandSource>literal("report") .<CommandSource>literal("report")
.requires(ctx -> ctx.hasPermission("command.chat.report")) .requires(ctx -> ctx.hasPermission("command.chat.report"))
.then(RequiredArgumentBuilder.<CommandSource, String>argument("username", StringArgumentType.string()) .then(RequiredArgumentBuilder
.suggests((context, builder) -> { .<CommandSource, String>argument("report", StringArgumentType.greedyString())
Collection<String> possibleValues = new ArrayList<>(); .executes(context -> {
for (Player player : proxyServer.getAllPlayers()) { if (!(context.getSource() instanceof Player player)) {
possibleValues.add(player.getGameProfile().getName()); context.getSource().sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
return 1;
} }
if(possibleValues.isEmpty()) return Suggestions.empty(); Optional<ServerConnection> optionalServerConnection = player.getCurrentServer();
String remaining = builder.getRemaining().toLowerCase(); if (optionalServerConnection.isEmpty()) {
for (String str : possibleValues) { return 1;
if (str.toLowerCase().startsWith(remaining)) {
builder.suggest(StringArgumentType.escapeIfRequired(str));
}
} }
return builder.buildFuture(); ServerConnection serverConnection = optionalServerConnection.get();
String serverName = serverConnection.getServer().getServerInfo().getName();
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setAuthor(player.getUsername(), null, "https://crafatar.com/avatars/" + player.getUniqueId() + "?overlay");
embedBuilder.setTitle("Player Report");
embedBuilder.setColor(Color.CYAN);
embedBuilder.addField("Incident",
context.getArgument("report", String.class),
false);
embedBuilder.addField("Server",
serverName.substring(0, 1).toUpperCase() + serverName.substring(1),
false);
Long id = Config.serverChannelId.get(serverName.toLowerCase());
if (id <= 0)
id = Config.serverChannelId.get("general");
DiscordLink.getPlugin().getBot().sendEmbedToDiscord(id, embedBuilder, -1);
player.sendMessage(Utility.parseMiniMessage(Config.REPORT_SENT));
return 1;
}) })
.then(RequiredArgumentBuilder
.<CommandSource, String>argument("report", StringArgumentType.greedyString())
.executes(context -> {
if (!(context.getSource() instanceof Player player)) {
context.getSource().sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
return 1;
}
Optional<ServerConnection> optionalServerConnection = player.getCurrentServer();
if (optionalServerConnection.isEmpty()) {
return 1;
}
ServerConnection serverConnection = optionalServerConnection.get();
String serverName = serverConnection.getServer().getServerInfo().getName();
//TODO send message to channel with that server name
return 1;
})
)
) )
.executes(context -> 0) .executes(context -> {
context.getSource().sendMessage(Utility.parseMiniMessage(Config.HELP_REPORT));
return 0;
})
.build(); .build();
BrigadierCommand brigadierCommand = new BrigadierCommand(command); BrigadierCommand brigadierCommand = new BrigadierCommand(command);

View File

@ -59,6 +59,11 @@ public class Invite implements SubCommand {
Placeholder.unparsed("party", party.getPartyName()), Placeholder.unparsed("party", party.getPartyName()),
Placeholder.unparsed("party_password", party.getPartyPassword()) Placeholder.unparsed("party_password", party.getPartyPassword())
)); ));
source.sendMessage(Utility.parseMiniMessage(Config.SENT_PARTY_INV,
Placeholder.unparsed("player", target.getUsername()),
Placeholder.unparsed("party", party.getPartyName()),
Placeholder.unparsed("party_password", party.getPartyPassword())
));
source.sendMessage(Utility.parseMiniMessage(Config.SENT_PARTY_INV, source.sendMessage(Utility.parseMiniMessage(Config.SENT_PARTY_INV,
Placeholder.unparsed("player", target.getUsername()) Placeholder.unparsed("player", target.getUsername())
)); ));

View File

@ -45,12 +45,17 @@ public class Join implements SubCommand {
// party.addUser(ChatUserManager.getChatUser(player.getUniqueId())); //Removed until we can get nicknames to translate to colors correctly // party.addUser(ChatUserManager.getChatUser(player.getUniqueId())); //Removed until we can get nicknames to translate to colors correctly
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId()); ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
if (chatUser.getPartyId() == party.getPartyId()) {
source.sendMessage(Utility.parseMiniMessage(Config.ALREADY_IN_THIS_PARTY, Placeholder.parsed("party", party.getPartyName())));
return;
}
party.addUser(chatUser, player.getUsername()); party.addUser(chatUser, player.getUsername());
source.sendMessage(Utility.parseMiniMessage(Config.JOINED_PARTY, Placeholder.unparsed("party_name", party.getPartyName()))); source.sendMessage(Utility.parseMiniMessage(Config.JOINED_PARTY, Placeholder.parsed("party_name", party.getPartyName())));
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party, VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
Utility.parseMiniMessage(Config.PLAYER_JOINED_PARTY, Utility.parseMiniMessage(Config.PLAYER_JOINED_PARTY,
Placeholder.component("player_name", chatUser.getDisplayName()), Placeholder.component("player_name", chatUser.getDisplayName()),
Placeholder.unparsed("party_name", party.getPartyName()) Placeholder.parsed("party_name", party.getPartyName())
), null); ), null);
} }

View File

@ -23,7 +23,6 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
public class ChatHandler { public class ChatHandler {
@ -39,20 +38,19 @@ public class ChatHandler {
Player player2 = optionalPlayer2.get(); Player player2 = optionalPlayer2.get();
ChatUser targetUser = ChatUserManager.getChatUser(player2.getUniqueId()); ChatUser targetUser = ChatUserManager.getChatUser(player2.getUniqueId());
TagResolver placeholders = TagResolver.resolver( TagResolver Placeholders = TagResolver.resolver(
Placeholder.component("sender", senderUser.getDisplayName()), Placeholder.component("sender", senderUser.getDisplayName()),
Placeholder.unparsed("sendername", player.getUsername()), Placeholder.unparsed("sendername", player.getUsername()),
Placeholder.component("receiver", targetUser.getDisplayName()), Placeholder.component("receiver", targetUser.getDisplayName()),
Placeholder.unparsed("receivername", player2.getUsername()), Placeholder.unparsed("receivername", player2.getUsername()),
Placeholder.component("message", GsonComponentSerializer.gson().deserialize(message)), Placeholder.component("message", GsonComponentSerializer.gson().deserialize(message)),
Placeholder.unparsed("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude") Placeholder.unparsed("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude"));
);
ServerConnection serverConnection; ServerConnection serverConnection;
if(player.getCurrentServer().isPresent() && player2.getCurrentServer().isPresent()) { if(player.getCurrentServer().isPresent() && player2.getCurrentServer().isPresent()) {
// redirect to the sender // redirect to the sender
serverConnection = player.getCurrentServer().get(); serverConnection = player.getCurrentServer().get();
Component component = Utility.parseMiniMessage(Config.MESSAGESENDER, placeholders); Component component = Utility.parseMiniMessage(Config.MESSAGESENDER, Placeholders);
ByteArrayDataOutput buf = ByteStreams.newDataOutput(); ByteArrayDataOutput buf = ByteStreams.newDataOutput();
buf.writeUTF("privatemessageout"); buf.writeUTF("privatemessageout");
buf.writeUTF(player.getUniqueId().toString()); buf.writeUTF(player.getUniqueId().toString());
@ -63,7 +61,7 @@ public class ChatHandler {
//redirect to the receiver //redirect to the receiver
serverConnection = player2.getCurrentServer().get(); serverConnection = player2.getCurrentServer().get();
component = Utility.parseMiniMessage(Config.MESSAGERECIEVER, placeholders); component = Utility.parseMiniMessage(Config.MESSAGERECIEVER, Placeholders);
buf = ByteStreams.newDataOutput(); buf = ByteStreams.newDataOutput();
buf.writeUTF("privatemessagein"); buf.writeUTF("privatemessagein");
buf.writeUTF(player2.getUniqueId().toString()); buf.writeUTF(player2.getUniqueId().toString());
@ -76,13 +74,13 @@ public class ChatHandler {
} }
public static void sendBlockedNotification(String prefix, Player player, String input, String target, ServerConnection serverConnection) { public static void sendBlockedNotification(String prefix, Player player, String input, String target, ServerConnection serverConnection) {
TagResolver placeholders = TagResolver.resolver( TagResolver Placeholders = TagResolver.resolver(
Placeholder.parsed("prefix", prefix), Placeholder.unparsed("prefix", prefix),
Placeholder.parsed("displayname", Utility.getDisplayName(player.getUniqueId(), player.getUsername())), Placeholder.parsed("displayname", Utility.getDisplayName(player.getUniqueId(), player.getUsername())),
Placeholder.parsed("target", (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")), Placeholder.unparsed("target", (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")),
Placeholder.parsed("input", input) Placeholder.unparsed("input", input)
); );
Component blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, placeholders); Component blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, Placeholders);
serverConnection.getServer().getPlayersConnected().forEach(pl ->{ serverConnection.getServer().getPlayersConnected().forEach(pl ->{
if (pl.hasPermission("chat.alert-blocked")) { if (pl.hasPermission("chat.alert-blocked")) {
@ -118,7 +116,8 @@ public class ChatHandler {
} }
Component senderName = user.getDisplayName(); Component senderName = user.getDisplayName();
String updatedMessage = RegexManager.replaceText(player.getUsername(), uuid, message); // String updatedMessage = RegexManager.replaceText(player.getUsername(), uuid, message);
String updatedMessage = message; // NEEDS FIXING
if(updatedMessage == null) { if(updatedMessage == null) {
sendBlockedNotification("Party Language", player, message, "", serverConnection); sendBlockedNotification("Party Language", player, message, "", serverConnection);
return; // the message was blocked return; // the message was blocked
@ -132,19 +131,19 @@ public class ChatHandler {
updatedMessage = Utility.formatText(updatedMessage); updatedMessage = Utility.formatText(updatedMessage);
TagResolver placeholders = TagResolver.resolver( TagResolver Placeholders = TagResolver.resolver(
Placeholder.component("sender", senderName), Placeholder.component("sender", senderName),
Placeholder.unparsed("username", player.getUsername()), Placeholder.component("sendername", senderName),
Placeholder.unparsed("party", party.getPartyName()), Placeholder.unparsed("partyname", party.getPartyName()),
Placeholder.parsed("message", updatedMessage), Placeholder.unparsed("message", updatedMessage),
Placeholder.unparsed("server", serverConnection.getServer().getServerInfo().getName()), Placeholder.unparsed("server", serverConnection.getServer().getServerInfo().getName()),
Placeholder.component("[i]", item) Placeholder.component("[i]", item)
); );
Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, placeholders); Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, Placeholders);
sendPartyMessage(party, partyMessage, user.getIgnoredBy()); sendPartyMessage(party, partyMessage, user.getIgnoredBy());
Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, placeholders); Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, Placeholders);
for(Player pl : serverConnection.getServer().getPlayersConnected()) { for(Player pl : serverConnection.getServer().getPlayersConnected()) {
if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) { if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
pl.sendMessage(spyMessage); pl.sendMessage(spyMessage);
@ -171,13 +170,12 @@ public class ChatHandler {
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude"; serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
} }
TagResolver placeholders = TagResolver.resolver( TagResolver Placeholders = TagResolver.resolver(
Placeholder.parsed("message", Utility.formatText(message)), Placeholder.unparsed("message", message),
Placeholder.component("sender", senderName), Placeholder.component("sender", senderName),
Placeholder.parsed("server", serverName) Placeholder.unparsed("server", serverName));
);
Component component = Utility.parseMiniMessage(Config.GACFORMAT, placeholders); Component component = Utility.parseMiniMessage(Config.GACFORMAT, Placeholders);
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.chat.globaladminchat")/*TODO permission*/).forEach(target -> { VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.chat.globaladminchat")/*TODO permission*/).forEach(target -> {
target.sendMessage(component); target.sendMessage(component);
@ -192,7 +190,6 @@ public class ChatHandler {
uuid = player.getUniqueId(); uuid = player.getUniqueId();
senderName = player.getUsername(); senderName = player.getUsername();
} }
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(recipient); Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(recipient);
if (optionalPlayer.isEmpty()) { if (optionalPlayer.isEmpty()) {
targetUUID = ServerHandler.getPlayerUUID(recipient); targetUUID = ServerHandler.getPlayerUUID(recipient);
@ -203,24 +200,12 @@ public class ChatHandler {
} else { } else {
targetUUID = optionalPlayer.get().getUniqueId(); targetUUID = optionalPlayer.get().getUniqueId();
} }
Mail mail = new Mail(uuid, targetUUID, message);
if (!commandSource.hasPermission("chat.format"))
message = Utility.stripTokens(message);
else
message = Utility.parseColors(message);
Mail mail = new Mail(targetUUID, uuid, message);
ChatUser chatUser = ChatUserManager.getChatUser(targetUUID); ChatUser chatUser = ChatUserManager.getChatUser(targetUUID);
chatUser.addMail(mail); chatUser.addMail(mail);
// TODO load from config // TODO load from config
TagResolver placeholders = TagResolver.resolver( String finalSenderName = senderName;
Placeholder.parsed("sender", senderName) optionalPlayer.ifPresent(player -> player.sendMessage(Utility.parseMiniMessage("<yellow>New mail from " + finalSenderName)));
);
optionalPlayer.ifPresent(player -> player.sendMessage(Utility.parseMiniMessage(Config.mailReceived, placeholders)));
commandSource.sendMessage(Utility.parseMiniMessage(Config.mailSent,
Placeholder.component("player_name", chatUser.getDisplayName()),
Placeholder.parsed("message", message)
));
} }
public void readMail(CommandSource commandSource, String targetPlayer) { public void readMail(CommandSource commandSource, String targetPlayer) {
@ -248,15 +233,13 @@ public class ChatHandler {
Queries.markMailRead(mail); Queries.markMailRead(mail);
} }
ChatUser chatUser = ChatUserManager.getChatUser(mail.getSender()); ChatUser chatUser = ChatUserManager.getChatUser(mail.getSender());
Date sentTime = new Date(mail.getSendTime()); TagResolver Placeholders = TagResolver.resolver(
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("staffprefix", chatUser.getStaffPrefix()), Placeholder.component("staffprefix", chatUser.getStaffPrefix()),
Placeholder.component("sender", chatUser.getDisplayName()), Placeholder.component("sender", chatUser.getDisplayName()),
Placeholder.parsed("message", mail.getMessage()), Placeholder.unparsed("message", mail.getMessage()),
Placeholder.parsed("date", sentTime.toString()), Placeholder.unparsed("date", new Date(mail.getSendTime()).toString())
Placeholder.parsed("time_ago", String.valueOf(TimeUnit.MILLISECONDS.toDays(new Date().getTime() - sentTime.getTime())))
); );
Component mailMessage = Utility.parseMiniMessage(Config.mailBody, placeholders); Component mailMessage = Utility.parseMiniMessage(Config.mailBody, Placeholders);
component = component.append(Component.newline()).append(mailMessage); component = component.append(Component.newline()).append(mailMessage);
} }
component = component.append(Component.newline()).append(Utility.parseMiniMessage(Config.mailFooter)); component = component.append(Component.newline()).append(Utility.parseMiniMessage(Config.mailFooter));