Update minimessage and add helper methods

This commit is contained in:
destro174 2022-01-27 21:05:50 +01:00
parent eb31a141d0
commit 831bac1be9
18 changed files with 173 additions and 159 deletions

View File

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

View File

@ -9,27 +9,28 @@ import java.util.stream.Collectors;
public final class ChatUserManager {
private static ArrayList<ChatUser> chatUsers;
private static Map<UUID, ChatUser> chatUsers;
public static void initialize() {
chatUsers = new ArrayList<>();
chatUsers = new TreeMap<>();
}
public static void addUser(ChatUser user) {
chatUsers.add(user);
chatUsers.put(user.getUuid(), user);
}
public static void removeUser(ChatUser user) {
chatUsers.remove(user);
}
/**
* Get the ChatUser for this player or query the database to read the data.
*
* @param uuid the player who's ChatUser you'd like to get
* @return The ChatUser loaded from database or null if it's not existing.
*/
public static ChatUser getChatUser(UUID uuid) {
for(ChatUser user : chatUsers) {
if(uuid.equals(user.getUuid())) {
return user;
}
}
return Queries.loadChatUser(uuid);
return chatUsers.computeIfAbsent(uuid, k -> Queries.loadChatUser(uuid));
}
public List<Mail> getUnReadMail(ChatUser user) {
@ -38,7 +39,4 @@ public final class ChatUserManager {
.collect(Collectors.toList());
}
protected static List<ChatUser> getChatUsers() {
return Collections.unmodifiableList(chatUsers);
}
}

View File

@ -7,6 +7,8 @@ import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.model.group.Group;
@ -25,6 +27,8 @@ public class Utility {
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;
public static String stringRegen = "\\{#[A-Fa-f0-9]{6}(<)?(>)?}";
public static HashMap<String, String> colors;
private static LegacyComponentSerializer legacySerializer;
@ -211,9 +215,8 @@ public class Utility {
stringBuilder.append("<").append(hexColor1).append(">").append(split[i]);
}
}
MiniMessage miniMessage = MiniMessage.get();
return stringBuilder.length()==0 ? miniMessage.parse(message)
: miniMessage.parse(stringBuilder.toString());
return stringBuilder.length() == 0 ? Utility.parseMiniMessage(message)
: Utility.parseMiniMessage(stringBuilder.toString());
}
public static String formatText(String message) {
@ -241,4 +244,25 @@ public class Utility {
return message;
}
public static Component parseMiniMessage(String message) {
return parseMiniMessage(message, null);
}
public static Component parseMiniMessage(String message, List<Template> templates) {
if (templates == null) {
return getMiniMessage().deserialize(message);
} else {
return getMiniMessage().deserialize(message, TemplateResolver.templates(templates));
}
}
public static String stripTokens(String input) {
return getMiniMessage().stripTokens(input);
}
public static MiniMessage getMiniMessage() {
if (miniMessage == null) miniMessage = MiniMessage.miniMessage();
return miniMessage;
}
}

View File

