MrArcane111 Posted December 17, 2012 Share Posted December 17, 2012 I would like to get an EntityPlayer instance inside my ServerTickHandler. So far, I've tried to use a static reference from another class, like this: EntityPlayer player = ClimbingGloveEngine.player; But all that does is pull a NullPointerException. I've seen people getting an instance of the player by using the tickData: EntityPlayer player = (EntityPlayer) tickData[1]; But that also causes an error: an out of bounds. If someone could please help me get a server instance of the player, that would be fantastic. I really don't want to use packets. Thanks for your help! Quote Link to comment Share on other sites More sharing options...
jammas615 Posted December 18, 2012 Share Posted December 18, 2012 How about: EntityPlayer player = server.getConfigurationManager().getPlayerForUsername("playerName"); where server = MinecraftServer.getServer(); This is assuming you know which player you want to get an instance of. Not exactly sure what you need to do with the instance though. Quote If I helped you, thank me. If I didn't, let me know. Link to comment Share on other sites More sharing options...
MrArcane111 Posted December 18, 2012 Author Share Posted December 18, 2012 Well, I would like for all players to be in. Quote Link to comment Share on other sites More sharing options...
jammas615 Posted December 18, 2012 Share Posted December 18, 2012 Have you had a look at the API you get from getConfigurationManager()? http://jd.minecraftforge.net/net/minecraft/server/management/ServerConfigurationManager.html There are methods like getAllUsernames() and getPlayerList() which return arrays or lists of all the names of players. You can then iterate over that list using getPlayerForUsername() for each player. I suggest you look through the javadoc and relevant API to get a grasp of what is available to you. Quote If I helped you, thank me. If I didn't, let me know. Link to comment Share on other sites More sharing options...
HoBoS_TaCo Posted December 19, 2012 Share Posted December 19, 2012 I use this, I hope it helps. @Override public void tickEnd(EnumSet<TickType> type, Object... tickData) { if (type.equals(EnumSet.of(TickType.PLAYER))) { onPlayerTick((EntityPlayer)tickData[0]); } } private void onPlayerTick(EntityPlayer player) { } Quote Link to comment Share on other sites More sharing options...
MrArcane111 Posted December 19, 2012 Author Share Posted December 19, 2012 I was actually able to solve the problem. If any of you are interested, here's how I got a server instance of the player and the world: if(type.equals(EnumSet.of(TickType.SERVER))) { ArrayList list = (ArrayList) MinecraftServer.getServer().getConfigurationManager().playerEntityList; Iterator iterator = list.iterator(); while(iterator.hasNext()) { EntityPlayerMP player = (EntityPlayerMP) iterator.next(); WorldServer world = MinecraftServer.getServer().worldServerForDimension(player.dimension); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.