[1.5.1] Custom Scoreboards

Discussion in 'Resources' started by Tzeentchful, Mar 16, 2013.

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

    devilquak

    This is probably pretty simple, but ((CraftPlayer) player) doesn't want to resolve and importing the normal line that I use to fix this problem doesn't help. I really want to make use of scoreboards, and this is the only thing in my way. What can I do?
     
  2. Offline

    Tzeentchful

    You need to be building against craftbukkit not bukkit to be able to access the CB and NMS code necessary for this to work.
     
  3. Offline

    devilquak

    No, I know that, remember that I said that what I normally do doesn't work now.

    Thanks anyways though, I fixed it myself right after I made this post, silly me.
     
  4. Offline

    Murderscene

    I have tried everything I can think of but I cannot figure out how to REMOVE an objective.

    I basically want to be able to replace the objective with others. Any way to remove an objective?

    I can simply set a new objective and it does override it, but then once I switch back to the old objective it says it already exists. I would like to remove it completely when I need
     
  5. Offline

    Tzeentchful

    Here is the function to remove an objective.
    Code:
    sb.k(sb.b("name of your objective"));
     
  6. Offline

    devilquak

    Tzeentchful

    Since I'm a stupid and you're the messiah of the scoreboard, and after a few hours of hopelessly fiddling with this scoreboard stuff, I am seeking you for guidance.

    Suppose I want to make a scoreboard to be able to be created for one player, and to display it to that one and only player, possibly update it quite often, and then be able to easily remove it at any time. I don't exactly understand the order of which I need to do most of the scoreboard operations, like sending/removing objectives, sending/removing the scoreboards to/from the player, ect. If it's not too much to ask, what is the basic gist of the order in which I need to make things execute?
     
  7. Offline

    Tzeentchful

    Ok well first off you are going to want to create a scoreboard and objective and send it to the client.
    Like so

    PHP:
    Scoreboard sb = new Scoreboard();//Create new scoreboard
    sb.a(name, new ScoreboardBaseObjective(name));//Create new objective in the scoreboard
     
    Packet206SetScoreboardObjective packet = new Packet206SetScoreboardObjective(sb.b(name), 0);//Create Scoreboard create packet
    Packet208SetScoreboardDisplayObjective display = new Packet208SetScoreboardDisplayObjective(1sb.b(name));//Create display packet set to sidebar mode
     
    sendPacket(playerpacket);//Send Scoreboard create packet
    sendPacket(playerdisplay);//Send the display packet
    Then you are going to want to populate the objective whit items/scores
    PHP:
    ScoreboardScore scoreItem1 sb.a("Answer to life"sb.b(name));//Create a new item
    ScoreboardScore scoreItem2 sb.a("4 * 4"sb.b(name));//Create a new item
    scoreItem1.c(42);//Set it's value to 42
    scoreItem2.c(12);//Set it's value to 12
     
    Packet207SetScoreboardScore pScoreItem1 = new Packet207SetScoreboardScore(scoreItem10);//Create score packet 1
    Packet207SetScoreboardScore pScoreItem2 = new Packet207SetScoreboardScore(scoreItem20);//Create score packet 2
    sendPacket(playerpScoreItem1);//Send score update packet
    sendPacket(playerpScoreItem2);//Send score update packet
    Then all you need to do is send score packets with either the update/add or remove flag and it will update to the client.
    PHP:
    ScoreboardScore scoreItem3 sb.a("Item added"sb.b(name));//Create a new item
    scoreItem3.c(42);//Set it's value to 42
     
     
    Packet207SetScoreboardScore pScoreItem3 = new Packet207SetScoreboardScore(scoreItem30);//0 is add or update
    Packet207SetScoreboardScore pScoreItem4 = new Packet207SetScoreboardScore(scoreItem31);//1 is remove
    sendPacket(playerpScoreItem3);//Send score update packet
    sendPacket(playerpScoreItem4);//Send score remove packet
     
    devilquak likes this.
  8. Offline

    devilquak

    Tzeentchful

    Thank you so much, that is all very helpful. I have gotten it to successfully display one thing once, the first time I try to display it, but I can't modify it or remove it after that. I'm trying to make a method so that I can update a value, but I don't know how to get an existing score item and put it in here to modify. Here's what I've got:

    PHP:
    public void updateBoard(Player p)
    {
        
    scoreItem1.c(value);
     
        
    Packet207SetScoreboardScore pScoreItem1 = new Packet207SetScoreboardScore(scoreItem10);
        
    sendPacket(ppScoreItem1);
    }
    Edit: If, again, it's not too much to ask, I'm trying to do the exact same thing but for a remove/eraseBoard method. Same problem, I can't grab the scoreboard object because I have no idea how to obtain it.
     
  9. Offline

    Tzeentchful

    You will have to save the scoreboard object somewhere. I would suggest using a hashmap with the players name as the key and the scoreboard as the value.
    Code:
    Map<String, ScoreBoard> savedScoreboards = new HashMap<String, ScoreBoard>();
     
    devilquak likes this.
  10. Offline

    Murderscene

    Thankyou.

    Also. ScoreboardBaseObjective seems to be removed from v1_5_R2
    Was it replaced with a new class?
     
  11. Offline

    devilquak

    Ah, that makes sense. I had thought about doing that, but hoped there would be a way to find an existing scoreboard. All in due time, I suppose. Thanks for your help, I'm certain I can finish this now.

    Tzeentchful

    I'm sorry to bother you with another pesky question, but like a few others that posted before me, I can't seem to send a scoreboard again after I've already sent and removed it. It all works well visually, but the client crashes when I try to send the board, and there's no error anywhere, neither the console or the usual Minecraft error log itself. I suspect my mistake is in the code I use to try and remove the board:

    Code:
    public void exitTurret(Player p)
        {
            ScoreboardScore sb = boards.get(p.getName());
         
            Scoreboard rsb = rawBoards.get(p.getName());
         
            Packet207SetScoreboardScore pScoreItem4 = new Packet207SetScoreboardScore(sb, 1);
            sendPacket(p, pScoreItem4);
            rsb.k(rsb.b("Ammunition"));
            boards.remove(p.getName());
            rawBoards.remove(p.getName());
        }
    Now that I look at it again, do I maybe have to send a packet to the client to tell it that I've deleted the scoreboard?

    Edit: Nevermind, I think I fixed it myself. Thanks for your help again.

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

    Rprrr

    Just wanted to show the way to do this in 1.5.1 (everything changed a little, had to struggle with this for a few minutes before I fixed it):

    Code:
                Scoreboard sb = new Scoreboard();
                sb.registerObjective(splitLines[0], new ScoreboardBaseCriteria(splitLines[0]));
               
                Packet206SetScoreboardObjective createPacket = new Packet206SetScoreboardObjective(sb.getObjective(splitLines[0]), 0);
                final Packet206SetScoreboardObjective removePacket = new Packet206SetScoreboardObjective(sb.getObjective(splitLines[0]), 1);
                Packet208SetScoreboardDisplayObjective display = new Packet208SetScoreboardDisplayObjective(1, sb.getObjective(splitLines[0]));
               
                for (final Player p : Bukkit.getServer().getOnlinePlayers()){
                    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(createPacket);
                    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(display);
                   
                    new BukkitRunnable(){
                        @Override
                        public void run(){
                            ((CraftPlayer) p).getHandle().playerConnection.sendPacket(removePacket);
                        }
                    }.runTaskLater(plugin, stayForHowLong * 20L);
                }
     
     
    ----
     
                    ScoreboardScore scoreItem = new ScoreboardScore(sb, sb.getObjective(splitLines[0]), splitLines[i]); //ScoreBoard, ScoreBoardObjective, String
                    scoreItem.setScore(i);
                   
                    Packet207SetScoreboardScore pScoreItem = new Packet207SetScoreboardScore(scoreItem, 0);
                   
                    for (Player p : Bukkit.getServer().getOnlinePlayers()){
                        if (p.hasPermission("scoreboardannouncer.see")){
                            ((CraftPlayer) p).getHandle().playerConnection.sendPacket(pScoreItem);
                        }
                    }
     
  13. Offline

    Tzeentchful

    Yea i have updated the op with the changes in 1.5.1.
     
  14. Offline

    the_merciless

    i made a method to create and display a scoreboard, which works fine if i call the method from a command, however if i call the method in a PlayerJoinEvent the scoreboard does not display. Do i need to set a delay or something?

    Nvm, my onEnable was bad.
     
  15. Offline

    the_merciless

    How do i remove the entire scoreboard, rather than just an objective or score item.
     
  16. Offline

    devilquak

    Code:
    Packet206SetScoreboardObjective packet = new Packet206SetScoreboardObjective(scoreBoard.getObjective(scoreboardName), 1);
    sendPacket(player, packet);
     
  17. Offline

    Metal Julien

    Tzeentchful NullPointerException at
    ScoreboardObjective objective =
    scoreBoards.get(scoreboard).b(obj);
    :(
     
  18. Offline

    kaZep

    I can't import Scoreboard Criteria, why?
     
  19. Offline

    the_merciless

     
  20. Is it possible to display two objectives at the same time?
     
  21. Offline

    the_merciless

    O
    One way to find out...
     
  22. I've already tried it but without success.
     
  23. Tzeentchful
    I tryed using your class and I can't seem to find the ScoreboardBaseObjective class and methods Scoreboard.b() and Scoreboard.c() :( Has there been a change to have this works or am I just being really dumb (totaly a possibility :p)?

    EDIT: OK, it seems like that wasn't updated for 1.5.1. I have changed all the methods, and it seems to be working nicely! Thanks a lot, this really helps me, you are awesome!
     
  24. Do you know if it is possible to check whether a client has already displayed a scoreboard or not?
     
  25. It's not gonna display it if you didn't send packets so you should know.
     
  26. Well I want to check if a client already has a scoreboard displayed with a plugin.
     
  27. Offline

    Tzeentchful

    Sadly there is no way to tell if the client has a scoreboard displayed. You will have to track it manually. I think the best way would be to have a Map with the players name as the key and a boolean as the value and just set the boolean when you load/unload the scoreboard.
    Code:java
    1. Map<String, Boolean> tracker = new HashMap<String, Boolean>();
     
  28. The problem is that the players are able to switch the servers with a single command and the client just keeps the Scoreboard at another server. 1. It looks bad and 2. When a player who already has the scoreboard joins the server with the scoreboard again the server sends the scoreboard again -> client crash. But I'm currently trying to remove the Scoreboard with a plugin at the other servers.
     
  29. Offline

    devilquak

    This might be a prime time for Metadata to shine, so to speak. For once it could actually be used for what it was designed for, you could give a player a Metadata tag when you assign him/her a scoreboard, and that tag would be readable by any other plugin.
     
  30. Offline

    Tzeentchful

    Are you using Bungee Cord? If you are you could write a plugin for it to handle/track the scoreboard.
     
Thread Status:
Not open for further replies.

Share This Page