Package com.kokakiwi.mclauncher.core.launcher

Source Code of com.kokakiwi.mclauncher.core.launcher.Wrapper

package com.kokakiwi.mclauncher.core.launcher;

import java.applet.Applet;
import java.io.File;
import java.lang.reflect.Field;

import com.kokakiwi.mclauncher.api.LauncherAPI;

public class Wrapper
{
    public static Applet wrap(LauncherAPI api) throws Exception
    {
        final Class<?> clazz = api.getLauncher().getClassLoader()
                .loadClass("net.minecraft.client.MinecraftApplet");
       
        doChanges(api, clazz);
       
        final Applet applet = (Applet) clazz.newInstance();
       
        return applet;
    }
   
    public static void doChanges(LauncherAPI api, Class<?> clazz)
    {
        try
        {
            final Class<?> c = api.getLauncher().getClassLoader()
                    .loadClass("net.minecraft.client.Minecraft");
           
            for (final Field field : c.getDeclaredFields())
            {
                if (field.getType() == File.class)
                {
                    field.setAccessible(true);
                    try
                    {
                        field.get(c);
                        field.set(null, api.getMinecraftDirectory());
                    }
                    catch (final IllegalArgumentException e)
                    {
                       
                    }
                    catch (final IllegalAccessException e)
                    {
                       
                    }
                }
            }
        }
        catch (final ClassNotFoundException e)
        {
           
        }
    }
}
TOP

Related Classes of com.kokakiwi.mclauncher.core.launcher.Wrapper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.