@ -33,7 +33,7 @@ dependencies {
// implementation(project(":api"))
implementation(project(":galaxy"))
implementation(project(":velocity"))
// implementation("net.kyori", "adventure-text-minimessage", "4.1.0-SNAPSHOT") {
// implementation("net.kyori", "adventure-text-minimessage", "4.2.0-SNAPSHOT") {
// exclude("net.kyori")
// exclude("net.kyori.examination")
// }
@ -52,7 +52,8 @@ tasks {
listOf(
"net.kyori.adventure.text.minimessage",
"org.spongepowered.configurate"
).forEach { relocate(it, "${rootProject.group}.lib.$it") }
// ).forEach { relocate(it, "${rootProject.group}.lib.$it") }
).forEach { relocate(it, "${rootProject.group}.lib.${it.substringAfterLast(".")}") }
}
build {

View File

@ -43,7 +43,6 @@ public class ChatParty implements CommandExecutor, TabCompleter {
new BukkitRunnable() {
@Override
public void run() {
MiniMessage miniMessage = MiniMessage.get();
switch (args[0].toLowerCase()) {
case "create" -> {
if (args.length < 3 || !args[1].matches("[\\w]{3,16}") || !args[2].matches("[\\w]{3,16}")) {
@ -51,14 +50,14 @@ public class ChatParty implements CommandExecutor, TabCompleter {
break;
}
if (PartyManager.getParty(args[1]) != null) {
sender.sendMessage(MiniMessage.get().parse("<red>A chat party with this name already exists.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>A chat party with this name already exists.</red>"));
break;
}
Party party = Queries.addParty(player.getUniqueId(), args[1], args[2]);
// party.addUser(ChatUserManager.getChatUser(player.getUniqueId())); //Removed until we can get nicknames to translate to colors correctly
party.addUser(ChatUserManager.getChatUser(player.getUniqueId()), player.getName());
PartyManager.addParty(party);
sender.sendMessage(MiniMessage.get().parse("<green>You created a chat party called: '<gold>" +
sender.sendMessage(Utility.parseMiniMessage("<green>You created a chat party called: '<gold>" +
party.getPartyName() + "</gold>' with the password: '<gold>" +
party.getPartyPassword() + "</gold>'</green>"));
update(player, party.getPartyId());
@ -70,22 +69,22 @@ public class ChatParty implements CommandExecutor, TabCompleter {
}
Party party = PartyManager.getParty(player.getUniqueId());
if (party == null) {
sender.sendMessage(MiniMessage.get().parse("<red>You're not in a chat party.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>You're not in a chat party.</red>"));
break;
}
if (!party.getOwnerUuid().equals(player.getUniqueId())) {
sender.sendMessage(MiniMessage.get().parse("<red>You don't own this chat party.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>You don't own this chat party.</red>"));
break;
}
Player target = Bukkit.getPlayer(args[1]);
if (target == null || !target.isOnline()) {
sender.sendMessage(MiniMessage.get().parse("<red>The player must be on the same server to receive an invite.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>The player must be on the same server to receive an invite.</red>"));
break;
}
target.sendMessage(MiniMessage.get().parse("<click:run_command:'/chatparty join " + party.getPartyName() + " " + party.getPartyPassword() +
target.sendMessage(Utility.parseMiniMessage("<click:run_command:'/chatparty join " + party.getPartyName() + " " + party.getPartyPassword() +
"'><dark_aqua>You received an invite to join " + party.getPartyName() + " click this message to accept.</dark_aqua></click>"));
sender.sendMessage(MiniMessage.get().parse("<green>You send a chat party invite to " + target.getName() + "!</green>"));
sender.sendMessage(Utility.parseMiniMessage("<green>You send a chat party invite to " + target.getName() + "!</green>"));
}
case "join" -> {
if (args.length < 3 || !args[1].matches("[\\w]{3,16}") || !args[2].matches("[\\w]{3,16}")) {
@ -95,23 +94,23 @@ public class ChatParty implements CommandExecutor, TabCompleter {
Party party = PartyManager.getParty(args[1]);
if (party == null) {
sender.sendMessage(MiniMessage.get().parse("<red>This chat party does not exist.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>This chat party does not exist.</red>"));
break;
}
if (!party.getPartyPassword().equals(args[2])) {
sender.sendMessage(MiniMessage.get().parse("<red>Invalid password.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>Invalid password.</red>"));
break;
}
// party.addUser(ChatUserManager.getChatUser(player.getUniqueId())); //Removed until we can get nicknames to translate to colors correctly
party.addUser(ChatUserManager.getChatUser(player.getUniqueId()), player.getName());
sender.sendMessage(MiniMessage.get().parse("<green>You joined " + party.getPartyName() + "!</green>"));
sender.sendMessage(Utility.parseMiniMessage("<green>You joined " + party.getPartyName() + "!</green>"));
update(player, party.getPartyId());
}
case "leave" -> {
Party party = PartyManager.getParty(player.getUniqueId());
if (party == null) {
sender.sendMessage(MiniMessage.get().parse("<red>You're not in a chat party.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>You're not in a chat party.</red>"));
break;
}
@ -119,7 +118,7 @@ public class ChatParty implements CommandExecutor, TabCompleter {
if (party.getOwnerUuid().equals(player.getUniqueId())) {
if (party.getPartyUsers().size() > 0) {
UUID uuid = party.newOwner();
sender.sendMessage(MiniMessage.get().parse("<dark_aqua>Since you own this chat party a new party owner will be chosen.<dark_aqua>"));
sender.sendMessage(Utility.parseMiniMessage("<dark_aqua>Since you own this chat party a new party owner will be chosen.<dark_aqua>"));
ChatPlugin.getInstance().getChatHandler().partyMessage(party, player, "<dark_aqua>" +
player.getName() +
" left the chat party, the new party owner is " + party.getPartyUser(uuid).getPlayerName());
@ -127,7 +126,7 @@ public class ChatParty implements CommandExecutor, TabCompleter {
party.delete();
}
} else {
sender.sendMessage(MiniMessage.get().parse("<green>You have left the chat party!</green>"));
sender.sendMessage(Utility.parseMiniMessage("<green>You have left the chat party!</green>"));
}
update(player, party.getPartyId());
}
@ -138,7 +137,7 @@ public class ChatParty implements CommandExecutor, TabCompleter {
}
Party party = PartyManager.getParty(player.getUniqueId());
if (party == null) {
sender.sendMessage(MiniMessage.get().parse("<red>You're not in a chat party.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>You're not in a chat party.</red>"));
break;
}
if (!party.getOwnerUuid().equals(player.getUniqueId())) {
@ -147,28 +146,28 @@ public class ChatParty implements CommandExecutor, TabCompleter {
}
OfflinePlayer offlinePlayerIfCached = Bukkit.getOfflinePlayerIfCached((args[1]));
if (offlinePlayerIfCached == null) {
sender.sendMessage(MiniMessage.get().parse("<red>Unable to find this player.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>Unable to find this player.</red>"));
return;
}
party.removeUser(ChatUserManager.getChatUser(offlinePlayerIfCached.getUniqueId()));
if (offlinePlayerIfCached.getUniqueId().equals(party.getOwnerUuid())) {
sender.sendMessage(MiniMessage.get().parse("<red>You can't remove yourself, please leave instead.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>You can't remove yourself, please leave instead.</red>"));
return;
}
if (offlinePlayerIfCached.isOnline()) {
Objects.requireNonNull(offlinePlayerIfCached.getPlayer())
.sendMessage(MiniMessage.get().parse("<red>You were removed from the '" + party.getPartyName() + "' chat party."));
.sendMessage(Utility.parseMiniMessage("<red>You were removed from the '" + party.getPartyName() + "' chat party."));
}
sender.sendMessage(MiniMessage.get().parse("<green>You removed " + offlinePlayerIfCached.getName() + " from the chat party!</green>"));
sender.sendMessage(Utility.parseMiniMessage("<green>You removed " + offlinePlayerIfCached.getName() + " from the chat party!</green>"));
update(player, party.getPartyId());
}
case "info" -> {
Party party = PartyManager.getParty(player.getUniqueId());
if (party == null) {
sender.sendMessage(MiniMessage.get().parse("<red>You're not in a chat party.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>You're not in a chat party.</red>"));
break;
}
@ -183,13 +182,13 @@ public class ChatParty implements CommandExecutor, TabCompleter {
}
List<Template> templates = new ArrayList<>(List.of(
Template.of("partyname", party.getPartyName()),
Template.of("password", party.getPartyPassword()),
Template.of("ownername", party.getPartyUser(party.getOwnerUuid()).getDisplayName()),
Template.of("members", Component.join(Component.text(", "), displayNames)),
Template.of("message", message)));
Template.template("partyname", party.getPartyName()),
Template.template("password", party.getPartyPassword()),
Template.template("ownername", party.getPartyUser(party.getOwnerUuid()).getDisplayName()),
Template.template("members", Component.join(Component.text(", "), displayNames)),
Template.template("message", message)));
sender.sendMessage(miniMessage.parse("<message>", templates));
sender.sendMessage(Utility.parseMiniMessage("<message>", templates));
}
// TODO: 08/08/2021 add a way to change the password and owner (and name?)
default -> {
@ -203,7 +202,7 @@ public class ChatParty implements CommandExecutor, TabCompleter {
}
private void invalidMessage(CommandSender sender, CommandUsage commandUsage) {
sender.sendMessage(MiniMessage.get().parse("<red>Invalid command, proper usage: %command%.</red>".replaceAll("%command%", commandUsage.message)));
sender.sendMessage(Utility.parseMiniMessage("<red>Invalid command, proper usage: %command%.</red>".replaceAll("%command%", commandUsage.message)));
}
private void helpMessage(CommandSender sender) {
@ -213,7 +212,7 @@ public class ChatParty implements CommandExecutor, TabCompleter {
stringBuilder.append("\n- ").append(commandUsage.message);
}
stringBuilder.append("</green>");
sender.sendMessage(MiniMessage.get().parse(stringBuilder.toString()));
sender.sendMessage(Utility.parseMiniMessage(stringBuilder.toString()));
}
@Override

View File

@ -5,6 +5,7 @@ import com.alttd.chat.config.Config;
import com.alttd.chat.database.Queries;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.Utility;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.kyori.adventure.text.minimessage.MiniMessage;
@ -43,7 +44,7 @@ public class Ignore implements CommandExecutor {
StringBuilder ignoredMessage = new StringBuilder();
if (userNames.isEmpty()) {
player.sendMessage(MiniMessage.get().parse("You don't have anyone ignored!")); //TODO load from config
player.sendMessage(Utility.parseMiniMessage("You don't have anyone ignored!")); //TODO load from config
return;
}
@ -51,7 +52,7 @@ public class Ignore implements CommandExecutor {
userNames.forEach(username -> ignoredMessage.append(username).append("\n"));
ignoredMessage.delete(ignoredMessage.length() - 1, ignoredMessage.length());
player.sendMessage(MiniMessage.get().parse(ignoredMessage.toString()));
player.sendMessage(Utility.parseMiniMessage(ignoredMessage.toString()));
}
}.runTaskAsynchronously(plugin);
return false;

View File

@ -26,7 +26,7 @@ public class MuteServer implements CommandExecutor {
public void run() {
UUID uuid = player.getUniqueId();
if (!Utility.hasPermission(uuid, Config.SERVERMUTEPERMISSION)) {
sender.sendMessage(MiniMessage.get().parse("<red>You don't have permission to use this command.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>You don't have permission to use this command.</red>"));
return;
}
@ -34,9 +34,9 @@ public class MuteServer implements CommandExecutor {
Component component;
if (ChatPlugin.getInstance().serverMuted()) {
component = MiniMessage.get().parse(Utility.getDisplayName(player.getUniqueId(), player.getName()) + " <red>muted</red><white> chat.");
component = Utility.parseMiniMessage(Utility.getDisplayName(player.getUniqueId(), player.getName()) + " <red>muted</red><white> chat.");
} else {
component = MiniMessage.get().parse(Utility.getDisplayName(player.getUniqueId(), player.getName()) + " <green>un-muted</green><white> chat.");
component = Utility.parseMiniMessage(Utility.getDisplayName(player.getUniqueId(), player.getName()) + " <green>un-muted</green><white> chat.");
}
Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage(component));

View File

@ -3,6 +3,7 @@ package com.alttd.chat.commands;
import com.alttd.chat.ChatPlugin;
import com.alttd.chat.managers.PartyManager;
import com.alttd.chat.objects.Party;
import com.alttd.chat.util.Utility;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
@ -21,7 +22,7 @@ public class PartyChat implements CommandExecutor {
}
Party party = PartyManager.getParty(player.getUniqueId());
if (party == null) {
sender.sendMessage(MiniMessage.get().parse("<red>You are not in a party. For more info do <gold>/party</gold>.</red>"));
sender.sendMessage(Utility.parseMiniMessage("<red>You are not in a party. For more info do <gold>/party</gold>.</red>"));
return true;
}

View File

@ -27,7 +27,7 @@ public class Spy implements CommandExecutor {
UUID uuid = ((Player) sender).getUniqueId();
ChatUser user = ChatUserManager.getChatUser(uuid);
user.toggleSpy();
sender.sendMessage(MiniMessage.get().parse("You have turned spy " + (user.isSpy() ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
sender.sendMessage(Utility.parseMiniMessage("You have turned spy " + (user.isSpy() ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
}
}.runTaskAsynchronously(ChatPlugin.getInstance());
return false;

View File

@ -33,7 +33,7 @@ public class ToggleGlobalChat implements CommandExecutor {
//chatUser.toggleGc();
Utility.flipPermission(uuid, Config.GCPERMISSION);
//Queries.setGlobalChatState(chatUser.isGcOn(), chatUser.getUuid());
sender.sendMessage(MiniMessage.get().parse("You have turned globalchat " + (!Utility.hasPermission(uuid, Config.GCPERMISSION) ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
sender.sendMessage(Utility.parseMiniMessage("You have turned globalchat " + (!Utility.hasPermission(uuid, Config.GCPERMISSION) ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
}
}.runTaskAsynchronously(ChatPlugin.getInstance());
return false;

View File

@ -30,13 +30,11 @@ public class ChatHandler {
private final ChatPlugin plugin;
private final MiniMessage miniMessage;
private final Component GCNOTENABLED;
public ChatHandler() {
plugin = ChatPlugin.getInstance();
miniMessage = MiniMessage.get();
GCNOTENABLED = miniMessage.parse(Config.GCNOTENABLED);
GCNOTENABLED = Utility.parseMiniMessage(Config.GCNOTENABLED);
}
public void privateMessage(Player player, String target, String message) {
@ -49,7 +47,7 @@ public class ChatHandler {
}
if(!player.hasPermission("chat.format")) {
updatedMessage = miniMessage.stripTokens(updatedMessage);
updatedMessage = Utility.stripTokens(updatedMessage);
} else {
updatedMessage = Utility.parseColors(updatedMessage);
}
@ -60,15 +58,15 @@ public class ChatHandler {
updatedMessage = Utility.formatText(updatedMessage);
List<Template> templates = new ArrayList<>(List.of(
Template.of("message", updatedMessage),
Template.of("sendername", player.getName()),
Template.of("receivername", target),
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
Template.template("message", updatedMessage),
Template.template("sendername", player.getName()),
Template.template("receivername", target),
Template.template("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
Component component = miniMessage.parse("<message>", templates);
Component component = Utility.parseMiniMessage("<message>", templates);
sendPrivateMessage(player, target, "privatemessage", component);
Component spymessage = miniMessage.parse(Config.MESSAGESPY, templates);
Component spymessage = Utility.parseMiniMessage(Config.MESSAGESPY, templates);
for(Player pl : Bukkit.getOnlinePlayers()) {
if(pl.hasPermission(Config.SPYPERMISSION) && ChatUserManager.getChatUser(pl.getUniqueId()).isSpy() && !pl.equals(player) && !pl.getName().equalsIgnoreCase(target)) {
pl.sendMessage(spymessage);
@ -89,7 +87,7 @@ public class ChatHandler {
long timeLeft = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - user.getGcCooldown());
if(timeLeft <= Config.GCCOOLDOWN && !player.hasPermission("chat.globalchat.cooldownbypass")) { // player is on cooldown and should wait x seconds
player.sendMessage(miniMessage.parse(Config.GCONCOOLDOWN, Template.of("cooldown", Config.GCCOOLDOWN-timeLeft+"")));
player.sendMessage(Utility.parseMiniMessage(Config.GCONCOOLDOWN, List.of(Template.template("cooldown", Config.GCCOOLDOWN-timeLeft+""))));
return;
}
@ -103,7 +101,7 @@ public class ChatHandler {
}
if(!player.hasPermission("chat.format")) {
updatedMessage = miniMessage.stripTokens(updatedMessage);
updatedMessage = Utility.stripTokens(updatedMessage);
} else {
updatedMessage = Utility.parseColors(updatedMessage);
}
@ -114,20 +112,20 @@ public class ChatHandler {
updatedMessage = Utility.formatText(updatedMessage);
List<Template> templates = new ArrayList<>(List.of(
Template.of("sender", senderName),
Template.of("prefix", prefix),
Template.of("message", updatedMessage),
Template.of("server", Bukkit.getServerName()),
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
Template.template("sender", senderName),
Template.template("prefix", prefix),
Template.template("message", updatedMessage),
Template.template("server", Bukkit.getServerName()),
Template.template("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
Component component = miniMessage.parse(Config.GCFORMAT, templates);
Component component = Utility.parseMiniMessage(Config.GCFORMAT, templates);
user.setGcCooldown(System.currentTimeMillis());
sendPluginMessage(player, "globalchat", component);
}
public void chatChannel(Player player, CustomChannel channel, String message) {
if (!player.hasPermission(channel.getPermission())) {
player.sendMessage(MiniMessage.get().parse("<red>You don't have permission to use this channel.</red>"));
player.sendMessage(Utility.parseMiniMessage("<red>You don't have permission to use this channel.</red>"));
return;
}
@ -143,7 +141,7 @@ public class ChatHandler {
}
if(!player.hasPermission("chat.format")) {
updatedMessage = miniMessage.stripTokens(updatedMessage);
updatedMessage = Utility.stripTokens(updatedMessage);
}
if(updatedMessage.contains("[i]")) updatedMessage = updatedMessage.replace("[i]", "<[i]>");
@ -151,13 +149,13 @@ public class ChatHandler {
updatedMessage = Utility.formatText(updatedMessage);
List<Template> templates = new ArrayList<>(List.of(
Template.of("sender", senderName),
Template.of("message", updatedMessage),
Template.of("server", Bukkit.getServerName()),
Template.of("channel", channel.getChannelName()),
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
Template.template("sender", senderName),
Template.template("message", updatedMessage),
Template.template("server", Bukkit.getServerName()),
Template.template("channel", channel.getChannelName()),
Template.template("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
Component component = miniMessage.parse(channel.getFormat(), templates);
Component component = Utility.parseMiniMessage(channel.getFormat(), templates);
if (channel.isProxy()) {
sendChatChannelMessage(player, channel.getChannelName(), "chatchannel", component);
@ -179,7 +177,7 @@ public class ChatHandler {
}
if(!player.hasPermission("chat.format")) {
updatedMessage = miniMessage.stripTokens(updatedMessage);
updatedMessage = Utility.stripTokens(updatedMessage);
}
if(updatedMessage.contains("[i]")) updatedMessage = updatedMessage.replace("[i]", "<[i]>");
@ -187,17 +185,17 @@ public class ChatHandler {
updatedMessage = Utility.formatText(updatedMessage);
List<Template> templates = new ArrayList<>(List.of(
Template.of("sender", senderName),
Template.of("sendername", senderName),
Template.of("partyname", party.getPartyName()),
Template.of("message", updatedMessage),
Template.of("server", Bukkit.getServerName()),
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
Template.template("sender", senderName),
Template.template("sendername", senderName),
Template.template("partyname", party.getPartyName()),
Template.template("message", updatedMessage),
Template.template("server", Bukkit.getServerName()),
Template.template("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
Component component = miniMessage.parse(Config.PARTY_FORMAT, templates);
Component component = Utility.parseMiniMessage(Config.PARTY_FORMAT, templates);
sendPartyMessage(player, party.getPartyId(), component);
Component spyMessage = miniMessage.parse(Config.PARTY_SPY, templates);
Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, templates);
for(Player pl : Bukkit.getOnlinePlayers()) {
if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
pl.sendMessage(spyMessage);

View File

@ -47,8 +47,6 @@ public class ChatListener implements Listener, ChatRenderer {
Component input = event.message();
String message = PlainComponentSerializer.plain().serialize(input);
MiniMessage miniMessage = MiniMessage.get();
message = RegexManager.replaceText(player.getName(), player.getUniqueId(), message); // todo a better way for this
if(message == null) {
event.setCancelled(true);
@ -56,9 +54,8 @@ public class ChatListener implements Listener, ChatRenderer {
return; // the message was blocked
}
if(!player.hasPermission("chat.format")) {
message = miniMessage.stripTokens(message);
message = Utility.stripTokens(message);
} else {
message = Utility.parseColors(message);
}
@ -69,11 +66,11 @@ public class ChatListener implements Listener, ChatRenderer {
message = Utility.formatText(message);
List<Template> templates = new ArrayList<>(List.of(
Template.of("message", message),
Template.of("[i]", ChatHandler.itemComponent(player.getInventory().getItemInMainHand()))
Template.template("message", message),
Template.template("[i]", ChatHandler.itemComponent(player.getInventory().getItemInMainHand()))
));
Component component = miniMessage.parse("<message>", templates);
Component component = Utility.parseMiniMessage("<message>", templates);
event.message(component);
event.renderer(this);
@ -84,15 +81,15 @@ public class ChatListener implements Listener, ChatRenderer {
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
List<Template> templates = new ArrayList<>(List.of(
Template.of("sender", user.getDisplayName()),
Template.of("sendername", player.getName()),
Template.of("prefix", user.getPrefix()),
Template.of("prefixall", user.getPrefixAll()),
Template.of("staffprefix", user.getStaffPrefix()),
Template.of("message", message)
Template.template("sender", user.getDisplayName()),
Template.template("sendername", player.getName()),
Template.template("prefix", user.getPrefix()),
Template.template("prefixall", user.getPrefixAll()),
Template.template("staffprefix", user.getStaffPrefix()),
Template.template("message", message)
));
return MiniMessage.get().parse(Config.CHATFORMAT, templates);
return Utility.parseMiniMessage(Config.CHATFORMAT, templates);
}
}

View File

@ -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.Utility;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import net.kyori.adventure.text.Component;
@ -124,7 +125,7 @@ public class PluginMessage implements PluginMessageListener {
public void run() {
PartyUser user = party.getPartyUser(uuid);
if(user != null) {
Component component = MiniMessage.get().parse("<dark_aqua>* " + user.getPlayerName() + " logged in to Altitude.");
Component component = Utility.parseMiniMessage("<dark_aqua>* " + user.getPlayerName() + " logged in to Altitude.");
Bukkit.getOnlinePlayers().stream()
.filter(p -> party.getPartyUsersUuid().contains(p.getUniqueId()))
@ -148,7 +149,7 @@ public class PluginMessage implements PluginMessageListener {
public void run() {
PartyUser user = party.getPartyUser(uuid);
if(user != null) {
Component component = MiniMessage.get().parse("<dark_aqua>* " + user.getPlayerName() + " logged out of Altitude.");
Component component = Utility.parseMiniMessage("<dark_aqua>* " + user.getPlayerName() + " logged out of Altitude.");
Bukkit.getOnlinePlayers().stream()
.filter(p -> party.getPartyUsersUuid().contains(p.getUniqueId()))

View File

@ -13,22 +13,20 @@ import java.util.List;
public class GalaxyUtility {
public static void sendBlockedNotification(String prefix, Player player, String input, String target) {
MiniMessage miniMessage = MiniMessage.get();
List<Template> templates = new ArrayList<>(List.of(
Template.of("prefix", prefix),
Template.of("displayname", Utility.getDisplayName(player.getUniqueId(), player.getName())),
Template.of("target", (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")),
Template.of("input", input)
Template.template("prefix", prefix),
Template.template("displayname", Utility.getDisplayName(player.getUniqueId(), player.getName())),
Template.template("target", (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")),
Template.template("input", input)
));
Component blockedNotification = miniMessage.parse(Config.NOTIFICATIONFORMAT, templates);
Component blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, templates);
Bukkit.getOnlinePlayers().forEach(a ->{
if (a.hasPermission("chat.alert-blocked")) {
a.sendMessage(blockedNotification);
}
});
player.sendMessage(miniMessage.parse("<red>The language you used in your message is not allowed, " +
player.sendMessage(Utility.parseMiniMessage("<red>The language you used in your message is not allowed, " +
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
}

View File

@ -9,7 +9,7 @@ dependencies {
annotationProcessor("com.velocitypowered:velocity-api:3.0.0")
implementation("mysql:mysql-connector-java:8.0.27") // mysql
implementation("org.spongepowered", "configurate-yaml", "4.1.2")
implementation("net.kyori", "adventure-text-minimessage", "4.1.0-SNAPSHOT") {
implementation("net.kyori", "adventure-text-minimessage", "4.2.0-SNAPSHOT") {
exclude("net.kyori")
exclude("net.kyori.examination")
}
@ -24,7 +24,7 @@ tasks {
listOf(
"net.kyori.adventure.text.minimessage",
"org.spongepowered.configurate"
).forEach { relocate(it, "${rootProject.group}.lib.$it") }
).forEach { relocate(it, "${rootProject.group}.lib.${it.substringAfterLast(".")}") }
}
build {

View File

@ -1,5 +1,6 @@
package com.alttd.velocitychat.handlers;
import com.alttd.chat.util.Utility;
import com.alttd.velocitychat.VelocityChat;
import com.alttd.chat.config.Config;
import com.alttd.chat.managers.ChatUserManager;
@ -33,21 +34,19 @@ public class ChatHandler {
Player player2 = optionalPlayer2.get();
ChatUser targetUser = ChatUserManager.getChatUser(player2.getUniqueId());
MiniMessage miniMessage = MiniMessage.get();
List<Template> templates = new ArrayList<>(List.of(
Template.of("sender", senderUser.getDisplayName()),
Template.of("sendername", player.getUsername()),
Template.of("receiver", targetUser.getDisplayName()),
Template.of("receivername", player2.getUsername()),
Template.of("message", GsonComponentSerializer.gson().deserialize(message)),
Template.of("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")));
Template.template("sender", senderUser.getDisplayName()),
Template.template("sendername", player.getUsername()),
Template.template("receiver", targetUser.getDisplayName()),
Template.template("receivername", player2.getUsername()),
Template.template("message", GsonComponentSerializer.gson().deserialize(message)),
Template.template("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")));
ServerConnection serverConnection;
if(player.getCurrentServer().isPresent() && player2.getCurrentServer().isPresent()) {
// redirect to the sender
serverConnection = player.getCurrentServer().get();
Component component = miniMessage.parse(Config.MESSAGESENDER, templates);
Component component = Utility.parseMiniMessage(Config.MESSAGESENDER, templates);
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
buf.writeUTF("privatemessageout");
buf.writeUTF(player.getUniqueId().toString());
@ -58,7 +57,7 @@ public class ChatHandler {
//redirect to the receiver
serverConnection = player2.getCurrentServer().get();
component = miniMessage.parse(Config.MESSAGERECIEVER, templates);
component = Utility.parseMiniMessage(Config.MESSAGERECIEVER, templates);
buf = ByteStreams.newDataOutput();
buf.writeUTF("privatemessagein");
buf.writeUTF(player2.getUniqueId().toString());
@ -70,16 +69,14 @@ public class ChatHandler {
// ChatUser targetUser = ChatUserManager.getChatUser(player2.getUniqueId());
//
// MiniMessage miniMessage = MiniMessage.get();
//
// List<Template> templates = new ArrayList<>(List.of(
// Template.of("sender", senderUser.getDisplayName()),
// Template.of("receiver", targetUser.getDisplayName()),
// Template.of("message", message),
// Template.of("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")));
// Template.template("sender", senderUser.getDisplayName()),
// Template.template("receiver", targetUser.getDisplayName()),
// Template.template("message", message),
// Template.template("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")));
//
// Component senderMessage = miniMessage.parse(Config.MESSAGESENDER, templates);
// Component receiverMessage = miniMessage.parse(Config.MESSAGERECIEVER, templates);
// Component senderMessage = Utility.parseMiniMessage(Config.MESSAGESENDER, templates);
// Component receiverMessage = Utility.parseMiniMessage(Config.MESSAGERECIEVER, templates);
//
// player.sendMessage(senderMessage);
// player2.sendMessage(receiverMessage);
@ -104,14 +101,12 @@ public class ChatHandler {
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
}
MiniMessage miniMessage = MiniMessage.get();
List<Template> templates = new ArrayList<>(List.of(
Template.of("message", message),
Template.of("sender", senderName),
Template.of("server", serverName)));
Template.template("message", message),
Template.template("sender", senderName),
Template.template("server", serverName)));
Component component = miniMessage.parse(Config.GACFORMAT, templates);
Component component = Utility.parseMiniMessage(Config.GACFORMAT, templates);
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.proxy.globaladminchat")/*TODO permission*/).forEach(target -> {
target.sendMessage(component);

View File

@ -1,5 +1,6 @@
package com.alttd.velocitychat.listeners;
import com.alttd.chat.util.Utility;
import com.alttd.velocitychat.VelocityChat;
import com.alttd.velocitychat.events.GlobalAdminChatEvent;
import com.alttd.chat.config.Config;
@ -9,8 +10,11 @@ import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
// TODO code CLEANUP
public class ChatListener {
@ -32,15 +36,13 @@ public class ChatListener {
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
}
MiniMessage miniMessage = MiniMessage.get();
List<Template> templates = new ArrayList<>(List.of(
Template.template("sender", senderName),
Template.template("message", event.getMessage()),
Template.template("server", serverName)
));
Map<String, String> map = new HashMap<>();
map.put("sender", senderName);
map.put("message", event.getMessage());
map.put("server", serverName);
Component message = miniMessage.parse(Config.GACFORMAT, map);
Component message = Utility.parseMiniMessage(Config.GACFORMAT, templates);
plugin.getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.proxy.globaladminchat")).forEach(target -> {
target.sendMessage(message);

View File

@ -1,5 +1,6 @@
package com.alttd.velocitychat.listeners;
import com.alttd.chat.util.Utility;
import com.alttd.velocitychat.VelocityChat;
import com.alttd.chat.config.Config;
import com.alttd.velocitychat.data.ServerWrapper;
@ -57,31 +58,30 @@ public class ProxyPlayerListener {
@Subscribe
public void serverConnected(ServerConnectedEvent event) {
ServerHandler serverHandler = VelocityChat.getPlugin().getServerHandler();
MiniMessage miniMessage = MiniMessage.get();
if (event.getPreviousServer().isPresent()) {
RegisteredServer previousServer = event.getPreviousServer().get();
Player player = event.getPlayer();
List<Template> templates = new ArrayList<>(List.of(
Template.of("player", player.getUsername()),
Template.of("from_server", previousServer.getServerInfo().getName()),
Template.of("to_server", event.getServer().getServerInfo().getName())));
Template.template("player", player.getUsername()),
Template.template("from_server", previousServer.getServerInfo().getName()),
Template.template("to_server", event.getServer().getServerInfo().getName())));
ServerWrapper wrapper = serverHandler.getWrapper(previousServer.getServerInfo().getName());
if(wrapper != null) {
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), miniMessage.parse(Config.SERVERSWTICHMESSAGETO, templates));
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERSWTICHMESSAGETO, templates));
}
wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().getName());
if(wrapper != null) {
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), miniMessage.parse(Config.SERVERSWTICHMESSAGEFROM, templates));
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERSWTICHMESSAGEFROM, templates));
}
} else {
List<Template> templates = new ArrayList<>(List.of(
Template.of("player", event.getPlayer().getUsername())
Template.template("player", event.getPlayer().getUsername())
));
ServerWrapper wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().getName());
if(wrapper != null) {
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), miniMessage.parse(Config.SERVERJOINMESSAGE, templates));
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERJOINMESSAGE, templates));
}
}
}
@ -89,17 +89,16 @@ public class ProxyPlayerListener {
@Subscribe
public void serverDisconnected(DisconnectEvent event) {
ServerHandler serverHandler = VelocityChat.getPlugin().getServerHandler();
MiniMessage miniMessage = MiniMessage.get();
if (event.getLoginStatus().equals(DisconnectEvent.LoginStatus.SUCCESSFUL_LOGIN) && event.getPlayer().getCurrentServer().isPresent()) {
RegisteredServer registeredServer = event.getPlayer().getCurrentServer().get().getServer();
List<Template> templates = new ArrayList<>(List.of(
Template.of("player", event.getPlayer().getUsername()),
Template.of("from_server", registeredServer.getServerInfo().getName())));
Template.template("player", event.getPlayer().getUsername()),
Template.template("from_server", registeredServer.getServerInfo().getName())));
ServerWrapper wrapper = serverHandler.getWrapper(registeredServer.getServerInfo().getName());
if(wrapper != null) {
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), miniMessage.parse(Config.SERVERLEAVEMESSAGE, templates));
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERLEAVEMESSAGE, templates));
}
}
}