From 0ca678dae1a4eb5b76b1bfe93fb6b6b7005ea56a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 13 Aug 2016 02:21:50 +0200 Subject: [PATCH] Made player data less world independent but still world independent --- .../mod/data/PlayerData.java | 4 +- .../actuallyadditions/mod/data/WorldData.java | 54 +++++++++---------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/data/PlayerData.java b/src/main/java/de/ellpeck/actuallyadditions/mod/data/PlayerData.java index 2abf22131..7fab450e4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/data/PlayerData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/data/PlayerData.java @@ -13,13 +13,13 @@ package de.ellpeck.actuallyadditions.mod.data; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; -import java.util.ArrayList; +import java.util.List; import java.util.UUID; public final class PlayerData{ public static PlayerSave getDataFromPlayer(UUID id){ - ArrayList data = WorldData.PLAYER_SAVE_DATA; + List data = WorldData.getWorldUnspecificData().playerSaveData; //Get Data from existing data for(PlayerSave save : data){ if(save.theId != null && save.theId.equals(id)){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/data/WorldData.java b/src/main/java/de/ellpeck/actuallyadditions/mod/data/WorldData.java index 594329c34..5017a9c85 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/data/WorldData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/data/WorldData.java @@ -18,6 +18,7 @@ import io.netty.util.internal.ConcurrentSet; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.world.DimensionType; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraft.world.storage.ISaveHandler; @@ -27,14 +28,15 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.ArrayList; +import java.util.List; import java.util.concurrent.ConcurrentHashMap; public class WorldData{ public static final String DATA_TAG = ModUtil.MOD_ID+"data"; - public static final ArrayList PLAYER_SAVE_DATA = new ArrayList(); private static final ConcurrentHashMap WORLD_DATA = new ConcurrentHashMap(); public final ConcurrentSet laserRelayNetworks = new ConcurrentSet(); + public final ArrayList playerSaveData = new ArrayList(); private final ISaveHandler handler; private final int dimension; @@ -43,20 +45,20 @@ public class WorldData{ this.dimension = dimension; } + public static WorldData getWorldUnspecificData(){ + return getDataForWorld(DimensionType.OVERWORLD.getId()); + } + public static WorldData getDataForWorld(World world){ - int dim = world.provider.getDimension(); + return getDataForWorld(world.provider.getDimension()); + } + + public static WorldData getDataForWorld(int dim){ WorldData data = WORLD_DATA.get(dim); if(data == null){ data = new WorldData(null, dim); - - if(world.isRemote){ - WORLD_DATA.put(dim, data); - ModUtil.LOGGER.info("Creating temporary WorldData for world "+dim+" on the client!"); - } - else{ - ModUtil.LOGGER.warn("Trying to get WorldData from world "+dim+" that doesn't have any data!? This shouldn't happen!"); - } + WORLD_DATA.put(dim, data); } return data; @@ -64,9 +66,6 @@ public class WorldData{ public static void load(World world){ if(!world.isRemote && world instanceof WorldServer){ - //Just to be sure it actually gets cleared all the time - PLAYER_SAVE_DATA.clear(); - WorldData data = new WorldData(new WorldSpecificSaveHandler((WorldServer)world, world.getSaveHandler()), world.provider.getDimension()); WORLD_DATA.put(data.dimension, data); @@ -117,7 +116,7 @@ public class WorldData{ } } else{ - ModUtil.LOGGER.error("Tried to save WorldData for "+world.provider.getDimension()+" without any data being present!?"); + ModUtil.LOGGER.error("Tried to save WorldData for "+world.provider.getDimension()+" without any data handler being present!?"); } } } @@ -139,15 +138,12 @@ public class WorldData{ this.laserRelayNetworks.add(network); } - if(this.dimension == 0){ - //Player Data - PLAYER_SAVE_DATA.clear(); - - NBTTagList playerList = compound.getTagList("PlayerData", 10); - for(int i = 0; i < playerList.tagCount(); i++){ - PlayerSave aSave = PlayerSave.fromNBT(playerList.getCompoundTagAt(i)); - PLAYER_SAVE_DATA.add(aSave); - } + //Player Data + this.playerSaveData.clear(); + NBTTagList playerList = compound.getTagList("PlayerData", 10); + for(int i = 0; i < playerList.tagCount(); i++){ + PlayerSave aSave = PlayerSave.fromNBT(playerList.getCompoundTagAt(i)); + this.playerSaveData.add(aSave); } } @@ -159,13 +155,11 @@ public class WorldData{ } compound.setTag("Networks", networkList); - if(this.dimension == 0){ - //Player Data - NBTTagList playerList = new NBTTagList(); - for(PlayerSave theSave : PLAYER_SAVE_DATA){ - playerList.appendTag(theSave.toNBT()); - } - compound.setTag("PlayerData", playerList); + //Player Data + NBTTagList playerList = new NBTTagList(); + for(PlayerSave theSave : this.playerSaveData){ + playerList.appendTag(theSave.toNBT()); } + compound.setTag("PlayerData", playerList); } }