Posted April 25, 201510 yr i'm sure I've missed something dead simple... i need to get an instance of a player by using it's username in a command. i have had a look around the API and can't seem to find this. i vaguely remember Server.getPlayer("username") ... but that's obviously wrong because if it was right i wouldn't be here haha... does anybody know how to do this?
April 25, 201510 yr Author I actually managed to solve this myself for anybody looking for this solution: public EntityPlayer getPlayer(String name){ ServerConfigurationManager server = MinecraftServer.getServer().getConfigurationManager(); ArrayList pl = (ArrayList) server.playerEntityList; ListIterator li = pl.listIterator(); while (li.hasNext()){ EntityPlayer p = (EntityPlayer) li.next(); if(p.getGameProfile().getName().equals(name)){ return p; } } return null; }
April 26, 201510 yr Or getConfigurationManager().getPlayerByUsername("NAME"); Exists in both 1.7.10 and 1.8 (func_152612_a if your mappings are out-dated)
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.