<commit_before>package cpup.mc.lib.network

import cpup.mc.lib.{ModLifecycleHandler, CPupModRef, CPupMod}
import cpw.mods.fml.common.event.{FMLPostInitializationEvent, FMLInitializationEvent}
import java.util
import cpw.mods.fml.common.network.{NetworkRegistry, FMLEmbeddedChannel}
import cpw.mods.fml.relauncher.{SideOnly, Side}
import io.netty.handler.codec.MessageToMessageCodec
import cpw.mods.fml.common.network.internal.FMLProxyPacket
import io.netty.channel.{ChannelHandlerContext, ChannelHandler}
import io.netty.buffer.{ByteBuf, Unpooled}
import java.lang.reflect.Constructor
import cpw.mods.fml.common.FMLCommonHandler
import net.minecraft.network.NetHandlerPlayServer
import net.minecraft.client.Minecraft
import net.minecraft.entity.player.EntityPlayer

@ChannelHandler.Sharable
trait CPupNetwork[MOD <: CPupMod[_ <: CPupModRef, MSG], MSG <: CPupMessage] extends MessageToMessageCodec[FMLProxyPacket, MSG] with ModLifecycleHandler {
	def mod: MOD

	var channels: util.EnumMap[Side, FMLEmbeddedChannel]
	var finished = false
	protected var messages = List[Class[_ <: MSG]]()

	def register {
		channels = NetworkRegistry.INSTANCE.newChannel(mod.ref.modID, this)
	}

	def finish {
		if(finished) {
			return
		}

		finished = true

		messages = messages.sortBy(_.getCanonicalName)
	}

	override def init(e: FMLInitializationEvent) { register }
	override def postInit(e: FMLPostInitializationEvent) { finish }

	def handleMessage(msg: MSG, player: EntityPlayer) {
		if(msg.isInstanceOf[TEMsg]) {

		}
	}

	def register(cla: Class[_ <: MSG]): Boolean = {
		if(finished) {
			throw new Exception("Attempt to register a message after post initialization: " + cla.getCanonicalName)
			return false<commit_msg>Make finished only writable from CPupNetwork<commit_after>package cpup.mc.lib.network

import cpup.mc.lib.{ModLifecycleHandler, CPupModRef, CPupMod}
import cpw.mods.fml.common.event.{FMLPostInitializationEvent, FMLInitializationEvent}
import java.util
import cpw.mods.fml.common.network.{NetworkRegistry, FMLEmbeddedChannel}
import cpw.mods.fml.relauncher.{SideOnly, Side}
import io.netty.handler.codec.MessageToMessageCodec
import cpw.mods.fml.common.network.internal.FMLProxyPacket
import io.netty.channel.{ChannelHandlerContext, ChannelHandler}
import io.netty.buffer.{ByteBuf, Unpooled}
import java.lang.reflect.Constructor
import cpw.mods.fml.common.FMLCommonHandler
import net.minecraft.network.NetHandlerPlayServer
import net.minecraft.client.Minecraft
import net.minecraft.entity.player.EntityPlayer

@ChannelHandler.Sharable
trait CPupNetwork[MOD <: CPupMod[_ <: CPupModRef, MSG], MSG <: CPupMessage] extends MessageToMessageCodec[FMLProxyPacket, MSG] with ModLifecycleHandler {
	def mod: MOD

	var channels: util.EnumMap[Side, FMLEmbeddedChannel]
	protected var messages = List[Class[_ <: MSG]]()
	def register {
		channels = NetworkRegistry.INSTANCE.newChannel(mod.ref.modID, this)
	}

	protected var _finished = false
	def finished = _finished
	def finish {
		if(_finished) {
			return
		}

		_finished = true

		messages = messages.sortBy(_.getCanonicalName)
	}

	override def init(e: FMLInitializationEvent) { register }
	override def postInit(e: FMLPostInitializationEvent) { finish }

	def handleMessage(msg: MSG, player: EntityPlayer) {
		if(msg.isInstanceOf[TEMsg]) {

		}
	}

	def register(cla: Class[_ <: MSG]): Boolean = {
		if(_finished) {
			throw new Exception("Attempt to register a message after post initialization: " + cla.getCanonicalName)
			return false
{'fraction_non_alphanumeric': 0.10091480846197827, 'fraction_numerical': 0.0, 'mean_word_length': 5.7159309021113245, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5826408', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1150, 'n_words': 234}