Jump to content

Recommended Posts

Posted

Hi,

I have a simple Question but I cant figure out how to solve it. 

I want to get the Player by the given UUID when the Mod is running on the Client not on the Server.

To show you what I want here my current code:

public static EntityPlayer findPlayer(World world, UUID uuid) {
	return !world.isRemote ? Minecraft.getMinecraft().player : // The Getter when the Player is on a Server
}

I have a Static Method which returns an EntityPlayer Object. I check via world.IsRemote if the Player is on the Server or not, when not it returns the Minecraft Player because there is only one Player but when he is playing on a Server I want to return the Player from the given UUID.

I hope I could show you what I want^^

Thanks in advanced.

Darki

Posted
1 hour ago, Darki said:

Hi,

I have a simple Question but I cant figure out how to solve it. 

I want to get the Player by the given UUID when the Mod is running on the Client not on the Server.

To show you what I want here my current code:


public static EntityPlayer findPlayer(World world, UUID uuid) {
	return !world.isRemote ? Minecraft.getMinecraft().player : // The Getter when the Player is on a Server
}

I have a Static Method which returns an EntityPlayer Object. I check via world.IsRemote if the Player is on the Server or not, when not it returns the Minecraft Player because there is only one Player but when he is playing on a Server I want to return the Player from the given UUID.

I hope I could show you what I want^^

Thanks in advanced.

Darki

why not just user username well you get the player list object from a server instance make sure it's done on server side. There is a getter for both username and uuid

Posted
1 hour ago, diesieben07 said:

If you need this method this hints and some pretty bad code. Only the server should be getting a player by UUID, and just assuming Minecraft#player on the client is not correct.

On the server you can use PlayerList#getPlayerByUUID.

Would this work?

public static EntityPlayer findPlayer(World world, UUID uuid) {
	return !DeathNote.getInstance().getProxy().isServer() ? world.getPlayerEntityByUUID(uuid)
			: FMLServerHandler.instance().getServer().getPlayerList().getPlayerByUUID(uuid);
}

 

Posted (edited)
10 hours ago, Darki said:

Would this work?


public static EntityPlayer findPlayer(World world, UUID uuid) {
	return !DeathNote.getInstance().getProxy().isServer() ? world.getPlayerEntityByUUID(uuid)
			: FMLServerHandler.instance().getServer().getPlayerList().getPlayerByUUID(uuid);
}

 

no on server side you call mcServer.getPlayerList().getPlayerByUUID() or something like that. I recommend username unless you only have acess to uuid unless your storing something to the disk then I guess use uuid

Edited by jredfox
Posted
1 minute ago, jredfox said:

unless your storing something to the disk then I guess use uuid

And this would be the Problem^^ I am storing the UUID of the User in the NBT Tags of an Entity. To explain a little bit more: I have a custom Entity which is not tamable but kind of....The Owner gets set by the mod itsselfs....

Posted
1 minute ago, diesieben07 said:

Please (again): Explain why you think you need to do that.

Its a simple and dumb answer: Because Mojang does it in the same Way.

 @Nullable
    public EntityLivingBase getOwner()
    {
        try
        {
            UUID uuid = this.getOwnerId();
            return uuid == null ? null : this.world.getPlayerEntityByUUID(uuid);
        }
        catch (IllegalArgumentException var2)
        {
            return null;
        }
    }

This is the Code of EntityTameable#getOwner

Posted (edited)

Ok. For now I'll leave it like this because its working on the Client....Server-Side I did not test anything in my Mod....Maybe I have to re code some code so that my mod can be played in MP. But for now its just find. 

 

And at the moment my mod has other "problems" ;D

Edited by Darki
Posted

What....Oh ok. I am completely new in coding mods....I can code plugins....and java it selfs....But coding mods is so much diffrent to coding plugins. 

So does that mean as long as I do nothing completely wrong with the proxies....it should work? Or are there any other things I need to watch out for?

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.

Guest
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.

Announcements



×
×
  • Create New...

Important Information

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