added backwards compatibility for legacy (pre 1.7.10) savefiles

This commit is contained in:
Azanor committed 2014-07-10 14:17:59 +02:00
1 parent 00d4c4aed0
commit 52956f04f3
5 files changed
+40 -5

No files matched your search

@@ -1,14 +1,19 @@
package baubles.common.event;
import java.io.File;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import baubles.api.IBauble;
import baubles.common.Baubles;
import baubles.common.container.InventoryBaubles;
import baubles.common.lib.PlayerHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import com.google.common.io.Files;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
public class EventHandlerEntity {
@@ -47,12 +52,34 @@ public class EventHandlerEntity {
@SubscribeEvent
public void playerLoad(PlayerEvent.LoadFromFile event) {
PlayerHandler.clearPlayerBaubles(event.entityPlayer);
PlayerHandler.loadPlayerBaubles(event.entityPlayer, event.getPlayerFile("baub"), event.getPlayerFile("baubback"));
File file1 = event.getPlayerFile("baub");
if (!file1.exists()) {
File filet = getLegacyFileFromPlayer(event.entityPlayer);
if (filet.exists()) {
try {
Files.copy(filet, file1);
Baubles.log.info("Using pre MC 1.7.10 Baubles savefile for "+event.entityPlayer.getCommandSenderName());
} catch (IOException e) {}
}
}
PlayerHandler.loadPlayerBaubles(event.entityPlayer, file1, event.getPlayerFile("baubback"));
for (int a = 0; a < 4; a++)
PlayerHandler.getPlayerBaubles(event.entityPlayer)
.syncSlotToClients(a);
}
public static File getLegacyFileFromPlayer(EntityPlayer player)
{
try {
File playersDirectory = new File(player.worldObj.getSaveHandler().getWorldDirectory(), "players");
return new File(playersDirectory, player.getCommandSenderName() + ".baub");
} catch (Exception e) { e.printStackTrace(); }
return null;
}
@SubscribeEvent
public void playerSave(PlayerEvent.SaveToFile event) {