Merge pull request #289 from Focusvity/pr/discord

Enable media tag to be included in messages
This commit is contained in:
Telesphoreo 2020-10-16 21:36:38 -05:00 committed by GitHub
commit d4d1000c16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,44 +29,41 @@ 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()) ComponentBuilder builder = new ComponentBuilder(message);
if (!msg.getContentDisplay().isEmpty())
{ {
message += ChatColor.stripColor(event.getMessage().getContentDisplay()); builder.append(" ").append(ChatColor.stripColor(msg.getContentDisplay()));
for (Player player : Bukkit.getOnlinePlayers()) message += " " + ChatColor.stripColor(msg.getContentDisplay()); // for logging
{
if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord())
{
player.sendMessage(message);
}
}
FLog.info(message);
} }
else if (!msg.getAttachments().isEmpty())
{ {
ComponentBuilder builder = new ComponentBuilder(message); for (Message.Attachment attachment : msg.getAttachments())
for (Message.Attachment attachment : event.getMessage().getAttachments())
{ {
if (attachment.getUrl() == null) if (attachment.getUrl() == null)
{ {
continue; continue;
} }
TextComponent text = new TextComponent(net.md_5.bungee.api.ChatColor.YELLOW + "[Media]"); builder.append(" ");
TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]");
text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl())); text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl()));
builder.append(text).append(" "); builder.append(text);
} message += " [Media]"; // for logging
for (Player player : Bukkit.getOnlinePlayers())
{
if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord())
{
player.spigot().sendMessage(builder.create());
}
} }
} }
for (Player player : Bukkit.getOnlinePlayers())
{
if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord())
{
player.spigot().sendMessage(builder.create());
}
}
FLog.info(message);
} }
} }
} }