Solved Change player name in TAB list

Discussion in 'Plugin Development' started by IanSzot, Jan 22, 2014.

Thread Status:
Not open for further replies.
  1. I'm creating one plugin that add colors to the player name, I know how to do this in the chat, but I have no idea of how to do this in the TAB list (player list)

    I tried this:
    Code:java
    1. if(player.hasPermission("namecolor.yellow")){
    2. return player.setPlayerListName(ChatColor.YELLOW);
    3. }
    4. return ChatColor.WHITE;


    But it says
    Anyone can help me please
     
  2. Offline

    Mathias Eklund

    You need a string. that would set the name to nothing.
     
  3. Offline

    Shockwave317

    What about
    Code:java
    1. if(player.hasPermission("namecolor.yellow")){
    2. player.setPlayerListName(ChatColor.YELLOW + player.getName());
    3. }


    or even
    Code:java
    1. if(player.hasPermission("namecolor.yellow")){
    2. player.setPlayerListName(ChatColor.YELLOW + player.getName());
    3. } else {
    4. player.serPlayerListName(ChatColor.YELLOW + player.getName());
    5. }

    IanSzot

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  4. Shockwave317

    Both dont worked, the first one says:
    And the second one dont give any error, but it dont work D:
     
  5. Offline

    Shockwave317

    then I am not sure... where is it in your code?
     
  6. Offline

    Mathias Eklund

    IanSzot Post the entire class.
     
  7. Code:java
    1. package com.outlook.ianszot;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.AsyncPlayerChatEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class NameColor extends JavaPlugin implements Listener {
    12.  
    13. @Override
    14. public void onEnable() {
    15. getLogger().info("Enabled");
    16. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    17.  
    18. }
    19. @Override
    20. public void onDisable() {
    21. getLogger().info("Disabled");
    22. }
    23.  
    24.  
    25. public ChatColor getColour(Player player) {
    26. if(player.hasPermission("inamecolor.yellow")){
    27. return ChatColor.YELLOW;
    28. }
    29. return ChatColor.WHITE;
    30. }
    31.  
    32.  
    33.  
    34. @EventHandler
    35. public void onPlayerChat(AsyncPlayerChatEvent event) {
    36. Player player = event.getPlayer();
    37. ChatColor colour = NameColor.this.getColour(player);
    38. event.setFormat("<" + colour + "%1$s" + ChatColor.WHITE + ">" +": " + "%2$s");
    39. }
    40.  
    41. }
    42.  


    I'm new to this Java thing :S
     
  8. Offline

    Shockwave317

    IanSzot
    You don't do it that way... you need a command or something that implicates that you want that code run...
    best way to do this is when the player logs in you check if he has the permission then add the yellow colour!

    IanSzot
    Since your new to Java and I am so kind here is a snippet of code just for u!
    Code:java
    1. public void onPlayerJoin(PlayerJoinEvent event) {
    2. if(event.getPlayer().hasPermission("tabnamecolor.yellow")){
    3. event.getPlayer().setPlayerListName(ChatColor.YELLOW + event.getPlayer().getName());
    4. }
    5. }

    P.S Make sure u register your events

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  9. Offline

    Shockwave317

  10. Offline

    22vortex22

    IanSzot pm on Skype if you need more help ;)
     
    The__Master_Coder likes this.
Thread Status:
Not open for further replies.

Share This Page