mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-30 21:07:48 +01:00
Properly return to previous scoreboard
This commit is contained in:
parent
e20d470712
commit
00819d8eed
@ -65,11 +65,11 @@ public class gtop implements Cmd {
|
||||
}
|
||||
} else {
|
||||
|
||||
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
|
||||
|
||||
ScoreboardManager manager = Bukkit.getScoreboardManager();
|
||||
Scoreboard board = manager.getNewScoreboard();
|
||||
Objective objective = board.registerNewObjective("JobsTopPlayers", "dummy");
|
||||
Jobs.getScboard().addNew(player);
|
||||
Scoreboard board = player.getScoreboard();
|
||||
Objective objective = board.getObjective("JobsTopPlayers");
|
||||
if (objective == null)
|
||||
objective = board.registerNewObjective("JobsTopPlayers", "dummy");
|
||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.gtopline"));
|
||||
int i = page * 15 - 15;
|
||||
@ -83,8 +83,6 @@ public class gtop implements Cmd {
|
||||
}
|
||||
player.setScoreboard(board);
|
||||
|
||||
Jobs.getScboard().addNew(player);
|
||||
|
||||
int prev = page < 2 ? 1 : page - 1;
|
||||
int next = page + 1;
|
||||
|
||||
|
@ -78,12 +78,11 @@ public class top implements Cmd {
|
||||
One.getExp()));
|
||||
}
|
||||
} else {
|
||||
|
||||
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
|
||||
|
||||
ScoreboardManager manager = Bukkit.getScoreboardManager();
|
||||
Scoreboard board = manager.getNewScoreboard();
|
||||
Objective objective = board.registerNewObjective("JobsTopPlayers", "dummy");
|
||||
Jobs.getScboard().addNew(player);
|
||||
Scoreboard board = player.getScoreboard();
|
||||
Objective objective = board.getObjective("JobsTopPlayers");
|
||||
if (objective == null)
|
||||
objective = board.registerNewObjective("JobsTopPlayers", "dummy");
|
||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", jobName));
|
||||
int i = start;
|
||||
@ -99,7 +98,6 @@ public class top implements Cmd {
|
||||
}
|
||||
player.setScoreboard(board);
|
||||
|
||||
Jobs.getScboard().addNew(player);
|
||||
|
||||
int from = start;
|
||||
if (start >= 15)
|
||||
|
@ -2,17 +2,21 @@ package com.gamingmesh.jobs.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.container.ScoreboardInfo;
|
||||
|
||||
public class ScboardManager {
|
||||
|
||||
private ConcurrentHashMap<String, Long> timerMap = new ConcurrentHashMap<String, Long>();
|
||||
private ConcurrentHashMap<UUID, ScoreboardInfo> timerMap = new ConcurrentHashMap<UUID, ScoreboardInfo>();
|
||||
private Jobs plugin;
|
||||
|
||||
public ScboardManager(Jobs plugin) {
|
||||
@ -20,14 +24,19 @@ public class ScboardManager {
|
||||
}
|
||||
|
||||
private void RunScheduler() {
|
||||
Iterator<Entry<String, Long>> MeinMapIter = timerMap.entrySet().iterator();
|
||||
Iterator<Entry<UUID, ScoreboardInfo>> MeinMapIter = timerMap.entrySet().iterator();
|
||||
while (MeinMapIter.hasNext()) {
|
||||
Entry<String, Long> Map = MeinMapIter.next();
|
||||
Entry<UUID, ScoreboardInfo> Map = MeinMapIter.next();
|
||||
|
||||
if (System.currentTimeMillis() > Map.getValue() + (Jobs.getGCManager().ToplistInScoreboardInterval * 1000)) {
|
||||
if (System.currentTimeMillis() > Map.getValue().getTime() + (Jobs.getGCManager().ToplistInScoreboardInterval * 1000)) {
|
||||
Player player = Bukkit.getPlayer(Map.getKey());
|
||||
if (player != null) {
|
||||
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
|
||||
if (Map.getValue().getObj() != null) {
|
||||
Objective obj = player.getScoreboard().getObjective(Map.getValue().getObj().getName());
|
||||
if (obj != null)
|
||||
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
}
|
||||
}
|
||||
timerMap.remove(Map.getKey());
|
||||
}
|
||||
@ -45,7 +54,8 @@ public class ScboardManager {
|
||||
}
|
||||
|
||||
public void addNew(Player player) {
|
||||
timerMap.put(player.getName(), System.currentTimeMillis());
|
||||
Scoreboard scoreBoard = player.getScoreboard();
|
||||
timerMap.put(player.getUniqueId(), new ScoreboardInfo(scoreBoard, DisplaySlot.SIDEBAR));
|
||||
RunScheduler();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.gamingmesh.jobs.container;
|
||||
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
public class ScoreboardInfo {
|
||||
|
||||
private Scoreboard scoreBoard;
|
||||
private Objective obj;
|
||||
private Long time;
|
||||
|
||||
public ScoreboardInfo(Scoreboard scoreBoard, DisplaySlot slot) {
|
||||
this.scoreBoard = scoreBoard;
|
||||
|
||||
for (Objective one : this.scoreBoard.getObjectives()) {
|
||||
if (one.getDisplaySlot() == slot)
|
||||
obj = one;
|
||||
}
|
||||
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public Scoreboard getScoreBoard() {
|
||||
return scoreBoard;
|
||||
}
|
||||
|
||||
public void setScoreBoard(Scoreboard scoreBoard) {
|
||||
this.scoreBoard = scoreBoard;
|
||||
}
|
||||
|
||||
public Long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(Long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public Objective getObj() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public void setObj(Objective obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user