1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +01:00

Properly return to previous scoreboard

This commit is contained in:
Zrips 2017-06-22 15:17:34 +03:00
parent e20d470712
commit 00819d8eed
4 changed files with 73 additions and 19 deletions

View File

@ -65,11 +65,11 @@ public class gtop implements Cmd {
} }
} else { } else {
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); Jobs.getScboard().addNew(player);
Scoreboard board = player.getScoreboard();
ScoreboardManager manager = Bukkit.getScoreboardManager(); Objective objective = board.getObjective("JobsTopPlayers");
Scoreboard board = manager.getNewScoreboard(); if (objective == null)
Objective objective = board.registerNewObjective("JobsTopPlayers", "dummy"); objective = board.registerNewObjective("JobsTopPlayers", "dummy");
objective.setDisplaySlot(DisplaySlot.SIDEBAR); objective.setDisplaySlot(DisplaySlot.SIDEBAR);
objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.gtopline")); objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.gtopline"));
int i = page * 15 - 15; int i = page * 15 - 15;
@ -83,8 +83,6 @@ public class gtop implements Cmd {
} }
player.setScoreboard(board); player.setScoreboard(board);
Jobs.getScboard().addNew(player);
int prev = page < 2 ? 1 : page - 1; int prev = page < 2 ? 1 : page - 1;
int next = page + 1; int next = page + 1;

View File

@ -78,12 +78,11 @@ public class top implements Cmd {
One.getExp())); One.getExp()));
} }
} else { } else {
Jobs.getScboard().addNew(player);
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); Scoreboard board = player.getScoreboard();
Objective objective = board.getObjective("JobsTopPlayers");
ScoreboardManager manager = Bukkit.getScoreboardManager(); if (objective == null)
Scoreboard board = manager.getNewScoreboard(); objective = board.registerNewObjective("JobsTopPlayers", "dummy");
Objective objective = board.registerNewObjective("JobsTopPlayers", "dummy");
objective.setDisplaySlot(DisplaySlot.SIDEBAR); objective.setDisplaySlot(DisplaySlot.SIDEBAR);
objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", jobName)); objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", jobName));
int i = start; int i = start;
@ -99,7 +98,6 @@ public class top implements Cmd {
} }
player.setScoreboard(board); player.setScoreboard(board);
Jobs.getScboard().addNew(player);
int from = start; int from = start;
if (start >= 15) if (start >= 15)

View File

@ -2,17 +2,21 @@ package com.gamingmesh.jobs.config;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.ScoreboardInfo;
public class ScboardManager { public class ScboardManager {
private ConcurrentHashMap<String, Long> timerMap = new ConcurrentHashMap<String, Long>(); private ConcurrentHashMap<UUID, ScoreboardInfo> timerMap = new ConcurrentHashMap<UUID, ScoreboardInfo>();
private Jobs plugin; private Jobs plugin;
public ScboardManager(Jobs plugin) { public ScboardManager(Jobs plugin) {
@ -20,14 +24,19 @@ public class ScboardManager {
} }
private void RunScheduler() { private void RunScheduler() {
Iterator<Entry<String, Long>> MeinMapIter = timerMap.entrySet().iterator(); Iterator<Entry<UUID, ScoreboardInfo>> MeinMapIter = timerMap.entrySet().iterator();
while (MeinMapIter.hasNext()) { 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()); Player player = Bukkit.getPlayer(Map.getKey());
if (player != null) { if (player != null) {
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); 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()); timerMap.remove(Map.getKey());
} }
@ -45,7 +54,8 @@ public class ScboardManager {
} }
public void addNew(Player player) { 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(); RunScheduler();
} }

View File

@ -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;
}
}