2015-09-27 15:31:43 +02:00
|
|
|
/*
|
2015-10-06 16:36:25 +02:00
|
|
|
* This file ("PersistentServerData.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
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2015-11-02 20:55:19 +01:00
|
|
|
* © 2015 Ellpeck
|
2015-09-27 15:31:43 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package ellpeck.actuallyadditions.util.playerdata;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
2015-10-22 22:18:33 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.UUID;
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2015-10-22 22:18:33 +02:00
|
|
|
public class PersistentServerData{
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2015-10-22 22:18:33 +02:00
|
|
|
public static ArrayList<PlayerSave> playerSaveData = new ArrayList<PlayerSave>();
|
|
|
|
|
|
|
|
public static NBTTagCompound getDataFromPlayer(EntityPlayer player){
|
|
|
|
//Get Data from existing data
|
|
|
|
for(PlayerSave save : playerSaveData){
|
|
|
|
if(save.thePlayerUUID.equals(player.getUniqueID())){
|
|
|
|
return save.theCompound;
|
|
|
|
}
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
2015-10-22 22:18:33 +02:00
|
|
|
|
|
|
|
//Add Data if none is existant
|
|
|
|
PlayerSave aSave = new PlayerSave(player.getUniqueID(), new NBTTagCompound());
|
|
|
|
playerSaveData.add(aSave);
|
|
|
|
return aSave.theCompound;
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
|
2015-10-22 22:18:33 +02:00
|
|
|
public static class PlayerSave{
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2015-10-22 22:18:33 +02:00
|
|
|
public UUID thePlayerUUID;
|
|
|
|
public NBTTagCompound theCompound;
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2015-10-22 22:18:33 +02:00
|
|
|
public PlayerSave(UUID theUUID, NBTTagCompound theCompound){
|
|
|
|
this.thePlayerUUID = theUUID;
|
|
|
|
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){
|
|
|
|
UUID theID = new UUID(compound.getLong("MostSignificant"), compound.getLong("LeastSignificant"));
|
|
|
|
NBTTagCompound theCompound = compound.getCompoundTag("Tag");
|
2015-10-23 16:54:33 +02:00
|
|
|
return new PlayerSave(theID, theCompound);
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:51:00 +01:00
|
|
|
public NBTTagCompound toNBT(){
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
compound.setLong("LeastSignificant", this.thePlayerUUID.getLeastSignificantBits());
|
|
|
|
compound.setLong("MostSignificant", this.thePlayerUUID.getMostSignificantBits());
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2015-10-29 19:51:00 +01:00
|
|
|
compound.setTag("Tag", this.theCompound);
|
|
|
|
|
|
|
|
return compound;
|
2015-09-27 15:31:43 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-22 22:18:33 +02:00
|
|
|
|
2015-09-27 15:31:43 +02:00
|
|
|
}
|