// Path: main/java/com/yyon/grapplinghook/network/LoggedInMessage.java
// public class LoggedInMessage implements IMessage {
//     GrappleConfig.Config conf = null;
// 
//     public LoggedInMessage() { }
//     
//     public LoggedInMessage(GrappleConfig.Config serverconf) {
//     	this.conf = serverconf;
//     }
// 
//     @Override
//     public void fromBytes(ByteBuf buf) {
//     	Class<GrappleConfig.Config> confclass = GrappleConfig.Config.class;
//     	Field[] fields = confclass.getDeclaredFields();
//     	Arrays.sort(fields, new Comparator<Field>() {
//     	    @Override
//     	    public int compare(Field o1, Field o2) {
//     	        return o1.getName().compareTo(o2.getName());
//     	    }
//     	});
//     	
//     	this.conf = new GrappleConfig.Config();
//     	
//     	for (Field field : fields) {
//     		Type fieldtype = field.getGenericType();
//     		try {
//         		if (fieldtype.getTypeName().equals("int")) {
//         			field.setInt(this.conf, buf.readInt());
//         		} else if (fieldtype.getTypeName().equals("double")) {
//         			field.setDouble(this.conf, buf.readDouble());
//         		} else if (fieldtype.getTypeName().equals("boolean")) {
//         			field.setBoolean(this.conf, buf.readBoolean());
//         		} else if (fieldtype.getTypeName().equals("java.lang.String")) {
//         			int len = buf.readInt();
//         			CharSequence charseq = buf.readCharSequence(len, Charset.defaultCharset());
//         			field.set(this.conf, charseq.toString());
//         		} else {
//         			System.out.println("Unknown Type");
//         			System.out.println(fieldtype.getTypeName());
//         		}
//     		} catch (IllegalAccessException e) {
//     			System.out.println(e);
//     		}
//     	}
//     }
// 
//     @Override
//     public void toBytes(ByteBuf buf) {
//     	Class<GrappleConfig.Config> confclass = GrappleConfig.Config.class;
//     	Field[] fields = confclass.getDeclaredFields();
//     	Arrays.sort(fields, new Comparator<Field>() {
//     	    @Override
//     	    public int compare(Field o1, Field o2) {
//     	        return o1.getName().compareTo(o2.getName());
//     	    }
//     	});
//     	
//     	for (Field field : fields) {
//     		Type fieldtype = field.getGenericType();
//     		try {
//         		if (fieldtype.getTypeName().equals("int")) {
//         			buf.writeInt(field.getInt(this.conf));
//         		} else if (fieldtype.getTypeName().equals("double")) {
//         			buf.writeDouble(field.getDouble(this.conf));
//         		} else if (fieldtype.getTypeName().equals("boolean")) {
//         			buf.writeBoolean(field.getBoolean(this.conf));
//         		} else if (fieldtype.getTypeName().equals("java.lang.String")) {
//         			String str = (String) field.get(this.conf);
//         			buf.writeInt(str.length());
//         			buf.writeCharSequence(str.subSequence(0, str.length()), Charset.defaultCharset());
//         		} else {
//         			System.out.println("Unknown Type");
//         			System.out.println(fieldtype.getTypeName());
//         		}
//     		} catch (IllegalAccessException e) {
//     			System.out.println(e);
//     		}
//     	}
//     }
// 
//     public static class Handler implements IMessageHandler<LoggedInMessage, IMessage> {
//     	public class runner implements Runnable {
//     		LoggedInMessage message;
//     		MessageContext ctx;
//     		public runner(LoggedInMessage message, MessageContext ctx) {
//     			super();
//     			this.message = message;
//     			this.ctx = ctx;
//     		}
//     		
//             @Override
//             public void run() {
//             	GrappleConfig.setserveroptions(this.message.conf);
//             }
//     	}
//     	
//        
//         @Override
//         public IMessage onMessage(LoggedInMessage message, MessageContext ctx) {
// 
//         	IThreadListener mainThread = Minecraft.getMinecraft();
//             mainThread.addScheduledTask(new runner(message, ctx));
// 
//             return null; 
//         }
//     }
// }


import com.yyon.grapplinghook.network.LoggedInMessage;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
package com.yyon.grapplinghook;





public class ServerProxyClass extends CommonProxyClass {
	@Override
	public void preInit(FMLPreInitializationEvent event) {
		super.preInit(event);
	}

	@Override
	public void init(FMLInitializationEvent event, grapplemod grapplemod) {
		super.init(event, grapplemod);
	}
	
	@Override
	public void postInit(FMLPostInitializationEvent event) {
		super.postInit(event);
		
		if (GrappleConfig.getconf().override_allowflight) {
			FMLCommonHandler.instance().getMinecraftServerInstance().setAllowFlight(true);
		}
	}
	
