package coolsquid.react.network;

import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;

import coolsquid.react.ConfigManager;
import coolsquid.react.event.InternalEventManager;

import com.typesafe.config.ConfigFactory;

import io.netty.buffer.ByteBuf;

public class PacketConfig implements IMessage {

	byte[] config;

	public PacketConfig() {

	}

	public PacketConfig(byte[] config) {
		this.config = config;
	}

	@Override
	public void fromBytes(ByteBuf buf) {
		this.config = new byte[buf.readableBytes()];
		buf.readBytes(this.config);
		buf.release();
	}

	@Override
	public void toBytes(ByteBuf buf) {
		buf.writeBytes(this.config);
	}

	public static class Handler implements IMessageHandler<PacketConfig, IMessage> {

		private static boolean hasServerConfigs;

		@Override
		public IMessage onMessage(PacketConfig message, MessageContext ctx) {
			if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
				InternalEventManager.LISTENERS.clear();
				ConfigManager.load(ConfigFactory.parseString(new String(message.config)));
				hasServerConfigs = true;
			}
			return null;
		}

		public static boolean hasServerConfigs() {
			return hasServerConfigs;
		}
	}
}
@@ -391,60 +391,8 @@
 er;%0D
-%0Aimport coolsquid.react.event.InternalEventManager;%0D
 %0A%0D%0Ai
@@ -1170,53 +1170,8 @@
  %7B%0D%0A
-%09%09%09%09InternalEventManager.LISTENERS.clear();%0D%0A
 %09%09%09%09

Fix bug that prevented multiple config files from being synced