Jump to content

[Solved!] Getting a player instance in ServerTickHandler


Recommended Posts

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!

Link to comment
Share on other sites

How about:

EntityPlayer player = server.getConfigurationManager().getPlayerForUsername("playerName");


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.

Link to comment
Share on other sites

Have you had a look at the API you get from getConfigurationManager()?



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.

Link to comment
Share on other sites

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:


		ArrayList list = (ArrayList) MinecraftServer.getServer().getConfigurationManager().playerEntityList;
		Iterator iterator = list.iterator();

			EntityPlayerMP player = (EntityPlayerMP) iterator.next();
			WorldServer world = MinecraftServer.getServer().worldServerForDimension(player.dimension);

Link to comment
Share on other sites

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.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.