	@SubscribeEvent
	public void onPlayerLoggedInEvent(PlayerLoggedInEvent e) {
		if (e.player instanceof EntityPlayerMP) {
// Path: main/java/com/yyon/grapplinghook/network/LoggedInMessage.java
// public class LoggedInMessage implements IMessage {
//     GrappleConfig.Config conf = null;
// 
//     public LoggedInMessage() { }
//     
//     public LoggedInMessage(GrappleConfig.Config serverconf) {
//     	this.conf = serverconf;
//     }
// 
//     @Override
//     public void fromBytes(ByteBuf buf) {
//     	Class<GrappleConfig.Config> confclass = GrappleConfig.Config.class;
//     	Field[] fields = confclass.getDeclaredFields();
//     	Arrays.sort(fields, new Comparator<Field>() {
//     	    @Override
//     	    public int compare(Field o1, Field o2) {
//     	        return o1.getName().compareTo(o2.getName());
//     	    }
//     	});
//     	
//     	this.conf = new GrappleConfig.Config();
//     	
//     	for (Field field : fields) {
//     		Type fieldtype = field.getGenericType();
//     		try {
//         		if (fieldtype.getTypeName().equals("int")) {
//         			field.setInt(this.conf, buf.readInt());
//         		} else if (fieldtype.getTypeName().equals("double")) {
//         			field.setDouble(this.conf, buf.readDouble());
//         		} else if (fieldtype.getTypeName().equals("boolean")) {
//         			field.setBoolean(this.conf, buf.readBoolean());
//         		} else if (fieldtype.getTypeName().equals("java.lang.String")) {
//         			int len = buf.readInt();
//         			CharSequence charseq = buf.readCharSequence(len, Charset.defaultCharset());
//         			field.set(this.conf, charseq.toString());
//         		} else {
//         			System.out.println("Unknown Type");
//         			System.out.println(fieldtype.getTypeName());
//         		}
//     		} catch (IllegalAccessException e) {
//     			System.out.println(e);
//     		}
//     	}
//     }
// 
//     @Override
//     public void toBytes(ByteBuf buf) {
//     	Class<GrappleConfig.Config> confclass = GrappleConfig.Config.class;
//     	Field[] fields = confclass.getDeclaredFields();
//     	Arrays.sort(fields, new Comparator<Field>() {
//     	    @Override
//     	    public int compare(Field o1, Field o2) {
//     	        return o1.getName().compareTo(o2.getName());
//     	    }
//     	});
//     	
//     	for (Field field : fields) {
//     		Type fieldtype = field.getGenericType();
//     		try {
//         		if (fieldtype.getTypeName().equals("int")) {
//         			buf.writeInt(field.getInt(this.conf));
//         		} else if (fieldtype.getTypeName().equals("double")) {
//         			buf.writeDouble(field.getDouble(this.conf));
//         		} else if (fieldtype.getTypeName().equals("boolean")) {
//         			buf.writeBoolean(field.getBoolean(this.conf));
//         		} else if (fieldtype.getTypeName().equals("java.lang.String")) {
//         			String str = (String) field.get(this.conf);
//         			buf.writeInt(str.length());
//         			buf.writeCharSequence(str.subSequence(0, str.length()), Charset.defaultCharset());
//         		} else {
//         			System.out.println("Unknown Type");
//         			System.out.println(fieldtype.getTypeName());
//         		}
//     		} catch (IllegalAccessException e) {
//     			System.out.println(e);
//     		}
//     	}
//     }
// 
//     public static class Handler implements IMessageHandler<LoggedInMessage, IMessage> {
//     	public class runner implements Runnable {
//     		LoggedInMessage message;
//     		MessageContext ctx;
//     		public runner(LoggedInMessage message, MessageContext ctx) {
//     			super();
//     			this.message = message;
//     			this.ctx = ctx;
//     		}
//     		
//             @Override
//             public void run() {
//             	GrappleConfig.setserveroptions(this.message.conf);
//             }
//     	}
//     	
//        
//         @Override
//         public IMessage onMessage(LoggedInMessage message, MessageContext ctx) {
// 
//         	IThreadListener mainThread = Minecraft.getMinecraft();
//             mainThread.addScheduledTask(new runner(message, ctx));
// 
//             return null; 
//         }
//     }
// }


// Path: main/java/com/yyon/grapplinghook/ServerProxyClass.java
import com.yyon.grapplinghook.network.LoggedInMessage;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;

package com.yyon.grapplinghook;





public class ServerProxyClass extends CommonProxyClass {
	@Override
	public void preInit(FMLPreInitializationEvent event) {
		super.preInit(event);
	}

	@Override
	public void init(FMLInitializationEvent event, grapplemod grapplemod) {
		super.init(event, grapplemod);
	}
	
	@Override
	public void postInit(FMLPostInitializationEvent event) {
		super.postInit(event);
		
		if (GrappleConfig.getconf().override_allowflight) {
			FMLCommonHandler.instance().getMinecraftServerInstance().setAllowFlight(true);
		}
	}
	
	@SubscribeEvent
	public void onPlayerLoggedInEvent(PlayerLoggedInEvent e) {
		if (e.player instanceof EntityPlayerMP) {
			grapplemod.network.sendTo(new LoggedInMessage(GrappleConfig.options), (EntityPlayerMP) e.player);