Jump to content

[1.15.2] Change player name in Tab List (Player List)


Recommended Posts

Posted

Hi everyone,

 

I want to add a suffix to every players name, but I cant get it to work.

I'm doing it like this:

 

@SubscribeEvent
public void onNameFormat(PlayerEvent.NameFormat event) {
    if (event.getEntity() instanceof PlayerEntity) {
        event.setDisplayname(event.getUsername() + " test");
    }
}

 

If I use

event.getDisplayname()

it shows the name + test, but it doesn't change on the tab list. 

Do I need to somehow update the tab list for it to work or am I doing it completely wrong?

 

Thanks!

Posted

 That doesn't seem to work for me 🤔

 

This is what I got rn:

public class ChangeTabListEvents {

    @SubscribeEvent
    public void onNameFormat(PlayerEvent.NameFormat event) {
        if (event.getEntity() instanceof PlayerEntity) {
            event.setDisplayname(event.getUsername() + " (" + event.getPlayer().getMaxHealth() + ")");
            event.getEntity().sendMessage(new KeybindTextComponent("NameFormat event fired."));
        }
    }

    @SubscribeEvent
    public void onPlayerLogin(EntityJoinWorldEvent event) {
        if (event.getEntity() instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) event.getEntity();
            if (player.getServer() != null) {
                ForgeEventFactory.getPlayerDisplayName(player, player.getGameProfile().getName());
                player.getServer().getPlayerList().sendPacketToAllPlayers(new SPlayerListItemPacket(SPlayerListItemPacket.Action.UPDATE_DISPLAY_NAME));
                player.sendMessage(new KeybindTextComponent("Display name updated."));
            }
        }
    }
}

 

image.png.9e57ad8165bcfa5a3b89acb8f04a8111.png

Posted (edited)

So, I've looked at reflection together with a friend of mine, but we could get it to work. 

 

We now have this:
 

    @SubscribeEvent
    public void onPlayerLogin(EntityJoinWorldEvent event) {
        if (event.getEntity() instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) event.getEntity();
            if (player.getServer() != null) {
                ForgeEventFactory.getPlayerDisplayName(player, player.getGameProfile().getName());
                try {
                    Field field = ObfuscationReflectionHelper.findField(SPlayerListItemPacket.class, "field_179769_b");
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                player.getServer().getPlayerList().sendPacketToAllPlayers(new SPlayerListItemPacket(SPlayerListItemPacket.Action.UPDATE_DISPLAY_NAME, (ServerPlayerEntity) player));
                player.sendMessage(new KeybindTextComponent("Display name updated."));
            }
        }
    }

 

field_179769_b = players from:

private final List<SPlayerListItemPacket.AddPlayerData> players = Lists.newArrayList();
  

from the SPlayerListItemPacket class. That is the entries you were talking about right?

 

But we don't know wat to do now.

 

P.S. I'm still using the ForgeEventFactory because getDisplayname() wouldn't fire the even for some reason...

 

Help would be much apriciated, thanks.

Edited by Babatunde
Posted

It looks like you will need to use reflection twice.

After you create the packet object, you will need to access SPlayerListItemPacket#players. SPlayerListItem#getEntries() only exists on the client, so you won't be able to use this.

The elements of the list (of type SPlayerListItemPacket.AddPlayerData) contain a private 'displayName' member, which you will also need access to. (I would advise creating the Field objects in a static context instead of every EntityJoinWorldEvent, to save performance).

Iterate through all the objects in the list and set their display names accordingly - although from your code it looks like there should only be one object in the list.

 

 

Posted
  On 1/14/2021 at 11:00 PM, diesieben07 said:

You need to call refreshDisplayName if you want the event to be fired again when calling getDisplayName again. This is explained in the event's documentation.

Expand  

refreshDisplayName is from 1.12.2. A lot is the documentation is outdated.

  On 1/14/2021 at 11:00 PM, diesieben07 said:

Probably better to use PlayerLoggedInEvent.

Expand  

Thanks, I forgot that existed.

 

  On 1/14/2021 at 11:00 PM, diesieben07 said:

You need to get the entries from the packet you create and forcibly set the display name property inside there.

Expand  

I'm sorry, I've never worked with packets before. is there a tutorial or documentation on how to create packets?

Posted (edited)
  On 1/15/2021 at 7:24 PM, Babatunde said:

How do I do this tho?

Expand  

You've already done it, here:

new SPlayerListItemPacket(SPlayerListItemPacket.Action.UPDATE_DISPLAY_NAME, (ServerPlayerEntity) player)

A packet is just a bit of data that is sent between two or more computers over a network. Usually you don't have to manually send packets because Minecraft takes care of this for you for standard vanilla gameplay, but in this case I think it's the best solution. You can dig around the 'net.minecraft.network' or 'net.minecraft.network.play' packages to look at some example packet implementations; AFAIK there isn't any documentation on them. What IDE are you using?

Edited by coalbricks
Posted (edited)
  On 1/16/2021 at 3:50 AM, coalbricks said:

What IDE are you using?

Expand  

Intellij IDEA Ultimate.

 

  On 1/16/2021 at 3:50 AM, coalbricks said:

You've already done it, here:

Expand  

Oh nice! completely forgot about that line lmao.

 

This is what I've got so far, I'm kinda stuck because I have no idea what to do:

public class ChangeTabListEvents {

    private final Field fieldPlayers = ObfuscationReflectionHelper.findField(SPlayerListItemPacket.class, "field_179769_b");
    private final Field fieldDisplayName = ObfuscationReflectionHelper.findField(SPlayerListItemPacket.AddPlayerData.class, "field_179965_e");

    @SubscribeEvent
    public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
        PlayerEntity player = event.getPlayer();
        if (player.getServer() != null) {
            try {
                
            } catch (Throwable e) {
                e.printStackTrace();
            }
            player.getServer().getPlayerList().sendPacketToAllPlayers(new SPlayerListItemPacket(SPlayerListItemPacket.Action.UPDATE_DISPLAY_NAME, (ServerPlayerEntity) player));
            player.sendMessage(new KeybindTextComponent("Display name updated."));
        }
    }
}

Do I need to get the list somehow, or do I need to make my own and set my list as the players list? 

And why do I need the 'displayName'?

 

Thanks for the help so far, I appreciate it!

Edited by Babatunde

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. Contact : Whats...App : +.1 .4 7.4.3 5.3.7 7..1.9 Website : https://       digitalhackrecovery.com     Mail:            digitalhackrecovery         @techie.       com 
    • I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. Contact : Wh.ats.Ap.p : +1 .4 .7  4 3. 5  3  .7 7.1.9 Website : https://     digitalhackrecovery.   com Mail:       digitalhackrecovery     @         techie.                     com  
    • Ran it one more time just to check, and there's no errors this time on the log??? Log : https://mclo.gs/LnuaAiu I tried allocating more memory to the modpack, around 8000MB and it's still the same; stopping at "LOAD_REGISTRIES". Are some of the mods clashing, maybe? I have no clue what to do LOL
    • Tried removing some biome generation mods and test ran it again, but it's still the same; still not responding as soon as it gets to "LOAD_REGISTRIES". This time with more errors though. Log : https://mclo.gs/uygZzD8 Is there too little memory allocated to the modpack maybe? Can someone help please.    (T.T)💔
    • This is sad. Over 3300 people have checked the thread and no one is able to help or give any ideas :(.
  • Topics

×
×
  • Create New...

Important Information

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