Hey guy's, I'm here because I would like stop a coundown when I type /countpause. And if I type /countunpause, the countdown runing. one part of code: Code (Text): public void setMatchInfo(){ Objective obj = null; try{ obj = this.sb.getObjective(this.sbobjname); obj.setDisplaySlot(null); obj.unregister(); }catch(Exception e){ } if(pause){ obj.getScore(ChatColor.GOLD + "Episode: " + ChatColor.RED + getConfig().getInt("timer.ep")).setScore(5); obj.getScore(ChatColor.WHITE + Main.this.formatter.format(getConfig().getInt("timer.m")) + ChatColor.GRAY + ":" + ChatColor.WHITE + Main.this.formatter.format(getConfig().getInt("timer.s"))).setScore(1); obj = this.sb.getObjective(this.sbobjname); obj.setDisplaySlot(null); obj.unregister(); return; } Random r = new Random(); Main.this.sbobjname = ("WIJ" + r.nextInt(10000000)); obj = Main.this.sb.registerNewObjective(Main.this.sbobjname, "dummy"); obj = Main.this.sb.getObjective(Main.this.sbobjname); obj.setDisplayName(ChatColor.AQUA + "Minigame"); obj.setDisplaySlot(DisplaySlot.SIDEBAR); obj.getScore(ChatColor.GOLD + "Episode: " + ChatColor.RED + Main.this.episode).setScore(5); obj.getScore(ChatColor.AQUA + "Joueurs: " + ChatColor.RED + Bukkit.getOnlinePlayers().size()).setScore(4); obj.getScore(" ").setScore(2); obj.getScore(ChatColor.WHITE + Main.this.formatter.format(Main.this.minutesLeft) + ChatColor.GRAY + ":" + ChatColor.WHITE + Main.this.formatter.format(Main.this.secondsLeft)).setScore(1); if(pause){ obj.getScore(ChatColor.RED + "En pause !").setScore(0); }else{ Main.this.sb.resetScores(ChatColor.RED + "En pause !"); } } Thank's for your help ___ EDIT: Sorry for my bad English, I'm french :3
Maybe check if the scoreboard is 0 when its stopped then set the score on the scoreboard to something else. Something like this: Code (Text): if(TIMER == 0){ //Set the timer score to something else }else{ //Add the score for the timer here }
Ok, I try to code with a boolean, It's working but when the counter is in pause, the Scoreboard is invisible, why ?, it's the version of Spigot who did this ? Code (Text): private static boolean pause; public void setMatchInfo(){ Objective obj = null; try{ obj = this.sb.getObjective(this.sbobjname); obj.setDisplaySlot(null); obj.unregister(); }catch(Exception e){ } if(pause){ obj.getScore(ChatColor.GOLD + "Episode: " + ChatColor.RED + getConfig().getInt("timer.ep")).setScore(5); obj.getScore(ChatColor.WHITE + Main.this.formatter.format(getConfig().getInt("timer.m")) + ChatColor.GRAY + ":" + ChatColor.WHITE + Main.this.formatter.format(getConfig().getInt("timer.s"))).setScore(1); obj.getScore(ChatColor.RED + "In pause !").setScore(0); obj = this.sb.getObjective(this.sbobjname); obj.setDisplaySlot(null); obj.unregister(); return; }else{ Random r = new Random(); Main.this.sbobjname = ("WIJ" + r.nextInt(10000000)); obj = Main.this.sb.registerNewObjective(Main.this.sbobjname, "dummy"); obj = Main.this.sb.getObjective(Main.this.sbobjname); obj.setDisplayName(ChatColor.AQUA + "MiniGame"); obj.setDisplaySlot(DisplaySlot.SIDEBAR); obj.getScore(ChatColor.GOLD + "Episode: " + ChatColor.RED + Main.this.episode).setScore(5); obj.getScore(ChatColor.AQUA + "Players: " + ChatColor.RED + Bukkit.getOnlinePlayers().size()).setScore(4); obj.getScore(" ").setScore(2); obj.getScore(ChatColor.WHITE + Main.this.formatter.format(Main.this.minutesLeft) + ChatColor.GRAY + ":" + ChatColor.WHITE + Main.this.formatter.format(Main.this.secondsLeft)).setScore(1); } } if(args[0].equalsIgnoreCase("pause")){ for(Player pa : Bukkit.getOnlinePlayers()){ pa.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "MiniGame" + ChatColor.GRAY + "]" + ChatColor.RED + " Pause by: " + ChatColor.AQUA + p.getName()); p.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "MiniGame" + ChatColor.GRAY + "]" + ChatColor.RED + " You have set the pause"); getConfig().set("timer.m", Long.valueOf(this.minutesLeft)); getConfig().set("timer.s", Long.valueOf(this.secondsLeft)); getConfig().set("timer.ep", Long.valueOf(this.episode)); this.pause = Boolean.valueOf(true); } } if(args[0].equalsIgnoreCase("unpause")){ for(Player pa : Bukkit.getOnlinePlayers()){ pa.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "MiniGame" + ChatColor.GRAY + "]" + ChatColor.RED + " Ending of pause by: " + ChatColor.AQUA + p.getName()); p.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "MiniGame" + ChatColor.GRAY + "]" + ChatColor.RED + " You have set the ending of the pause"); this.pause = Boolean.valueOf(false); } }
I would make a class that implement Runnable and remove 1 from your int seconds and else (so its 0) do stuff.
Have you ever looked at your code? Or have you even written it? I don't think so. Else you would have noticed that you unregister your objective if(pause){... obj.setDisplaySlot(null); obj.unregister();
Yes, I have already fix that, but, when I type: /pause the SB show "PAUSED", but the time have change when I type: /unpause (I don't know if my sentence is correct :S)
That's how I would do it... make a TimerManager class and set the Timer. Example... Timer A is running Code (Text): public void methodNameHere(){ TimerManager.getTimer("TimerA").setTimerActive(false); } Then have a boolean that checks a hashmap every cycle that reads the current status of the Timer