Format event message

This commit is contained in:
Draycia committed 2020-08-23 01:54:56 -07:00
1 parent 610f75d2cc
commit 9abdc0df4c
6 files changed
+46 -27

No files matched your search

@@ -87,7 +87,7 @@ public class CarbonChatChannel extends ChatChannel {
}
}
public void sendMessage(ChatUser user, Collection<ChatUser> recipients, String message, boolean fromRemote) {
public Component sendMessage(ChatUser user, Collection<ChatUser> recipients, String message, boolean fromRemote) {
updateUserNickname(user);
// Get player's formatting
@@ -99,12 +99,8 @@ public class CarbonChatChannel extends ChatChannel {
// Return if cancelled or message is emptied
if (preFormatEvent.isCancelled()) {
return;
}
if (preFormatEvent.getMessage().trim().isEmpty()) {
return;
if (preFormatEvent.isCancelled() || preFormatEvent.getMessage().trim().isEmpty()) {
return TextComponent.empty();
}
String displayName;
@@ -122,14 +118,10 @@ public class CarbonChatChannel extends ChatChannel {
Bukkit.getPluginManager().callEvent(formatEvent);
// Again, return if cancelled or message is emptied
if (formatEvent.isCancelled()) {
if (formatEvent.isCancelled() || formatEvent.getMessage().trim().isEmpty()) {
continue;
}
if (formatEvent.getMessage().trim().isEmpty()) {
return;
}
TextComponent formattedMessage = (TextComponent) carbonChat.getAdventureManager().processMessage(formatEvent.getFormat(),
"br", "\n",
"displayname", displayName,
@@ -171,20 +163,19 @@ public class CarbonChatChannel extends ChatChannel {
Bukkit.getPluginManager().callEvent(consoleEvent);
// Log message to console
System.out.println(CarbonChat.LEGACY.serialize(consoleEvent.getComponent()));
// Route message to bungee / discord (if message originates from this server)
// Use instanceof and not isOnline, if this message originates from another then the instanceof will
// fail, but isOnline may succeed if the player is online on both servers (somehow).
if (user.isOnline() && !fromRemote && shouldBungee()) {
sendMessageToBungee(user.asPlayer(), consoleEvent.getComponent());
}
return consoleEvent.getComponent();
}
@Override
public void sendMessage(ChatUser user, String message, boolean fromRemote) {
this.sendMessage(user, this.audiences(), message, fromRemote);
public Component sendMessage(ChatUser user, String message, boolean fromRemote) {
return this.sendMessage(user, this.audiences(), message, fromRemote);
}
public String getFormat(ChatUser user) {
@@ -285,8 +276,6 @@ public class CarbonChatChannel extends ChatChannel {
user.sendMessage(component);
}
}
System.out.println(CarbonChat.LEGACY.serialize(component));
}
public void sendMessageToBungee(Player player, Component component) {