Enable media tag to be included in messages

This commit is contained in:
Nathan Curran 2020-10-16 17:33:58 +11:00
parent a4c8dad865
commit 3bd72dacda
No known key found for this signature in database
GPG Key ID: B3A964B30C2E56B8

View File

@ -29,19 +29,35 @@ public class DiscordToMinecraftListener extends ListenerAdapter
Member member = event.getMember(); Member member = event.getMember();
String tag = getDisplay(member); String tag = getDisplay(member);
String message = ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Discord" + ChatColor.DARK_GRAY + "]"; String message = ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Discord" + ChatColor.DARK_GRAY + "]";
Message msg = event.getMessage();
if (tag != null) if (tag != null)
{ {
message += " " + tag; message += " " + tag;
} }
message += " " + ChatColor.RED + ChatColor.stripColor(member.getEffectiveName()) + ChatColor.DARK_GRAY + ": " + ChatColor.RESET; message += " " + ChatColor.RED + ChatColor.stripColor(member.getEffectiveName()) + ChatColor.DARK_GRAY + ": " + ChatColor.RESET;
if (!event.getMessage().getContentDisplay().isEmpty()) if (!msg.getContentDisplay().isEmpty())
{ {
message += ChatColor.stripColor(event.getMessage().getContentDisplay()); message += ChatColor.stripColor(msg.getContentDisplay());
ComponentBuilder builder = new ComponentBuilder(message);
if (!msg.getAttachments().isEmpty())
{
for (Message.Attachment attachment : msg.getAttachments())
{
if (attachment.getUrl() == null)
{
continue;
}
builder.append(" ");
TextComponent text = new TextComponent(net.md_5.bungee.api.ChatColor.YELLOW + "[Media]");
text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl()));
builder.append(text).append(" ");
}
}
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
{ {
if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord()) if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord())
{ {
player.sendMessage(message); player.spigot().sendMessage(builder.create());
} }
} }
FLog.info(message); FLog.info(message);
@ -49,7 +65,7 @@ public class DiscordToMinecraftListener extends ListenerAdapter
else else
{ {
ComponentBuilder builder = new ComponentBuilder(message); ComponentBuilder builder = new ComponentBuilder(message);
for (Message.Attachment attachment : event.getMessage().getAttachments()) for (Message.Attachment attachment : msg.getAttachments())
{ {
if (attachment.getUrl() == null) if (attachment.getUrl() == null)
{ {