2014-06-22 16:50:31 +02:00
|
|
|
package com.pahimar.ee3.handler;
|
|
|
|
|
2014-09-04 17:30:22 +02:00
|
|
|
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
|
|
|
import com.pahimar.ee3.network.PacketHandler;
|
2014-09-11 22:13:39 +02:00
|
|
|
import com.pahimar.ee3.network.message.MessageSyncEnergyValues;
|
2014-07-20 00:15:40 +02:00
|
|
|
import com.pahimar.ee3.reference.Reference;
|
2014-06-22 16:50:31 +02:00
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
2014-09-04 17:30:22 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2014-06-22 16:50:31 +02:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
|
|
|
|
2015-01-11 21:36:41 +01:00
|
|
|
import java.io.File;
|
2014-06-22 20:03:30 +02:00
|
|
|
|
2014-06-22 16:50:31 +02:00
|
|
|
public class PlayerEventHandler
|
|
|
|
{
|
|
|
|
@SubscribeEvent
|
2014-06-26 21:19:59 +02:00
|
|
|
public void onPlayerLoadFromFileEvent(PlayerEvent.LoadFromFile event)
|
2014-06-22 16:50:31 +02:00
|
|
|
{
|
2014-06-26 21:19:59 +02:00
|
|
|
if (!event.entityPlayer.worldObj.isRemote)
|
2014-06-22 20:03:30 +02:00
|
|
|
{
|
2014-07-18 18:58:35 +02:00
|
|
|
// Grab the correct directory to be reading/writing player knowledge data to
|
2015-01-19 17:39:04 +01:00
|
|
|
if (TransmutationKnowledgeHandler.playerDataDirectory == null || !TransmutationKnowledgeHandler.playerDataDirectory.getAbsolutePath().equalsIgnoreCase(event.playerDirectory.getAbsolutePath()))
|
2014-06-22 20:03:30 +02:00
|
|
|
{
|
2015-01-19 17:39:04 +01:00
|
|
|
TransmutationKnowledgeHandler.playerDataDirectory = new File(event.playerDirectory, Reference.MOD_ID.toLowerCase());
|
2014-07-20 00:15:40 +02:00
|
|
|
|
2015-01-19 17:39:04 +01:00
|
|
|
if (!TransmutationKnowledgeHandler.playerDataDirectory.exists())
|
2014-07-20 00:15:40 +02:00
|
|
|
{
|
2015-01-19 17:39:04 +01:00
|
|
|
TransmutationKnowledgeHandler.playerDataDirectory.mkdir();
|
2014-07-20 00:15:40 +02:00
|
|
|
}
|
2014-06-26 21:19:59 +02:00
|
|
|
|
2015-01-19 17:39:04 +01:00
|
|
|
TransmutationKnowledgeHandler.transmutationKnowledgeDirectory = new File(TransmutationKnowledgeHandler.playerDataDirectory, "knowledge" + File.pathSeparator + "transmutation");
|
2015-01-11 21:36:41 +01:00
|
|
|
|
2015-01-19 17:39:04 +01:00
|
|
|
if (!TransmutationKnowledgeHandler.transmutationKnowledgeDirectory.exists())
|
2014-07-20 00:15:40 +02:00
|
|
|
{
|
2015-01-19 17:39:04 +01:00
|
|
|
TransmutationKnowledgeHandler.transmutationKnowledgeDirectory.mkdir();
|
2014-07-20 00:15:40 +02:00
|
|
|
}
|
2015-01-11 21:36:41 +01:00
|
|
|
}
|
2014-07-20 00:15:40 +02:00
|
|
|
|
2015-01-11 21:36:41 +01:00
|
|
|
// If player knowledge data doesn't exist, initialize a file for the player
|
2015-01-19 17:39:04 +01:00
|
|
|
File playerTransmutationKnowledgeFile = new File(TransmutationKnowledgeHandler.transmutationKnowledgeDirectory, event.entityPlayer.getUniqueID() + TransmutationKnowledgeHandler.KNOWLEDGE_FILE_EXTENSION);
|
2015-01-11 21:36:41 +01:00
|
|
|
if (!playerTransmutationKnowledgeFile.exists())
|
|
|
|
{
|
2015-01-19 17:39:04 +01:00
|
|
|
TransmutationKnowledgeHandler.savePlayerKnowledge(event.entityPlayer);
|
2014-06-22 20:03:30 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-22 16:50:31 +02:00
|
|
|
}
|
2014-09-04 17:30:22 +02:00
|
|
|
|
|
|
|
@SubscribeEvent
|
2014-10-07 22:20:41 +02:00
|
|
|
public void syncEnergyValuesOnLogin(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event)
|
2014-09-04 17:30:22 +02:00
|
|
|
{
|
2014-09-11 22:13:39 +02:00
|
|
|
PacketHandler.INSTANCE.sendTo(new MessageSyncEnergyValues(EnergyValueRegistry.getInstance()), (EntityPlayerMP) event.player);
|
2014-09-04 17:30:22 +02:00
|
|
|
}
|
2014-06-22 16:50:31 +02:00
|
|
|
}
|