You can create a method for this, and call it when you need it in your events. For your specific example something like this would work. Code:java @EventHandlerpublic void onRankJoin(PlayerJoinEvent e) {setRank(e.getPlayer);} public void setRank(Player p){if (p.hasPermission("default")) {p.setDisplayName(ChatColor.WHITE+ p.getName());} else if (p.hasPermission("moderator")) {p.setDisplayName(ChatColor.DARK_PURPLE + p.getName());}}
Try something like: Code:java public static void updateDisplayName(Player player){// Your display name code here} Then call... Code:java ClassName.updateDisplayName(player); ...whenever you'd like to update the name.
You could always make a enum, kinda like Code: public enum Ranks{ MODERATOR, DEFAULT }; this is only a example do not copy!