2015-09-27 15:31:43 +02:00
|
|
|
/*
|
2016-08-02 13:08:22 +02:00
|
|
|
* This file ("PlayerData.java") is part of the Actually Additions mod for Minecraft.
|
2015-09-27 15:31:43 +02:00
|
|
|
* 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
|
2015-09-27 15:31:43 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-09-27 15:31:43 +02:00
|
|
|
*/
|
|
|
|
|
2016-06-04 13:51:06 +02:00
|
|
|
package de.ellpeck.actuallyadditions.mod.data;
|
2015-09-27 15:31:43 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
2016-08-13 02:21:50 +02:00
|
|
|
import java.util.List;
|
2016-07-14 20:25:12 +02:00
|
|
|
import java.util.UUID;
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2016-06-17 23:50:38 +02:00
|
|
|
public final class PlayerData{
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2016-07-14 20:25:12 +02:00
|
|
|
public static PlayerSave getDataFromPlayer(UUID id){
|
2016-08-13 02:21:50 +02:00
|
|
|
List<PlayerSave> data = WorldData.getWorldUnspecificData().playerSaveData;
|
2015-10-22 22:18:33 +02:00
|
|
|
//Get Data from existing data
|
2016-06-04 13:51:06 +02:00
|
|
|
for(PlayerSave save : data){
|
2016-07-14 20:25:12 +02:00
|
|
|
if(save.theId != null && save.theId.equals(id)){
|
2016-06-15 17:15:26 +02:00
|
|
|
return save;
|
2015-10-22 22:18:33 +02:00
|
|
|
}
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
2015-10-22 22:18:33 +02:00
|
|
|
|
|
|
|
//Add Data if none is existant
|
2016-07-14 20:25:12 +02:00
|
|
|
PlayerSave aSave = new PlayerSave(id, new NBTTagCompound());
|
2016-06-04 13:51:06 +02:00
|
|
|
data.add(aSave);
|
2016-06-15 17:15:26 +02:00
|
|
|
return aSave;
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
|
2016-07-12 22:13:50 +02:00
|
|
|
public static PlayerSave getDataFromPlayer(EntityPlayer player){
|
2016-07-14 20:25:12 +02:00
|
|
|
return getDataFromPlayer(player.getUniqueID());
|
2016-07-12 22:13:50 +02:00
|
|
|
}
|
|
|
|
|
2015-10-22 22:18:33 +02:00
|
|
|
public static class PlayerSave{
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2016-07-14 20:25:12 +02:00
|
|
|
public final UUID theId;
|
2016-06-15 17:15:26 +02:00
|
|
|
public NBTTagCompound theCompound;
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2016-07-14 20:25:12 +02:00
|
|
|
public PlayerSave(UUID theId, NBTTagCompound theCompound){
|
|
|
|
this.theId = theId;
|
2015-10-22 22:18:33 +02:00
|
|
|
this.theCompound = theCompound;
|
|
|
|
}
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2015-10-29 19:51:00 +01:00
|
|
|
public static PlayerSave fromNBT(NBTTagCompound compound){
|
2016-07-14 20:25:12 +02:00
|
|
|
UUID theID = new UUID(compound.getLong("MostSignificant"), compound.getLong("LeastSignificant"));
|
2015-10-29 19:51:00 +01:00
|
|
|
NBTTagCompound theCompound = compound.getCompoundTag("Tag");
|
2016-07-14 20:25:12 +02:00
|
|
|
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();
|
2016-07-14 20:25:12 +02:00
|
|
|
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);
|
2016-07-14 20:25:12 +02:00
|
|
|
|
2015-10-29 19:51:00 +01:00
|
|
|
return compound;
|
2015-09-27 15:31:43 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-22 22:18:33 +02:00
|
|
|
|
2016-07-14 20:25:12 +02:00
|
|
|
|
2015-09-27 15:31:43 +02:00
|
|
|
}
|