Jump to content

Get EntityPlayer on Server + Added NBT data persisting on Death


WayofTime

Recommended Posts

Hey, guys, it's me again!

 

The issue I am having this time is that I need an item to be able to store the player entity, and how I do that is by storing the name. That works well and everything, works perfectly while in SSP, but for some reason it does NOT work when I am testing this while on a server.

 

Below is the code that I use to get the EntityPlayer from the string.

EntityPlayer owner = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(tag.getString("ownerName"));

 

(There is some null checking before and after this line)

 

From what I understand, seeing as when the client uses this on a server receives a NPE, the client is unable to get the server (or config manager, etc) from this line of code, and thus can not obtain the EntityPlayer from this. I either need a method that will return the EntityPlayer from a string representation, or be able to instead get the .dat file instead, since I am mainly interested in the stored data of the player's .dat file.

 

Second part, a separate matter, is that when the player dies any custom information that I add to the Entity data is erased. What I use is this:

NBTTagCompound playerTag = owner.getEntityData();
if(playerTag.getInteger("currentEssence")>=this.getEnergyUsed())
    	{
    		return true;
    	}

 

I suppose that when I save/access the information to/from the Entity, I am not saving it in an area that persists. I suppose the main issue with this is that I am not directly accessing the player's .dat file, and thus am not able to write persistent information.

 

I think that both of these issues relate to the need of directly getting the player's .dat information from a string, so if anyone has a method to do this for a server, that would be greatly appreciated!

Link to comment
Share on other sites

use a class that extends IExtendedEntityProperties

 

I suppose that will work for the second issue, but it doesn't help with the first. Basically I'd need to get the NBTTagCompound (the one returned by .getEntityData()) by a different method.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.