Posted December 17, 201212 yr 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!
December 18, 201212 yr 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. If I helped you, thank me. If I didn't, let me know.
December 18, 201212 yr 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. If I helped you, thank me. If I didn't, let me know.
December 19, 201212 yr 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) { }
December 19, 201212 yr Author 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); } }
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.