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 036938e65..e3631917f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/data/PlayerData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/data/PlayerData.java @@ -14,52 +14,55 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import java.util.ArrayList; +import java.util.UUID; -//Yes, this is name based instead of UUID-based. -//It just works better this way because of vanilla quirks. Don't judge me. public final class PlayerData{ - public static PlayerSave getDataFromPlayer(String name){ + public static PlayerSave getDataFromPlayer(UUID id){ ArrayList data = WorldData.PLAYER_SAVE_DATA; //Get Data from existing data for(PlayerSave save : data){ - if(save.theName != null && save.theName.equals(name)){ + if(save.theId != null && save.theId.equals(id)){ return save; } } //Add Data if none is existant - PlayerSave aSave = new PlayerSave(name, new NBTTagCompound()); + PlayerSave aSave = new PlayerSave(id, new NBTTagCompound()); data.add(aSave); return aSave; } public static PlayerSave getDataFromPlayer(EntityPlayer player){ - return getDataFromPlayer(player.getName()); + return getDataFromPlayer(player.getUniqueID()); } public static class PlayerSave{ - public final String theName; + public final UUID theId; public NBTTagCompound theCompound; - public PlayerSave(String name, NBTTagCompound theCompound){ - this.theName = name; + public PlayerSave(UUID theId, NBTTagCompound theCompound){ + this.theId = theId; this.theCompound = theCompound; } public static PlayerSave fromNBT(NBTTagCompound compound){ - String name = compound.getString("Name"); + UUID theID = new UUID(compound.getLong("MostSignificant"), compound.getLong("LeastSignificant")); NBTTagCompound theCompound = compound.getCompoundTag("Tag"); - return new PlayerSave(name, theCompound); + return new PlayerSave(theID, theCompound); } public NBTTagCompound toNBT(){ NBTTagCompound compound = new NBTTagCompound(); - compound.setString("Name", this.theName); + compound.setLong("LeastSignificant", this.theId.getLeastSignificantBits()); + compound.setLong("MostSignificant", this.theId.getMostSignificantBits()); + compound.setTag("Tag", this.theCompound); + return compound; } } + } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java index d053430b2..0a53fc410 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java @@ -98,14 +98,14 @@ public class CommonEvents{ PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player); if(!data.theCompound.hasNoTags()){ NBTTagCompound compound = new NBTTagCompound(); - compound.setString("Name", player.getName()); + compound.setUniqueId("UUID", player.getUniqueID()); compound.setTag("Data", data.theCompound); compound.setBoolean("Log", true); PacketHandler.theNetwork.sendTo(new PacketServerToClient(compound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), player); - ModUtil.LOGGER.info("Sending Player Data to player "+player.getName()+" with info "+data.theCompound+"."); + ModUtil.LOGGER.info("Sending Player Data to player "+player.getName()+" with UUID "+player.getUniqueID()+" with info "+data.theCompound+"."); } else{ - ModUtil.LOGGER.info("Not sending Player Data to player "+player.getName()+" because he doesn't have any."); + ModUtil.LOGGER.info("Not sending Player Data to player "+player.getName()+" with UUID "+player.getUniqueID()+" because he doesn't have any."); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java index 34d70f351..3e51a7ec5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java @@ -95,7 +95,7 @@ public class ItemLaserWrench extends ItemBase{ if(player instanceof EntityPlayerMP){ NBTTagCompound compound = new NBTTagCompound(); - compound.setString("Name", player.getName()); + compound.setUniqueId("UUID", player.getUniqueID()); compound.setTag("Data", save.theCompound); PacketHandler.theNetwork.sendTo(new PacketServerToClient(compound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java index 7501078da..a2e5de46e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java @@ -34,6 +34,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import java.util.ArrayList; import java.util.List; +import java.util.UUID; public final class PacketHandler{ @@ -99,10 +100,10 @@ public final class PacketHandler{ @SideOnly(Side.CLIENT) public void handleData(NBTTagCompound compound){ NBTTagCompound data = compound.getCompoundTag("Data"); - String name = compound.getString("Name"); - PlayerData.getDataFromPlayer(name).theCompound = data; + UUID id = compound.getUniqueId("UUID"); + PlayerData.getDataFromPlayer(id).theCompound = data; if(compound.getBoolean("Log")){ - ModUtil.LOGGER.info("Receiving Player Data for player "+name+" with info "+data+"."); + ModUtil.LOGGER.info("Receiving Player Data for current player with UUID "+id+" with info "+data+"."); } } }; @@ -136,7 +137,7 @@ public final class PacketHandler{ playerData.theCompound.merge(data); if(player instanceof EntityPlayerMP){ NBTTagCompound tag = new NBTTagCompound(); - tag.setString("Name", player.getName()); + tag.setUniqueId("UUID", player.getUniqueID()); tag.setTag("Data", playerData.theCompound); PacketHandler.theNetwork.sendTo(new PacketServerToClient(tag, PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player); }