package com.unascribed.lanthanoid.network;

import com.unascribed.lanthanoid.Lanthanoid;
import com.unascribed.lanthanoid.LanthanoidProperties;
import com.unascribed.lanthanoid.item.eldritch.armor.ItemEldritchArmor;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;

public final class SetFlyingState {

	public enum State {
		NONE,
		HOVER,
		FLYING
	}
	
	public static class Handler implements IMessageHandler<Message, IMessage> {

		@Override
		public IMessage onMessage(Message message, MessageContext ctx) {
			EntityPlayerMP player = ctx.getServerHandler().playerEntity;
			State state = message.state;
			if (ItemEldritchArmor.hasSetBonus(player)) {
				int totalGlyphs = 0;
				for (ItemStack is : player.inventory.armorInventory) {
					totalGlyphs += ((ItemEldritchArmor)is.getItem()).getMilliglyphs(is);
				}
				if (totalGlyphs < 1000) {
					if (state != State.NONE) {
						state = State.NONE;
						Lanthanoid.log.warn(player.getGameProfile().getName()+" tried to fly without enough glyphs!");
					}
				}
			} else {
				if (state != State.NONE) {
					state = State.NONE;
					Lanthanoid.log.warn(player.getGameProfile().getName()+" tried to fly without a full set of Eldritch armor!");
				}
			}
			LanthanoidProperties props = (LanthanoidProperties) player.getExtendedProperties("lanthanoid");
			props.flyingState = state;
			return null;
		}
		
	}
	
	public static class Message implements IMessage {
		public State state;
		
		public Message() {}
		public Message(State state) {
			this.state = state;
		}
		
		@Override
		public void fromBytes(ByteBuf buf) {
			state = State.values()[buf.readUnsignedByte()%State.values().length];
		}

		@Override
		public void toBytes(ByteBuf buf) {
			buf.writeByte(state.ordinal());
		}
		
	}
	
	private SetFlyingState() {}
}

@@ -41,53 +41,8 @@
 k;%0A%0A
-import com.unascribed.lanthanoid.Lanthanoid;%0A
 impo
@@ -1118,298 +1118,82 @@
 %09%09%09%09
-%09Lanthanoid.log.warn(player.getGameProfile().getName()+%22 tried to fly without enough glyphs!%22);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D else %7B%0A%09%09%09%09if (state != State.NONE) %7B%0A%09%09%09%09%09state = State.NONE;%0A%09%09%09%09%09Lanthanoid.log.warn(player.getGameProfile().getName()+%22 tried to fly without a full set of Eldritch armor!%22)
+%7D%0A%09%09%09%09%7D%0A%09%09%09%7D else %7B%0A%09%09%09%09if (state != State.NONE) %7B%0A%09%09%09%09%09state = State.NONE
 ;%0A%09%09

Fix console spam in SetFlyingState