Jump to content

[1.7.10] [SOLVED] My UUID is not my UUID [old title: UUID and Name Problems]


Bektor

Recommended Posts

Hello,

 

I have written a small Item that stores the UUID of the player that only this player can use it, but now I want that instead of the UUID the player name will be shown, so that every other player knows "Ok, this isn't my item". So is there a way to get the Player name by the UUID and to update it if the player name was changed? I want to use the addInformation method for that.

 

Bektor

 

"NEW" PROBLEM: look a bit down or use that link ;)http://www.minecraftforge.net/forum/index.php?action=post;quote=114249;topic=22491.0;last_msg=114249

Developer of Primeval Forest.

Link to comment
Share on other sites

How about store the UUID and player name when the ownership is given and at some point check to see if the UUID is the same, but username isn't. If the two names are different and UUIDs are the same, then change the name then. And the addInformation is good for this stuff. Just make sure the NBT exists in the ItemStack.

-Mitchellbrine

 

Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible.

It may be freaking fucking hard though, but still possible ;)

 

If you create a topic on Modder Support, live by this motto:

I don't want your charity, I want your information
Link to comment
Share on other sites

Ok. I did this, but something is wrong:

 

It says that this items didn't belong to me, but it is my item and it won't send the right chat message (only the path where I can find it in the language file...).

So here is the code:

 

	/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
{
	if(world.isRemote)
		return itemStack;

	if(!itemStack.hasTagCompound())
		itemStack.setTagCompound(new NBTTagCompound());

	NBTTagCompound nbttagcompound = itemStack.getTagCompound();
	NBTTagString nbttagstring = (NBTTagString)nbttagcompound.getTag("author");
	NBTTagString nbtnamestring = (NBTTagString)nbttagcompound.getTag("name");

	if(nbttagstring == null)
		itemStack.setTagInfo("author", new NBTTagString(player.getUniqueID().toString()));

	if(nbtnamestring == null)
		itemStack.setTagInfo("name", new NBTTagString("Hallo")); // for testing it  // TODO: player.getDisplayName()

	if(nbttagstring != null && nbtnamestring != null)
	{
		if(!nbttagstring.equals(player.getUniqueID().toString()))
		{
			if(!world.isRemote)
				player.addChatComponentMessage(new ChatComponentTranslation("msg.wrong_player.txt"));
		}
		else
		{
			if(!nbtnamestring.equals(player.getDisplayName()))
				itemStack.setTagInfo("name", new NBTTagString(player.getDisplayName()));

			player.openGui(PrimevalForest.instance, EnumGUI.QUESTLOG.getID(), world, (int)player.posX, (int)player.posY, (int)player.posZ);
		}
	}

	return itemStack;
}

/**
 * Called when item is crafted/smelted.
 */
@Override
public void onCreated(ItemStack itemStack, World world, EntityPlayer player)
{
	super.onCreated(itemStack, world, player);

	if(!itemStack.hasTagCompound())
		itemStack.setTagCompound(new NBTTagCompound());

	NBTTagCompound nbttagcompound = itemStack.getTagCompound();
	NBTTagString nbttagstring = (NBTTagString)nbttagcompound.getTag("author");
	NBTTagString nbtnamestring = (NBTTagString)nbttagcompound.getTag("name");

	if(nbttagstring == null)
		itemStack.setTagInfo("author", new NBTTagString(player.getUniqueID().toString()));

	if(nbtnamestring == null)
		itemStack.setTagInfo("name", new NBTTagString(player.getDisplayName()));
}

/**
 * allows items to add custom lines of information to the mouseover description
 */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4)
{
	if(itemStack.hasTagCompound())
	{
		NBTTagCompound nbttagcompound = itemStack.getTagCompound();
		NBTTagString nbtnamestring = (NBTTagString)nbttagcompound.getTag("name");

		if(nbtnamestring != null)
			list.add(EnumChatFormatting.GOLD + String.format("Owner: " + nbtnamestring));
		else
			list.add(EnumChatFormatting.RED + String.format("No Owner!"));
	}
}

 

So what is there wrong?

 

Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

Ok. I found something out. If I let write Minecraft my UUID and the UUID of the NBTTagString in the Chat then this happens:

 

UUID

"UUID"

 

(Well, I replaced the UUID with the word UUID here...)

But if I fix this then, then it says that this isn't my item, too:

 

"UUID"

"UUID"

 

I tested it with nbttagstring.toString() != player.getUniqueID().toString() -> if this is true, then it says me, that this item is not yours.

And I tested it with nbttagstring.equals(player.getUniqueID) and then I tested both on a way that the output is "UUID" so because NBTTagString saves it with "" (I'm don't know the english word for " ) and inside of "" its putting the UUID, so I tried it by checking that it add " before and after the player.getUniqueID() so that the chat output is the same, but for an unknown reason it returns everytime true, so everytime it thinks that I'm not the owner of the item that I'm the owner from.

 

And the second problem is, that the method

player.addChatComponentMessage(new ChatComponentTranslation("msg.wrong_player.txt"));

will always return

msg.wrong_player.txt
instead of the chat message that I put in the language file.

 

So whats wrong.

 

Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

player.getUniqueID() is not what you think it is.

 

Use player.getGameProfile().getId(); That will always stay the same.

-Mitchellbrine

 

Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible.

It may be freaking fucking hard though, but still possible ;)

 

If you create a topic on Modder Support, live by this motto:

I don't want your charity, I want your information
Link to comment
Share on other sites

Right, toString()! Forgot about that. What he said is correct, Bektor. Do not use getUniqueID() or getPersistentID() because they are per session (or world, I can't figure it out either).

-Mitchellbrine

 

Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible.

It may be freaking fucking hard though, but still possible ;)

 

If you create a topic on Modder Support, live by this motto:

I don't want your charity, I want your information
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.