2018-09-12 05:43:59 +00:00
|
|
|
package com.seodisparate.TurnBasedMinecraft.common;
|
2018-08-28 02:26:34 +00:00
|
|
|
|
2018-08-28 06:13:14 +00:00
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
2018-08-29 06:09:44 +00:00
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision;
|
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleInfo;
|
2018-09-06 08:08:36 +00:00
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage;
|
2018-08-29 06:09:44 +00:00
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleRequestInfo;
|
2018-10-16 05:02:44 +00:00
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketGeneralMessage;
|
2018-08-28 06:13:14 +00:00
|
|
|
|
2018-09-12 05:43:59 +00:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2018-08-28 02:26:34 +00:00
|
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventHandler;
|
2018-09-12 06:39:55 +00:00
|
|
|
import net.minecraftforge.fml.common.SidedProxy;
|
2018-08-28 02:26:34 +00:00
|
|
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
2018-09-03 06:19:33 +00:00
|
|
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
2018-08-28 02:26:34 +00:00
|
|
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
2018-09-20 06:15:34 +00:00
|
|
|
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
|
2018-09-12 07:00:55 +00:00
|
|
|
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
|
|
|
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
2018-08-29 06:09:44 +00:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
2018-08-28 02:26:34 +00:00
|
|
|
|
2018-08-28 02:51:26 +00:00
|
|
|
@Mod(modid = TurnBasedMinecraftMod.MODID, name = TurnBasedMinecraftMod.NAME, version = TurnBasedMinecraftMod.VERSION)
|
2018-08-28 02:26:34 +00:00
|
|
|
public class TurnBasedMinecraftMod
|
|
|
|
{
|
2018-08-28 02:51:26 +00:00
|
|
|
public static final String MODID = "com.seodisparate.turnbasedminecraft";
|
2018-08-28 02:26:34 +00:00
|
|
|
public static final String NAME = "Turn Based Minecraft Mod";
|
2018-10-18 07:28:47 +00:00
|
|
|
public static final String VERSION = "1.4";
|
2018-09-03 06:19:33 +00:00
|
|
|
public static final String CONFIG_FILENAME = "TBM_Config.xml";
|
|
|
|
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
|
|
|
|
public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME;
|
2018-09-07 07:41:22 +00:00
|
|
|
public static final String CONFIG_INTERNAL_PATH = "/assets/TurnBasedMinecraft/" + CONFIG_FILENAME;
|
2018-09-14 05:14:10 +00:00
|
|
|
public static final String MUSIC_ROOT = CONFIG_DIRECTORY + "Music/";
|
|
|
|
public static final String MUSIC_SILLY = MUSIC_ROOT + "silly/";
|
|
|
|
public static final String MUSIC_BATTLE = MUSIC_ROOT + "battle/";
|
2018-09-10 05:59:56 +00:00
|
|
|
|
2018-09-12 07:00:55 +00:00
|
|
|
public static final SimpleNetworkWrapper NWINSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("seodisparate.tbmc");
|
2018-09-12 05:43:59 +00:00
|
|
|
protected static Logger logger;
|
2018-08-29 06:09:44 +00:00
|
|
|
private static int packetHandlerID = 0;
|
|
|
|
|
2018-09-12 06:39:55 +00:00
|
|
|
@SidedProxy(modId=MODID, serverSide="com.seodisparate.TurnBasedMinecraft.common.CommonProxy", clientSide="com.seodisparate.TurnBasedMinecraft.client.ClientProxy")
|
2018-09-28 08:45:32 +00:00
|
|
|
public static CommonProxy proxy;
|
2018-08-28 02:26:34 +00:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void preInit(FMLPreInitializationEvent event)
|
|
|
|
{
|
|
|
|
logger = event.getModLog();
|
2018-09-28 08:45:32 +00:00
|
|
|
proxy.setLogger(logger);
|
2018-08-28 02:26:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void init(FMLInitializationEvent event)
|
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
proxy.initialize();
|
2018-08-29 06:09:44 +00:00
|
|
|
|
|
|
|
// register packets
|
2018-09-12 07:00:55 +00:00
|
|
|
NWINSTANCE.registerMessage(
|
2018-08-29 06:09:44 +00:00
|
|
|
PacketBattleInfo.HandlerBattleInfo.class,
|
|
|
|
PacketBattleInfo.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.CLIENT);
|
2018-09-12 07:00:55 +00:00
|
|
|
NWINSTANCE.registerMessage(
|
2018-08-29 06:09:44 +00:00
|
|
|
PacketBattleRequestInfo.HandlerBattleRequestInfo.class,
|
|
|
|
PacketBattleRequestInfo.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.SERVER);
|
2018-09-12 07:00:55 +00:00
|
|
|
NWINSTANCE.registerMessage(
|
2018-08-29 06:09:44 +00:00
|
|
|
PacketBattleDecision.HandleBattleDecision.class,
|
|
|
|
PacketBattleDecision.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.SERVER);
|
2018-09-12 07:00:55 +00:00
|
|
|
NWINSTANCE.registerMessage(
|
2018-09-06 08:08:36 +00:00
|
|
|
PacketBattleMessage.HandlerBattleMessage.class,
|
|
|
|
PacketBattleMessage.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.CLIENT);
|
2018-10-16 05:02:44 +00:00
|
|
|
NWINSTANCE.registerMessage(
|
|
|
|
PacketGeneralMessage.HandlerGeneralMessage.class,
|
|
|
|
PacketGeneralMessage.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.CLIENT);
|
2018-09-12 05:43:59 +00:00
|
|
|
|
|
|
|
// register event handler(s)
|
|
|
|
MinecraftForge.EVENT_BUS.register(new AttackEventHandler());
|
2018-10-17 03:19:16 +00:00
|
|
|
MinecraftForge.EVENT_BUS.register(new PlayerJoinEventHandler());
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void postInit(FMLPostInitializationEvent event)
|
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
proxy.postInit();
|
2018-09-20 06:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void serverStarting(FMLServerStartingEvent event)
|
|
|
|
{
|
|
|
|
logger.debug("About to initialize BattleManager");
|
2018-09-28 08:45:32 +00:00
|
|
|
if(proxy.initializeBattleManager())
|
2018-09-20 06:15:34 +00:00
|
|
|
{
|
|
|
|
logger.debug("Initialized BattleManager");
|
|
|
|
}
|
2018-10-16 05:02:44 +00:00
|
|
|
|
|
|
|
proxy.getConfig().clearBattleIgnoringPlayers();
|
|
|
|
|
|
|
|
// register commands
|
|
|
|
event.registerServerCommand(new CommandTBMDisable(proxy.getConfig()));
|
|
|
|
event.registerServerCommand(new CommandTBMEnable(proxy.getConfig()));
|
|
|
|
event.registerServerCommand(new CommandTBMSet(proxy.getConfig()));
|
2018-10-17 03:19:16 +00:00
|
|
|
event.registerServerCommand(new CommandTBMDisableAll(proxy.getConfig()));
|
|
|
|
event.registerServerCommand(new CommandTBMEnableAll(proxy.getConfig()));
|
2018-09-20 06:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void serverStopping(FMLServerStoppingEvent event)
|
|
|
|
{
|
|
|
|
logger.debug("About to cleanup BattleManager");
|
2018-09-28 08:45:32 +00:00
|
|
|
if(proxy.cleanupBattleManager())
|
2018-09-20 06:15:34 +00:00
|
|
|
{
|
|
|
|
logger.debug("Cleaned up BattleManager");
|
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
2018-08-28 02:26:34 +00:00
|
|
|
}
|