Jump to content

Help Changing the Player DisplayName Not Working Fully


jredfox
 Share

Recommended Posts

So I made a command for nickname but, it only works for chat nothing else here is my code the capability stores a string and then during the forge event it uses said string: 
According to bukkit's command this is all they practically do is change a display name and is only server side so I don't think packets are required so tell me what else I need to do


CMD:

	@Override
	public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException 
	{
		EntityPlayer player = (EntityPlayer) sender;
		CapNick name = (CapNick) CapabilityReg.getCapabilityConatainer(player).getCapability(new ResourceLocation(Reference.MODID + ":" + "nick"));
		name.nick = args.length == 1 ? args[0] : player.getName();
		player.refreshDisplayName();
	}

Event:
 

@SubscribeEvent
public void skinCap(PlayerEvent.NameFormat e)
{
	EntityPlayer player = e.getEntityPlayer();
	CapNick name = (CapNick) CapabilityReg.getCapabilityConatainer(player).getCapability(new ResourceLocation(Reference.MODID + ":" + "nick"));
   	if(!Strings.isNullOrEmpty(name.nick))
   		e.setDisplayname(name.nick);
}

 

Edited by jredfox
Link to comment
Share on other sites

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

18 minutes ago, diesieben07 said:

This is not Bukkit. The event is fired on both server and client and both need to set the player name properly.

And what the f is this? 

 

external capability system not directly attached to the object of the player similar to bukkit and bukkit plugins. All you need to know is I attach a string the if statement does execute and the only thing that changes is the chat name what else do I need to do.

during command refreshes player name > String nick = args[0]

during event > event.setName(nick);

Bukkit can change player name without having custom packets to send to the client so what else needs to happen????

Edited by jredfox
Link to comment
Share on other sites

1 minute ago, jredfox said:

external capability system not directly attached to the object of the player similar to bukkit and bukkit plugins.

Please stop. I can almost guarantee you that your system is broken. Not because it's you, but because "just attach data to a player" is not a simple concept. Forge has systems for it for a reason. Please use them.

 

1 minute ago, jredfox said:

All you need to know is I attach a string the if statement does execute and the only thing that changes is the chat name what else do I need to do.

19 minutes ago, diesieben07 said:

The event is fired on both server and client and both need to set the player name properly.

(Emphasis added).

Link to comment
Share on other sites

9 minutes ago, diesieben07 said:

Please stop. I can almost guarantee you that your system is broken. Not because it's you, but because "just attach data to a player" is not a simple concept. Forge has systems for it for a reason. Please use them.

 

(Emphasis added).

I can change my code to public static string nick to transfer to the forge event doesn't do anything.

 

public static String nick = args[0];

during event > set name to nick if not null same result 

Here is my capability system isn't broken:
https://github.com/jredfox/evilnotchlib/tree/master/src/main/java/com/EvilNotch/lib/minecraft/content/pcapabilites

and here: 

https://github.com/jredfox/evilnotchlib/blob/931c6eab0f5a3ba733f3515cd395764b745d4798/src/main/java/com/EvilNotch/lib/main/MainJava.java#L270
How to use it:
Create a capability provider > basically to register your caps when the time occurs
Create capabilities to use for the container.
Make sure you have readFromNBT/writeToNBT fullly working then your done

 

"The event is fired on both server and client and both need to set the player name properly."

why bukkit doesn't need that code running on client side and my command is server only. I want to keep this like bukkit what packet do I send to the clients to update the names?

Edited by jredfox
Link to comment
Share on other sites

1 minute ago, jredfox said:

I can change my code to public static string nick to transfer to the forge event doesn't do anything.

public static is not how you exchange data between server and client.

 

2 minutes ago, jredfox said:
  • You have a memory leak, you never unload capabilities when a player logs out. The only reliable way to do so would be using a WeakReference. No, PlayerLoggedOutEvent is not sufficient.
  • Nothing about this is ready for client-server. You just have a static map somewhere indexed by name. This is just completely broken.

These are just the first two things I found by looking at it for 2 minutes. And these are major flaws. I am sure there are many smaller things.

Link to comment
Share on other sites

6 minutes ago, diesieben07 said:

public static is not how you exchange data between server and client.

 

  • You have a memory leak, you never unload capabilities when a player logs out. The only reliable way to do so would be using a WeakReference. No, PlayerLoggedOutEvent is not sufficient.
  • Nothing about this is ready for client-server. You just have a static map somewhere indexed by name. This is just completely broken.

These are just the first two things I found by looking at it for 2 minutes. And these are major flaws. I am sure there are many smaller things.

I do player logout and server stop and tested player logout fires for disconnecting the player. How??? The capability system is server only for now I haven't figured out how to (fast enough) sync data from load file event(before login occurs during serialization). If I did a weak reference that means people could only view the capability once before it disposes sounds  awful I want to use it all during the game until logout. The player save event occurs way too often so I decided logout and server stop would be more optimized?

Again the PlayerEvent.NameFormat is fired on client side to? Well I want to keep it server side utility now since everything else is so far for the mod I am working on. What packet do I send to all players telling them of the name change????

Edited by jredfox
Link to comment
Share on other sites

Just now, jredfox said:

Again the PlayerEvent.NameFormat is fired on client side to?

Yes, it is fired on the client. Why "Again"?

 

