Scoreboard Lock

Discussion in 'Plugin Development' started by NoSpanMan, Nov 21, 2015.

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

    NoSpanMan

    Every second my scoreboard updates but when the for example the time updates this happens:
    (it happens with all of it)
    [​IMG]

    Code:
    Code:
    public void startTime()
        {
        this.countdown = new BukkitRunnable()
        {
        public void run()
        {
        if (gameTime != -1) {
        if (gameTime != 0) {
        if (gameTime <= 60) {
         
           Score score = o.getScore(ChatColor.AQUA + "Time: " + gameTime);
           score.setScore(7);
         
           Score devS = o.getScore(ChatColor.AQUA + "Devsscore: " + devscore);
            devS.setScore(6);
           
            Score bugsS = o.getScore(ChatColor.AQUA + "Bugsscore: " + buggscore);
            bugsS.setScore(5);
           
            Score neutral = o.getScore(ChatColor.AQUA + "Neutral: " + general);
            neutral.setScore(4);
           
            Score point1 = o.getScore(ChatColor.AQUA + "Point 1: " + Capture1);
            point1.setScore(3);
           
            Score point2 = o.getScore(ChatColor.AQUA + "Point 2: " + Capture2);
            point2.setScore(2);
           
            Score point3 = o.getScore(ChatColor.AQUA + "Point 3: " + Capture3);
            point3.setScore(1);
        } else {
           Score score = o.getScore(ChatColor.AQUA + "Time: " + gameTime);
           score.setScore(7);
         
        Score devS = o.getScore(ChatColor.AQUA + "Devsscore: " + devscore);
          devS.setScore(6);
         
          Score bugsS = o.getScore(ChatColor.AQUA + "Bugsscore: " + buggscore);
          bugsS.setScore(5);
         
          Score neutral = o.getScore(ChatColor.AQUA + "Neutral: " + general);
          neutral.setScore(4);
         
          Score point1 = o.getScore(ChatColor.AQUA + "Point 1: " + Capture1);
          point1.setScore(3);
         
          Score point2 = o.getScore(ChatColor.AQUA + "Point 2: " + Capture2);
          point2.setScore(2);
         
          Score point3 = o.getScore(ChatColor.AQUA + "Point 3: " + Capture3);
          point3.setScore(1);
        }
        gameTime -= 1;
        } else {
        sendMessage(Main.this.DB + "The buggs has won the game");
        End();
        countdown.cancel();
        }
        }
        }
        };
        this.countdown.runTaskTimer(this, 20L, 20L);
        }
    
     
  2. Offline

    teej107

    @NoSpanMan You need to remove the scoreboard entry with the old value since the entry with the new value is a completely different String.
     
  3. Offline

    NoSpanMan

    So every second remove and add?
     
  4. Offline

    teej107

    @NoSpanMan yes, remove the old entry, add the new entry
     
  5. Offline

    NoSpanMan

    I have made this but now i never see the scoreboard.
    Code:
      public void startTime()
        {
        this.countdown = new BukkitRunnable()
        {
        public void run()
        {
        if (gameTime != -1) {
        if (gameTime != 0) {
        if (gameTime <= 60) {
          
           Score score = o.getScore(ChatColor.AQUA + "Time: " + gameTime);
           score.setScore(7);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Time: " + gameTime);
          
           Score devS = o.getScore(ChatColor.AQUA + "Devsscore: " + devscore);
            devS.setScore(6);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Devsscore: " + devscore);
            
            Score bugsS = o.getScore(ChatColor.AQUA + "Bugsscore: " + buggscore);
            bugsS.setScore(5);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Bugsscore: " + buggscore);
            
            Score neutral = o.getScore(ChatColor.AQUA + "Neutral: " + general);
            neutral.setScore(4);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Neutral: " + general);
            
            Score point1 = o.getScore(ChatColor.AQUA + "Point 1: " + Capture1);
            point1.setScore(3);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Point 1: " + Capture1);
            
            Score point2 = o.getScore(ChatColor.AQUA + "Point 2: " + Capture2);
            point2.setScore(2);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Point 2: " + Capture2);
            
            Score point3 = o.getScore(ChatColor.AQUA + "Point 3: " + Capture3);
            point3.setScore(1);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Point 3: " + Capture3);
           
        } else {
           Score score = o.getScore(ChatColor.AQUA + "Time: " + gameTime);
           score.setScore(7);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Time: " + gameTime);
          
           Score devS = o.getScore(ChatColor.AQUA + "Devsscore: " + devscore);
            devS.setScore(6);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Devsscore: " + devscore);
            
            Score bugsS = o.getScore(ChatColor.AQUA + "Bugsscore: " + buggscore);
            bugsS.setScore(5);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Bugsscore: " + buggscore);
            
            Score neutral = o.getScore(ChatColor.AQUA + "Neutral: " + general);
            neutral.setScore(4);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Neutral: " + general);
            
            Score point1 = o.getScore(ChatColor.AQUA + "Point 1: " + Capture1);
            point1.setScore(3);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Point 1: " + Capture1);
            
            Score point2 = o.getScore(ChatColor.AQUA + "Point 2: " + Capture2);
            point2.setScore(2);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Point 2: " + Capture2);
            
            Score point3 = o.getScore(ChatColor.AQUA + "Point 3: " + Capture3);
            point3.setScore(1);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Point 3: " + Capture3);
            
    
        }
    
        
        gameTime -= 1;
        } else {
        sendMessage(Main.this.DB + "The buggs has won the game");
        End();
        countdown.cancel();
        }
        }
        }
        };
        this.countdown.runTaskTimer(this, 20L, 20L);
        }
    
     
  6. Offline

    teej107

  7. Offline

    mcdorli

    1.: Looks like you're a C# developer
    Code:
    public void startTime()
        {
    Put the braces in the same line, as the method declaration, this is the coding "rule".
    2.: ???
    Code:
    Main.this.DB
    
    What is this? You have a static field called this in your Main class, wich somehow has a field called DB? Or you simply don't know, how static access works.
    3.: You're violating D.R.Y.
    Code:
    Score score = o.getScore(ChatColor.AQUA + "Time: " + gameTime);
           score.setScore(7);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Time: " + gameTime);
         
           Score devS = o.getScore(ChatColor.AQUA + "Devsscore: " + devscore);
            devS.setScore(6);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Devsscore: " + devscore);
           
            Score bugsS = o.getScore(ChatColor.AQUA + "Bugsscore: " + buggscore);
            bugsS.setScore(5);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Bugsscore: " + buggscore);
           
            Score neutral = o.getScore(ChatColor.AQUA + "Neutral: " + general);
            neutral.setScore(4);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Neutral: " + general);
           
            Score point1 = o.getScore(ChatColor.AQUA + "Point 1: " + Capture1);
            point1.setScore(3);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Point 1: " + Capture1);
           
            Score point2 = o.getScore(ChatColor.AQUA + "Point 2: " + Capture2);
            point2.setScore(2);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Point 2: " + Capture2);
           
            Score point3 = o.getScore(ChatColor.AQUA + "Point 3: " + Capture3);
            point3.setScore(1);
            o.getScoreboard().resetScores(ChatColor.AQUA + "Point 3: " + Capture3);
    
    I'm certain this can be solved with 10~ lines
    4.:
    Code:
    if (gameTime != -1) {
        if (gameTime != 0) {
            if (gameTime <= 60) {
    
    Why? Why not just
    Code:
    if (gameTime != -1 && gameTime != 0 && gameTime <= 60) {
    
    ?
    5.: A little tip, this
    Code:
    gameTime -= 1;
    
    can be solved by using gameTime--;
    6.: Naming conventions
    Code:
    End();
    
    7.: It's really hard to read your code with a formatting like this. Press Ctrl+Shift+F in eclipse or Ctrl+Alt+L in IntelliJ
     
    Zombie_Striker likes this.
  8. Offline

    NoSpanMan

    Thanks next time i will look at it! But im still looking for the solution and im really doing and trying to fix it!
     
    Last edited: Nov 24, 2015
Thread Status:
Not open for further replies.

Share This Page