How do I get a player's username using Minecraft Forge?

What I want to do is when a player picks up an item I can check the username against mine and if it matches they can keep the item and if it doesn't it gets deleted out of there inventory so only I can use the item.

I'm currently trying to do this onItemUseFist to be honest I have no idea where to start with doing this. I already have the item I want to do this to. I just don't know how to do that. I think xComp does something like this with his glasses in Mystcraft.

Thanks in advance,

Josh


Solution 1:

According to http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/mods-discussion/1399911-how-do-i-get-a-players-username-with-forge,

Minecraft.getMinecraft().thePlayer.username.equals("username")

works. You can put that as the arguments of an if. then statement then an else statement to do what you want to happen if it doesn't match your username. You could also invert the if statement with a ! before the first M then have the code run in the then statement.