use of com.loohp.interactivechatdiscordsrvaddon.objectholders.ImageDisplayData in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class OutboundToDiscordEvents method processGameMessage.
@SuppressWarnings("deprecation")
public Component processGameMessage(ICPlayer icSender, Component component) {
boolean reserializer = DiscordSRV.config().getBoolean("Experiment_MCDiscordReserializer_ToDiscord");
PlaceholderCooldownManager cooldownManager = InteractiveChatDiscordSrvAddon.plugin.placeholderCooldownManager;
long now = cooldownManager.checkMessage(icSender.getUniqueId(), PlainTextComponentSerializer.plainText().serialize(component)).getTimeNow();
GameMessagePreProcessEvent gameMessagePreProcessEvent = new GameMessagePreProcessEvent(icSender, component, false);
Bukkit.getPluginManager().callEvent(gameMessagePreProcessEvent);
if (gameMessagePreProcessEvent.isCancelled()) {
return null;
}
component = ComponentFlattening.flatten(gameMessagePreProcessEvent.getComponent());
String plain = InteractiveChatComponentSerializer.plainText().serialize(component);
if (InteractiveChat.useItem && PlayerUtils.hasPermission(icSender.getUniqueId(), "interactivechat.module.item", true, 200)) {
Debug.debug("onGameToDiscord processing item display");
if (!cooldownManager.isPlaceholderOnCooldownAt(icSender.getUniqueId(), InteractiveChat.placeholderList.values().stream().filter(each -> each.getKeyword().equals(InteractiveChat.itemPlaceholder)).findFirst().get(), now)) {
Matcher matcher = InteractiveChat.itemPlaceholder.matcher(plain);
if (matcher.find()) {
ItemStack item = PlayerUtils.getHeldItem(icSender);
boolean isAir = item.getType().equals(Material.AIR);
XMaterial xMaterial = XMaterialUtils.matchXMaterial(item);
String itemStr = PlainTextComponentSerializer.plainText().serialize(ComponentStringUtils.convertTranslatables(ComponentModernizing.modernize(ItemStackUtils.getDisplayName(item)), InteractiveChatDiscordSrvAddon.plugin.resourceManager.getLanguageManager().getTranslateFunction().ofLanguage(InteractiveChatDiscordSrvAddon.plugin.language)));
itemStr = ComponentStringUtils.stripColorAndConvertMagic(itemStr);
int amount = item.getAmount();
if (isAir) {
amount = 1;
}
String replaceText = PlaceholderParser.parse(icSender, (amount == 1 ? ComponentStringUtils.stripColorAndConvertMagic(InteractiveChat.itemSingularReplaceText) : ComponentStringUtils.stripColorAndConvertMagic(InteractiveChat.itemReplaceText).replace("{Amount}", String.valueOf(amount))).replace("{Item}", itemStr));
if (reserializer) {
replaceText = MessageUtil.reserializeToDiscord(github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component.text(replaceText));
}
AtomicBoolean replaced = new AtomicBoolean(false);
Component replaceComponent = LegacyComponentSerializer.legacySection().deserialize(replaceText);
component = ComponentReplacing.replace(component, InteractiveChat.itemPlaceholder.pattern(), true, (groups) -> {
replaced.set(true);
return replaceComponent;
});
if (replaced.get() && InteractiveChatDiscordSrvAddon.plugin.itemImage) {
int inventoryId = DATA_ID_PROVIDER.getNext();
int position = matcher.start();
String title = PlaceholderParser.parse(icSender, ComponentStringUtils.stripColorAndConvertMagic(InteractiveChat.itemTitle));
Inventory inv = null;
if (item.hasItemMeta() && item.getItemMeta() instanceof BlockStateMeta) {
BlockState bsm = ((BlockStateMeta) item.getItemMeta()).getBlockState();
if (bsm instanceof InventoryHolder) {
Inventory container = ((InventoryHolder) bsm).getInventory();
if (!container.isEmpty()) {
inv = Bukkit.createInventory(null, InventoryUtils.toMultipleOf9(container.getSize()));
for (int j = 0; j < container.getSize(); j++) {
if (container.getItem(j) != null) {
if (!container.getItem(j).getType().equals(Material.AIR)) {
inv.setItem(j, container.getItem(j).clone());
}
}
}
}
}
}
GameMessageProcessItemEvent gameMessageProcessItemEvent = new GameMessageProcessItemEvent(icSender, title, component, false, inventoryId, item.clone(), inv);
Bukkit.getPluginManager().callEvent(gameMessageProcessItemEvent);
if (!gameMessageProcessItemEvent.isCancelled()) {
component = gameMessageProcessItemEvent.getComponent();
title = gameMessageProcessItemEvent.getTitle();
if (gameMessageProcessItemEvent.hasInventory()) {
DATA.put(inventoryId, new ImageDisplayData(icSender, position, title, ImageDisplayType.ITEM_CONTAINER, gameMessageProcessItemEvent.getItemStack().clone(), new TitledInventoryWrapper(ItemStackUtils.getDisplayName(item, null), gameMessageProcessItemEvent.getInventory())));
} else {
DATA.put(inventoryId, new ImageDisplayData(icSender, position, title, ImageDisplayType.ITEM, gameMessageProcessItemEvent.getItemStack().clone()));
}
}
component = component.append(Component.text("<ICD=" + inventoryId + ">"));
}
}
}
}
if (InteractiveChat.useInventory && PlayerUtils.hasPermission(icSender.getUniqueId(), "interactivechat.module.inventory", true, 200)) {
Debug.debug("onGameToDiscord processing inventory display");
if (!cooldownManager.isPlaceholderOnCooldownAt(icSender.getUniqueId(), InteractiveChat.placeholderList.values().stream().filter(each -> each.getKeyword().equals(InteractiveChat.invPlaceholder)).findFirst().get(), now)) {
Matcher matcher = InteractiveChat.invPlaceholder.matcher(plain);
if (matcher.find()) {
String replaceText = PlaceholderParser.parse(icSender, ComponentStringUtils.stripColorAndConvertMagic(InteractiveChat.invReplaceText));
if (reserializer) {
replaceText = MessageUtil.reserializeToDiscord(github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component.text(replaceText));
}
AtomicBoolean replaced = new AtomicBoolean(false);
Component replaceComponent = LegacyComponentSerializer.legacySection().deserialize(replaceText);
component = ComponentReplacing.replace(component, InteractiveChat.invPlaceholder.pattern(), true, (groups) -> {
replaced.set(true);
return replaceComponent;
});
if (replaced.get() && InteractiveChatDiscordSrvAddon.plugin.invImage) {
int inventoryId = DATA_ID_PROVIDER.getNext();
int position = matcher.start();
Inventory inv = Bukkit.createInventory(null, 45);
for (int j = 0; j < icSender.getInventory().getSize(); j++) {
if (icSender.getInventory().getItem(j) != null) {
if (!icSender.getInventory().getItem(j).getType().equals(Material.AIR)) {
inv.setItem(j, icSender.getInventory().getItem(j).clone());
}
}
}
String title = PlaceholderParser.parse(icSender, ComponentStringUtils.stripColorAndConvertMagic(InteractiveChat.invTitle));
GameMessageProcessPlayerInventoryEvent gameMessageProcessPlayerInventoryEvent = new GameMessageProcessPlayerInventoryEvent(icSender, title, component, false, inventoryId, inv);
Bukkit.getPluginManager().callEvent(gameMessageProcessPlayerInventoryEvent);
if (!gameMessageProcessPlayerInventoryEvent.isCancelled()) {
component = gameMessageProcessPlayerInventoryEvent.getComponent();
title = gameMessageProcessPlayerInventoryEvent.getTitle();
DATA.put(inventoryId, new ImageDisplayData(icSender, position, title, ImageDisplayType.INVENTORY, true, new TitledInventoryWrapper(Component.translatable(TranslationKeyUtils.getDefaultContainerTitle()), gameMessageProcessPlayerInventoryEvent.getInventory())));
}
component = component.append(Component.text("<ICD=" + inventoryId + ">"));
}
}
}
}
if (InteractiveChat.useEnder && PlayerUtils.hasPermission(icSender.getUniqueId(), "interactivechat.module.enderchest", true, 200)) {
Debug.debug("onGameToDiscord processing enderchest display");
if (!cooldownManager.isPlaceholderOnCooldownAt(icSender.getUniqueId(), InteractiveChat.placeholderList.values().stream().filter(each -> each.getKeyword().equals(InteractiveChat.enderPlaceholder)).findFirst().get(), now)) {
Matcher matcher = InteractiveChat.enderPlaceholder.matcher(plain);
if (matcher.find()) {
String replaceText = PlaceholderParser.parse(icSender, ComponentStringUtils.stripColorAndConvertMagic(InteractiveChat.enderReplaceText));
if (reserializer) {
replaceText = MessageUtil.reserializeToDiscord(github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component.text(replaceText));
}
AtomicBoolean replaced = new AtomicBoolean(false);
Component replaceComponent = LegacyComponentSerializer.legacySection().deserialize(replaceText);
component = ComponentReplacing.replace(component, InteractiveChat.enderPlaceholder.pattern(), true, (groups) -> {
replaced.set(true);
return replaceComponent;
});
if (replaced.get() && InteractiveChatDiscordSrvAddon.plugin.enderImage) {
int inventoryId = DATA_ID_PROVIDER.getNext();
int position = matcher.start();
Inventory inv = Bukkit.createInventory(null, InventoryUtils.toMultipleOf9(icSender.getEnderChest().getSize()));
for (int j = 0; j < icSender.getEnderChest().getSize(); j++) {
if (icSender.getEnderChest().getItem(j) != null) {
if (!icSender.getEnderChest().getItem(j).getType().equals(Material.AIR)) {
inv.setItem(j, icSender.getEnderChest().getItem(j).clone());
}
}
}
String title = PlaceholderParser.parse(icSender, ComponentStringUtils.stripColorAndConvertMagic(InteractiveChat.enderTitle));
GameMessageProcessInventoryEvent gameMessageProcessInventoryEvent = new GameMessageProcessInventoryEvent(icSender, title, component, false, inventoryId, inv);
Bukkit.getPluginManager().callEvent(gameMessageProcessInventoryEvent);
if (!gameMessageProcessInventoryEvent.isCancelled()) {
component = gameMessageProcessInventoryEvent.getComponent();
title = gameMessageProcessInventoryEvent.getTitle();
DATA.put(inventoryId, new ImageDisplayData(icSender, position, title, ImageDisplayType.ENDERCHEST, new TitledInventoryWrapper(Component.translatable(TranslationKeyUtils.getEnderChestContainerTitle()), gameMessageProcessInventoryEvent.getInventory())));
}
component = component.append(Component.text("<ICD=" + inventoryId + ">"));
}
}
}
}
Debug.debug("onGameToDiscord processing custom placeholders");
for (ICPlaceholder placeholder : InteractiveChatAPI.getICPlaceholderList()) {
if (!placeholder.isBuildIn()) {
CustomPlaceholder customP = (CustomPlaceholder) placeholder;
if (!InteractiveChat.useCustomPlaceholderPermissions || (InteractiveChat.useCustomPlaceholderPermissions && PlayerUtils.hasPermission(icSender.getUniqueId(), customP.getPermission(), true, 200))) {
boolean onCooldown = cooldownManager.isPlaceholderOnCooldownAt(icSender.getUniqueId(), customP, now);
Matcher matcher = customP.getKeyword().matcher(plain);
if (matcher.find() && !onCooldown) {
String replaceText;
if (customP.getReplace().isEnabled()) {
replaceText = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderParser.parse(icSender, customP.getReplace().getReplaceText()));
} else {
replaceText = null;
}
List<Component> toAppend = new LinkedList<>();
Set<String> shown = new HashSet<>();
component = ComponentReplacing.replace(component, customP.getKeyword().pattern(), true, (result, matchedComponents) -> {
String replaceString = replaceText == null ? result.group() : CustomStringUtils.applyReplacementRegex(replaceText, result, 1);
if (!shown.contains(replaceString)) {
shown.add(replaceString);
int position = result.start();
if (InteractiveChatDiscordSrvAddon.plugin.hoverEnabled && !InteractiveChatDiscordSrvAddon.plugin.hoverIgnore.contains(customP.getPosition())) {
HoverClickDisplayData.Builder hoverClick = new HoverClickDisplayData.Builder().player(icSender).postion(position).color(DiscordDataRegistry.DISCORD_HOVER_COLOR).displayText(ChatColorUtils.stripColor(replaceString));
boolean usingHoverClick = false;
if (customP.getHover().isEnabled()) {
usingHoverClick = true;
String hoverText = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderParser.parse(icSender, CustomStringUtils.applyReplacementRegex(customP.getHover().getText(), result, 1)));
Color color = ColorUtils.getFirstColor(hoverText);
hoverClick.hoverText(LegacyComponentSerializer.legacySection().deserialize(hoverText));
if (color != null) {
hoverClick.color(color);
}
}
if (customP.getClick().isEnabled()) {
usingHoverClick = true;
hoverClick.clickAction(customP.getClick().getAction()).clickValue(CustomStringUtils.applyReplacementRegex(customP.getClick().getValue(), result, 1));
}
if (usingHoverClick) {
int hoverId = DATA_ID_PROVIDER.getNext();
DATA.put(hoverId, hoverClick.build());
toAppend.add(Component.text("<ICD=" + hoverId + ">"));
}
}
}
return replaceText == null ? Component.empty().children(matchedComponents) : LegacyComponentSerializer.legacySection().deserialize(replaceString);
});
for (Component componentToAppend : toAppend) {
component = component.append(componentToAppend);
}
}
}
}
}
if (InteractiveChat.t && WebData.getInstance() != null) {
for (CustomPlaceholder customP : WebData.getInstance().getSpecialPlaceholders()) {
boolean onCooldown = cooldownManager.isPlaceholderOnCooldownAt(icSender.getUniqueId(), customP, now);
Matcher matcher = customP.getKeyword().matcher(plain);
if (matcher.find() && !onCooldown) {
String replaceText;
if (customP.getReplace().isEnabled()) {
replaceText = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderParser.parse(icSender, customP.getReplace().getReplaceText()));
} else {
replaceText = null;
}
List<Component> toAppend = new LinkedList<>();
Set<String> shown = new HashSet<>();
component = ComponentReplacing.replace(component, customP.getKeyword().pattern(), true, (result, matchedComponents) -> {
String replaceString = replaceText == null ? result.group() : CustomStringUtils.applyReplacementRegex(replaceText, result, 1);
if (!shown.contains(replaceString)) {
shown.add(replaceString);
int position = result.start();
if (InteractiveChatDiscordSrvAddon.plugin.hoverEnabled && !InteractiveChatDiscordSrvAddon.plugin.hoverIgnore.contains(customP.getPosition())) {
HoverClickDisplayData.Builder hoverClick = new HoverClickDisplayData.Builder().player(icSender).postion(position).color(DiscordDataRegistry.DISCORD_HOVER_COLOR).displayText(ChatColorUtils.stripColor(replaceString));
boolean usingHoverClick = false;
if (customP.getHover().isEnabled()) {
usingHoverClick = true;
String hoverText = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderParser.parse(icSender, CustomStringUtils.applyReplacementRegex(customP.getHover().getText(), result, 1)));
Color color = ColorUtils.getFirstColor(hoverText);
hoverClick.hoverText(LegacyComponentSerializer.legacySection().deserialize(hoverText));
if (color != null) {
hoverClick.color(color);
}
}
if (customP.getClick().isEnabled()) {
usingHoverClick = true;
hoverClick.clickAction(customP.getClick().getAction()).clickValue(CustomStringUtils.applyReplacementRegex(customP.getClick().getValue(), result, 1));
}
if (usingHoverClick) {
int hoverId = DATA_ID_PROVIDER.getNext();
DATA.put(hoverId, hoverClick.build());
toAppend.add(Component.text("<ICD=" + hoverId + ">"));
}
}
}
return replaceText == null ? Component.empty().children(matchedComponents) : LegacyComponentSerializer.legacySection().deserialize(replaceString);
});
for (Component componentToAppend : toAppend) {
component = component.append(componentToAppend);
}
}
}
}
DiscordSRV srv = InteractiveChatDiscordSrvAddon.discordsrv;
if (InteractiveChatDiscordSrvAddon.plugin.translateMentions) {
Debug.debug("onGameToDiscord processing mentions");
List<MentionPair> distinctMentionPairs = new ArrayList<>();
Set<UUID> processedReceivers = new HashSet<>();
synchronized (InteractiveChat.mentionPair) {
for (MentionPair pair : InteractiveChat.mentionPair) {
if (!processedReceivers.contains(pair.getReciever())) {
distinctMentionPairs.add(pair);
processedReceivers.add(pair.getReciever());
}
}
}
for (MentionPair pair : distinctMentionPairs) {
if (pair.getSender().equals(icSender.getUniqueId())) {
UUID receiverUUID = pair.getReciever();
Set<String> names = new HashSet<>();
ICPlayer receiver = ICPlayerFactory.getICPlayer(receiverUUID);
if (receiver != null) {
names.add(ChatColorUtils.stripColor(receiver.getName()));
List<String> list = InteractiveChatAPI.getNicknames(receiver.getUniqueId());
for (String name : list) {
names.add(ChatColorUtils.stripColor(name));
}
}
String userId = srv.getAccountLinkManager().getDiscordId(receiverUUID);
if (userId != null) {
User user = srv.getJda().getUserById(userId);
if (user != null) {
String discordMention = user.getAsMention();
for (String name : names) {
component = ComponentReplacing.replace(component, CustomStringUtils.escapeMetaCharacters(Registry.MENTION_TAG_CONVERTER.getTagStyle(InteractiveChat.mentionPrefix + name)), true, LegacyComponentSerializer.legacySection().deserialize(discordMention));
}
}
}
}
}
}
GameMessagePostProcessEvent gameMessagePostProcessEvent = new GameMessagePostProcessEvent(icSender, component, false);
Bukkit.getPluginManager().callEvent(gameMessagePostProcessEvent);
if (gameMessagePostProcessEvent.isCancelled()) {
return null;
}
component = gameMessagePostProcessEvent.getComponent();
return component;
}
use of com.loohp.interactivechatdiscordsrvaddon.objectholders.ImageDisplayData in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class OutboundToDiscordEvents method createContents.
private static List<DiscordMessageContent> createContents(List<DiscordDisplayData> dataList, Player player) {
List<DiscordMessageContent> contents = new ArrayList<>();
for (DiscordDisplayData data : dataList) {
if (data instanceof ImageDisplayData) {
ImageDisplayData iData = (ImageDisplayData) data;
ImageDisplayType type = iData.getType();
String title = iData.getTitle();
if (iData.getItemStack().isPresent()) {
Debug.debug("createContents creating item discord content");
ItemStack item = iData.getItemStack().get();
Color color = DiscordItemStackUtils.getDiscordColor(item);
if (color == null || color.equals(Color.WHITE)) {
color = new Color(0xFFFFFE);
}
try {
BufferedImage image = ImageGeneration.getItemStackImage(item, data.getPlayer(), InteractiveChatDiscordSrvAddon.plugin.itemAltAir);
byte[] imageData = ImageUtils.toArray(image);
DiscordDescription description = DiscordItemStackUtils.getDiscordDescription(item, player);
DiscordMessageContent content = new DiscordMessageContent(description.getName(), "attachment://Item.png", color);
content.addAttachment("Item.png", imageData);
contents.add(content);
if (InteractiveChatDiscordSrvAddon.plugin.itemUseTooltipImage) {
DiscordToolTip discordToolTip = DiscordItemStackUtils.getToolTip(item, player);
if (!discordToolTip.isBaseItem() || InteractiveChatDiscordSrvAddon.plugin.itemUseTooltipImageOnBaseItem) {
BufferedImage tooltip = ImageGeneration.getToolTipImage(discordToolTip.getComponents());
byte[] tooltipData = ImageUtils.toArray(tooltip);
content.addAttachment("ToolTip.png", tooltipData);
content.addImageUrl("attachment://ToolTip.png");
} else {
content.addDescription(description.getDescription().orElse(null));
}
} else {
content.addDescription(description.getDescription().orElse(null));
}
if (type.equals(ImageDisplayType.ITEM_CONTAINER)) {
if (!description.getDescription().isPresent()) {
content.getImageUrls().remove("attachment://ToolTip.png");
content.getAttachments().remove("ToolTip.png");
}
TitledInventoryWrapper inv = iData.getInventory().get();
BufferedImage container = ImageGeneration.getInventoryImage(inv.getInventory(), inv.getTitle(), data.getPlayer());
byte[] containerData = ImageUtils.toArray(container);
content.addAttachment("Container.png", containerData);
content.addImageUrl("attachment://Container.png");
} else {
if (iData.isFilledMap() && iData.getPlayer().isLocal()) {
if (!description.getDescription().isPresent()) {
content.getImageUrls().remove("attachment://ToolTip.png");
content.getAttachments().remove("ToolTip.png");
}
BufferedImage map = ImageGeneration.getMapImage(item, iData.getPlayer().getLocalPlayer());
byte[] mapData = ImageUtils.toArray(map);
content.addAttachment("Map.png", mapData);
content.addImageUrl("attachment://Map.png");
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (iData.getInventory().isPresent()) {
Debug.debug("createContents creating inventory discord content");
TitledInventoryWrapper inv = iData.getInventory().get();
try {
BufferedImage image;
if (iData.isPlayerInventory()) {
if (InteractiveChatDiscordSrvAddon.plugin.usePlayerInvView) {
image = ImageGeneration.getPlayerInventoryImage(inv.getInventory(), iData.getPlayer());
} else {
image = ImageGeneration.getInventoryImage(inv.getInventory(), inv.getTitle(), data.getPlayer());
}
} else {
image = ImageGeneration.getInventoryImage(inv.getInventory(), inv.getTitle(), data.getPlayer());
}
Color color;
switch(type) {
case ENDERCHEST:
color = InteractiveChatDiscordSrvAddon.plugin.enderColor;
break;
case INVENTORY:
color = InteractiveChatDiscordSrvAddon.plugin.invColor;
break;
default:
color = Color.black;
break;
}
byte[] imageData = ImageUtils.toArray(image);
DiscordMessageContent content = new DiscordMessageContent(title, null, null, "attachment://Inventory.png", color);
content.addAttachment("Inventory.png", imageData);
if (type.equals(ImageDisplayType.INVENTORY) && InteractiveChatDiscordSrvAddon.plugin.invShowLevel) {
int level = iData.getPlayer().getExperienceLevel();
byte[] bottleData = ImageUtils.toArray(InteractiveChatDiscordSrvAddon.plugin.modelRenderer.render(32, 32, InteractiveChatDiscordSrvAddon.plugin.resourceManager, InteractiveChat.version.isOld(), "minecraft:item/experience_bottle", ModelDisplayPosition.GUI, false).getImage());
content.addAttachment("Level.png", bottleData);
content.setFooter(LanguageUtils.getTranslation(TranslationKeyUtils.getLevelTranslation(level), InteractiveChatDiscordSrvAddon.plugin.language).replaceFirst("%s", level + ""));
content.setFooterImageUrl("attachment://Level.png");
}
contents.add(content);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (data instanceof HoverClickDisplayData) {
Debug.debug("createContents creating hover event discord content");
try {
HoverClickDisplayData hData = (HoverClickDisplayData) data;
String title = hData.getDisplayText();
Color color = hData.getColor();
DiscordMessageContent content = new DiscordMessageContent(title, null, color);
String body = "";
String preview = null;
if (hData.hasHover()) {
if (InteractiveChatDiscordSrvAddon.plugin.hoverUseTooltipImage) {
Component print = hData.getHoverText();
BufferedImage tooltip = ImageGeneration.getToolTipImage(print, true);
byte[] tooltipData = ImageUtils.toArray(tooltip);
content.addAttachment("ToolTip.png", tooltipData);
content.addImageUrl("attachment://ToolTip.png");
content.addDescription(null);
} else {
body += ComponentStringUtils.stripColorAndConvertMagic(InteractiveChatComponentSerializer.bungeecordApiLegacy().serialize(hData.getHoverText()));
}
}
if (hData.hasClick()) {
switch(hData.getClickAction()) {
case COPY_TO_CLIPBOARD:
if (body.length() > 0) {
body += "\n\n";
}
body += LanguageUtils.getTranslation(TranslationKeyUtils.getCopyToClipboard(), InteractiveChatDiscordSrvAddon.plugin.language) + ": __" + hData.getClickValue() + "__";
break;
case OPEN_URL:
if (body.length() > 0) {
body += "\n\n";
}
String url = hData.getClickValue();
body += LanguageUtils.getTranslation(TranslationKeyUtils.getOpenUrl(), InteractiveChatDiscordSrvAddon.plugin.language) + ": __" + url + "__";
if (URLRequestUtils.IMAGE_URL_PATTERN.matcher(url).matches() && URLRequestUtils.isAllowed(url)) {
preview = url;
}
break;
default:
break;
}
}
if (!body.isEmpty()) {
content.addDescription(body);
}
if (InteractiveChatDiscordSrvAddon.plugin.hoverImage) {
BufferedImage image = InteractiveChatDiscordSrvAddon.plugin.resourceManager.getTextureManager().getTexture(ResourceRegistry.IC_MISC_TEXTURE_LOCATION + "hover_cursor").getTexture();
byte[] imageData = ImageUtils.toArray(image);
content.setAuthorIconUrl("attachment://Hover.png");
content.addAttachment("Hover.png", imageData);
}
if (preview != null) {
content.addImageUrl(preview);
}
contents.add(content);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return contents;
}
Aggregations