ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/data/PlayerData.java

69 lines
2.1 KiB
Java
Raw Normal View History

/*
2016-08-02 13:08:22 +02:00
* This file ("PlayerData.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.data;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import java.util.List;
import java.util.UUID;
2016-06-17 23:50:38 +02:00
public final class PlayerData{
public static PlayerSave getDataFromPlayer(UUID id){
List<PlayerSave> data = WorldData.getWorldUnspecificData().playerSaveData;
//Get Data from existing data
for(PlayerSave save : data){
if(save.theId != null && save.theId.equals(id)){
return save;
}
2015-10-03 10:16:18 +02:00
}
//Add Data if none is existant
PlayerSave aSave = new PlayerSave(id, new NBTTagCompound());
data.add(aSave);
return aSave;
2015-10-03 10:16:18 +02:00
}
public static PlayerSave getDataFromPlayer(EntityPlayer player){
return getDataFromPlayer(player.getUniqueID());
}
public static class PlayerSave{
public final UUID theId;
public NBTTagCompound theCompound;
public PlayerSave(UUID theId, NBTTagCompound theCompound){
this.theId = theId;
this.theCompound = theCompound;
}
2015-10-29 19:51:00 +01:00
public static PlayerSave fromNBT(NBTTagCompound compound){
UUID theID = new UUID(compound.getLong("MostSignificant"), compound.getLong("LeastSignificant"));
2015-10-29 19:51:00 +01:00
NBTTagCompound theCompound = compound.getCompoundTag("Tag");
return new PlayerSave(theID, theCompound);
2015-10-23 16:54:33 +02:00
}
2015-10-29 19:51:00 +01:00
public NBTTagCompound toNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setLong("LeastSignificant", this.theId.getLeastSignificantBits());
compound.setLong("MostSignificant", this.theId.getMostSignificantBits());
2015-10-29 19:51:00 +01:00
compound.setTag("Tag", this.theCompound);
2015-10-29 19:51:00 +01:00
return compound;
}
}
}