[1.5.1] Custom Scoreboards

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

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

    CreeperShift

    I see. That's sad. Maybe you should really just try to find some help over at the spigot forums ;) I bet they know more about this than us :p
     
    black_ixx likes this.
  2. Hm ok thanks I'll try it there.
     
  3. Offline

    TheUpdater

    now i have done it cus you said use minecraft.net server and craftbukkit
    -.-

    Code:
    package me.ScoreBoard;
     
    import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import net.minecraft.server.v1_5_R2.Packet206SetScoreboardObjective;
    import net.minecraft.server.v1_5_R2.Packet207SetScoreboardScore;
    import net.minecraft.server.v1_5_R2.Packet208SetScoreboardDisplayObjective;
    import net.minecraft.server.v1_5_R2.ScoreboardBaseCriteria;
    import net.minecraft.server.v1_5_R2.ScoreboardObjective;
    import net.minecraft.server.v1_5_R2.ScoreboardScore;
     
    public class ScoreBoard extends JavaPlugin{
        public void test(final Player player){
            getServer().getScheduler().runTask(this, new Runnable(){
     
                @Override
                public void run() {
                    String name = "Test";
                   
                    ScoreBoard sb = new ScoreBoard();
                    sb.registerObjective(name, new ScoreboardBaseCriteria(name));
                   
                   
                    Packet206SetScoreboardObjective packet = new Packet206SetScoreboardObjective(sb.getObjective(name), 0);
                    Packet208SetScoreboardDisplayObjective display = new Packet208SetScoreboardDisplayObjective(1, sb.getObjective(name));
                   
                    sendPacket(player, packet);
                    sendPacket(player, display);
                   
                    ScoreboardScore scoreItem1 = sb.getPlayerScoreForObjective("Answer to life", sb.getObjective(name));//Create a new item
                    ScoreboardScore scoreItem2 = sb.getPlayerScoreForObjective("4 * 4", sb.getObjective(name));//Create a new item
                    scoreItem1.setScore(42);//Set it's value to 42
                    scoreItem2.setScore(12);//Set it's value to 12
                   
                    Packet207SetScoreboardScore pScoreItem1 = new Packet207SetScoreboardScore(scoreItem1, 0);//Create score packet 1
                    Packet207SetScoreboardScore pScoreItem2 = new Packet207SetScoreboardScore(scoreItem2, 0);//Create score packet 2
                    sendPacket(player, pScoreItem1);//Send score update packet
                    sendPacket(player, pScoreItem2);//Send score update packet
                   
                   
                }
               
            });
        }
       
        public static void sendPaket(Player player, net.minecraft.server.v1_4_R1.Packet packet){
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
       
     
        protected void sendPacket(Player player,
                Packet207SetScoreboardScore pScoreItem1) {
            // TODO Auto-generated method stub
           
        }
     
        protected ScoreboardScore getPlayerScoreForObjective(String string,
                ScoreboardObjective objective) {
            // TODO Auto-generated method stub
            return null;
        }
     
        protected void sendPacket(Player player,
                Packet208SetScoreboardDisplayObjective display) {
            // TODO Auto-generated method stub
           
        }
     
        protected void sendPacket(Player player,
                Packet206SetScoreboardObjective packet) {
            // TODO Auto-generated method stub
           
        }
     
        protected ScoreboardObjective getObjective(String name) {
            // TODO Auto-generated method stub
            return null;
        }
     
        protected void registerObjective(String name, ScoreboardBaseCriteria scoreboardBaseCriteria) {
            // TODO Auto-generated method stub
           
        }
       
    }
     
  4. what?
     
  5. Offline

    TheUpdater

    i just finish custom ScoreBoard when he told me to use vanilla server and craftbukkit 1.4.7
    the it was easyer
     
  6. You know that there are no scoreboards in minecraft 1.4.7...
     
    black_ixx likes this.
  7. Offline

    TheUpdater

    o thats why i dont get it? cus code is fully lol

    i use minecraft_server.jar
    and craftbukkit 1.5.1
    still dont get screen lol what is wrong

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  8. minecraft_server.jar is the wrong place to use craftbukkit code and craftbukkit 1.5 is the wrong place to import craftbukkit 1.4 stuff.....
     
  9. Offline

    TheUpdater

    Why is this not working

    Code:
    package me.ScoreBoard;
     
    import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import net.minecraft.server.v1_5_R2.Packet206SetScoreboardObjective;
    import net.minecraft.server.v1_5_R2.Packet207SetScoreboardScore;
    import net.minecraft.server.v1_5_R2.Packet208SetScoreboardDisplayObjective;
    import net.minecraft.server.v1_5_R2.ScoreboardBaseCriteria;
    import net.minecraft.server.v1_5_R2.ScoreboardObjective;
    import net.minecraft.server.v1_5_R2.ScoreboardScore;
     
    public class ScoreBoard extends JavaPlugin{
        public void test(final Player player){
            getServer().getScheduler().runTask(this, new Runnable(){
     
                @Override
                public void run() {
                    String name = "Test";
                 
                    ScoreBoard sb = new ScoreBoard();
                    sb.registerObjective(name, new ScoreboardBaseCriteria(name));
                 
                 
                    Packet206SetScoreboardObjective packet = new Packet206SetScoreboardObjective(sb.getObjective(name), 0);
                    Packet208SetScoreboardDisplayObjective display = new Packet208SetScoreboardDisplayObjective(1, sb.getObjective(name));
                 
                    sendPacket(player, packet);
                    sendPacket(player, display);
                 
                    ScoreboardScore scoreItem1 = sb.getPlayerScoreForObjective("Answer to life", sb.getObjective(name));//Create a new item
                    ScoreboardScore scoreItem2 = sb.getPlayerScoreForObjective("4 * 4", sb.getObjective(name));//Create a new item
                    scoreItem1.setScore(42);//Set it's value to 42
                    scoreItem2.setScore(12);//Set it's value to 12
                 
                    Packet207SetScoreboardScore pScoreItem1 = new Packet207SetScoreboardScore(scoreItem1, 0);//Create score packet 1
                    Packet207SetScoreboardScore pScoreItem2 = new Packet207SetScoreboardScore(scoreItem2, 0);//Create score packet 2
                    sendPacket(player, pScoreItem1);//Send score update packet
                    sendPacket(player, pScoreItem2);//Send score update packet
                 
                 
                }
             
            });
        }
     
        public static void sendPaket(Player player, net.minecraft.server.v1_5_R2.Packet packet){
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
     
     
        protected void sendPacket(Player player,
                Packet207SetScoreboardScore pScoreItem1) {
            // TODO Auto-generated method stub
         
        }
     
        protected ScoreboardScore getPlayerScoreForObjective(String string,
                ScoreboardObjective objective) {
            // TODO Auto-generated method stub
            return null;
        }
     
        protected void sendPacket(Player player,
                Packet208SetScoreboardDisplayObjective display) {
            // TODO Auto-generated method stub
         
        }
     
        protected void sendPacket(Player player,
                Packet206SetScoreboardObjective packet) {
            // TODO Auto-generated method stub
         
        }
     
        protected ScoreboardObjective getObjective(String name) {
            // TODO Auto-generated method stub
            return null;
        }
     
        protected void registerObjective(String name, ScoreboardBaseCriteria scoreboardBaseCriteria) {
            // TODO Auto-generated method stub
         
        }
     
    }
    read above and see if can find the wrong
    plz

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

    devilquak

    Buddy. For the last time, this stuff is way above your level. For the love of god, please stop trying to mess with scoreboards and watch some Java tutorials. We can't help you if you don't understand a single part of any of this, and especially so when your sentences make less sense than anything I can make an analogy with.

    It took 5 people and at least 20 posts to get you to just import Craftbukkit into your IDE. That alone means that you aren't ready for this.
     
  11. Offline

    the_merciless

  12. Take a look her and learn how to write basic plugins:
    http://wiki.bukkit.org/Plugin_Tutorial

    Come back when you know how to create a listener which kicks the player "Hans" when he writes "lol" in the chat. It will probably need more knowledge to work with Scoreboards but without the basic information you can't do ANYTHING.
     
  13. Offline

    TheUpdater

    i now how to code have just never see those codes befor of any sort
     
  14. Could you link me a plugin you wrote?
     
  15. Offline

    TheUpdater

    well i can code 1 now if you want

    cus am not giving you my big project one wait then
    it goes fast
     
  16. Offline

    devilquak

    No offense, but I'm going to beg you to start writing legibly, it's painful to read what you write.
     
  17. Ok so write a little plugin which hooks into Vault and allows you to buy a tnt with money. When a player places this TnT it automatically explodes without redstone. Oh and if a player places a normal TnT without redstoen nothing happens. So just the "TnT" of the shop works with your plugin. This should be a very simple and little plugin but you have to know some stuff about bukkit to create it.
     
    devilquak likes this.
  18. Offline

    TheUpdater

    well then i start it might take some time tho
     
  19. Offline

    the_merciless

    TheUpdater stop trying to prove yourself, i have been coding for a long time and even this confused me when i first looked at it. All the info you need has already been posted, if your struggling to understand it theres not much else we can do to help you anymore, short of writing it for you. Either request the plugin in the request section or move on to something you understand. Keep on coding and you will learn to understand this in time.
     
  20. Offline

    Waffletastic

    I lol'd at TheUpdater .

    But yeah, I'm trying to create a list scoreboard and a sidebar scoreboard, but I can't get them both to appear without sending packets twice which is making the client crash. >_> Any suggestions?
     
  21. Offline

    devilquak

  22. Offline

    Waffletastic

    devilquak

    Yeah. I'm actually hooking into the ScoreboardAPI plugin, which the source can be found here:
    https://github.com/xxmicloxx/ScoreboardAPI/tree/master/src/yt/codebukkit/scoreboardapi

    I can stop using that if you think it would be easier to write myself.

    But the main problem is that I can't seem to put a scoreboard in the tab list and on the side at the same time without the client crashing.

    Well here is where I do what I need with the scoreboards:

    Code:
    public class ScoreboardUtil {
     
        private static ScoreboardAPI scoreboardAPI;
        private static Scoreboard flagCaptureSB;
        private static Scoreboard matchKillsSB;
     
        public static void setupScoreBoards() {
            scoreboardAPI = ScoreboardAPI.getInstance();
            // Creating scoreboards.
            flagCaptureSB = scoreboardAPI.createScoreboard("FlagCaptures", 1);
            matchKillsSB = scoreboardAPI.createScoreboard("kills", 2);
            // Setting locations on screen.
            flagCaptureSB.setType(Scoreboard.Type.SIDEBAR);
            matchKillsSB.setType(Scoreboard.Type.PLAYER_LIST);
            // Setting display names.
            flagCaptureSB.setScoreboardName("&a&lFlag Captures");
            matchKillsSB.setScoreboardName("Match Kills");
        }
     
        public static Scoreboard getFlagCaptureSB() {
            return flagCaptureSB;
        }
     
        public static Scoreboard getMatchKillsSB() {
            return matchKillsSB;
        }
     
        public static ScoreboardAPI getScoreboardAPI() {
            return scoreboardAPI;
        }
     
        public static void updateMatchKillsSB() {
            for (CTFPlayer player : CTFPlayerUtil.getAllCTFPlayers()) {
                String color = "";
                if (player.isRedTeam()) {
                    color = "&4";
                } else {
                    color = "&3";
                }
                getMatchKillsSB().setItem(color + player.getName(), player.getKillsInArena());
            }
        }
     
        public static void updateFlagCaptureSB() {
            getFlagCaptureSB().setItem("&4Red", MCBCTF.manager.getArenaBeingUsed().getRedFlagCaptures());
            getFlagCaptureSB().setItem("&3Blue", MCBCTF.manager.getArenaBeingUsed().getBlueFlagCaptures());
        }
    }
    And when a player join event fires I do this:

    Code:
            ScoreboardUtil.getFlagCaptureSB().showToPlayer(event.getPlayer(), true);
            ScoreboardUtil.getMatchKillsSB().showToPlayer(event.getPlayer(), true);
    So basically it's crashing because I try and send the same type of packet for each scoreboard. Have you or anyone else had any success with creating two scoreboards at once? I know it works on singleplayer, but I haven't been able to stop a client crash on Bukkit.

    And here's a display of all the methods following showToPlayer() if you don't want to have to dig through the source:

    Oh and if you want to PM me your Skype name if you have one, we could work on it faster there.


    Code:
        public void showToPlayer(Player p, boolean show) {
            if (show) {
                if (!players.contains(p)) {
                    players.add(p);
                    plugin.updateForPlayer(p);
                }
            } else {
                if (players.remove(p)) {
                    Packet206SetScoreboardObjective pack = new Packet206SetScoreboardObjective();
                    pack.a = name;
                    pack.b = "";
                    pack.c = 1;
                    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(pack);
                    plugin.updateForPlayer(p);
                }
            }
        }
    Code:
        public void updateForPlayer(Player p) {
            for (Scoreboard s : scoreboards) {
                s.checkIfNeedsToBeDisabledForPlayer(p);
                s.checkIfNeedsToBeEnabledForPlayer(p);
            }
        }

    Code:
        public void checkIfNeedsToBeDisabledForPlayer(Player p) {
            if (!players.contains(p)) {
                return;
            }
            PlayerConnection conn = ((CraftPlayer) p).getHandle().playerConnection;
            if (!isUnique(p)) {
                Packet206SetScoreboardObjective pack = new Packet206SetScoreboardObjective();
                pack.a = name;
                pack.b = displayName;
                pack.c = 1;
                conn.sendPacket(pack);
            }
        }
     
        public void checkIfNeedsToBeEnabledForPlayer(Player p) {
            if (!players.contains(p)) {
                return;
            }
            PlayerConnection conn = ((CraftPlayer) p).getHandle().playerConnection;
            if (isUnique(p)) {
                Packet206SetScoreboardObjective pack = new Packet206SetScoreboardObjective();
                pack.a = name;
                pack.b = displayName;
                pack.c = 0;
                conn.sendPacket(pack);
                for (String name2 : items.keySet()) {
                    Integer valObj = items.get(name2);
                    if (valObj == null) {
                        continue;
                    }
                    int val = valObj.intValue();
                    Packet207SetScoreboardScore pack2 = new Packet207SetScoreboardScore();
                    pack2.a = name2;
                    pack2.c = val;
                    pack2.d = 0;
                    pack2.b = name;
                    conn.sendPacket(pack2);
                }
                updatePosition(p);
            }
     
        }
    Code:
        private void updatePosition(Player p) {
            if (!isUnique(p)) {
                return;
            }
            Packet208SetScoreboardDisplayObjective pack2 = new Packet208SetScoreboardDisplayObjective();
            pack2.a = type.ordinal();
            pack2.b = name;
            ((CraftPlayer) p).getHandle().playerConnection.sendPacket(pack2);
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  23. Offline

    devilquak

    Waffletastic

    Agh, I apologize, I thought I'd have time to help you out for a few minutes but it turns out that I have to go do some errands for a few hours, so I'll only have my phone and won't have access to the code I have for this. I'm sorry again, but I'll try and get to this again tonight when I'm back home.

    In the meantime, I might suggest just trying to figure it out outside of the API, just using the raw packet stuff itself.
     
  24. Offline

    Waffletastic

    I got it working, you can't use that API though. :)
     
  25. Offline

    iZanax

    - How can the displayname not be the same as the objective name ?
    - sb.registerObjective(name, new ScoreboardBaseCriteria("displayname")); // This still shows the name as displayname instead of "displayname"
    - How can I change/update the displayname ?
    - How can I update score of a getPlayerScoreForObjective ?

    Thanks in advance.
     
  26. Offline

    mrsagency

    Anyone can let economy money amount to show as scoreboard?

    Bump

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

    devilquak

    Are you asking if people have done it, or are you asking how to do it?

    Oh lookie. They just added official Scoreboard API.

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

    Tzeentchful

    Yep the commit is here
    This means that my method will be obsolete.:'(
     
  29. Offline

    kyenzie123

    I'm having a slight problem. When they're are a certain amount of people on my server, and it sends the scoreboard score packets, it kicks all the players with a message something like: blah blah max chars something (17 > 16). Please help!
     
  30. Offline

    Vislo

    Strings in scoreboard cant have more than 16 chars (Colors add like 2-1 more chars)
     
Thread Status:
Not open for further replies.

Share This Page