Prefix on player join

Discussion in 'Plugin Development' started by ThatGuyWhoDied13, Oct 21, 2013.

Thread Status:
Not open for further replies.
  1. I'm trying to make a plugin where when one of the staff members of my server join it auto adds a prefix to them. I have this so far but it's not working


    package me.Kevy.Hub;

    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;

    public class PlayerListener implements Listener {

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    event.setJoinMessage(ChatColor.DARK_GRAY + ("Join") + ChatColor.YELLOW + ("> ") + ChatColor.GRAY + player.getDisplayName());
    if(player.getName() == ("Kevy_Porter")) {
    player.setDisplayName(("") + ChatColor.AQUA + ChatColor.BOLD + ("[OWNER] ") + ChatColor.DARK_PURPLE + ChatColor.UNDERLINE + player.getName() + ChatColor.WHITE + (""));
    }
    }

    @EventHandler
    public void onPlayerQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();
    event.setQuitMessage(ChatColor.DARK_GRAY + ("Quit") + ChatColor.YELLOW + ("> ") + ChatColor.GRAY + player.getDisplayName());

    }


    }
     
  2. Offline

    5pHiNxX

  3. Offline

    Trevor1134

    Try if(p.getName().equals("Kevy_Porter"){

    Never use == for strings as == is to compare to objects, while .equals is to see if string a is the same as string b.
     
  4. Offline

    1Rogue


    == is used for comparing primitives, objects should almost always use .equals() unless the method isn't overwritten (which it should be)
     
  5. Offline

    rcth

    I'm not sure. I tried something like this. When a player leaves the game, the prefix is shown but when he joins the game, no prefix is being shown.
     
Thread Status:
Not open for further replies.

Share This Page