Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package your_package;
- import java.util.HashMap;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.nbt.NBTTagCompound;
- import cpw.mods.fml.common.IPlayerTracker;
- import path.to.a_class_that_can_store_your_values;
- class HelperHelper implements IPlayerTracker{
- public static final instance = new HelperHelper(); //You register this instance in your @Mod-file
- //by typing
- //GameRegistry.registerPlayerTracker(HelperHelper.instance);
- private static HashMap<EntityPlayer, a_class_that_can_store_your_values> playerData = new
- HashMap<EntityPlayer, a_class_that_can_store_your_values>(); //This HashMap stores the playerData while the
- //player is logged in.
- public static a_class_that_can_store_your_values getValuesFor(EntityPlayer player)
- //With this method you can access the player's data while he is on the server
- {
- return playerData.get(player);
- }
- @Override
- public void onPlayerLogin(EntityPlayer player) //This is the earliest point where you would need the data
- {
- if(player.getEntityData().hasKey("what_so_ever") //Replace what_so_ever with any String you want
- {
- playerData.put(player, readFromNBTStream(player.getEntityData().getCompoundTag("what_so_ever"); //Here the same String as before
- }else{
- playerData.put(player, new a_class_that_can_store_your_values()); //If the player has no
- //saved data
- //You create new data for him
- }
- }
- @Override
- public void onPlayerLogout(EntityPlayer player) //Here you can save the data for the player
- {
- playerData.remove(player); //You can now "unload" the player as you won't need the data anymore
- }
- private a_class_that_can_store_your_values readFromNBTStream(NBTTagCompound playerCompound) //This returns
- //a new instance of your player-data
- {
- a_class_that_can_store_your_values toReturn = new a_class_that_can_store_your_values();
- toReturn.readFromNBTTagCompound(playerCompound);
- return toReturn;
- }
- @Override
- public void onPlayerChangedDimension(EntityPlayer player) {}
- @Override
- public void onPlayerRespawn(EntityPlayer player) {}
- }
- public class a_class_that_can_store_your_values { //You can put it anywhere you want. Also in other files
- //your values
- public a_class_that_can_store_your_values()
- {
- //set your default values
- }
- public void readFromNBTTagCompound(NBTTagCompound toReadFrom) {
- //read the values you need
- }
- public void writeToNBTTagCompound(NBTTagCompound toWriteTo) {
- //write the values
- }
- //Feature methods to access the player data and all the variables you need
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement