[Tutorial] Scoreboards/Teams with the Bukkit API

Discussion in 'Resources' started by chasechocolate, Apr 5, 2013.

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

    kevin3220

    Guys could you please help me ? I tried a code what i found from youtube

    Code:
    public class mainClass extends JavaPlugin implements Listener{
          public static Economy econ = null;
          public static Chat chat = null;
       
        public void logMessage(String msg){
           
            PluginDescriptionFile pdFile=this.getDescription();
            this.log.info(pdFile.getName()+ " " +msg+ " " +pdFile.getVersion());
           
        }
       
       
     
       
       
       
       
        private Logger log=Logger.getLogger("minecraft");
     
       
        @Override
        public void onEnable() {
            this.logMessage("enabled");
            getServer().getPluginManager().registerEvents(this, this);
            ScoreboardManager sbManager=Bukkit.getScoreboardManager();
            Scoreboard sBoard=sbManager.getNewScoreboard();
           
            Team red=sBoard.registerNewTeam("red");
            Team blue=sBoard.registerNewTeam("blue");
           
            red.addPlayer(Bukkit.getOfflinePlayer("Kevin"));
            blue.removePlayer(Bukkit.getOfflinePlayer("rat"));
           
            red.setPrefix(ChatColor.RED+"");
            blue.setPrefix(ChatColor.BOLD+"");
           
            red.setAllowFriendlyFire(false);
           
        //    Objective o=sBoard.getObjective("benTest");
           
            Objective obj= sBoard.registerNewObjective("benTest", "Kill Players");
            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
            obj.setDisplayName("KILLS");
            Score score=obj.getScore(Bukkit.getOfflinePlayer("Total kills:"));
           
            score.setScore(50);
           
            for(Player player: Bukkit.getOnlinePlayers()){
                player.setScoreboard(sBoard);
                player.setScoreboard(sbManager.getNewScoreboard());
            }
           
            Scoreboard phealth=sbManager.getNewScoreboard();
            Objective health=phealth.registerNewObjective("under playeNamehealth", "health");
            health.setDisplaySlot(DisplaySlot.BELOW_NAME);
            health.setDisplayName("Heaths");
           
            for (Player player:Bukkit.getOnlinePlayers()){
                player.setScoreboard(phealth);
            }
           
           
           
           
           
           
           
           
           
           
           
           
            
    Please help me just reply to me so i can see! Thank you!
     
  2. Offline

    ELCHILEN0

    Even at 100 MB that is highly unlikely. Each Scoreboard takes up about 712 bytes. However they are most likely stored in an array which would ensure that the allocation is not linear for each Scoreboard. If it were 100-250 MB I would be seriously concerned. In reality it should be somewhere around 1 MB for 100 entries. Possibly less.
     
  3. Offline

    etaxi341

    ELCHILEN0 Better calculating too much then less :D
     
  4. Offline

    uvbeenzaned

    I have this major problem with scoreboards disappearing with my plugin after someone gets hit in a round. Can someone please explain to me all the things can make a scoreboard disappear for a player? I know there is p.setScoreboard(SnowballerListener.manager.getNewScoreboard()); but what else could cause the player to not see the board anymore? Is it ok to contain a scoreboard in a static field? IDK what on earth is going wrong.
     
  5. Offline

    cfil360

    etaxi341 what is the PlayerDataListener doing. It would be awesome if you would include the code for that class. If anyone else can help that would also be appreciated
     
  6. Offline

    Paxination

    chasechocolate

    Is there a way to get all players to see the PREFIX in your tag and not the scoreboard?
     
  7. Offline

    uvbeenzaned

    Bump
     
  8. Offline

    chasechocolate

    uvbeenzaned what's your code?
    Paxination do you mean that you don't want to have the scoreboard on the right (sidebar)? If so, then only create a below name objective.
     
  9. Offline

    uvbeenzaned

    I don't have any suspect code but the full fledged snowball plugin that it is has 9 classes and I have no idea where to start. The only thing I can do is give you the Github page but let me warn you, it's not commented. https://github.com/uvbeenzaned/SnowballER/tree/master/src/co/networkery/uvbeenzaned
     
  10. Offline

    Paxination

    chasechocolate

    No what I mean is I want only my staff to seee the SIDEBAR, ALL players to see the prefix of the STAFF team.
     
  11. Offline

    Acer_Mortem

    For some reason, this isn't working for me =/

    Know what's wrong, chasechocolate ?

    Code:
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            Objective objective = board.registerNewObjective("Stuff", "Mo Stuff");
            objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
            objective.setDisplayName("Stuff");
           
            for(Player online : Bukkit.getOnlinePlayers()){
                String name = online.getName();
                String aClass = getConfig().getString("Players." + name + ".Current-Class");
                int CurrentLevel = getConfig().getInt("Players." + name + "." + aClass + ".Level");
                Score score = objective.getScore(online);
                score.setScore(CurrentLevel);
                p.setScoreboard(board);
               
            }
    Also, in the join listener, I have it run the scoreboard method.
     
  12. Offline

    chasechocolate

    Acer_Mortem when registering the objective, change "Mo Stuff" to "dummy".
     
  13. Offline

    Acer_Mortem

    Oh, okay. Also, my plugin is sort of a class and level type thing. How could I reverse it so that the score is behind the objective, so it reads: "Warrior" "7"
     
  14. Offline

    uvbeenzaned

    chasechocolate Is it possible that teleporting and/or p.setRemoveWhenFarAway(true); could cause my scoreboard to disappear?
     
  15. Offline

    chasechocolate

    Not that I know of. Is it your sidebar scoreboard?
     
  16. Offline

    uvbeenzaned

    Yes it is.
     
  17. Very awesome! Thanks
     
  18. Offline

    Ethan

    When I go to set a players scoreboard when they login I get an "IllegalStateException: Cannot set scoreboard yet" at this line:
    PHP:
    player.setScoreboard(plugin.board);
    Not sure why though...
     
  19. Offline

    Nosliw

    It could be something to do with the order in which packets are sent, You could move your setScoreboard into the move event, and make it execute the first time they move. Or you could add a delayed task, so that the scoreboard loads after the login event has finnished.
     
  20. Offline

    uvbeenzaned

    Didn't ever hear back from ya on this one. What did you think? It is a sidebar board.
     
  21. Offline

    theisevan

    chasechocolate I'm having an issue on the second part of it! I have

    Code:
    ScoreboardManager manager = Bukkit.getScoreboardManager();
     
        Scoreboard board = manager.getNewScoreboard();
    it's telling me
    Type mismatch: cannot convert from org.bukkit.scoreboard.Scoreboard to com.theorizedgaming.TD.Scoreboard
     
  22. Offline

    chasechocolate

    theisevan it's because you are importing one of your plugin's Scoreboard classes when you should be importing org.bukkit.
     
  23. Offline

    Meatiex

    chasechocolate
    Is there a way to check if the player is in a team?
     
  24. Offline

    theisevan

    import org.bukkit.scoreboard.ScoreboardManager; that's what I imported, that's wrong?
     
  25. Offline

    chasechocolate

    Last edited by a moderator: Oct 30, 2015
  26. Offline

    theisevan

    Ah thanks, that fixed it. Didn't know that it would be picky over something like that.
     
  27. Offline

    sgavster

    This is probably a stupid question, but I can't seem to find out, so I'm gonna ask here.
    I made it so when I do a command, it'll set up the scoreboard, but I have it so it's dummy. One of the names is "red" so if I try to do this:
    Code:java
    1. @EventHandler
    2. public void onEntityHitEvent(ProjectileHitEvent e)
    3. {
    4. if(e instanceof Player)
    5. {
    6. Player p = ((Player) e).getPlayer();
    7. if(r.contains(p.getName()))
    8. {
    9. blue.setScore(blue.getScore() + 1);
    10. }
    11. }
    12. }
    13. }

    Blue cannot be resolved as a type. Any help?
    Sorry for being such a noob, still new to this :p
     
  28. Offline

    WhaleAnarchy

    chasechocolate I am having trouble here, with your "online.getHealth()". It keeps telling me "The method getHealth() is ambiguous for type Player". What should I do?
     
  29. Offline

    chasechocolate

    WhaleAnarchy there are already lots of threads regarding this, search it up.
     
  30. Offline

    WhaleAnarchy

    I have and all I come up with is a bunch of junk.
     
Thread Status:
Not open for further replies.

Share This Page