2014-08-05 17:17:27 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.FPlayer;
|
|
|
|
import com.massivecraft.factions.P;
|
2014-10-16 03:58:37 +02:00
|
|
|
import com.massivecraft.factions.scoreboards.FDefaultBoard;
|
|
|
|
import com.massivecraft.factions.scoreboards.FScoreboard;
|
2014-08-05 17:17:27 +02:00
|
|
|
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 {
|
|
|
|
|
2014-10-15 22:29:04 +02:00
|
|
|
private YamlConfiguration yml;
|
2014-08-05 17:17:27 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-15 22:29:04 +02:00
|
|
|
yml = YamlConfiguration.loadConfiguration(file);
|
2014-08-05 17:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
2014-10-16 03:58:37 +02:00
|
|
|
boolean toggle = toggle(me.getPlayer().getUniqueId());
|
|
|
|
if(!toggle && fme.getActiveBoard() != null) {
|
|
|
|
fme.getActiveBoard().cancel();
|
2014-10-16 20:35:21 +02:00
|
|
|
} else if(toggle && P.p.getConfig().getBoolean("scoreboards.default-enabled", true)){
|
2014-10-16 03:58:37 +02:00
|
|
|
FScoreboard board = new FDefaultBoard(fme);
|
|
|
|
fme.setActiveBoard(board);
|
|
|
|
}
|
|
|
|
me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggle)));
|
2014-08-05 17:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2014-10-16 20:35:21 +02:00
|
|
|
if(!yml.getBoolean(uuid.toString(), true)) { // check if it's false, if never been toggled, default to false.
|
2014-10-15 22:29:04 +02:00
|
|
|
yml.set(uuid.toString(), true);
|
2014-08-05 17:17:27 +02:00
|
|
|
save();
|
|
|
|
return true;
|
|
|
|
} else {
|
2014-10-15 22:29:04 +02:00
|
|
|
yml.set(uuid.toString(), false);
|
2014-08-05 17:17:27 +02:00
|
|
|
save();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
try {
|
2014-10-15 22:29:04 +02:00
|
|
|
yml.save(file);
|
2014-08-05 17:17:27 +02:00
|
|
|
} 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) {
|
2014-10-15 22:29:04 +02:00
|
|
|
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) {
|
2014-10-16 20:35:21 +02:00
|
|
|
return yml.getBoolean(uuid.toString(), true);
|
2014-08-05 17:17:27 +02:00
|
|
|
}
|
|
|
|
}
|