Search in sources :

Example 1 with ChatComponentClickEvent

use of net.blay09.mods.chattweaks.event.ChatComponentClickEvent in project ChatTweaks by blay09.

the class GuiChatExt method handleComponentClick.

@Override
public boolean handleComponentClick(ITextComponent component) {
    if (component != null) {
        if (MinecraftForge.EVENT_BUS.post(new ChatComponentClickEvent(component))) {
            return true;
        }
        ClickEvent clickEvent = component.getStyle().getClickEvent();
        if (clickEvent != null) {
            if (clickEvent.getAction() == ClickEvent.Action.OPEN_URL) {
                String url = clickEvent.getValue();
                String directURL = null;
                for (Function<String, String> function : ChatTweaks.getImageURLTransformers()) {
                    directURL = function.apply(url);
                    if (directURL != null) {
                        break;
                    }
                }
                if (directURL != null) {
                    try {
                        Minecraft.getMinecraft().displayGuiScreen(new GuiImagePreview(Minecraft.getMinecraft().currentScreen, new URL(url), new URL(directURL)));
                        return true;
                    } catch (MalformedURLException e) {
                        ChatTweaks.logger.error("Could not open image preview: ", e);
                    }
                }
            }
        }
    }
    return super.handleComponentClick(component);
}
Also used : MalformedURLException(java.net.MalformedURLException) ChatComponentClickEvent(net.blay09.mods.chattweaks.event.ChatComponentClickEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) ChatComponentClickEvent(net.blay09.mods.chattweaks.event.ChatComponentClickEvent) URL(java.net.URL)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ChatComponentClickEvent (net.blay09.mods.chattweaks.event.ChatComponentClickEvent)1 ClickEvent (net.minecraft.util.text.event.ClickEvent)1