Be friendly to other plugins that show scoreboards. Adds #74.

This commit is contained in:
drtshock 2014-10-15 16:21:27 -05:00
parent 4f3310d88f
commit 525d31c2b2
2 changed files with 16 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Score; import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@ -20,12 +21,13 @@ public class FInfoBoard extends FScoreboard {
public FInfoBoard(Player player, Faction faction, boolean timed) { public FInfoBoard(Player player, Faction faction, boolean timed) {
this.faction = faction; this.faction = faction;
Scoreboard former = player.getScoreboard();
scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
setup(player); setup(player);
apply(player); apply(player);
if (timed) { if (timed) {
new ExpirationTask(player.getName(), scoreboard).runTaskLater(P.p, P.p.getConfig().getInt("scoreboard.expiration", 7) * 20L); // remove after 10 seconds. new ExpirationTask(player.getName(), scoreboard, former).runTaskLater(P.p, P.p.getConfig().getInt("scoreboard.expiration", 7) * 20L); // remove after 10 seconds.
} }
} }

View File

@ -12,12 +12,19 @@ public class ExpirationTask extends BukkitRunnable {
private String name; private String name;
private Scoreboard board; private Scoreboard board;
private Scoreboard former;
public ExpirationTask(String name, Scoreboard scoreboard) { public ExpirationTask(String name, Scoreboard scoreboard) {
this.board = scoreboard; this.board = scoreboard;
this.name = name; this.name = name;
} }
public ExpirationTask(String name, Scoreboard scoreboard, Scoreboard former) {
this.board = scoreboard;
this.name = name;
this.former = former;
}
@Override @Override
public void run() { public void run() {
Player player = Bukkit.getPlayer(name); Player player = Bukkit.getPlayer(name);
@ -25,8 +32,12 @@ public class ExpirationTask extends BukkitRunnable {
return; return;
} }
if (player.getScoreboard().equals(board)) { // Incase someone else changed the board. if (player.getScoreboard().equals(board)) { // In case someone else changed the board.
if(former != null) {
player.setScoreboard(former); // restore their old scoreboard
} else {
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()); player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
} }
} }
}
} }