My plugin doesn't read Essentials's displayname when joining.

Discussion in 'Spigot Plugin Development' started by GewoonIraj, May 3, 2017.

  1. Hi there!

    I coded my own join- & quit-message plugin, but I have a few issues with it.
    When I join the game, it says: '[+] Mr_LegendzZ', but it have to say: '[+] [Owner] MY_NICKNAME'.
    My plugin isn't coded from Essentials but how can I make it read my displayname from Essentials?
    With the quit-message it does work though, only the join-message not.

    Hope you can help me fellows! =D
    - GewoonIraj
    #1 GewoonIraj, May 3, 2017
    Last edited: May 7, 2017
    • Optimistic Optimistic x 1
  2. Always good to provide your code too so we ( may ) can modify or describe it using your code
  3. Are you using Player.getDisplayName instead of getName?
  4. @Phloxz Coming! Give me a second :)

    #4 GewoonIraj, May 4, 2017
    Last edited: May 6, 2017
  5. @NathanWolf Yes, I do. Should I use getName instead?
  6. If essentials have some form of api, you can try retrieve the player's nickname that way.
  7. The problem is that essentials loads the player's data asynchronously, and applies the player's display name afterwards. So the display name hasn't been applied yet when you try to use it from inside the player join event.

    I have created a ticket for this in the past here:
    • Informative Informative x 1
    • Optimistic Optimistic x 1
  8. They just use a simple Player#setDisplayName() I believe.

    OP, why are you looping through all online players? You might have to tick it as so:
    Code (Text):
    public void onJoin(final PlayerJoinEvent event) {
        // Should be final because tasks
        final Player p = event.getPlayer();
        Bukkit.getScheduler().scheduleSyncDelayedTask(GKitPvPPlugin.getInstance(), new Runnable() {
            public void run() {
                event.setJoinMessage("Joined: " + p.getDisplayName());
        }, 30L);
    They should be loaded then.

    EDIT: Might be silly, setting the message after the event has been called. Might not broadcast it at all.
  9. @ExpDev Do I have to set it as .scheduleSyncDelayedTask or .scheduleAsyncDelayedTask?
  10. I would do it sync.
  11. Why don't just use e.getplayer.getdisplayname? it return the name you already seted
  12. @mkcoldwolf It doesn't work!
    Neither as yours idea, @ExpDev , but both thanks for the tips!
  13. This is by design, not a bug. This should be marked as WONTFIX
  14. We can always suggest hacky workarounds.
  15. So, straight to the point:
    There is no fix a.t.m. ?