mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-07 03:00:29 +01:00
Allow toggling scoreboards with /is scoreboard
This commit is contained in:
parent
dffd68e503
commit
62f05196c7
@ -89,6 +89,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
|
|||||||
new VisitCommand(),
|
new VisitCommand(),
|
||||||
new VisitorsCommand(),
|
new VisitorsCommand(),
|
||||||
new VoteCommand(),
|
new VoteCommand(),
|
||||||
|
new ScoreboardCommand(),
|
||||||
new WeatherCommand()
|
new WeatherCommand()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
package com.songoda.skyblock.command.commands.island;
|
||||||
|
|
||||||
|
import com.songoda.core.compatibility.CompatibleSound;
|
||||||
|
import com.songoda.skyblock.command.SubCommand;
|
||||||
|
import com.songoda.skyblock.config.FileManager.Config;
|
||||||
|
import com.songoda.skyblock.island.Island;
|
||||||
|
import com.songoda.skyblock.island.IslandManager;
|
||||||
|
import com.songoda.skyblock.island.IslandRole;
|
||||||
|
import com.songoda.skyblock.message.MessageManager;
|
||||||
|
import com.songoda.skyblock.permission.PermissionManager;
|
||||||
|
import com.songoda.skyblock.playerdata.PlayerData;
|
||||||
|
import com.songoda.skyblock.playerdata.PlayerDataManager;
|
||||||
|
import com.songoda.skyblock.scoreboard.ScoreboardManager;
|
||||||
|
import com.songoda.skyblock.sound.SoundManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class ScoreboardCommand extends SubCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCommandByPlayer(Player player, String[] args) {
|
||||||
|
MessageManager messageManager = skyblock.getMessageManager();
|
||||||
|
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
|
||||||
|
SoundManager soundManager = skyblock.getSoundManager();
|
||||||
|
ScoreboardManager scoreboardManager = skyblock.getScoreboardManager();
|
||||||
|
|
||||||
|
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||||
|
FileConfiguration configLoad = config.getFileConfiguration();
|
||||||
|
|
||||||
|
PlayerData playerData = playerDataManager.getPlayerData(player);
|
||||||
|
|
||||||
|
if (playerData == null) {
|
||||||
|
messageManager.sendMessage(player, configLoad.getString("Command.Scoreboard.Error.Message"));
|
||||||
|
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||||
|
} else if(!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"))
|
||||||
|
.getFileConfiguration().getBoolean("Island.Scoreboard.Enable", false)) {
|
||||||
|
messageManager.sendMessage(player, configLoad.getString("Command.Scoreboard.GlobalDisable.Message"));
|
||||||
|
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||||
|
}else if (playerData.isScoreboard()) {
|
||||||
|
playerData.setScoreboard(false);
|
||||||
|
scoreboardManager.removePlayer(player);
|
||||||
|
|
||||||
|
messageManager.sendMessage(player, configLoad.getString("Command.Scoreboard.Disabled.Message"));
|
||||||
|
soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F);
|
||||||
|
} else {
|
||||||
|
playerData.setScoreboard(true);
|
||||||
|
scoreboardManager.addPlayer(player);
|
||||||
|
|
||||||
|
messageManager.sendMessage(player, configLoad.getString("Command.Scoreboard.Enabled.Message"));
|
||||||
|
soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1.0F, 1.0F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCommandByConsole(ConsoleCommandSender sender, String[] args) {
|
||||||
|
sender.sendMessage("SkyBlock | Error: You must be a player to perform that command.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "scoreboard";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getInfoMessagePath() {
|
||||||
|
return "Command.Scoreboard.Info.Message";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getAliases() {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
}
|
@ -105,41 +105,7 @@ public class Join implements Listener {
|
|||||||
cooldownManager.addCooldownPlayer(CooldownType.Deletion, cooldownManager.loadCooldownPlayer(CooldownType.Deletion, player));
|
cooldownManager.addCooldownPlayer(CooldownType.Deletion, cooldownManager.loadCooldownPlayer(CooldownType.Deletion, player));
|
||||||
|
|
||||||
if (scoreboardManager != null) {
|
if (scoreboardManager != null) {
|
||||||
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
scoreboardManager.addPlayer(player);
|
||||||
Scoreboard scoreboard = new Scoreboard(skyblock, player);
|
|
||||||
Island island = islandManager.getIsland(player);
|
|
||||||
|
|
||||||
if (island != null) {
|
|
||||||
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(island.getOwnerUUID());
|
|
||||||
|
|
||||||
cooldownManager.addCooldownPlayer(CooldownType.Levelling, cooldownManager.loadCooldownPlayer(CooldownType.Levelling, offlinePlayer));
|
|
||||||
cooldownManager.addCooldownPlayer(CooldownType.Ownership, cooldownManager.loadCooldownPlayer(CooldownType.Ownership, offlinePlayer));
|
|
||||||
|
|
||||||
if (island.getRole(IslandRole.Member).size() == 0 && island.getRole(IslandRole.Operator).size() == 0) {
|
|
||||||
scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getFileConfiguration().getString("Scoreboard.Island.Solo.Displayname")));
|
|
||||||
|
|
||||||
if (islandManager.getVisitorsAtIsland(island).size() == 0) {
|
|
||||||
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Empty.Displaylines"));
|
|
||||||
} else {
|
|
||||||
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Occupied.Displaylines"));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getFileConfiguration().getString("Scoreboard.Island.Team.Displayname")));
|
|
||||||
|
|
||||||
if (islandManager.getVisitorsAtIsland(island).size() == 0) {
|
|
||||||
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Team.Empty.Displaylines"));
|
|
||||||
} else {
|
|
||||||
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Team.Occupied.Displaylines"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getFileConfiguration().getString("Scoreboard.Tutorial.Displayname")));
|
|
||||||
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Tutorial.Displaylines"));
|
|
||||||
}
|
|
||||||
|
|
||||||
scoreboard.run();
|
|
||||||
scoreboardManager.storeScoreboard(player, scoreboard);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Island island = islandManager.getIslandPlayerAt(player);
|
Island island = islandManager.getIslandPlayerAt(player);
|
||||||
|
@ -153,15 +153,22 @@ public class PlayerData {
|
|||||||
this.playTime = playTime;
|
this.playTime = playTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isScoreboard() {
|
||||||
|
return getConfig().getFileConfiguration().getBoolean("Scoreboard", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScoreboard(boolean scoreboard) {
|
||||||
|
getConfig().getFileConfiguration().set("Scoreboard", scoreboard);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isPreview() {
|
public boolean isPreview() {
|
||||||
return preview;
|
return preview;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreview(boolean preview) {
|
public void setPreview(boolean preview) {
|
||||||
this.preview = preview;
|
this.preview = preview;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getVisitTime() {
|
public int getVisitTime() {
|
||||||
return visitTime;
|
return visitTime;
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,17 @@ package com.songoda.skyblock.scoreboard;
|
|||||||
import com.songoda.skyblock.SkyBlock;
|
import com.songoda.skyblock.SkyBlock;
|
||||||
import com.songoda.skyblock.config.FileManager;
|
import com.songoda.skyblock.config.FileManager;
|
||||||
import com.songoda.skyblock.config.FileManager.Config;
|
import com.songoda.skyblock.config.FileManager.Config;
|
||||||
|
import com.songoda.skyblock.cooldown.CooldownManager;
|
||||||
|
import com.songoda.skyblock.cooldown.CooldownType;
|
||||||
import com.songoda.skyblock.island.Island;
|
import com.songoda.skyblock.island.Island;
|
||||||
import com.songoda.skyblock.island.IslandManager;
|
import com.songoda.skyblock.island.IslandManager;
|
||||||
import com.songoda.skyblock.island.IslandRole;
|
import com.songoda.skyblock.island.IslandRole;
|
||||||
|
import com.songoda.skyblock.playerdata.PlayerData;
|
||||||
|
import com.songoda.skyblock.playerdata.PlayerDataManager;
|
||||||
import com.songoda.skyblock.utils.version.NMSUtil;
|
import com.songoda.skyblock.utils.version.NMSUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.scoreboard.Objective;
|
import org.bukkit.scoreboard.Objective;
|
||||||
@ -23,6 +28,8 @@ public class ScoreboardManager extends BukkitRunnable {
|
|||||||
private final static int VERSION = NMSUtil.getVersionNumber();
|
private final static int VERSION = NMSUtil.getVersionNumber();
|
||||||
private final SkyBlock skyblock;
|
private final SkyBlock skyblock;
|
||||||
private final Map<UUID, Scoreboard> scoreboardStorage = new HashMap<>();
|
private final Map<UUID, Scoreboard> scoreboardStorage = new HashMap<>();
|
||||||
|
|
||||||
|
private final PlayerDataManager playerDataManager;
|
||||||
|
|
||||||
private int runTicks = 0;
|
private int runTicks = 0;
|
||||||
|
|
||||||
@ -31,6 +38,7 @@ public class ScoreboardManager extends BukkitRunnable {
|
|||||||
|
|
||||||
public ScoreboardManager(SkyBlock skyblock) {
|
public ScoreboardManager(SkyBlock skyblock) {
|
||||||
this.skyblock = skyblock;
|
this.skyblock = skyblock;
|
||||||
|
this.playerDataManager = skyblock.getPlayerDataManager();
|
||||||
this.runTaskTimer(skyblock, 20, 40);
|
this.runTaskTimer(skyblock, 20, 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,42 +103,45 @@ public class ScoreboardManager extends BukkitRunnable {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (Player player : players) {
|
for (Player player : players) {
|
||||||
|
|
||||||
final org.bukkit.scoreboard.Scoreboard playerBoard = player.getScoreboard();
|
PlayerData pd = playerDataManager.getPlayerData(player);
|
||||||
|
if(pd != null && pd.isScoreboard()){
|
||||||
for (Objective primaryObjective : objectives) {
|
final org.bukkit.scoreboard.Scoreboard playerBoard = player.getScoreboard();
|
||||||
|
|
||||||
Objective obj = playerBoard.getObjective(primaryObjective.getName());
|
for (Objective primaryObjective : objectives) {
|
||||||
|
|
||||||
if (obj == null)
|
Objective obj = playerBoard.getObjective(primaryObjective.getName());
|
||||||
obj = playerBoard.registerNewObjective(primaryObjective.getName(), primaryObjective.getCriteria());
|
|
||||||
|
if (obj == null)
|
||||||
obj.setDisplayName(primaryObjective.getDisplayName());
|
obj = playerBoard.registerNewObjective(primaryObjective.getName(), primaryObjective.getCriteria());
|
||||||
obj.setDisplaySlot(primaryObjective.getDisplaySlot());
|
|
||||||
if (VERSION > 12) obj.setRenderType(primaryObjective.getRenderType());
|
obj.setDisplayName(primaryObjective.getDisplayName());
|
||||||
}
|
obj.setDisplaySlot(primaryObjective.getDisplaySlot());
|
||||||
|
if (VERSION > 12) obj.setRenderType(primaryObjective.getRenderType());
|
||||||
for (Team primaryTeam : teams) {
|
|
||||||
|
|
||||||
Team obj = playerBoard.getTeam(primaryTeam.getName());
|
|
||||||
|
|
||||||
if (obj == null) obj = playerBoard.registerNewTeam(primaryTeam.getName());
|
|
||||||
|
|
||||||
obj.setAllowFriendlyFire(primaryTeam.allowFriendlyFire());
|
|
||||||
obj.setCanSeeFriendlyInvisibles(primaryTeam.canSeeFriendlyInvisibles());
|
|
||||||
if (VERSION > 11) obj.setColor(primaryTeam.getColor());
|
|
||||||
obj.setDisplayName(primaryTeam.getDisplayName());
|
|
||||||
obj.setNameTagVisibility(primaryTeam.getNameTagVisibility());
|
|
||||||
obj.setPrefix(primaryTeam.getPrefix());
|
|
||||||
obj.setSuffix(primaryTeam.getSuffix());
|
|
||||||
|
|
||||||
for (String primaryEntry : primaryTeam.getEntries()) {
|
|
||||||
obj.addEntry(primaryEntry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VERSION > 8) {
|
for (Team primaryTeam : teams) {
|
||||||
for (Option option : Option.values()) {
|
|
||||||
obj.setOption(option, primaryTeam.getOption(option));
|
Team obj = playerBoard.getTeam(primaryTeam.getName());
|
||||||
|
|
||||||
|
if (obj == null) obj = playerBoard.registerNewTeam(primaryTeam.getName());
|
||||||
|
|
||||||
|
obj.setAllowFriendlyFire(primaryTeam.allowFriendlyFire());
|
||||||
|
obj.setCanSeeFriendlyInvisibles(primaryTeam.canSeeFriendlyInvisibles());
|
||||||
|
if (VERSION > 11) obj.setColor(primaryTeam.getColor());
|
||||||
|
obj.setDisplayName(primaryTeam.getDisplayName());
|
||||||
|
obj.setNameTagVisibility(primaryTeam.getNameTagVisibility());
|
||||||
|
obj.setPrefix(primaryTeam.getPrefix());
|
||||||
|
obj.setSuffix(primaryTeam.getSuffix());
|
||||||
|
|
||||||
|
for (String primaryEntry : primaryTeam.getEntries()) {
|
||||||
|
obj.addEntry(primaryEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VERSION > 8) {
|
||||||
|
for (Option option : Option.values()) {
|
||||||
|
obj.setOption(option, primaryTeam.getOption(option));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,4 +222,55 @@ public class ScoreboardManager extends BukkitRunnable {
|
|||||||
public boolean hasScoreboard(Player player) {
|
public boolean hasScoreboard(Player player) {
|
||||||
return scoreboardStorage.containsKey(player.getUniqueId());
|
return scoreboardStorage.containsKey(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<UUID, Scoreboard> getScoreboardStorage() {
|
||||||
|
return this.scoreboardStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPlayer(Player player){
|
||||||
|
CooldownManager cooldownManager = skyblock.getCooldownManager();
|
||||||
|
FileManager fileManager = skyblock.getFileManager();
|
||||||
|
IslandManager islandManager = skyblock.getIslandManager();
|
||||||
|
|
||||||
|
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||||
|
Scoreboard scoreboard = new Scoreboard(skyblock, player);
|
||||||
|
Island island = islandManager.getIsland(player);
|
||||||
|
|
||||||
|
if (island != null) {
|
||||||
|
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(island.getOwnerUUID());
|
||||||
|
|
||||||
|
cooldownManager.addCooldownPlayer(CooldownType.Levelling, cooldownManager.loadCooldownPlayer(CooldownType.Levelling, offlinePlayer));
|
||||||
|
cooldownManager.addCooldownPlayer(CooldownType.Ownership, cooldownManager.loadCooldownPlayer(CooldownType.Ownership, offlinePlayer));
|
||||||
|
|
||||||
|
if (island.getRole(IslandRole.Member).size() == 0 && island.getRole(IslandRole.Operator).size() == 0) {
|
||||||
|
scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getFileConfiguration().getString("Scoreboard.Island.Solo.Displayname")));
|
||||||
|
|
||||||
|
if (islandManager.getVisitorsAtIsland(island).size() == 0) {
|
||||||
|
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Empty.Displaylines"));
|
||||||
|
} else {
|
||||||
|
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Occupied.Displaylines"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getFileConfiguration().getString("Scoreboard.Island.Team.Displayname")));
|
||||||
|
|
||||||
|
if (islandManager.getVisitorsAtIsland(island).size() == 0) {
|
||||||
|
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Team.Empty.Displaylines"));
|
||||||
|
} else {
|
||||||
|
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Team.Occupied.Displaylines"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getFileConfiguration().getString("Scoreboard.Tutorial.Displayname")));
|
||||||
|
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Tutorial.Displaylines"));
|
||||||
|
}
|
||||||
|
|
||||||
|
scoreboard.run();
|
||||||
|
this.storeScoreboard(player, scoreboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removePlayer(Player player){
|
||||||
|
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
|
||||||
|
this.scoreboardStorage.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
}
|
}
|
@ -7,6 +7,17 @@ ClassLocalization:
|
|||||||
Operator: 'Operator'
|
Operator: 'Operator'
|
||||||
Owner: 'Owner'
|
Owner: 'Owner'
|
||||||
Command:
|
Command:
|
||||||
|
Scoreboard:
|
||||||
|
Disabled:
|
||||||
|
Message: '&bSkyBlock &8| &aInfo&8: &eScoreboard disabled.'
|
||||||
|
Enabled:
|
||||||
|
Message: '&bSkyBlock &8| &aInfo&8: &eScoreboard enabled.'
|
||||||
|
Error:
|
||||||
|
Message: '&bSkyBlock &8| &cError&8: &eAn error occurred.'
|
||||||
|
GlobalDisable:
|
||||||
|
Message: '&bSkyBlock &8| &cError&8: &eScoreboard are globally disabled.'
|
||||||
|
Info:
|
||||||
|
Message: '&bSkyBlock &8| &aInfo&8: &eEnable or disabled the scoreboard.'
|
||||||
Island:
|
Island:
|
||||||
Bans:
|
Bans:
|
||||||
Owner:
|
Owner:
|
||||||
|
Loading…
Reference in New Issue
Block a user