use of com.loohp.interactivechatdiscordsrvaddon.objectholders.HoverClickDisplayData 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