Properly persist scoreboard toggles. Fixes issue #61

This commit is contained in:
drtshock 2014-10-15 15:29:04 -05:00
parent 9baf297ff7
commit 2fc17c62b5
2 changed files with 20 additions and 11 deletions

View File

@ -13,7 +13,7 @@ import java.util.UUID;
public class CmdSB extends FCommand { public class CmdSB extends FCommand {
private YamlConfiguration settings; private YamlConfiguration yml;
private File file; private File file;
public CmdSB() { public CmdSB() {
@ -31,13 +31,12 @@ public class CmdSB extends FCommand {
} }
} }
settings = YamlConfiguration.loadConfiguration(file); yml = YamlConfiguration.loadConfiguration(file);
} }
@Override @Override
public void perform() { public void perform() {
boolean toggle = toggle(me.getPlayer().getUniqueId()); me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggle(me.getPlayer().getUniqueId()))));
me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggle)));
} }
/** /**
@ -48,12 +47,12 @@ public class CmdSB extends FCommand {
* @return - true if now set to seeing scoreboards, otherwise false. * @return - true if now set to seeing scoreboards, otherwise false.
*/ */
public boolean toggle(UUID uuid) { public boolean toggle(UUID uuid) {
if (settings.getStringList("off").contains(uuid.toString())) { if(!yml.getBoolean(uuid.toString(), false)) { // check if it's false, if never been toggled, default to false.
settings.getStringList("off").remove(uuid.toString()); yml.set(uuid.toString(), true);
save(); save();
return true; return true;
} else { } else {
settings.getStringList("off").add(uuid.toString()); yml.set(uuid.toString(), false);
save(); save();
return false; return false;
} }
@ -61,7 +60,7 @@ public class CmdSB extends FCommand {
public void save() { public void save() {
try { try {
settings.save(file); yml.save(file);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -86,6 +85,17 @@ public class CmdSB extends FCommand {
* @return - true if should show, otherwise false. * @return - true if should show, otherwise false.
*/ */
public boolean showBoard(Player player) { 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);
} }
} }

View File

@ -1,5 +1,4 @@
# This file is handled via the plugin. # 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. # 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 # It can be toggled with /f sb
off: # These comments should be erased but I'll have them here anyway because why not.
- someuuidhere