# 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.

Josh

• @Judge2020 Thanks for the reply but I have already tried that and it doesn't seem to work. – joshbas0300 Feb 7 '16 at 9:07

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.
Minecraft.getMinecraft().player.getName()