Make Player Data UUID dependent again because apparently that works correctly now~

This commit is contained in:
Ellpeck 2016-07-14 20:25:12 +02:00
parent a0a23b90c7
commit 84c6549c86
4 changed files with 24 additions and 20 deletions

View file

@ -14,52 +14,55 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import java.util.ArrayList; 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 final class PlayerData{
public static PlayerSave getDataFromPlayer(String name){ public static PlayerSave getDataFromPlayer(UUID id){
ArrayList<PlayerSave> data = WorldData.PLAYER_SAVE_DATA; ArrayList<PlayerSave> data = WorldData.PLAYER_SAVE_DATA;
//Get Data from existing data //Get Data from existing data
for(PlayerSave save : data){ for(PlayerSave save : data){
if(save.theName != null && save.theName.equals(name)){ if(save.theId != null && save.theId.equals(id)){
return save; return save;
} }
} }
//Add Data if none is existant //Add Data if none is existant
PlayerSave aSave = new PlayerSave(name, new NBTTagCompound()); PlayerSave aSave = new PlayerSave(id, new NBTTagCompound());
data.add(aSave); data.add(aSave);
return aSave; return aSave;
} }
public static PlayerSave getDataFromPlayer(EntityPlayer player){ public static PlayerSave getDataFromPlayer(EntityPlayer player){
return getDataFromPlayer(player.getName()); return getDataFromPlayer(player.getUniqueID());
} }
public static class PlayerSave{ public static class PlayerSave{
public final String theName; public final UUID theId;
public NBTTagCompound theCompound; public NBTTagCompound theCompound;
public PlayerSave(String name, NBTTagCompound theCompound){ public PlayerSave(UUID theId, NBTTagCompound theCompound){
this.theName = name; this.theId = theId;
this.theCompound = theCompound; this.theCompound = theCompound;
} }
public static PlayerSave fromNBT(NBTTagCompound compound){ 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"); NBTTagCompound theCompound = compound.getCompoundTag("Tag");
return new PlayerSave(name, theCompound); return new PlayerSave(theID, theCompound);
} }
public NBTTagCompound toNBT(){ public NBTTagCompound toNBT(){
NBTTagCompound compound = new NBTTagCompound(); 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); compound.setTag("Tag", this.theCompound);
return compound; return compound;
} }
} }
} }

View file

@ -98,14 +98,14 @@ public class CommonEvents{
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player); PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
if(!data.theCompound.hasNoTags()){ if(!data.theCompound.hasNoTags()){
NBTTagCompound compound = new NBTTagCompound(); NBTTagCompound compound = new NBTTagCompound();
compound.setString("Name", player.getName()); compound.setUniqueId("UUID", player.getUniqueID());
compound.setTag("Data", data.theCompound); compound.setTag("Data", data.theCompound);
compound.setBoolean("Log", true); compound.setBoolean("Log", true);
PacketHandler.theNetwork.sendTo(new PacketServerToClient(compound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), player); 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{ 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.");
} }
} }
} }

View file

@ -95,7 +95,7 @@ public class ItemLaserWrench extends ItemBase{
if(player instanceof EntityPlayerMP){ if(player instanceof EntityPlayerMP){
NBTTagCompound compound = new NBTTagCompound(); NBTTagCompound compound = new NBTTagCompound();
compound.setString("Name", player.getName()); compound.setUniqueId("UUID", player.getUniqueID());
compound.setTag("Data", save.theCompound); compound.setTag("Data", save.theCompound);
PacketHandler.theNetwork.sendTo(new PacketServerToClient(compound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player); PacketHandler.theNetwork.sendTo(new PacketServerToClient(compound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player);
} }

View file

@ -34,6 +34,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
public final class PacketHandler{ public final class PacketHandler{
@ -99,10 +100,10 @@ public final class PacketHandler{
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void handleData(NBTTagCompound compound){ public void handleData(NBTTagCompound compound){
NBTTagCompound data = compound.getCompoundTag("Data"); NBTTagCompound data = compound.getCompoundTag("Data");
String name = compound.getString("Name"); UUID id = compound.getUniqueId("UUID");
PlayerData.getDataFromPlayer(name).theCompound = data; PlayerData.getDataFromPlayer(id).theCompound = data;
if(compound.getBoolean("Log")){ 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); playerData.theCompound.merge(data);
if(player instanceof EntityPlayerMP){ if(player instanceof EntityPlayerMP){
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
tag.setString("Name", player.getName()); tag.setUniqueId("UUID", player.getUniqueID());
tag.setTag("Data", playerData.theCompound); tag.setTag("Data", playerData.theCompound);
PacketHandler.theNetwork.sendTo(new PacketServerToClient(tag, PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player); PacketHandler.theNetwork.sendTo(new PacketServerToClient(tag, PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player);
} }