<commit_before>package com.ForgeEssentials.core;

import java.io.File;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.world.WorldEvent;

import com.ForgeEssentials.core.commands.CommandFECredits;
import com.ForgeEssentials.core.commands.CommandFEDebug;
import com.ForgeEssentials.core.commands.CommandFEReload;
import com.ForgeEssentials.core.commands.CommandFEVersion;
import com.ForgeEssentials.core.misc.BannedItems;
import com.ForgeEssentials.core.misc.ItemList;
import com.ForgeEssentials.core.misc.LoginMessage;
import com.ForgeEssentials.core.misc.ModListFile;
import com.ForgeEssentials.core.moduleLauncher.ModuleLauncher;
import com.ForgeEssentials.core.network.PacketHandler;
import com.ForgeEssentials.data.DataStorageManager;
import com.ForgeEssentials.data.ForgeConfigDataDriver;
import com.ForgeEssentials.data.H2DataDriver;
import com.ForgeEssentials.data.MySQLDataDriver;
import com.ForgeEssentials.data.NBTDataDriver;
import com.ForgeEssentials.permission.PermissionRegistrationEvent;
import com.ForgeEssentials.util.FunctionHelper;
import com.ForgeEssentials.util.Localization;
import com.ForgeEssentials.util.MiscEventHandler;
import com.ForgeEssentials.util.OutputHandler;
import com.ForgeEssentials.util.TeleportCenter;
import com.ForgeEssentials.util.AreaSelector.Point;
import com.ForgeEssentials.util.AreaSelector.WarpPoint;
import com.ForgeEssentials.util.AreaSelector.WorldPoint;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.Mod.ServerStarted;
import cpw.mods.fml.common.Mod.ServerStarting;
import cpw.mods.fml.common.Mod.ServerStopping;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartedEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkMod.SidedPacketHandler;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;

/**
 * Main mod class
 */

@NetworkMod(clientSideRequired = false, serverSideRequired = false, serverPacketHandlerSpec = @SidedPacketHandler(channels = { "ForgeEssentials" }, packetHandler = PacketHandler.class))
@Mod(modid = "ForgeEssentials", name = "Forge Essentials", version = "@VERSION@")
public class ForgeEssentials
{

	@Instance(value = "ForgeEssentials")
	public static ForgeEssentials instance;

	public static CoreConfig config;
	public ModuleLauncher mdlaunch;
	public Localization localization;
	public static boolean verCheck = true;
	public static boolean preload;

	public static String modlistLocation;
	public static String fedirloc = "ForgeEssentials/";

	public static final File FEDIR = new File(FunctionHelper.getBaseDir(), fedirloc);

	public static DataStorageManager dataManager;
	public BannedItems bannedItems;
	private ItemList itemList;

	private MiscEventHandler miscEventHandler;

	@PreInit
	public void preInit(FMLPreInitializationEvent e)
	{
		OutputHandler.SOP("Forge Essentials is still in alpha. There are plenty of incomplete features in the mod. We hope to seek your understanding.");
		config = new CoreConfig();

		// Data API stuff
		{
			// setup
			dataManager = new DataStorageManager(config.config);

			// register DataDrivers
			DataStorageManager.registerDriver("ForgeConfig", ForgeConfigDataDriver.class);
			DataStorageManager.registerDriver("NBT", NBTDataDriver.class);
			DataStorageManager.registerDriver("MySQL", MySQLDataDriver.class);
			DataStorageManager.registerDriver("H2", H2DataDriver.class);

			// Register saveables..
			DataStorageManager.registerSaveableClass(PlayerInfo.class);
			DataStorageManager.registerSaveableClass(Point.class);
			DataStorageManager.registerSaveableClass(WorldPoint.class);
			DataStorageManager.registerSaveableClass(WarpPoint.class);
		}

		// setup modules AFTER data stuff...
		miscEventHandler = new MiscEventHandler();
		bannedItems = new BannedItems();
		MinecraftForge.EVENT_BUS.register(bannedItems);
		LoginMessage.loadFile();
		mdlaunch = new ModuleLauncher();
		mdlaunch.preLoad(e);
		
		localization = new Localization();
	}

