Solved DisplayName OnJoin Not Working

Discussion in 'Plugin Development' started by Ben67482, Apr 14, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Ben67482

    Hey!
    So basically I'm creating a simple plugin in which it replaces the default join/leave msg's with a nicer format. However the display name is not showing on the join msg. The code is exactly the pretty much the same as on quit, but it is showing the users name rather than displayname.
    Thanks in advance!

    Full Class
    Code:java
    1. package me.BenKeith.Server;
    2.  
    3. Solved :P
    4. }

    The result:
    http://gyazo.com/08f4b41c8a1dc6b33b663f7d9f9dbb92

    It doesn't show the displayname onjoin :(BTW this plugin does contain other features, however they shouldn't impact these msg's.
     
  2. Offline

    rfsantos1996

    Try making it one tick delayed:
    final Player player = e.getPlayer();
    new BukkitRunnable() {
    public void run(){
    player.setDisplayName(<display name here>);
    }
    }.runTaskLater(plugin, 1);
     
  3. Offline

    Ben67482

    Thanks for the help, but I had a hard time understanding what your trying to say. How should I implement this into my code?
     
  4. Offline

    Blackveil

    Get rid of

    @EventHandler(priority = EventPriority.MONITOR)

    Just use

    @EventHandler
     
  5. Offline

    rfsantos1996

    I recommend learning java, this is basic >.> i would teach you but im on the cellphone
     
  6. Offline

    itzrobotix

    Is it not just getName()?
    Code:java
    1. //Player Leave Message
    2. @EventHandler(priority = EventPriority.MONITOR)
    3. public void onPlayerQuit(PlayerQuitEvent e)
    4. {
    5. String p = e.getPlayer().getName();
    6. e.setQuitMessage(ChatColor.GRAY + "" + ChatColor.BOLD + "Quit>> " + p);
    7. }
    8.  
    9. //Player Join Message
    10. @EventHandler(priority = EventPriority.MONITOR)
    11. public void onPlayerJoin(PlayerJoinEvent e)
    12. {
    13. String p = e.getPlayer().getName();
    14. e.setJoinMessage(ChatColor.GRAY + "" + ChatColor.BOLD + "Join>> " + p);
    15. }
     
  7. Offline

    Ben67482

    getName() would get the users acctual name.
    I want it to show prefixes that are set using pex, which is what displayName() does.
    I tried that, didn't work :(
     
  8. Offline

    itzrobotix

    Changing the priority shouldn't make a difference, lol. And how is it currently work does it just send the message and misses off the name of the player?
     
  9. Offline

    Go Hard

    Ben67482 Try something like this
    Code:
    @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
           
            if(p.hasPermission("example.join")) {
                e.setJoinMessage(p.getDisplayName() + " has joined the server!");
            }
           
           
           
        }
    I don't know if it will work i haven't tested it.
     
  10. Offline

    Blackveil

    You can't have a set display name without first defining a display name. You never defined any custom values for a display name, even if PEX does "do that" for you because this is YOUR plugin, it's not PEX.
     
  11. Offline

    Ben67482

    The problem is that it only shows the players name, rather than their display name. Display names are affected by prefixes, nicknames and such. Example - I have a nickname that makes my name blue, so with displayname it should show that nickname. getName wouldn't use nicknames, only their actual IGN. The strange part is that it only happens on join, on leave it can successfully get the users displayname.

    A display name is set using pex, and my plugin can get that displayname correctly as it does work with the player quit msg's.
    My display name is Blue, and as you can see in the screenshot provided, it has successfully obtained that display name with the quit event, but not in the join event.
    Nope :( this didn't work, same issue as before where it fails to obtain the displayname, and only get's the name.
     
  12. Offline

    Blackveil

    Well then, try making sure that the player's display name is ready somehow by creating a PlayerLoginEvent event handler. Because, Pex isn't defining that player's display name until after they join the game, and that's obvious because if it did define it before they joined the game, then you wouldn't be having this issue.
     
  13. Offline

    Ben67482

    Ok, I think I understand what you're saying and I'll try and work this out, thanks for the help! :)
    I'll post updates!
     
  14. Offline

    Go Hard

    Ben67482 Are you trying to get the display name for a player in a group? Like if i join and i was a guest it will say something like "[Guest]Pixxima has joined the server!" or something along those lines?
     
  15. Offline

    Ben67482

    Similar to that yes, I have pex set up and each group has a different colour prefix, on joining I want it to show my name with my groups colored prefix.
     
  16. Offline

    Go Hard

    Ben67482 You can always hook into PEX and get the group the player is in. Kinda like this:
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent e) {
    3. Player p = e.getPlayer();
    4.  
    5. PermissionUser user = PermissionsEx.getUser(p.getName());
    6.  
    7. if(user.inGroup("Guest")) {
    8. e.setJoinMessage("[Guest]" + p.getName() + " has joined the server!");
    9. }
    10. }
     
  17. Offline

    jensdeboom

    What Blackveil is saying is probably true. If so, try, like rfsantos1996 said, delaying it a bit.
    Cant really type code for you bc im on my phone but just do the getServer.getScheduler() thing and make a delayed task. In the task set the join msg to what u want and set the delay to 1-2 ticks
     
  18. Offline

    rfsantos1996

    getServer.getScheduler() isn't efficient.

    Here, its my first plugin. I edited the join message based on permission.

    To use DISPLAYNAME, I think you can't use on Join because there isn't any displayname set by other plugin yet.
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent e) {
    3. Player p = e.getPlayer();
    4. e.setJoinMessage("");
    5. broadcastPlayerDisplayName(p);
    6. }
    7.  
    8. private void broadcastPlayerDisplayName(final Player p) {
    9. new BukkitRunnable() {
    10. public void run() {
    11. for(Player online : getServer().getOnlinePlayers()) {
    12. online.sendMessage("§7§lJoined>> "+ p.getDisplayName());
    13. }
    14. }
    15. }.runTaskLater(this, 2);
    16. }
     
  19. Offline

    Bobit

    rfsantos1996

    To clarify:
    One version of the "wait a bit before doing something" code in bukkit is:

    Code:java
    1. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask([your plugin], new Runnable() {
    2.  
    3. @Override
    4. public void run(){
    5. [what you want to run]
    6. }
    7.  
    8. }, [time, in 20ths of a second, to wait]


    rfsantos was showing a different version.
     
  20. Offline

    jensdeboom

    rfsantos1996 why isn't Bukkit.getServer().getScheduler efficient? Works fine...
     
  21. Offline

    Ben67482

    Thanks to everyone that has helped, with all your input together I managed to solve this issue :D
     
  22. Offline

    rfsantos1996

    It works, but new BukkitRunnable().runLater is more performance efficient (http://forums.bukkit.org/threads/delay-between-loop.254679/#post-2397145)

    Yeah, I forgot the run ;o sorry, edited the code
     
  23. Offline

    Bobit


    Oh. Apparently, we're using basically the same code. :confused:

    By the way, this is not basic java. It took me upwards of an hour to find that code, and I've been coding for 2 years, and am the best in my (tiny) class. Moreover, it's really specific to bukkit.

    Although, since Ben didn't find it, either his desire to DIY or his googling skillz leave something to be desired. [sheep]
     
  24. Offline

    rfsantos1996

    Well, my first experience with java were 5 years ago, I didn't understood too much, I just ctrl + c and v and edited some code to make a MapleStory server. My real coding thing (like projects that I did myself) started 1 year ago...

    A lot of people have no idea on how constructors, enums and objects with any of these works, I received some PMs about these and how to work with.

    BukkitRunnable implements Runnable, you could use new Runnable inside a getServer().getScheduler().schedule that would work (something that is from java library, and constantly used on aplications coded in java). Well, I dont mean to be rude or anything, but I think it is basic stuff that you need to really understand Java... Like, you can't learn how to speak portuguese without verbs or nouns...

    I prefer give him a piece of code than let he search for the answer (how to implement the code) than give the coded class.
     
  25. Offline

    Bobit

    Well that's...sadistic. :eek:

    Anyhow, it's relative how basic it is. My version of "really basic" goes about as high as for loops, because most people have trouble with that (for (some reason){}).
     
  26. Offline

    rfsantos1996

    LOL I LAUGHED AT for (some reason){} I think my basic is a lot u.u like, Who can code Java are who can do basicly everything with the code, know every structure. for example, I consider I can't code c++, I just know what you call basic

    And I learned Java by myself, and everything that I learned by myself is normally what I remember and know how to manage/use. So I think giving "tips" are better than solving a request
     
  27. Offline

    Bobit

    I don't know the syntax for enums, but I could probably google it and figure it out in like 10 minutes.
     
Thread Status:
Not open for further replies.

Share This Page