use of com.loohp.interactivechatdiscordsrvaddon.listeners.InboundToGameEvents.DiscordAttachmentData in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class InteractiveChatDiscordSrvAddonAPI method getDiscordImageWrapperByUUID.
/**
* Get the preview image map by the assigned uuid
*
* @param uuid the uuid of the image wrapper
* @return The image preview map (Could be null)
*/
public static GraphicsToPacketMapWrapper getDiscordImageWrapperByUUID(UUID uuid) {
Optional<DiscordAttachmentData> opt = InboundToGameEvents.DATA.values().stream().filter(each -> each.getUniqueId().equals(uuid)).findFirst();
DiscordAttachmentData data;
if (opt.isPresent() && (data = opt.get()).isImage()) {
return data.getImageMap();
} else {
return null;
}
}
use of com.loohp.interactivechatdiscordsrvaddon.listeners.InboundToGameEvents.DiscordAttachmentData in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class Commands method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!label.equalsIgnoreCase("interactivechatdiscordsrv") && !label.equalsIgnoreCase("icd")) {
return true;
}
if (args.length == 0) {
sender.sendMessage(ChatColor.AQUA + "InteractiveChat DiscordSRV Addon written by LOOHP!");
sender.sendMessage(ChatColor.GOLD + "You are running ICDiscordSRVAddon version: " + InteractiveChatDiscordSrvAddon.plugin.getDescription().getVersion());
return true;
}
if (args[0].equalsIgnoreCase("status")) {
if (sender.hasPermission("interactivechatdiscordsrv.status")) {
sender.sendMessage(InteractiveChatDiscordSrvAddon.plugin.defaultResourceHashLang.replaceFirst("%s", InteractiveChatDiscordSrvAddon.plugin.defaultResourceHash + " (" + InteractiveChat.exactMinecraftVersion + ")"));
sender.sendMessage(InteractiveChatDiscordSrvAddon.plugin.loadedResourcesLang);
for (ResourcePackInfo info : InteractiveChatDiscordSrvAddon.plugin.resourceManager.getResourcePackInfo()) {
String name = info.getName();
if (info.getStatus()) {
Component component = Component.text(" - " + name).color(info.comparePackFormat() == 0 ? NamedTextColor.GREEN : NamedTextColor.YELLOW);
Component hoverComponent = info.getDescription();
if (info.comparePackFormat() > 0) {
hoverComponent = hoverComponent.append(LegacyComponentSerializer.legacySection().deserialize("\n" + ChatColor.YELLOW + LanguageUtils.getTranslation(TranslationKeyUtils.getNewIncompatiblePack(), InteractiveChatDiscordSrvAddon.plugin.language)));
} else if (info.comparePackFormat() < 0) {
hoverComponent = hoverComponent.append(LegacyComponentSerializer.legacySection().deserialize("\n" + ChatColor.YELLOW + LanguageUtils.getTranslation(TranslationKeyUtils.getOldIncompatiblePack(), InteractiveChatDiscordSrvAddon.plugin.language)));
}
component = component.hoverEvent(HoverEvent.showText(hoverComponent));
InteractiveChatAPI.sendMessage(sender, component);
if (!(sender instanceof Player)) {
for (Component each : ComponentStyling.splitAtLineBreaks(info.getDescription())) {
InteractiveChatAPI.sendMessage(sender, Component.text(" - ").color(NamedTextColor.GRAY).append(each));
if (info.comparePackFormat() > 0) {
sender.sendMessage(ChatColor.YELLOW + " " + LanguageUtils.getTranslation(TranslationKeyUtils.getNewIncompatiblePack(), InteractiveChatDiscordSrvAddon.plugin.language));
} else if (info.comparePackFormat() < 0) {
sender.sendMessage(ChatColor.YELLOW + " " + LanguageUtils.getTranslation(TranslationKeyUtils.getOldIncompatiblePack(), InteractiveChatDiscordSrvAddon.plugin.language));
}
}
}
} else {
Component component = Component.text(" - " + name).color(NamedTextColor.RED);
if (info.getRejectedReason() != null) {
component = component.hoverEvent(HoverEvent.showText(Component.text(info.getRejectedReason()).color(NamedTextColor.RED)));
}
InteractiveChatAPI.sendMessage(sender, component);
if (!(sender instanceof Player)) {
InteractiveChatAPI.sendMessage(sender, Component.text(" - ").append(Component.text(info.getRejectedReason()).color(NamedTextColor.RED)).color(NamedTextColor.RED));
}
}
}
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
return true;
}
if (args[0].equalsIgnoreCase("reloadconfig")) {
if (sender.hasPermission("interactivechatdiscordsrv.reloadconfig")) {
try {
if (InteractiveChatDiscordSrvAddon.plugin.resourceReloadLock.tryLock(0, TimeUnit.MILLISECONDS)) {
try {
InteractiveChatDiscordSrvAddon.plugin.reloadConfig();
Bukkit.getPluginManager().callEvent(new InteractiveChatDiscordSRVConfigReloadEvent());
sender.sendMessage(InteractiveChatDiscordSrvAddon.plugin.reloadConfigMessage);
} catch (Throwable e) {
e.printStackTrace();
}
InteractiveChatDiscordSrvAddon.plugin.resourceReloadLock.unlock();
} else {
sender.sendMessage(ChatColor.YELLOW + "Resource reloading in progress, please wait!");
}
} catch (IllegalStateException | InterruptedException e) {
}
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
return true;
}
if (args[0].equalsIgnoreCase("reloadtexture")) {
List<String> argList = Arrays.asList(args);
boolean clean = argList.contains("--reset");
boolean redownload = argList.contains("--redownload") || clean;
if (sender.hasPermission("interactivechatdiscordsrv.reloadtexture")) {
sender.sendMessage(InteractiveChatDiscordSrvAddon.plugin.reloadTextureMessage);
InteractiveChatDiscordSrvAddon.plugin.reloadTextures(redownload, clean, sender);
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
return true;
}
if (args[0].equalsIgnoreCase("update")) {
if (sender.hasPermission("interactivechatdiscordsrv.update")) {
sender.sendMessage(ChatColor.AQUA + "[ICDiscordSrvAddon] InteractiveChat DiscordSRV Addon written by LOOHP!");
sender.sendMessage(ChatColor.GOLD + "[ICDiscordSrvAddon] You are running ICDiscordSRVAddon version: " + InteractiveChatDiscordSrvAddon.plugin.getDescription().getVersion());
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChatDiscordSrvAddon.plugin, () -> {
UpdaterResponse version = Updater.checkUpdate();
if (version.getResult().equals("latest")) {
if (version.isDevBuildLatest()) {
sender.sendMessage(ChatColor.GREEN + "[ICDiscordSrvAddon] You are running the latest version!");
} else {
Updater.sendUpdateMessage(sender, version.getResult(), version.getSpigotPluginId(), true);
}
} else {
Updater.sendUpdateMessage(sender, version.getResult(), version.getSpigotPluginId());
}
});
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
return true;
}
if (args[0].equalsIgnoreCase("imagemap")) {
if (args.length > 1 && sender instanceof Player) {
try {
DiscordAttachmentData data = InboundToGameEvents.DATA.get(UUID.fromString(args[1]));
if (data != null && (data.isImage() || data.isVideo())) {
GraphicsToPacketMapWrapper imageMap = data.getImageMap();
if (imageMap.futureCancelled()) {
sender.sendMessage(InteractiveChatDiscordSrvAddon.plugin.linkExpired);
} else if (imageMap.futureCompleted()) {
imageMap.show((Player) sender);
} else {
sender.sendMessage(InteractiveChatDiscordSrvAddon.plugin.previewLoading);
}
} else {
sender.sendMessage(InteractiveChatDiscordSrvAddon.plugin.linkExpired);
}
} catch (Exception e) {
sender.sendMessage(InteractiveChatDiscordSrvAddon.plugin.linkExpired);
}
}
return true;
}
sender.sendMessage(ChatColorUtils.translateAlternateColorCodes('&', Bukkit.spigot().getConfig().getString("messages.unknown-command")));
return true;
}
Aggregations