diff --git a/src/main/java/ellpeck/actuallyadditions/event/CraftEvent.java b/src/main/java/ellpeck/actuallyadditions/event/CraftEvent.java index a6c21c960..2e6c6ae88 100644 --- a/src/main/java/ellpeck/actuallyadditions/event/CraftEvent.java +++ b/src/main/java/ellpeck/actuallyadditions/event/CraftEvent.java @@ -36,7 +36,7 @@ public class CraftEvent{ NBTTagCompound compound = PersistentServerData.getDataFromPlayer(event.player); if(compound != null && !compound.getBoolean("BookGottenAlready")){ compound.setBoolean("BookGottenAlready", true); - WorldData.makeDirty(false); + WorldData.makeDirty(); EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemLexicon)); entityItem.delayBeforeCanPickup = 0; diff --git a/src/main/java/ellpeck/actuallyadditions/event/WorldLoadingEvents.java b/src/main/java/ellpeck/actuallyadditions/event/WorldLoadingEvents.java index e753ee80c..1426e5c0f 100644 --- a/src/main/java/ellpeck/actuallyadditions/event/WorldLoadingEvents.java +++ b/src/main/java/ellpeck/actuallyadditions/event/WorldLoadingEvents.java @@ -26,11 +26,11 @@ public class WorldLoadingEvents{ @SubscribeEvent public void onUnload(WorldEvent.Unload event){ - WorldData.makeDirty(true); + WorldData.makeDirty(); } @SubscribeEvent public void onSave(WorldEvent.Save event){ - WorldData.makeDirty(false); + WorldData.makeDirty(); } } diff --git a/src/main/java/ellpeck/actuallyadditions/misc/LaserRelayConnectionHandler.java b/src/main/java/ellpeck/actuallyadditions/misc/LaserRelayConnectionHandler.java index 6acbf8fc0..d88374dad 100644 --- a/src/main/java/ellpeck/actuallyadditions/misc/LaserRelayConnectionHandler.java +++ b/src/main/java/ellpeck/actuallyadditions/misc/LaserRelayConnectionHandler.java @@ -87,7 +87,7 @@ public class LaserRelayConnectionHandler{ } //System.out.println("Removing a Relay from the Network!"); } - WorldData.makeDirty(false); + WorldData.makeDirty(); } /** @@ -140,7 +140,7 @@ public class LaserRelayConnectionHandler{ else if(secondNetwork != null){ secondNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay)); } - WorldData.makeDirty(false); + WorldData.makeDirty(); //System.out.println("Connected "+firstRelay.toString()+" to "+secondRelay.toString()); //System.out.println(firstNetwork == null ? secondNetwork.toString() : firstNetwork.toString()); //System.out.println(this.networks); @@ -156,7 +156,7 @@ public class LaserRelayConnectionHandler{ firstNetwork.connections.add(secondPair); } this.networks.remove(secondNetwork); - WorldData.makeDirty(false); + WorldData.makeDirty(); //System.out.println("Merged Two Networks!"); } diff --git a/src/main/java/ellpeck/actuallyadditions/misc/WorldData.java b/src/main/java/ellpeck/actuallyadditions/misc/WorldData.java index 52f7ad7ac..92cc5542f 100644 --- a/src/main/java/ellpeck/actuallyadditions/misc/WorldData.java +++ b/src/main/java/ellpeck/actuallyadditions/misc/WorldData.java @@ -23,16 +23,13 @@ public class WorldData extends WorldSavedData{ public static final String DATA_TAG = ModUtil.MOD_ID+"WorldData"; public static WorldData instance; - public boolean shouldClearAfterSave; - public WorldData(String tag){ super(tag); } - public static void makeDirty(boolean shouldClearAfterSave){ + public static void makeDirty(){ if(instance != null){ instance.markDirty(); - instance.shouldClearAfterSave = shouldClearAfterSave; } } @@ -40,6 +37,7 @@ public class WorldData extends WorldSavedData{ if(server != null){ World world = server.getEntityWorld(); if(!world.isRemote){ + clearOldData(); ModUtil.LOGGER.info("Loading WorldData!"); WorldData savedData = (WorldData)world.loadItemData(WorldData.class, WorldData.DATA_TAG); @@ -60,6 +58,15 @@ public class WorldData extends WorldSavedData{ } } + public static void clearOldData(){ + if(!LaserRelayConnectionHandler.getInstance().networks.isEmpty()){ + ModUtil.LOGGER.info("Clearing leftover Laser Relay Connection Data from other worlds!"); + } + if(!PersistentServerData.playerSaveData.isEmpty()){ + ModUtil.LOGGER.info("Clearing leftover Persistent Server Data from other worlds!"); + } + } + @Override public void readFromNBT(NBTTagCompound compound){ //Laser World Data @@ -93,13 +100,5 @@ public class WorldData extends WorldSavedData{ playerList.appendTag(theSave.toNBT()); } compound.setTag("PlayerData", playerList); - - if(this.shouldClearAfterSave){ - ModUtil.LOGGER.info("Clearing WorldData after saving! (Probably because the world is getting unloaded)"); - this.shouldClearAfterSave = false; - - PersistentServerData.playerSaveData.clear(); - LaserRelayConnectionHandler.getInstance().networks.clear(); - } } }