From e20995464e09bd23e056249cc09c1a52777aff97 Mon Sep 17 00:00:00 2001 From: drtshock Date: Wed, 15 Oct 2014 20:58:37 -0500 Subject: [PATCH] Toggling of scoreboards now affects the default board. --- src/main/java/com/massivecraft/factions/FPlayer.java | 11 +++++++++++ .../java/com/massivecraft/factions/cmd/CmdSB.java | 11 ++++++++++- .../factions/listeners/FactionsPlayerListener.java | 6 ++++-- .../factions/scoreboards/FDefaultBoard.java | 6 +++++- .../massivecraft/factions/scoreboards/FInfoBoard.java | 4 ++++ .../factions/scoreboards/FScoreboard.java | 2 ++ 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/FPlayer.java b/src/main/java/com/massivecraft/factions/FPlayer.java index a506daa1..a7790dc1 100644 --- a/src/main/java/com/massivecraft/factions/FPlayer.java +++ b/src/main/java/com/massivecraft/factions/FPlayer.java @@ -7,6 +7,7 @@ import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.scoreboards.FInfoBoard; +import com.massivecraft.factions.scoreboards.FScoreboard; import com.massivecraft.factions.struct.ChatMode; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; @@ -120,6 +121,16 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator { } } + public FScoreboard activeBoard; + + public FScoreboard getActiveBoard() { + return this.activeBoard; + } + + public void setActiveBoard(FScoreboard board) { + this.activeBoard = board; + } + // FIELD: autoSafeZoneEnabled private transient boolean autoSafeZoneEnabled; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSB.java b/src/main/java/com/massivecraft/factions/cmd/CmdSB.java index 195e202a..35f151b9 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSB.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSB.java @@ -2,6 +2,8 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.P; +import com.massivecraft.factions.scoreboards.FDefaultBoard; +import com.massivecraft.factions.scoreboards.FScoreboard; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.configuration.file.YamlConfiguration; @@ -36,7 +38,14 @@ public class CmdSB extends FCommand { @Override public void perform() { - me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggle(me.getPlayer().getUniqueId())))); + boolean toggle = toggle(me.getPlayer().getUniqueId()); + if(!toggle && fme.getActiveBoard() != null) { + fme.getActiveBoard().cancel(); + } else if(toggle && P.p.getConfig().getBoolean("scoreboards.default-enabled", false)){ + FScoreboard board = new FDefaultBoard(fme); + fme.setActiveBoard(board); + } + me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggle))); } /** diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index ce27bb53..936d55c6 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.listeners; import com.massivecraft.factions.*; import com.massivecraft.factions.scoreboards.FDefaultBoard; +import com.massivecraft.factions.scoreboards.FScoreboard; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; @@ -44,12 +45,13 @@ public class FactionsPlayerListener implements Listener { // Store player's current FLocation and notify them where they are me.setLastStoodAt(new FLocation(event.getPlayer().getLocation())); - if (P.p.getConfig().getBoolean("scoreboard.default-enabled", false)) { + if (P.p.getConfig().getBoolean("scoreboard.default-enabled", false) && P.p.cmdBase.cmdSB.showBoard(me)) { Bukkit.getScheduler().runTaskLater(P.p, new Runnable() { // I think we still have to delay this a few seconds. @Override public void run() { if (me.getPlayer().isOnline()) { // In case people are quickly joining and quitting. - new FDefaultBoard(me); + FScoreboard board = new FDefaultBoard(me); + me.setActiveBoard(board); } } }, 20L); diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FDefaultBoard.java b/src/main/java/com/massivecraft/factions/scoreboards/FDefaultBoard.java index 1bb97150..f3f7f477 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/FDefaultBoard.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/FDefaultBoard.java @@ -47,7 +47,7 @@ public class FDefaultBoard implements FScoreboard { public void update(Objective buffer) { if(fPlayer.getPlayer() == null || !fPlayer.getPlayer().isOnline()) { - Bukkit.getScheduler().cancelTask(taskId); + cancel(); return; } buffer.setDisplayName(ChatColor.translateAlternateColorCodes('&', P.p.getConfig().getString("scoreboard.default-title", "i love drt"))); @@ -89,6 +89,10 @@ public class FDefaultBoard implements FScoreboard { return ChatColor.translateAlternateColorCodes('&', s); } + public void cancel() { + Bukkit.getScheduler().cancelTask(taskId); + } + public Scoreboard getScoreboard() { return this.scoreboard; } diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FInfoBoard.java b/src/main/java/com/massivecraft/factions/scoreboards/FInfoBoard.java index 5a4e4a9e..2a2e9995 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/FInfoBoard.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/FInfoBoard.java @@ -88,6 +88,10 @@ public class FInfoBoard implements FScoreboard { } } + public void cancel() { + + } + public Scoreboard getScoreboard() { return this.scoreboard; } diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java b/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java index 84b1126d..05b915e5 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java @@ -15,4 +15,6 @@ public interface FScoreboard { public void setup(); public Scoreboard getScoreboard(); + + public void cancel(); }