Adding Lines to Name-Tags

Discussion in 'Plugin Development' started by xWatermelon, Mar 20, 2013.

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

    xWatermelon

    How can I add lines to player's name-tags? I have seen this in servers before, I just need to know how I can achieve this. I assume it has something to do with Scoreboards?
     
  2. Offline

    Tirelessly

    Probably won't work, but try adding a \n. For example, and this is ignoring length limits,

    "First line\nSecond Line"
     
  3. Offline

    xWatermelon

    Tirelessly Hmmm... that may work, but is there any other way? Here is where it is on, the server IP is "mcsmash.com" (blanked out foul language :p):
    [​IMG]
     
  4. Offline

    Tirelessly

    No idea, I've never experienced anything like it before.
     
  5. Offline

    Compressions

    xWatermelon Welcome to Bukkit! I used to play loads of McPVP! My old account was MakeItSoGodly if you remember me. :p
     
  6. Offline

    MCForger

    xWatermelon
    I believe they are using the Scoreboard Packets that came out in 1.5 and are just leaving blank the defining of a variable before the 0 and then after making another item and only showing the %.
    Again this is what I believe they are doing.
    There is two good tutorials under the resource section.
     
    number1_Master likes this.
  7. Offline

    skipperguy12

    MCForger
    Someone seriously needs to make an API or a class full of methods, too many Scoreboard problems!
     
  8. Offline

    xWatermelon

    Oh, yes, I remember you :). Perhaps you know my friend Nauss (I think his Bukkit account is chasechocolate)?
    MCForger What packets? Can you give an example?
     
  9. Offline

    chasechocolate

  10. Offline

    macguy8

    chasechocolate
    I feel really dumb, but how would you tell the client what player to display the nametag for in that packet?
     
  11. Offline

    Harry5573

    mbaxter Add this and an easy method to your tagapi please. And give us an example of how to use it
     
  12. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    The second line is the scoreboard. That should not be managed in a per-player way like TagAPI does.
     
  13. Offline

    chasechocolate

    macguy8 ((CraftPlayer) player).getHandle().playerConnection.sendPacket(<packet>) I think.
     
  14. Offline

    macguy8

    chasechocolate no no, I mean which player to display it under. Eg I send player A that packet, how do I tell it if it should display it under player B or C's head?
     
  15. Offline

    chasechocolate

    macguy8 Use a loop and send it to those players.
     
  16. Offline

    macguy8

    chasechocolate
    Wha?

    I'm still confused. On that packet thing you sent, it says the args are the position, and the String. How would I tell the client I'm sending it to what player it's to be displayed under?
     
  17. Offline

    chasechocolate

    macguy8 Don't fully understand... But the player you send the packet to is the player who will get the name change.
     
  18. Offline

    macguy8

    chasechocolate
    So, if I send it to playerA with the contents "Test", would everyone else see playerA with that under their name, or? That sort of seems to be the case from what you're saying, but that sort of goes against what I know about packets (very little)
     
  19. Offline

    chasechocolate

    macguy8 oh never mind, I misunderstood you. For example, if you send a packet to playerA that tells them that playerB's name should be green, then only playerA will see playerB's name green.
     
  20. Offline

    macguy8

    chasechocolate
    That's what I'm asking. I don't see a way to what player it is applying to. Eg, I get how to send playerA the packet, just not how to tell playerA the packet is for playerB.
     
  21. Offline

    chasechocolate

    macguy8 in some circumstances playerB is in the parameters when you create a instance of the packet.
     
  22. Offline

    macguy8

    chasechocolate
    It doesn't seem to be here though. Any ideas how I would make it per player, or what this packet even does in terms of who can see it?
     
  23. Offline

    xWatermelon

    Bump... Can anyone show me an example in code? Not very knowledgeable when it comes to packets... Some people who seem to know what they are doing: fireblast709 gomeow chasechocolate Comphenix and some more who I can't think of...
     
  24. Offline

    gomeow

    I've messed around a little with Scoreboard packets, but I haven't seen a way to send the percent sign/no number value
     
  25. Offline

    xWatermelon

    Tzeentchful? You seem to be the scoreboard master...
     
  26. Offline

    Tzeentchful

    Ok it works by having an integer followed by a string. The string is the objective's name and the integer can be set by creating a scoreboared score with the players name.
    Here is an example.
    Code:java
    1.  
    2. public void test(final Player gplayer) {
    3. getServer().getScheduler().runTask(this, new Runnable() {
    4. @Override
    5. public void run() {
    6. String name = "Test";//the string next to the name will be called test
    7.  
    8. Scoreboard sb = new Scoreboard();//Create new scoreboard
    9. sb.registerObjective(name, new ScoreboardBaseCriteria(name));
    10.  
    11. Packet206SetScoreboardObjective packet = new Packet206SetScoreboardObjective(sb.getObjective(name), 0);//Create Scoreboard create packet
    12. Packet208SetScoreboardDisplayObjective display = new Packet208SetScoreboardDisplayObjective(2, sb.getObjective(name));//Create display packet set to under name mode
    13.  
    14. ScoreboardScore scoreItem1 = sb.getPlayerScoreForObjective(gplayer.getDisplayName(), sb.getObjective(name));//Create a new item with the players name
    15. scoreItem1.setScore(42);//this will set the integer under to the player's name, who ran the command to 42
    16.  
    17. Packet207SetScoreboardScore pScoreItem1 = new Packet207SetScoreboardScore(scoreItem1, 0);//Create score packet 1
    18. for(Player player : Bukkit.getOnlinePlayers()){//send to all the players on the server
    19. sendPacket(player, packet);//Send Scoreboard create packet
    20. sendPacket(player, display);//Send the display packet
    21. sendPacket(player, pScoreItem1);//Send score update packet
    22. }
    23. }
    24.  
    25. });
    26. }
    27.  

    It will look something like this for the player that was set in the gplayer variable.[​IMG]

    And any other player will look like this.
    [​IMG]

    If you want to set the integer for a particular player you will have to send another SetScoreboardScore for the player you want to update.
    Code:java
    1.  
    2. ScoreboardScore scoreItem2 = sb.getPlayerScoreForObjective("players name here", sb.getObjective(name));//Create a new item with the players name
    3. scoreItem2.setScore(42);//this will set the integer under to the player's name specified above to 42
    4.  
    5. Packet207SetScoreboardScore pScoreItem2 = new Packet207SetScoreboardScore(scoreItem2, 0);//Create score packet 1
    6. for(Player player : Bukkit.getOnlinePlayers()){//send to all the players on the server
    7. sendPacket(player, pScoreItem1);//Send score update packet
    8. }
    9.  

    DO NOT send the SetScoreboardObjective and or the SetScoreboardDisplayObjective twice to the client it will crash it. You will only need to send it once when they first login. You can then use the method above to set the value under a particular players name.

    If you need any help feel free to ask :D
     
    xWatermelon and chasechocolate like this.
  27. Offline

    xWatermelon

    Tzeentchful wow... thanks! I can't seem to find the methods in the Scoreboard variable... All I can get is .a(), .b(), .c(), etc.
     
  28. Offline

    gomeow

  29. Offline

    Tzeentchful

    You are building against the 1.5 build. In 1.5 the method names a re obfuscated. How ever in 1.5.1 they aren't. So building against 1.5.1 will fix your issue.
     
  30. Offline

    gomeow

Thread Status:
Not open for further replies.

Share This Page