From 525d31c2b2328f91f9bef75110e0e5a8e80072a3 Mon Sep 17 00:00:00 2001 From: drtshock Date: Wed, 15 Oct 2014 16:21:27 -0500 Subject: [PATCH] Be friendly to other plugins that show scoreboards. Adds #74. --- .../factions/scoreboards/FInfoBoard.java | 4 +++- .../scoreboards/tasks/ExpirationTask.java | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FInfoBoard.java b/src/main/java/com/massivecraft/factions/scoreboards/FInfoBoard.java index 3fa668ee..39a16a43 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/FInfoBoard.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/FInfoBoard.java @@ -10,6 +10,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Score; +import org.bukkit.scoreboard.Scoreboard; import java.util.List; import java.util.logging.Level; @@ -20,12 +21,13 @@ public class FInfoBoard extends FScoreboard { public FInfoBoard(Player player, Faction faction, boolean timed) { this.faction = faction; + Scoreboard former = player.getScoreboard(); scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); setup(player); apply(player); 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. } } diff --git a/src/main/java/com/massivecraft/factions/scoreboards/tasks/ExpirationTask.java b/src/main/java/com/massivecraft/factions/scoreboards/tasks/ExpirationTask.java index 46511073..90085a24 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/tasks/ExpirationTask.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/tasks/ExpirationTask.java @@ -12,12 +12,19 @@ public class ExpirationTask extends BukkitRunnable { private String name; private Scoreboard board; + private Scoreboard former; public ExpirationTask(String name, Scoreboard scoreboard) { this.board = scoreboard; this.name = name; } + public ExpirationTask(String name, Scoreboard scoreboard, Scoreboard former) { + this.board = scoreboard; + this.name = name; + this.former = former; + } + @Override public void run() { Player player = Bukkit.getPlayer(name); @@ -25,8 +32,12 @@ public class ExpirationTask extends BukkitRunnable { return; } - if (player.getScoreboard().equals(board)) { // Incase someone else changed the board. - player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()); + 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()); + } } } }