Fix nicknames and prefixes

This commit is contained in:
destro174 2021-07-18 00:48:55 +02:00
parent 3f7084eeb7
commit 96dbdc6dd0
18 changed files with 178 additions and 109 deletions

View File

@ -20,7 +20,7 @@
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>
<dependency><!--TODO update to version 4.0.0--> <dependency>
<groupId>org.spongepowered</groupId> <groupId>org.spongepowered</groupId>
<artifactId>configurate-yaml</artifactId> <artifactId>configurate-yaml</artifactId>
<version>3.7.1</version> <version>3.7.1</version>

View File

@ -13,15 +13,15 @@ public class ChatImplementation implements ChatAPI{
private static ChatAPI instance; private static ChatAPI instance;
private LuckPerms luckPerms; private LuckPerms luckPerms;
private DatabaseConnection databaseConnection; // todo this isn't needed can be removed private DatabaseConnection databaseConnection;
public ChatImplementation() { public ChatImplementation() {
instance = this; instance = this;
Config.init(); Config.init();
luckPerms = getLuckPerms(); luckPerms = getLuckPerms();
databaseConnection = getDataBase(); // todo fix sql databaseConnection = getDataBase();
Queries.createTables(); // todo fix sql Queries.createTables();
ChatUserManager.initialize(); // loads all the users from the db and adds them. ChatUserManager.initialize(); // loads all the users from the db and adds them.
RegexManager.initialize(); // load the filters and regexes from config RegexManager.initialize(); // load the filters and regexes from config

View File

@ -202,7 +202,7 @@ public final class Config {
} }
// TODO prefixes need hovers, this hasn't been setup yet! // TODO prefixes need hovers, this hasn't been setup yet!
public static String CHATFORMAT = "<white><light_purple><prefixall></light_purple> <gray><sender>: </gray><message>"; // @teri help with the default formatting? public static String CHATFORMAT = "<white><light_purple><prefixall> <gray><sender>: <message>";
private static void Chat() { private static void Chat() {
CHATFORMAT = getString("chat.format", CHATFORMAT); CHATFORMAT = getString("chat.format", CHATFORMAT);
} }

View File

@ -45,8 +45,6 @@ public class DatabaseConnection {
e.printStackTrace(); e.printStackTrace();
} }
ALogger.info("jdbc:mysql://" + Config.IP + ":" + Config.PORT + "/" + Config.DATABASE + "?autoReconnect=true"+
"&useSSL=false");
connection = DriverManager.getConnection( connection = DriverManager.getConnection(
"jdbc:mysql://" + Config.IP + ":" + Config.PORT + "/" + Config.DATABASE + "?autoReconnect=true"+ "jdbc:mysql://" + Config.IP + ":" + Config.PORT + "/" + Config.DATABASE + "?autoReconnect=true"+
"&useSSL=false", "&useSSL=false",

View File

@ -2,6 +2,7 @@ package com.alttd.chat.objects;
import com.alttd.chat.database.Queries; import com.alttd.chat.database.Queries;
import com.alttd.chat.util.Utility; import com.alttd.chat.util.Utility;
import net.kyori.adventure.text.Component;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.UUID; import java.util.UUID;
@ -10,10 +11,11 @@ public class ChatUser {
private final UUID uuid; // player uuid private final UUID uuid; // player uuid
private final int partyId; // the party they are in private final int partyId; // the party they are in
private boolean toggledPartyChat; // should chat messages instantly go to party chat when added, idk if this should be saved private boolean toggledPartyChat; // should chat messages instantly go to party chat when added, idk if this should be saved
private String displayName; // the nickname, doesn't need to be saved with the chatuser object, could be saved but we can get it from the nicknamesview private String name; // the nickname, doesn't need to be saved with the chatuser object, could be saved but we can get it from the nicknamesview
private String prefix; // doesn't need saving, we get this from luckperms private Component displayName; // the nickname, doesn't need to be saved with the chatuser object, could be saved but we can get it from the nicknamesview
private String staffPrefix; // doesn't need saving, we get this from luckperms private Component prefix; // doesn't need saving, we get this from luckperms
private String prefixAll; // doesn't need saving, we get this from luckperms private Component staffPrefix; // doesn't need saving, we get this from luckperms
private Component prefixAll; // doesn't need saving, we get this from luckperms
private boolean toggleGc; // should be saved, this toggles if the player can see and use global chat private boolean toggleGc; // should be saved, this toggles if the player can see and use global chat
private String replyTarget; // reply target for use in /msg i don't mind setting this to null on login, feedback? private String replyTarget; // reply target for use in /msg i don't mind setting this to null on login, feedback?
private long gcCooldown; // the time when they last used gc, is used for the cooldown, i wouldn't save this, but setting this to the login time means they can't use gc for 30 seconds after logging in private long gcCooldown; // the time when they last used gc, is used for the cooldown, i wouldn't save this, but setting this to the login time means they can't use gc for 30 seconds after logging in
@ -27,10 +29,11 @@ public class ChatUser {
this.partyId = partyId; this.partyId = partyId;
this.toggledPartyChat = toggledChat; this.toggledPartyChat = toggledChat;
displayName = Queries.getNickname(uuid); // todo fix sql name = Queries.getNickname(uuid);
if (displayName == null) { if (name == null) {
displayName = Utility.getDisplayName(uuid); name = Utility.getDisplayName(uuid);
} }
setDisplayName(name);
prefix = Utility.getPrefix(uuid, true); prefix = Utility.getPrefix(uuid, true);
staffPrefix = Utility.getStaffPrefix(uuid); staffPrefix = Utility.getStaffPrefix(uuid);
@ -62,38 +65,26 @@ public class ChatUser {
Queries.setPartyChatState(toggledPartyChat, uuid); //TODO: Async pls - no CompleteableFuture<>! Queries.setPartyChatState(toggledPartyChat, uuid); //TODO: Async pls - no CompleteableFuture<>!
} }
public String getDisplayName() { public Component getDisplayName() {
return displayName; return displayName;
} }
public void setDisplayName(String displayName) { public void setDisplayName(String displayName) {
this.displayName = displayName; this.displayName = Utility.applyColor(displayName);
} }
public String getPrefix() { public Component getPrefix() {
return prefix; return prefix;
} }
public void setPrefix(String prefix) { public Component getStaffPrefix() {
this.prefix = prefix;
}
public String getStaffPrefix() {
return staffPrefix; return staffPrefix;
} }
public void setStaffPrefix(String staffPrefix) { public Component getPrefixAll() {
this.staffPrefix = staffPrefix;
}
public String getPrefixAll() {
return prefixAll; return prefixAll;
} }
public void setPrefixAll(String prefixAll) {
this.prefixAll = prefixAll;
}
public void toggleGc() { public void toggleGc() {
toggleGc = !toggleGc; toggleGc = !toggleGc;
} }

View File

@ -2,21 +2,25 @@ package com.alttd.chat.util;
import com.alttd.chat.ChatAPI; import com.alttd.chat.ChatAPI;
import com.alttd.chat.config.Config; import com.alttd.chat.config.Config;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPerms;
import net.luckperms.api.model.group.Group; import net.luckperms.api.model.group.Group;
import net.luckperms.api.model.user.User; import net.luckperms.api.model.user.User;
import java.util.Collection; import java.awt.*;
import java.util.Comparator; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
public class Utility { public class Utility {
public static String stringRegen = "\\{#[A-Fa-f0-9]{6}(<)?(>)?}";
public static HashMap<String, String> colors; public static HashMap<String, String> colors;
static { // this might be in minimessage already? static { // this might be in minimessage already?
colors = new HashMap<>(); // todo map all colors to minimessage colors = new HashMap<>();
colors.put("&0", "<black>"); // and confirm these are correct colors.put("&0", "<black>"); // and confirm these are correct
colors.put("&1", "<dark_blue>"); // could also add some default hex colors here? colors.put("&1", "<dark_blue>"); // could also add some default hex colors here?
colors.put("&2", "<dark_green>"); colors.put("&2", "<dark_green>");
@ -33,7 +37,6 @@ public class Utility {
colors.put("&d", "<light_purple>"); colors.put("&d", "<light_purple>");
colors.put("&e", "<yellow>"); colors.put("&e", "<yellow>");
colors.put("&f", "<white>"); colors.put("&f", "<white>");
colors.put("&g", "<minecoin_gold>"); // is this a thing?
} }
public static String parseColors(String message) { public static String parseColors(String message) {
@ -47,45 +50,123 @@ public class Utility {
return message; return message;
} }
public static String getPrefix(UUID uuid, boolean highest) { public static Component getPrefix(UUID uuid, boolean single) {
StringBuilder prefix = new StringBuilder(); StringBuilder prefix = new StringBuilder();
LuckPerms luckPerms = ChatAPI.get().getLuckPerms(); LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
User user = luckPerms.getUserManager().getUser(uuid); User user = luckPerms.getUserManager().getUser(uuid);
if(user == null) return ""; if(user == null) return Component.empty();
if(!highest) { if(single) {
Collection<Group> inheritedGroups = user.getInheritedGroups(user.getQueryOptions()); Group group = luckPerms.getGroupManager().getGroup(user.getPrimaryGroup());
inheritedGroups.stream() if(group != null)
.sorted(Comparator.comparingInt(o -> o.getWeight().orElse(0))) prefix.append(group.getCachedData().getMetaData().getPrefix());
.forEach(group -> { // Collection<Group> inheritedGroups = user.getInheritedGroups(user.getQueryOptions());
if (Config.PREFIXGROUPS.contains(group.getName())) { // inheritedGroups.stream()
prefix.append("<white>[").append(group.getCachedData().getMetaData().getPrefix()).append("]</white>"); // .sorted(Comparator.comparingInt(o -> o.getWeight().orElse(0)))
} // .distinct()
}); // .forEach(group -> {
// if (Config.PREFIXGROUPS.contains(group.getName())) {
// prefix.append("[").append(group.getCachedData().getMetaData().getPrefix()).append("]");
// }
// });
} else {
prefix.append(user.getCachedData().getMetaData().getPrefix());
} }
LegacyComponentSerializer.builder().character('&').hexColors();
prefix.append("<white>[").append(user.getCachedData().getMetaData().getPrefix()).append("]</white>");
return prefix.toString(); return LegacyComponentSerializer.builder().character('&').hexColors().build().deserialize(prefix.toString());
} }
// @teri you don't reference the plugin instance from the API instance, this creates a circular reference and breaks on compile and will never run public static Component getStaffPrefix(UUID uuid) {
public static String getStaffPrefix(UUID uuid) {
StringBuilder prefix = new StringBuilder(); StringBuilder prefix = new StringBuilder();
LuckPerms luckPerms = ChatAPI.get().getLuckPerms(); LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
User user = luckPerms.getUserManager().getUser(uuid); User user = luckPerms.getUserManager().getUser(uuid);
if(user == null) return prefix.toString(); if(user == null) return Component.empty();
if(user.getCachedData().getPermissionData().checkPermission("group." + Config.MINIMIUMSTAFFRANK).asBoolean()) { if(user.getCachedData().getPermissionData().checkPermission("group." + Config.MINIMIUMSTAFFRANK).asBoolean()) {
prefix.append("<white>[").append(user.getCachedData().getMetaData().getPrefix()).append("]</white>"); Group group = luckPerms.getGroupManager().getGroup(user.getPrimaryGroup());
if(group != null)
prefix.append(group.getCachedData().getMetaData().getPrefix());
} }
return prefix.toString(); return LegacyComponentSerializer.builder().character('&').hexColors().build().deserialize(prefix.toString());
} }
public static String getDisplayName(UUID uuid) { public static String getDisplayName(UUID uuid) {
StringBuilder prefix = new StringBuilder();
LuckPerms luckPerms = ChatAPI.get().getLuckPerms(); LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
User user = luckPerms.getUserManager().getUser(uuid); User user = luckPerms.getUserManager().getUser(uuid);
if(user == null) return ""; if(user == null) return "";
return user.getUsername(); return user.getUsername();
} }
public static Component applyColor(String message) {
String hexColor1 = "";
String hexColor2 = "";
StringBuilder stringBuilder = new StringBuilder();
message = parseColors(message);
boolean startsWithColor = false;
boolean lastColorMatters = false;
if (message.matches(".*" + stringRegen + ".*")) {
String[] split = message.split(stringRegen);
ArrayList<String> list = new ArrayList<>();
int nextIndex = 0;
if (message.indexOf("}") <= 11) {
startsWithColor = true;
list.add(message.substring(0, message.indexOf("}") + 1));
}
for (String s : split) {
nextIndex += s.length();
int tmp = message.indexOf("}", nextIndex);
if (tmp < message.length() && tmp>=0) {
list.add(message.substring(nextIndex, tmp + 1));
nextIndex = tmp + 1;
}
}
int i;
boolean firstLoop = true;
if (startsWithColor) {
i = -1;
} else {
i = 0;
stringBuilder.append(split[i]);
}
for (String s : list) {
boolean lesser = s.contains("<");
boolean bigger = s.contains(">");
if (bigger && lesser) {
hexColor2 = s.substring(1, s.length() - 3);
} else if (bigger || lesser) {
hexColor2 = s.substring(1, s.length() - 2);
} else {
hexColor2 = s.substring(1, s.length() -1);
}
if (firstLoop) {
lastColorMatters = bigger;
hexColor1 = hexColor2;
firstLoop = false;
i++;
continue;
}
if (lesser && lastColorMatters) {
stringBuilder.append("<gradient:").append(hexColor1).append(":").append(hexColor2).append(">").append(split[i]).append("</gradient>");
} else {
stringBuilder.append("<").append(hexColor1).append(">").append(split[i]);
}
hexColor1 = hexColor2;
lastColorMatters = bigger;
i++;
}
if (split.length > i){
stringBuilder.append("<").append(hexColor1).append(">").append(split[i]);
}
}
MiniMessage miniMessage = MiniMessage.get();
return stringBuilder.length()==0 ? miniMessage.parse(message)
: miniMessage.parse(stringBuilder.toString());
}
} }

View File

@ -51,6 +51,12 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<repositories>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.alttd</groupId> <groupId>com.alttd</groupId>
@ -58,6 +64,18 @@
<version>1.17-R0.1-SNAPSHOT</version> <version>1.17-R0.1-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.10</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<properties> <properties>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>11</maven.compiler.target>

View File

@ -67,7 +67,10 @@
</build> </build>
<repositories> <repositories>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -77,7 +80,7 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency><!--TODO update to version 4.0.0--> <dependency>
<groupId>org.spongepowered</groupId> <groupId>org.spongepowered</groupId>
<artifactId>configurate-yaml</artifactId> <artifactId>configurate-yaml</artifactId>
<version>3.7.1</version> <version>3.7.1</version>
@ -87,5 +90,16 @@
<artifactId>galaxy-api</artifactId> <artifactId>galaxy-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version> <version>1.17-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.10</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -22,5 +22,4 @@ public class Message implements CommandExecutor {
return false; return false;
} }
// Teri, is Tabcompleter needed here? we already have spigot setup to complete playernames on tab, doesn't work for crossserver stuff and offline players
} }

View File

@ -42,8 +42,6 @@ public class ChatHandler {
if(!player.hasPermission("chat.format")) { if(!player.hasPermission("chat.format")) {
message = miniMessage.stripTokens(message); message = miniMessage.stripTokens(message);
} else {
message = Utility.parseColors(message);
} }
if(message.contains("[i]")) if(message.contains("[i]"))
@ -71,16 +69,14 @@ public class ChatHandler {
return; return;
} }
Component senderName = player.displayName(); Component senderName = user.getDisplayName();
String prefix = user.getPrefix(); Component prefix = user.getPrefix();
message = RegexManager.replaceText(message); // todo a better way for this message = RegexManager.replaceText(message); // todo a better way for this
if(message == null) return; // the message was blocked if(message == null) return; // the message was blocked
if(!player.hasPermission("chat.format")) { if(!player.hasPermission("chat.format")) {
message = miniMessage.stripTokens(message); message = miniMessage.stripTokens(message);
} else {
message = Utility.parseColors(message);
} }
if(message.contains("[i]")) if(message.contains("[i]"))

View File

@ -5,9 +5,9 @@ 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.util.Utility;
import io.papermc.paper.chat.ChatRenderer; import io.papermc.paper.chat.ChatRenderer;
import io.papermc.paper.event.player.AsyncChatEvent; import io.papermc.paper.event.player.AsyncChatEvent;
import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
@ -24,25 +24,12 @@ import java.util.List;
public class ChatListener implements Listener, ChatRenderer { public class ChatListener implements Listener, ChatRenderer {
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onPlayerChat(AsyncChatEvent event) { // this should also include a way to prevent a player from seeing chat public void onPlayerChat(AsyncChatEvent event) {
// @teri what about mutes?
Player player = event.getPlayer(); Player player = event.getPlayer();
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId()); ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
// tweak this to make this slightly better:/
event.viewers().removeIf(audience -> audience instanceof Player event.viewers().removeIf(audience -> audience instanceof Player
&& user.getIgnoredPlayers().contains(((Player) audience).getUniqueId())); && user.getIgnoredPlayers().contains(((Player) audience).getUniqueId()));
/* Set<Audience> viewers = event.viewers();
Set<Audience> ignores = new HashSet<>();
for(Audience audience : viewers) { // I don't like this setup, might alter this API to expose players...
if(audience instanceof Player) { // the player option is removed in 1.17=/ bad paper devs
UUID uuid = ((Player) audience).getUniqueId();
if(user.getIgnoredPlayers().contains(uuid)) {
ignores.add(audience);
}
}
}
event.viewers().removeAll(ignores);*/
Component input = event.message(); Component input = event.message();
String message = PlainComponentSerializer.plain().serialize(input); String message = PlainComponentSerializer.plain().serialize(input);
@ -53,8 +40,6 @@ public class ChatListener implements Listener, ChatRenderer {
MiniMessage miniMessage = MiniMessage.get(); MiniMessage miniMessage = MiniMessage.get();
if(!player.hasPermission("chat.format")) { if(!player.hasPermission("chat.format")) {
message = miniMessage.stripTokens(message); message = miniMessage.stripTokens(message);
} else {
message = Utility.parseColors(message);
} }
if(message.contains("[i]")) if(message.contains("[i]"))

View File

@ -3,7 +3,7 @@ version: ${project.version}
main: com.alttd.chat.ChatPlugin main: com.alttd.chat.ChatPlugin
api-version: 1.16 api-version: 1.16
authors: [Destro, Teriuihi] authors: [Destro, Teriuihi]
depend: [LuckPerms] depend: [LuckPerms, PlaceholderAPI]
commands: commands:
globalchat: globalchat:
permission: command.globalchat permission: command.globalchat

View File

@ -71,12 +71,7 @@
</repository> </repository>
<repository> <repository>
<id>Alttd-Nexus</id> <id>Alttd-Nexus</id>
<url>http://leo:8081/snapshots/</url> <url>http://leo:8081/</url>
</repository>
<repository> <!-- can be removed when galaxy api is fixed, I fucked up when shading this in -->
<id>dv8tion</id>
<name>m2-dv8tion</name>
<url>https://m2.dv8tion.net/releases</url>
</repository> </repository>
</repositories> </repositories>

View File

@ -16,7 +16,7 @@ public class GlobalAdminChat {
public GlobalAdminChat(ProxyServer proxyServer) { public GlobalAdminChat(ProxyServer proxyServer) {
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
.<CommandSource>literal("globaladminchat") .<CommandSource>literal("globaladminchat")
.requires(ctx -> ctx.hasPermission("command.proxy.globaladminchat"))// TODO permission system? load permissions from config? .requires(ctx -> ctx.hasPermission("command.proxy.globaladminchat"))
.then(RequiredArgumentBuilder .then(RequiredArgumentBuilder
.<CommandSource, String>argument("message", StringArgumentType.greedyString()) .<CommandSource, String>argument("message", StringArgumentType.greedyString())
.executes(context -> { .executes(context -> {

View File

@ -24,7 +24,7 @@ public class Message {
/*public Message(ProxyServer proxyServer) { /*public Message(ProxyServer proxyServer) {
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
.<CommandSource>literal("message") .<CommandSource>literal("message")
.requires(ctx -> ctx.hasPermission("command.proxy.message"))// TODO permission system? load permissions from config? .requires(ctx -> ctx.hasPermission("command.proxy.message"))
.then(RequiredArgumentBuilder .then(RequiredArgumentBuilder
.<CommandSource, String>argument("player", StringArgumentType.word()) .<CommandSource, String>argument("player", StringArgumentType.word())
.suggests((context, builder) -> { .suggests((context, builder) -> {

View File

@ -42,7 +42,7 @@ public class SendMail {
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
.<CommandSource>literal("mail") .<CommandSource>literal("mail")
.requires(ctx -> ctx.hasPermission("command.proxy.mail"))// TODO permission .requires(ctx -> ctx.hasPermission("command.proxy.mail"))
.then(LiteralArgumentBuilder.<CommandSource>literal("send") .then(LiteralArgumentBuilder.<CommandSource>literal("send")
.then(playerNode .then(playerNode
.then(RequiredArgumentBuilder .then(RequiredArgumentBuilder

View File

@ -53,26 +53,24 @@ public class ChatHandler {
} }
public void globalAdminChat(CommandSource commandSource, String message) { public void globalAdminChat(CommandSource commandSource, String message) {
String senderName = Config.CONSOLENAME; Component senderName = Component.text(Config.CONSOLENAME);
String serverName = "Altitude"; String serverName = "Altitude";
if (commandSource instanceof Player) { if (commandSource instanceof Player) {
Player sender = (Player) commandSource; Player sender = (Player) commandSource;
senderName = sender.getUsername(); ChatUser user = ChatUserManager.getChatUser(sender.getUniqueId());
if(user == null) return;
senderName = user.getDisplayName();
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude"; serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
} }
MiniMessage miniMessage = MiniMessage.get(); MiniMessage miniMessage = MiniMessage.get();
message = Utility.parseColors(message); List<Template> templates = new ArrayList<>(List.of(
Template.of("message", message),
Template.of("sender", senderName),
Template.of("server", serverName)));
Map<String, String> map = new HashMap<>(); Component component = miniMessage.parse(Config.GACFORMAT, templates);
map.put("sender", senderName);
//map.put("message", event.getMessage());
map.put("message", Utility.parseColors(message));
map.put("server", serverName);
Component component = miniMessage.parse(Config.GACFORMAT, map);
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.proxy.globaladminchat")/*TODO permission*/).forEach(target -> { VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.proxy.globaladminchat")/*TODO permission*/).forEach(target -> {
target.sendMessage(component); target.sendMessage(component);

View File

@ -46,7 +46,7 @@ public class ChatListener {
map.put("sender", senderName); map.put("sender", senderName);
//map.put("message", event.getMessage()); //map.put("message", event.getMessage());
map.put("message", Utility.parseColors(event.getMessage())); map.put("message", event.getMessage());
map.put("server", serverName); map.put("server", serverName);
Component message = miniMessage.parse(Config.GACFORMAT, map); Component message = miniMessage.parse(Config.GACFORMAT, map);
@ -56,10 +56,4 @@ public class ChatListener {
}); });
} }
@Subscribe(order = PostOrder.FIRST)
public void onPlayerChat(PlayerChatEvent event) {
// do stuff
}
} }