From f69f1cc02562d62f86dc5bb4e8d32dfd7a1efadf Mon Sep 17 00:00:00 2001 From: drtshock Date: Mon, 18 May 2015 14:32:12 -0500 Subject: [PATCH] Use FPlayer to store board toggle instead of separate file. Honestly not sure why we ever did it like this in the first place. --- .../com/massivecraft/factions/FPlayer.java | 13 +-- .../java/com/massivecraft/factions/P.java | 1 - .../com/massivecraft/factions/cmd/CmdSB.java | 90 +------------------ .../listeners/FactionsPlayerListener.java | 2 +- .../factions/zcore/persist/MemoryFPlayer.java | 19 +++- src/main/resources/playerBoardToggle.yml | 4 - 6 files changed, 25 insertions(+), 104 deletions(-) delete mode 100644 src/main/resources/playerBoardToggle.yml diff --git a/src/main/java/com/massivecraft/factions/FPlayer.java b/src/main/java/com/massivecraft/factions/FPlayer.java index e6277ffc..19c3100e 100644 --- a/src/main/java/com/massivecraft/factions/FPlayer.java +++ b/src/main/java/com/massivecraft/factions/FPlayer.java @@ -74,6 +74,10 @@ public interface FPlayer extends EconomyParticipator { public boolean isSpyingChat(); + public boolean showScoreboard(); + + public void setShowScoreboard(boolean show); + // FIELD: account public String getAccountId(); @@ -193,15 +197,6 @@ public interface FPlayer extends EconomyParticipator { public void sendFactionHereMessage(Faction from); - /** - * Check if the scoreboard should be shown. Simple method to be used by above method. - * - * @param toShow Faction to be shown. - * - * @return true if should show, otherwise false. - */ - public boolean shouldShowScoreboard(Faction toShow); - // ------------------------------- // Actions // ------------------------------- diff --git a/src/main/java/com/massivecraft/factions/P.java b/src/main/java/com/massivecraft/factions/P.java index 76f35605..b2f0df47 100644 --- a/src/main/java/com/massivecraft/factions/P.java +++ b/src/main/java/com/massivecraft/factions/P.java @@ -147,7 +147,6 @@ public class P extends MPlugin { AutoLeaveTask = null; } - cmdBase.cmdSB.save(); super.onDisable(); } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSB.java b/src/main/java/com/massivecraft/factions/cmd/CmdSB.java index 974f3556..d5395f4a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSB.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSB.java @@ -1,110 +1,28 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.P; 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; -import org.bukkit.entity.Player; - -import java.io.File; -import java.io.IOException; -import java.util.UUID; public class CmdSB extends FCommand { - private YamlConfiguration yml; - private File file; - public CmdSB() { this.aliases.add("sb"); this.permission = Permission.SCOREBOARD.node; this.senderMustBePlayer = true; - // Hope I didn't miss anything. - - file = new File(P.p.getDataFolder(), "playerBoardToggle.yml"); - if (!file.exists()) { - try { - file.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - yml = YamlConfiguration.loadConfiguration(file); } @Override public void perform() { - boolean toggle = toggle(me.getPlayer().getUniqueId()); + boolean toggleTo = !fme.showScoreboard(); FScoreboard board = FScoreboard.get(fme); if (board == null) { me.sendMessage(TL.COMMAND_TOGGLESB_DISABLED.toString()); } else { - me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggle))); - board.setSidebarVisibility(toggle); + me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggleTo))); + board.setSidebarVisibility(toggleTo); } - } - - /** - * Toggle a player seeing scoreboards or not. - * - * @param uuid - uuid of player. - * - * @return - true if now set to seeing scoreboards, otherwise false. - */ - public boolean toggle(UUID uuid) { - if (!yml.getBoolean(uuid.toString(), true)) { // check if it's false, if never been toggled, default to false. - yml.set(uuid.toString(), true); - save(); - return true; - } else { - yml.set(uuid.toString(), false); - save(); - return false; - } - } - - public void save() { - try { - yml.save(file); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Determines whether or not to show the player a scoreboard. - * - * @param player - FPlayer in question. - * - * @return - true if should show, otherwise false. - */ - public boolean showBoard(FPlayer player) { - return showBoard(player.getPlayer()); - } - - /** - * Determines whether or not to show the player a scoreboard. - * - * @param player - Player in question. - * - * @return - true if should show, otherwise false. - */ - public boolean showBoard(Player player) { - return showBoard(player.getUniqueId()); - } - - /** - * Determines whether or not to show the player a scoreboard. - * - * @param uuid - UUID of player in question. - * - * @return - true if should show, otherwise false. - */ - public boolean showBoard(UUID uuid) { - return yml.getBoolean(uuid.toString(), true); + fme.setShowScoreboard(toggleTo); } @Override diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 35a5d8bf..22633fee 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -72,7 +72,7 @@ public class FactionsPlayerListener implements Listener { if (P.p.getConfig().getBoolean("scoreboard.default-enabled", false)) { FScoreboard.init(me); FScoreboard.get(me).setDefaultSidebar(new FDefaultSidebar(), P.p.getConfig().getInt("default-update-interval", 20)); - FScoreboard.get(me).setSidebarVisibility(P.p.cmdBase.cmdSB.showBoard(me)); + FScoreboard.get(me).setSidebarVisibility(me.showScoreboard()); } Faction myFaction = me.getFaction(); diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java index 2ab8d0f2..7b18b28e 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -93,6 +93,7 @@ public abstract class MemoryFPlayer implements FPlayer { protected transient boolean loginPvpDisabled; protected boolean spyingChat = false; + protected boolean showScoreboard; public Faction getFaction() { if (this.factionId == null) { @@ -238,6 +239,7 @@ public abstract class MemoryFPlayer implements FPlayer { this.autoWarZoneEnabled = false; this.loginPvpDisabled = Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0; this.powerBoost = 0.0; + this.showScoreboard = P.p.getConfig().getBoolean("scoreboard.default-enabled", false); if (!Conf.newPlayerStartingFactionID.equals("0") && Factions.getInstance().isValidFactionId(Conf.newPlayerStartingFactionID)) { this.factionId = Conf.newPlayerStartingFactionID; @@ -261,6 +263,7 @@ public abstract class MemoryFPlayer implements FPlayer { this.spyingChat = other.spyingChat; this.lastStoodAt = other.lastStoodAt; this.isAdminBypassing = other.isAdminBypassing; + this.showScoreboard = P.p.getConfig().getBoolean("scoreboard.default-enabled", false); } public void resetFactionData(boolean doSpoutUpdate) { @@ -562,7 +565,7 @@ public abstract class MemoryFPlayer implements FPlayer { public void sendFactionHereMessage(Faction from) { Faction toShow = Board.getInstance().getFactionAt(getLastStoodAt()); boolean showChat = true; - if (shouldShowScoreboard(toShow)) { + if (showInfoBoard(toShow)) { FScoreboard.get(this).setTemporarySidebar(new FInfoSidebar(toShow)); showChat = P.p.getConfig().getBoolean("scoreboard.also-send-chat", true); } @@ -578,8 +581,18 @@ public abstract class MemoryFPlayer implements FPlayer { * * @return true if should show, otherwise false. */ - public boolean shouldShowScoreboard(Faction toShow) { - return !toShow.isWarZone() && !toShow.isNone() && !toShow.isSafeZone() && P.p.getConfig().contains("scoreboard.finfo") && P.p.getConfig().getBoolean("scoreboard.finfo-enabled", false) && P.p.cmdBase.cmdSB.showBoard(this) && FScoreboard.get(this) != null; + public boolean showInfoBoard(Faction toShow) { + return showScoreboard && !toShow.isWarZone() && !toShow.isNone() && !toShow.isSafeZone() && P.p.getConfig().contains("scoreboard.finfo") && P.p.getConfig().getBoolean("scoreboard.finfo-enabled", false) && FScoreboard.get(this) != null; + } + + @Override + public boolean showScoreboard() { + return this.showScoreboard; + } + + @Override + public void setShowScoreboard(boolean show) { + this.showScoreboard = show; } // ------------------------------- diff --git a/src/main/resources/playerBoardToggle.yml b/src/main/resources/playerBoardToggle.yml deleted file mode 100644 index 841087f6..00000000 --- a/src/main/resources/playerBoardToggle.yml +++ /dev/null @@ -1,4 +0,0 @@ -# This file is handled via the plugin. -# This is a list of players that DO NOT want to have ANY scoreboards shown to them via this plugin. -# It can be toggled with /f sb -# These comments should be erased but I'll have them here anyway because why not. \ No newline at end of file