	@Init
	public void load(FMLInitializationEvent e)
	{
		mdlaunch.load(e);
		localization.load();
		GameRegistry.registerPlayerTracker(new PlayerTracker());
	}

	@PostInit
	public void postLoad(FMLPostInitializationEvent e)
	{
		mdlaunch.postLoad(e);
		bannedItems.postLoad(e);

		itemList = new ItemList();
	}

	@ServerStarting
	public void serverStarting(FMLServerStartingEvent e)
	{
		ModListFile.makeModList();

		// Data API stuff
		if (FMLCommonHandler.instance().getSide().isClient())
		{
			dataManager.clearDrivers(); // clear before fuilling up.. if its the
		}
		// client...
		dataManager.setupManager(e);

		// Central TP system
		TickRegistry.registerScheduledTickHandler(new TeleportCenter(), Side.SERVER);

		e.registerServerCommand(new CommandFEVersion());
		e.registerServerCommand(new CommandFECredits());
		e.registerServerCommand(new CommandFEReload());
		e.registerServerCommand(new CommandFEDebug());

		// do modules last... just in case...
		mdlaunch.serverStarting(e);
	}

	@ForgeSubscribe
	public void registerPermissions(PermissionRegistrationEvent event)
	{

	}

	@ServerStarted
	public void serverStarted(FMLServerStartedEvent e)
	{
		mdlaunch.serverStarted(e);
	}

	@ServerStopping
	public void serverStopping(FMLServerStoppingEvent e)
	{
		mdlaunch.serverStopping(e);

		if (FMLCommonHandler.instance().getSide().isServer())
		{
			dataManager.clearDrivers();
		}
	}

	@ForgeSubscribe<commit_msg>Test for saving PlayerInfo on server stop while the player is online.<commit_after>package com.ForgeEssentials.core;

import java.io.File;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.world.WorldEvent;

import com.ForgeEssentials.core.commands.CommandFECredits;
import com.ForgeEssentials.core.commands.CommandFEDebug;
import com.ForgeEssentials.core.commands.CommandFEReload;
import com.ForgeEssentials.core.commands.CommandFEVersion;
import com.ForgeEssentials.core.misc.BannedItems;
import com.ForgeEssentials.core.misc.ItemList;
import com.ForgeEssentials.core.misc.LoginMessage;
import com.ForgeEssentials.core.misc.ModListFile;
import com.ForgeEssentials.core.moduleLauncher.ModuleLauncher;
import com.ForgeEssentials.core.network.PacketHandler;
import com.ForgeEssentials.data.DataStorageManager;
import com.ForgeEssentials.data.ForgeConfigDataDriver;
import com.ForgeEssentials.data.H2DataDriver;
import com.ForgeEssentials.data.MySQLDataDriver;
import com.ForgeEssentials.data.NBTDataDriver;
import com.ForgeEssentials.permission.PermissionRegistrationEvent;
import com.ForgeEssentials.util.FunctionHelper;
import com.ForgeEssentials.util.Localization;
import com.ForgeEssentials.util.MiscEventHandler;
import com.ForgeEssentials.util.OutputHandler;
import com.ForgeEssentials.util.TeleportCenter;
import com.ForgeEssentials.util.AreaSelector.Point;
import com.ForgeEssentials.util.AreaSelector.WarpPoint;
import com.ForgeEssentials.util.AreaSelector.WorldPoint;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.Mod.ServerStarted;
import cpw.mods.fml.common.Mod.ServerStarting;
import cpw.mods.fml.common.Mod.ServerStopping;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartedEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkMod.SidedPacketHandler;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;

/**
 * Main mod class
 */

@NetworkMod(clientSideRequired = false, serverSideRequired = false, serverPacketHandlerSpec = @SidedPacketHandler(channels = { "ForgeEssentials" }, packetHandler = PacketHandler.class))
@Mod(modid = "ForgeEssentials", name = "Forge Essentials", version = "@VERSION@")
public class ForgeEssentials
{

