    001    package net.minecraft.client.gui;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.net.URI;
    006    import java.net.URISyntaxException;
    007    import java.util.logging.Level;
    008    import java.util.logging.Logger;
    009    import java.util.regex.Matcher;
    010    import java.util.regex.Pattern;
    011    import net.minecraft.util.StringUtils;
    012
    013    @SideOnly(Side.CLIENT)
    014    public class ChatClickData
    015    {
    016        public static final Pattern pattern = Pattern.compile("^(?:(https?)://)?([-\\w_\\.]{2,}\\.[a-z]{2,3})(/\\S*)?$");
    017        private final FontRenderer fontR;
    018        private final ChatLine line;
    019        private final int field_78312_d;
    020        private final int field_78313_e;
    021        private final String field_78310_f;
    022
    023        /** The URL which was clicked on. */
    024        private final String clickedUrl;
    025
    026        public ChatClickData(FontRenderer par1FontRenderer, ChatLine par2ChatLine, int par3, int par4)
    027        {
    028            this.fontR = par1FontRenderer;
    029            this.line = par2ChatLine;
    030            this.field_78312_d = par3;
    031            this.field_78313_e = par4;
    032            this.field_78310_f = par1FontRenderer.trimStringToWidth(par2ChatLine.getChatLineString(), par3);
    033            this.clickedUrl = this.findClickedUrl();
    034        }
    035
    036        /**
    037         * Gets the URL which was clicked on.
    038         */
    039        public String getClickedUrl()
    040        {
    041            return this.clickedUrl;
    042        }
    043
    044        /**
    045         * computes the URI from the clicked chat data object
    046         */
    047        public URI getURI()
    048        {
    049            String var1 = this.getClickedUrl();
    050
    051            if (var1 == null)
    052            {
    053                return null;
    054            }
    055            else
    056            {
    057                Matcher var2 = pattern.matcher(var1);
    058
    059                if (var2.matches())
    060                {
    061                    try
    062                    {
    063                        String var3 = var2.group(0);
    064
    065                        if (var2.group(1) == null)
    066                        {
    067                            var3 = "http://" + var3;
    068                        }
    069
    070                        return new URI(var3);
    071                    }
    072                    catch (URISyntaxException var4)
    073                    {
    074                        Logger.getLogger("Minecraft").log(Level.SEVERE, "Couldn\'t create URI from chat", var4);
    075                    }
    076                }
    077
    078                return null;
    079            }
    080        }
    081
    082        private String findClickedUrl()
    083        {
    084            int var1 = this.field_78310_f.lastIndexOf(" ", this.field_78310_f.length()) + 1;
    085
    086            if (var1 < 0)
    087            {
    088                var1 = 0;
    089            }
    090
    091            int var2 = this.line.getChatLineString().indexOf(" ", var1);
    092
    093            if (var2 < 0)
    094            {
    095                var2 = this.line.getChatLineString().length();
    096            }
    097
    098            return StringUtils.stripControlCodes(this.line.getChatLineString().substring(var1, var2));
    099        }
    100    }