CommandHelper

CommandHelper

46.5k Downloads

Get directly a player name with entityID

LadyCailinBot opened this issue ยท 5 comments

commented

CMDHELPER-2697 - Reported by Hekta

Is it possible to add a function like pname(entityID) to get directly a player name ? I know it's possible to get the name oneself with a script, but i think a direct function will be more efficient.

commented

Comment by Tom.Gebbett

EDIT: Misinterpreted your request, thought you wanted to get a player name using a player.

You're right that you can't do this without an iteration, but the iteration could be very quick. I'd guess 0.01 - 0.1ms for 1-8 players.

commented

Comment by Hekta

But for example, I have not succeed to get the name of a player NPC with that way, and perhaps this will be possible with this function ?

commented

Comment by Tom.Gebbett

proc('_eid_player',@EID,foreach(all_players(),@p,if(pinfo(@p,13) == @EID){return(@p)}))

One line of code, just wrote in about a minute.
The paramater @EID is the entity ID.
It took 0.09ms to run, for one player. It returned correctly.
Do tell me if this is not what you wanted.

EDIT: Player NPC? That is a contradiction. Do you mean a fake player created by an NPC plugin? You'd likely need to get the plugin creator to do something about that, as the way i understand NPC plugins is that they do not handle the entities in the same way as actual players. It's mostly packet manipulation. I could be wrong.

If however, the player entity is stored as a regular player entity, then you will need to find out how their 'player name' is handled. If commandhelper can't access the entity like a normal player, as i asssume you have found, then it's likely that bukkit can't either, at least not by any exposed means. If you can get any information about the entity itself, then it may be possible the get the name.

commented

Comment by Hekta

Yes, by NPC players I was talking about fake players from Citizens plugin. All functions I tested work well with NPC, and to find their names I found out how to do with the events that always return the name of a player, even if it is a NPC.

And I also will continue to use the iteration when needed for real player name.

Thanks.

commented

Comment by jb_aero

Added in 1555