EntityPlayerMP from Player

I’m making a plugin that would be a sidemod to a forge mod and running a command as console would simplify my code a lot, I’m not sure it’s been implemented yet but i’ll ask anyways, is there any way to do it?

If not i have a workaround but it requires me to have an EntityPlayerMP(from forge).
The problem is that the function that i’m working on gets called when a player sends a command and that gives me an instance of Player.
My question is, how do i get EntityPlayerMP from a Player instance?

I’ve been trying to use

EntityPlayerMP p1 =(EntityPlayerMP) MinecraftServer.getServer().getEntityFromUuid(p.getPlayer().get().getUniqueId());

but it doesn’t seem to work.

When sponge is loaded, an EntityPlayerMP is a Player, and therefore you can cast one to another.
I think getting the entity from the UUID should work too, not sure why it’s not.

1 Like

Assuming that p isn’t null, I can’t imagine why it wouldn’t work. After-all, the EntityPlayerMP object is being called from the UUID which all players have. EntityPlayerMP or Player aside, the UUID values should be consistent. Although, like @simon816 said when ninja’ing me, in the Forge implementation of Sponge, Player is an instance of EntityPlayerMP and you should be able to safely cast it as such, without needing to resort to the UUID.

EDIT: Meaning;
EntityPlayerMP player = (EntityPlayerMP) p;


Damn i didn’t think of that. I feel stupid since i’ve been thinking about this for like 2 days :L
I feel dumb.

And MinecraftServer.getServer() doesn’t work at all on his own, maybe i got something wrong with my build path and stuff but, yeah, thank you very much for the fast reply both of you.