I'm making a simple plugin to change the join/quit messages. Here is my code so far: Spoiler: Code Code (Text): @EventHandler void onPlayerJoin(PlayerJoinEvent event) { String joinMsg = plugin.getConfig().getString("join-msg"); Player player = event.getPlayer(); if(joinMsg.contains("%player")) { joinMsg = joinMsg.replace("%player", player.getDisplayName()); } joinMsg = ChatColor.translateAlternateColorCodes('&', joinMsg); event.setJoinMessage(joinMsg); } //Quit @EventHandler void onPlayerQuit(PlayerQuitEvent event) { String leaveMsg = plugin.getConfig().getString("leave-msg"); Player player = event.getPlayer(); if(leaveMsg.contains("%player")) { leaveMsg = leaveMsg.replace("%player", player.getDisplayName()); } leaveMsg = ChatColor.translateAlternateColorCodes('&', leaveMsg); event.setQuitMessage(leaveMsg); } My problem with this is that when the player joins, it shows their actual username, not their display name. However, the display name shows up just fine when a player leaves. I know that there are several other threads on this, but none of their "solutions" have worked for me. I've tried setting the join message to null and using Bukkit.broadcast(), as well as making the player send a blank chat message. I'd really rather not have to use a scheduler, and I doubt that would work anyway... Any ideas?
That causes an error. I believe that .getCustomName(); is for getting a mobs nametag or something like that.
Nope, doesn't work. The rest of the message shows up fine, it just shows the actual username instead of the displayname from PEX or Essentials.
Essentials has their own way, you're gonna have to hook into essentials to get that. Unless someone else has some way of getting it from essentials.
If I do it that way, will it also use the group color from PEX? Or will it only get their nickname? (If they have one)
Tried this, didn't work. It now shows the Vanilla join message. (Might just be my code). Spoiler: Code Code (Text): @EventHandler void onPlayerJoin(final PlayerJoinEvent event) { Bukkit.getScheduler().scheduleSyncDelayedTask(KingdomTweaks.plugin, new Runnable() { public void run() { String joinMsg = KingdomTweaks.plugin.getConfig().getString("join-msg"); Player player = event.getPlayer(); if(joinMsg.contains("%player")) { joinMsg = joinMsg.replace("%player", player.getDisplayName()); } joinMsg = ChatColor.translateAlternateColorCodes('&', joinMsg); event.setJoinMessage(joinMsg); } }, 20L * 1); }
Try this: @EventHandler void onPlayerJoin(final PlayerJoinEvent event) { event.setJoinMessage(""); Bukkit.getScheduler().scheduleSyncDelayedTask(KingdomTweaks.plugin, new Runnable() { public void run() { String joinMsg = KingdomTweaks.plugin.getConfig().getString("join-msg"); Player player = event.getPlayer(); if(joinMsg.contains("%player")) { joinMsg = joinMsg.replace("%player", player.getDisplayName()); } joinMsg = ChatColor.translateAlternateColorCodes('&', joinMsg); Bukkit.broadcastMessage(joinMsg); } }, 20L * 1); }
Then: instead of "Bukkit.broadcastMessage(joinMsg);" write: for(Player p : Bukkit.getOnlinePlayers())if(!p.equals(event.getPlayer()))p.sendMessage(joinMsg); Then it gets hidden from the player itself!