TagAPI - Change/color the name over people's heads!

Discussion in 'Resources' started by mbaxter, Sep 6, 2012.

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

    MinecraftMart

    So is there a way to create something above the player head like Mcmmo does? With mcmmo is shows: Power 900
    for example.
     
  2. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Check out the scoreboard API.
     
  3. Offline

    SniperFodder

    mbaxter: on 3.0.5, when I go to check and see if the tag is modified, it returns true, even though the players name, and tags name is exactly the same.

    • [14:05:26 INFO]: This server is running CraftBukkit version git-Bukkit-1.7.9-R0.
      1-10-g8688bd4-b3092jnks (MC: 1.7.9) (Implementing API version 1.7.9-R0.2)
    • [14:05:54 INFO]: Plugins (2): TagAPI, DispNameChanger

    Code:
    [13:40:21 INFO]: UUID of player sniper_fodder12 is c36043e3-3198-42a0-b29f-5a58c71d35fe
    [13:40:21 INFO]: sniper_fodder12[/127.0.0.1:60855] logged in with entity id 147 at ([world] -384.08173479914365, 73.0, -117.25263410964041)
    [13:40:51 INFO]: UUID of player scanner8991 is 233f3cf4-ad08-4b41-85a9-3bca67783aab
    [13:40:51 INFO]: [DispNameChanger] [Debug] Tag Modified by another plugin: Player = scanner8991 | DisplayName = scanner8991 | Tag = scanner8991
    [13:40:51 INFO]: scanner8991[/127.0.0.1:60915] logged in with entity id 262 at ([world] -384.15377741771755, 73.0, -118.57140525182247)
    [13:40:51 INFO]: [DispNameChanger] [Debug] Tag Modified by another plugin: Player = sniper_fodder12 | DisplayName = SniperFodder| Tag = sniper_fodder12
    Here is my listener code:

    Code:java
    1. package me.captain.dnc;
    2.  
    3. import java.text.MessageFormat;
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.EventPriority;
    10. import org.bukkit.event.Listener;
    11. import org.kitteh.tag.AsyncPlayerReceiveNameTagEvent;
    12.  
    13. /**
    14. * This Class holds all the listeners used for Changing the tag of players
    15. * (Floating name) In vanilla Minecraft.
    16. *
    17. * @author Mark 'SniperFodder' Gunnett
    18. *
    19. */
    20. public class TagListener implements Listener
    21. {
    22. private static final Logger log = Bukkit.getLogger();
    23. private DispNameChanger plugin;
    24. private MessageFormat formatter;
    25. private DNCLocalization locale;
    26.  
    27. public TagListener()
    28. {
    29. super();
    30. plugin = DispNameChanger.getInstance();
    31. locale = plugin.getLocalization();
    32. formatter = new MessageFormat("");
    33. formatter.setLocale(plugin.getLocale());
    34. }
    35.  
    36. @EventHandler(priority = EventPriority.LOW)
    37. public void onNameTag(AsyncPlayerReceiveNameTagEvent event)
    38. {
    39. if(!plugin.useTagTitle())
    40. {
    41. return;
    42. }
    43.  
    44. Player target = event.getNamedPlayer();
    45.  
    46. if(event.isTagModified())
    47. {
    48. Object[] tagArgs = new Object[3];
    49. tagArgs[0] = target.getName();
    50. tagArgs[1] = target.getDisplayName();
    51. tagArgs[2] = event.getTag();
    52. formatter.applyPattern(locale.getString(DNCStrings.INFO_TAG_MODIFIED));
    53. if(plugin.isDebug())
    54. {
    55. log.info(DNCStrings.dnc_long + formatter.format(tagArgs));
    56. }
    57.  
    58. if(!event.getTag().equals(target.getDisplayName()))
    59. {
    60. log.info("Tag and Display name do not match.");
    61. }
    62. return;
    63. }
    64. if(!target.getName().equals(target.getDisplayName()))
    65. {
    66. event.setTag(target.getDisplayName());
    67. }
    68. }
    69. }
    70.  


    Any Ideas on what is going on?
     
  4. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    SniperFodder IIIIIIIIIIInteresting... Could you create a ticket so I can handle this when I'm less busy next week? :)
     
  5. Offline

    bars96

    1
    [​IMG] [​IMG]
    How to solve that TagAPI issue with player list?
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent e) {
    3. String group = plugin.perm.getPrimaryGroup(p);
    4. try {
    5. String prefix = plugin.getConfig().getString("groups." + group + ".prefix");
    6. prefix = ChatColor.translateAlternateColorCodes('&', prefix);
    7. String pn = p.getName();
    8. if ((prefix.length() + pn.length()) > 16) { // If player list name more than 16 symbols (my prefix length is 7: &6[G]&r)
    9. int max = 16 - prefix.length(); // Max player name (with my prefix it 16-7=9)
    10. pn = String.copyValueOf(pn.toCharArray(), 0, ((max - Math.abs(max - pn.length())) - 1)); // Trim nickname to 9 symbols
    11. }
    12.  
    13. p.setPlayerListName(prefix + pn);
    14. } catch (NullPointerException ex) { }
    15. TagAPI.refreshPlayer(p);
    16. }
    17.  
    18. @EventHandler(priority=EventPriority.HIGH)
    19. private void onPlayerReceiveNameTag(PlayerReceiveNameTagEvent e) {
    20. Player p = e.getNamedPlayer();
    21. String group = plugin.perm.getPrimaryGroup(p);
    22. try {
    23. String prefix = plugin.getConfig().getString("groups." + group + ".prefix");
    24. prefix = ChatColor.translateAlternateColorCodes('&', prefix);
    25. String pn = p.getName();
    26. e.setTag(prefix + pn);
    27. } catch (NullPointerException ex) { }
    28. }

    I trim only player list name, not name tag.

    2
    How to prefix player with example at 1 via plugin A and then color the name (not prefix) via plugin B?
    Plugin A: [A]Bars //black is white
    Plugin B: [A]Bars
     
  6. Offline

    viper_monster

    bars96 For things like that it would be better to use Scoreboards
     
  7. Offline

    bars96

    ?
     
  8. Offline

    viper_monster

    bars96 Scoreboards API? Adding players to teams and setting their prefixes would add that prefix in front of players name in TAB and above the character - however, its limited to 16 characters and it doesn't trim the name
     
  9. Offline

    SniperFodder

    I haven't looked, is Scoreboards apart of the Bukkit API? Or is it a separate plugin providing API like TagAPI?
     
  10. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    viper_monster likes this.
  11. Offline

    SniperFodder

    Excellent. I might have to start using that.
     
  12. Offline

    bars96

    I just want to use prefixes in TAB. I just want to disable symbols limit. I don't want use SBAPI if it don't help me with prefixes.

    Let developer answer me.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  13. Offline

    viper_monster

    you can't do that, tab names, just like names above players are limited to 16 characters, inclooding color codes
     
  14. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    bars96 The player list has nothing to do with TagAPI. Scoreboards let you add prefixes to names.
     
  15. Offline

    bars96

    Really? So why prefixes work above player head without trimming?
    No, you and viper_monster don't understand my issue. When I don't trim player TAB name, tag above head working even if nickname contains more than 16 symbols. But if I trim playerListName, tag above player head also trims, as if I use e.setTag(prefix + p.getPlayerListName) instead of e.setTag(prefix + p.getName());

    PlayerJoinEvent:
    • When I don't trim player name in TAB: tag above player head works even if tag contains >16 symbols
    • When I trim player name in TAB: tag above player head also trims, but I use e.setTag(prefix + p.getName()), not p.getPlayerListName()!
    Conclusion: it's just a TagAPI bug.
     
  16. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    bars96 Without using the scoreboard, the name tag above the head is limited to 16 characters.
     
  17. Offline

    bars96

    It's not limited, I've check it! :(
    I tell you not about TAB name, I tell you about TagAPI bug. Re-read my prev message(s).
     
  18. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    bars96 I'm talking about TagAPI. The name that that TagAPI sets is limited to 16 characters. You can add 32 more on either side with the Scoreboard API, but that's it. 16 for the name itself, and 32 for prefix and 32 for suffix.
     
  19. Offline

    bars96

    Ohh... I tell you what I can set tag via TagAPI like &7&rPlayer123456Name and it WORKS in game (what you say above?).
     
  20. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    bars96
    Your example there would cut out at &7&rPlayer123456
     
  21. Offline

    michael566

    mbaxter So when im using this api, all the people are steves is this normal?
     
  22. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Read the changelog. I'm working on a resolution to it though.
     
  23. Offline

    michael566

  24. Offline

    Krijn

    Code:java
    1. @EventHandler
    2. public void onNameTag(AsyncPlayerReceiveNameTagEvent e){
    3. Player p = e.getPlayer();
    4. if(p.hasPermission("test.vip")){
    5. e.setTag("§aVip " + p.getName());
    6. }
    7.  
    8. }


    This ^ is my code. But when another players joins. The player has my name on his nametag.
     
  25. Offline

    SniperFodder

    Krijn: Use e.getNamedPlayer() instead.
    mbaxter: Have you had a chance to look at that bug?
     
  26. Offline

    Josh Keighley

    Code:
    @EventHandler
        public void onNameTag(AsyncPlayerReceiveNameTagEvent event){
            SQLFunctions.openConnection();
            try {
                Player p = event.getNamedPlayer();
                PreparedStatement ps = SQLFunctions.connection.prepareStatement("SELECT nick FROM playerdata WHERE UUID=?;");
                ps.setString(1, event.getNamedPlayer().getUniqueId().toString());
                ResultSet rs = ps.executeQuery();
                if(rs.next()){
                    event.setTag(rs.getString("nick"));
                } else {
     
                }
            } catch(Exception e){
                e.printStackTrace();
            } finally {
                SQLFunctions.closeConnection();
            }
        }
    
    I have this code, but for some reason I'm getting a null pointer on this line: ps.setString(1, event.getNamedPlayer().getUniqueId().toString());.
    What have I done wrong?
     
  27. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Josh Keighley Try printing out the getUniqueId to see what happens.
     
  28. Offline

    codex01

    Thx bro for this nice library <3
     
  29. Offline

    Krijn

    Ok thanks

    But I still have 1 problem: Name Tags cannot be longer than 16 characters. Is there a way to change that?
     
  30. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    No.
     
Thread Status:
Not open for further replies.

Share This Page