1 minute ago, jredfox said:

Well I want to keep it server side utility now

Not possible.

 

1 minute ago, jredfox said:

The capability system is server only for now I haven't figured out how to (fast enough) sync data from load file event(before login occurs during serialization).

Well, if only there was a system that did all this already... If only...

Link to comment
Share on other sites

7 minutes ago, diesieben07 said:

Yes, it is fired on the client. Why "Again"?

 

Not possible.

 

Well, if only there was a system that did all this already... If only...

the capabilities fires on client's thanks I might move it to the capability event to register my system then. Doesn't solve my issue for older issues sadley. Forge's is very confusing nearly impossible to manipulate other mods and scan for what mod does what so I made my own for players at least now

I am sure there is a way bukkit does it and doesn't have any client code instant name changes. look for CraftPlayer.setDisplayName()
https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java

I will keep looking for a solution on what they use but, it appears it's possible without any new client code. Just don't know where and what vanilla packets they are using to use a work around for this.

Edited by jredfox
Link to comment
Share on other sites

1 minute ago, diesieben07 said:

As far as I can see CraftPlayer#setDisplayName does nothing for the client.

You can send SPacketPlayerListItem with UPDATE_DISPLAY_NAME, which will update the name in the player list (tab key by default). Not sure if the name is displayed elsewhere on the client.

not it but, I will look more online

Link to comment
Share on other sites

    @Override
    public void setPlayerListName(String name) {
        if (name == null) {
            name = getName();
        }
        getHandle().listName = name.equals(getName()) ? null : CraftChatMessage.fromString(name)[0];
        for (EntityPlayer player : (List<EntityPlayer>)server.getHandle().players) {
            if (player.getBukkitEntity().canSee(this)) {
                player.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME, getHandle()));
            }
        }
    }

 

Edited by jredfox
Link to comment
Share on other sites

1 minute ago, jredfox said:

this what spigot is using for all players the issue is The names don't exist for forge?


player.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME, getHandle()));

This is what I just told you to do:

21 minutes ago, diesieben07 said:

You can send SPacketPlayerListItem with UPDATE_DISPLAY_NAME, which will update the name in the player list (tab key by default). Not sure if the name is displayed elsewhere on the client.

 

Link to comment
Share on other sites

1 minute ago, diesieben07 said:

This is what I just told you to do:

 

nothing just tried this:
 

    	SPacketPlayerListItem item = new SPacketPlayerListItem(SPacketPlayerListItem.Action.UPDATE_DISPLAY_NAME,player.mcServer.getPlayerList().getPlayers());
    	for(EntityPlayerMP p : player.mcServer.getPlayerList().getPlayers())
    	{
    		p.connection.sendPacket(item);
    	}

 

Link to comment
Share on other sites

2 minutes ago, diesieben07 said:

Well, you are not actually sending any updated display name. You need to pass the new display name into the packet.

there are three constructors for SPacketPlayerListItem none of them allow for custom text. It just gives a tabname from the player which always returns null.

Link to comment
Share on other sites

also just had my friend relog and did a hard coded test(client and server from player login) the new name doesn't show up in tab only above the player head weird
 

	@SubscribeEvent
    public void skinCap(PlayerEvent.NameFormat e)
    {
		e.setDisplayname("notch");
    }

 

Edited by jredfox
Link to comment
Share on other sites

29 minutes ago, jredfox said:

there are three constructors for SPacketPlayerListItem none of them allow for custom text. It just gives a tabname from the player which always returns null.

You need to create the packet with the empty constructor and then set SPacketPlayerListItem#action and add your own instances of SPacketPlayerListItem.AddPlayerData to SPacketPlayerListItem#players.

 

54 minutes ago, jredfox said:

also just had my friend relog and did a hard coded test(client and server from player login) the new name doesn't show up in tab only above the player head weird
 


	@SubscribeEvent
    public void skinCap(PlayerEvent.NameFormat e)
    {
		e.setDisplayname("notch");
    }

You already knew it would not work. Why did you perform this test? How is this result "weird" or in any way unexpected?

Link to comment
Share on other sites

And this is why I have jredfox muted.

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

15 hours ago, diesieben07 said:

You need to create the packet with the empty constructor and then set SPacketPlayerListItem#action and add your own instances of SPacketPlayerListItem.AddPlayerData to SPacketPlayerListItem#players.

 

You already knew it would not work. Why did you perform this test? How is this result "weird" or in any way unexpected?

"add your own instances" so your saying try your own custom packet. I will be trying this out later but, from the code I read sending null for the name resets the clients names for the players or at least the comments said it was suppose to do that. Maybe it only does it once or something stupid like that

 

"You already knew it would not work"

no I tested on both sides from login not on command didn't know what would happen

Link to comment
Share on other sites

3 hours ago, diesieben07 said:

No, that is not what I said. If you do not know what an instance is, learn Java basics.

SPacketPlayerListItem.AddPlayerData wait I thought it wasn't a thing since it's not static inner class just re-read the post of stackoverflow. Will be trying this out

 

https://stackoverflow.com/questions/70324/java-inner-class-and-static-nested-class

public class A{
	
    public class B{
    	//cannot be constructed except for in class A  
    }
}

 

Edited by jredfox
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.

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

 Share




×
×
  • Create New...

Important Information

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