Development Assistance Scoreboard plugin help

Discussion in 'Plugin Help/Development/Requests' started by samyounes03, Apr 9, 2015.

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

    samyounes03

    Hello,
    I coded a scoreboard plugin, but when i join my server: the scoreboard does not appear. In Eclipse, nothing is marked wrong. I use Spigot build 1649 and the Bukkit API 1.7.10. Please help me!
    Here is the code:
    Code:
    package me.samyounes03.Scoreboard;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    
    public class Main extends JavaPlugin implements Listener {
        static Plugin plugin;
       
        public void onEnable() {
            plugin = this;
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        final Scoreboard board = manager.getNewScoreboard();
        final Objective objective = board.registerNewObjective("test", "dummy");
        @EventHandler
        public void PlayerJoin(PlayerJoinEvent e) {
    
           
            final Player p = e.getPlayer();
    
           
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, new Runnable() {
                public void run() {
                   
                    ScoreboardManager manager = Bukkit.getScoreboardManager();
                    final Scoreboard board = manager.getNewScoreboard();
                    final Objective objective = board.registerNewObjective("test", "dummy");
                   
                    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
                    objective.setDisplayName(ChatColor.RED + "Welcome" + ChatColor.AQUA + p.getDisplayName() + ChatColor.RED + "to McCrossings");
    
                    Score score = objective.getScore(ChatColor.AQUA + "Player name:");
                    score.setScore(10);
                   
                    Score score1 = objective.getScore(ChatColor.GRAY + p.getName());
                    score1.setScore(9);
                   
                    Score score2 = objective.getScore(ChatColor.AQUA + "Health:");
                    score2.setScore(8);
                   
                    long health = Math.round(p.getHealth());
                   
                    Score score3 = objective.getScore(ChatColor.GRAY + String.valueOf(health));
                    score3.setScore(7);
                   
                    p.setScoreboard(board);
    
                }
            },0, 20 * 10);
           
        }
    
    }
     
  2. Online

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
  3. Offline

    mine-care

    A few corrections at firs:
    • Please follow java naming conections (package)
    • Dont use non-needed static (plugin)
    • It is inefficient and a bit of a pain for the server to start a repeating task each time someone joins especially when you are not canceling it when the player disconnects. (Ram leak?)
    And now in-topic
    Why you initialize a new board and objective each time the task runs?
    You have already done that out of the event.
     
  4. Offline

    samyounes03

    Can you please give examples: I am new to Java and i didn't really understand what you said.
     
  5. Invisible

    nverdier

Thread Status:
Not open for further replies.

Share This Page