Use FPlayer to store board toggle instead of separate file.

Honestly not sure why we ever did it like this in the first place.
This commit is contained in:
drtshock 2015-05-18 14:32:12 -05:00
parent 7a2dcca067
commit f69f1cc025
6 changed files with 25 additions and 104 deletions

View File

@ -74,6 +74,10 @@ public interface FPlayer extends EconomyParticipator {
public boolean isSpyingChat(); public boolean isSpyingChat();
public boolean showScoreboard();
public void setShowScoreboard(boolean show);
// FIELD: account // FIELD: account
public String getAccountId(); public String getAccountId();
@ -193,15 +197,6 @@ public interface FPlayer extends EconomyParticipator {
public void sendFactionHereMessage(Faction from); 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 // Actions
// ------------------------------- // -------------------------------

View File

@ -147,7 +147,6 @@ public class P extends MPlugin {
AutoLeaveTask = null; AutoLeaveTask = null;
} }
cmdBase.cmdSB.save();
super.onDisable(); super.onDisable();
} }

View File

@ -1,110 +1,28 @@
package com.massivecraft.factions.cmd; 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.scoreboards.FScoreboard;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; 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 { public class CmdSB extends FCommand {
private YamlConfiguration yml;
private File file;
public CmdSB() { public CmdSB() {
this.aliases.add("sb"); this.aliases.add("sb");
this.permission = Permission.SCOREBOARD.node; this.permission = Permission.SCOREBOARD.node;
this.senderMustBePlayer = true; 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 @Override
public void perform() { public void perform() {
boolean toggle = toggle(me.getPlayer().getUniqueId()); boolean toggleTo = !fme.showScoreboard();
FScoreboard board = FScoreboard.get(fme); FScoreboard board = FScoreboard.get(fme);
if (board == null) { if (board == null) {
me.sendMessage(TL.COMMAND_TOGGLESB_DISABLED.toString()); me.sendMessage(TL.COMMAND_TOGGLESB_DISABLED.toString());
} else { } else {
me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggle))); me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggleTo)));
board.setSidebarVisibility(toggle); board.setSidebarVisibility(toggleTo);
} }
} fme.setShowScoreboard(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);
} }
@Override @Override

View File

@ -72,7 +72,7 @@ public class FactionsPlayerListener implements Listener {
if (P.p.getConfig().getBoolean("scoreboard.default-enabled", false)) { if (P.p.getConfig().getBoolean("scoreboard.default-enabled", false)) {
FScoreboard.init(me); FScoreboard.init(me);
FScoreboard.get(me).setDefaultSidebar(new FDefaultSidebar(), P.p.getConfig().getInt("default-update-interval", 20)); 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(); Faction myFaction = me.getFaction();

View File

@ -93,6 +93,7 @@ public abstract class MemoryFPlayer implements FPlayer {
protected transient boolean loginPvpDisabled; protected transient boolean loginPvpDisabled;
protected boolean spyingChat = false; protected boolean spyingChat = false;
protected boolean showScoreboard;
public Faction getFaction() { public Faction getFaction() {
if (this.factionId == null) { if (this.factionId == null) {
@ -238,6 +239,7 @@ public abstract class MemoryFPlayer implements FPlayer {
this.autoWarZoneEnabled = false; this.autoWarZoneEnabled = false;
this.loginPvpDisabled = Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0; this.loginPvpDisabled = Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0;
this.powerBoost = 0.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)) { if (!Conf.newPlayerStartingFactionID.equals("0") && Factions.getInstance().isValidFactionId(Conf.newPlayerStartingFactionID)) {
this.factionId = Conf.newPlayerStartingFactionID; this.factionId = Conf.newPlayerStartingFactionID;
@ -261,6 +263,7 @@ public abstract class MemoryFPlayer implements FPlayer {
this.spyingChat = other.spyingChat; this.spyingChat = other.spyingChat;
this.lastStoodAt = other.lastStoodAt; this.lastStoodAt = other.lastStoodAt;
this.isAdminBypassing = other.isAdminBypassing; this.isAdminBypassing = other.isAdminBypassing;
this.showScoreboard = P.p.getConfig().getBoolean("scoreboard.default-enabled", false);
} }
public void resetFactionData(boolean doSpoutUpdate) { public void resetFactionData(boolean doSpoutUpdate) {
@ -562,7 +565,7 @@ public abstract class MemoryFPlayer implements FPlayer {
public void sendFactionHereMessage(Faction from) { public void sendFactionHereMessage(Faction from) {
Faction toShow = Board.getInstance().getFactionAt(getLastStoodAt()); Faction toShow = Board.getInstance().getFactionAt(getLastStoodAt());
boolean showChat = true; boolean showChat = true;
if (shouldShowScoreboard(toShow)) { if (showInfoBoard(toShow)) {
FScoreboard.get(this).setTemporarySidebar(new FInfoSidebar(toShow)); FScoreboard.get(this).setTemporarySidebar(new FInfoSidebar(toShow));
showChat = P.p.getConfig().getBoolean("scoreboard.also-send-chat", true); 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. * @return true if should show, otherwise false.
*/ */
public boolean shouldShowScoreboard(Faction toShow) { public boolean showInfoBoard(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; 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;
} }
// ------------------------------- // -------------------------------

View File

@ -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.