From 2fc17c62b52a54ef588f3357d6d3c1d1c819027d Mon Sep 17 00:00:00 2001 From: drtshock Date: Wed, 15 Oct 2014 15:29:04 -0500 Subject: [PATCH] Properly persist scoreboard toggles. Fixes issue #61 --- .../com/massivecraft/factions/cmd/CmdSB.java | 28 +++++++++++++------ src/main/resources/playerBoardToggle.yml | 3 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSB.java b/src/main/java/com/massivecraft/factions/cmd/CmdSB.java index 73ace79b..195e202a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSB.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSB.java @@ -13,7 +13,7 @@ import java.util.UUID; public class CmdSB extends FCommand { - private YamlConfiguration settings; + private YamlConfiguration yml; private File file; public CmdSB() { @@ -31,13 +31,12 @@ public class CmdSB extends FCommand { } } - settings = YamlConfiguration.loadConfiguration(file); + yml = YamlConfiguration.loadConfiguration(file); } @Override public void perform() { - boolean toggle = toggle(me.getPlayer().getUniqueId()); - me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggle))); + me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggle(me.getPlayer().getUniqueId())))); } /** @@ -48,12 +47,12 @@ public class CmdSB extends FCommand { * @return - true if now set to seeing scoreboards, otherwise false. */ public boolean toggle(UUID uuid) { - if (settings.getStringList("off").contains(uuid.toString())) { - settings.getStringList("off").remove(uuid.toString()); + if(!yml.getBoolean(uuid.toString(), false)) { // check if it's false, if never been toggled, default to false. + yml.set(uuid.toString(), true); save(); return true; } else { - settings.getStringList("off").add(uuid.toString()); + yml.set(uuid.toString(), false); save(); return false; } @@ -61,7 +60,7 @@ public class CmdSB extends FCommand { public void save() { try { - settings.save(file); + yml.save(file); } catch (IOException e) { e.printStackTrace(); } @@ -86,6 +85,17 @@ public class CmdSB extends FCommand { * @return - true if should show, otherwise false. */ public boolean showBoard(Player player) { - return !settings.getStringList("off").contains(player.getUniqueId().toString()); + 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(), false); } } diff --git a/src/main/resources/playerBoardToggle.yml b/src/main/resources/playerBoardToggle.yml index 06efeac0..841087f6 100644 --- a/src/main/resources/playerBoardToggle.yml +++ b/src/main/resources/playerBoardToggle.yml @@ -1,5 +1,4 @@ # 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 -off: - - someuuidhere \ No newline at end of file +# These comments should be erased but I'll have them here anyway because why not. \ No newline at end of file