	@Instance(value = "ForgeEssentials")
	public static ForgeEssentials instance;

	public static CoreConfig config;
	public ModuleLauncher mdlaunch;
	public Localization localization;
	public static boolean verCheck = true;
	public static boolean preload;

	public static String modlistLocation;
	public static String fedirloc = "ForgeEssentials/";

	public static final File FEDIR = new File(FunctionHelper.getBaseDir(), fedirloc);

	public static DataStorageManager dataManager;
	public BannedItems bannedItems;
	private ItemList itemList;

	private MiscEventHandler miscEventHandler;

	@PreInit
	public void preInit(FMLPreInitializationEvent e)
	{
		OutputHandler.SOP("Forge Essentials is still in alpha. There are plenty of incomplete features in the mod. We hope to seek your understanding.");
		config = new CoreConfig();

		// Data API stuff
		{
			// setup
			dataManager = new DataStorageManager(config.config);

			// register DataDrivers
			DataStorageManager.registerDriver("ForgeConfig", ForgeConfigDataDriver.class);
			DataStorageManager.registerDriver("NBT", NBTDataDriver.class);
			DataStorageManager.registerDriver("MySQL", MySQLDataDriver.class);
			DataStorageManager.registerDriver("H2", H2DataDriver.class);

			// Register saveables..
			DataStorageManager.registerSaveableClass(PlayerInfo.class);
			DataStorageManager.registerSaveableClass(Point.class);
			DataStorageManager.registerSaveableClass(WorldPoint.class);
			DataStorageManager.registerSaveableClass(WarpPoint.class);
		}

		// setup modules AFTER data stuff...
		miscEventHandler = new MiscEventHandler();
		bannedItems = new BannedItems();
		MinecraftForge.EVENT_BUS.register(bannedItems);
		LoginMessage.loadFile();
		mdlaunch = new ModuleLauncher();
		mdlaunch.preLoad(e);
		
		localization = new Localization();
	}

	@Init
	public void load(FMLInitializationEvent e)
	{
		mdlaunch.load(e);
		localization.load();
		GameRegistry.registerPlayerTracker(new PlayerTracker());
	}

	@PostInit
	public void postLoad(FMLPostInitializationEvent e)
	{
		mdlaunch.postLoad(e);
		bannedItems.postLoad(e);

		itemList = new ItemList();
	}

	@ServerStarting
	public void serverStarting(FMLServerStartingEvent e)
	{
		ModListFile.makeModList();

		// Data API stuff
		if (FMLCommonHandler.instance().getSide().isClient())
		{
			dataManager.clearDrivers(); // clear before fuilling up.. if its the
		}
		// client...
		dataManager.setupManager(e);

		// Central TP system
		TickRegistry.registerScheduledTickHandler(new TeleportCenter(), Side.SERVER);

		e.registerServerCommand(new CommandFEVersion());
		e.registerServerCommand(new CommandFECredits());
		e.registerServerCommand(new CommandFEReload());
		e.registerServerCommand(new CommandFEDebug());

		// do modules last... just in case...
		mdlaunch.serverStarting(e);
	}

	@ForgeSubscribe
	public void registerPermissions(PermissionRegistrationEvent event)
	{

	}

	@ServerStarted
	public void serverStarted(FMLServerStartedEvent e)
	{
		mdlaunch.serverStarted(e);
	}

	@ServerStopping
	public void serverStopping(FMLServerStoppingEvent e)
	{
		mdlaunch.serverStopping(e);

//		if (FMLCommonHandler.instance().getSide().isServer())
//		{
//			dataManager.clearDrivers();
//		}
	}

	@ForgeSubscribe
{'fraction_non_alphanumeric': 0.10095756975400363, 'fraction_numerical': 0.0004952947003467063, 'mean_word_length': 5.8874360432063675, 'pattern_counts': {'":': 0, '<': 3, '<?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': '256884', 'n_tokens_mistral': 4089, 'n_tokens_neox': 3797, 'n_words': 668}