mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-23 18:55:25 +01:00
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:
parent
7a2dcca067
commit
f69f1cc025
@ -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
|
||||
// -------------------------------
|
||||
|
@ -147,7 +147,6 @@ public class P extends MPlugin {
|
||||
AutoLeaveTask = null;
|
||||
}
|
||||
|
||||
cmdBase.cmdSB.save();
|
||||
super.onDisable();
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user