mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-27 20:59:16 +01:00
Be friendly to other plugins that show scoreboards. Adds #74.
This commit is contained in:
parent
4f3310d88f
commit
525d31c2b2
@ -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.
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user