Merge branch 'development'

This commit is contained in:
Brianna 2020-04-18 10:00:34 -04:00
commit b0a64c23d9
4 changed files with 53 additions and 91 deletions

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.songoda</groupId>
<artifactId>skyblock</artifactId>
<version>2.2.8</version>
<version>2.2.9</version>
<build>
<defaultGoal>clean install</defaultGoal>
<finalName>FabledSkyblock-${project.version}</finalName>

View File

@ -69,7 +69,7 @@ public class ReloadCommand extends SubCommand {
skyblock.setScoreboardManager(new ScoreboardManager(skyblock));
}
} else {
skyblock.getScoreboardManager().resendScoreboard();
skyblock.getScoreboardManager().updateScoreboards(false);
}
if (skyblock.getGeneratorManager() == null) {

View File

@ -94,7 +94,7 @@ public class StructureCommand extends SubCommand {
+ suffix.replace("%info", ChatColor.translateAlternateColorCodes(
'&',
configLoad.getString(
"Command.Island.Admin.Structure.Save.Convert.Message"))),
"Command.Island.Admin.Structure.Convert.Info.Message"))),
false, null, null,
new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(
ChatColor.translateAlternateColorCodes('&', configLoad.getString(

View File

@ -1,22 +1,5 @@
package com.songoda.skyblock.scoreboard;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Team;
import org.bukkit.scoreboard.Team.Option;
import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.config.FileManager;
import com.songoda.skyblock.config.FileManager.Config;
@ -24,23 +7,30 @@ import com.songoda.skyblock.island.Island;
import com.songoda.skyblock.island.IslandManager;
import com.songoda.skyblock.island.IslandRole;
import com.songoda.skyblock.utils.version.NMSUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Team;
import org.bukkit.scoreboard.Team.Option;
import java.io.File;
import java.util.*;
public class ScoreboardManager extends BukkitRunnable {
private final static int VERSION = NMSUtil.getVersionNumber();
private final SkyBlock skyblock;
private final Map<UUID, Scoreboard> scoreboardStorage;
private final Map<UUID, Scoreboard> scoreboardStorage = new HashMap<>();
private int runTicks = 0;
private List<String> teamNames;
private List<String> objectiveNames;
private final List<String> teamNames = new ArrayList<>();
private final List<String> objectiveNames = new ArrayList<>();
public ScoreboardManager(SkyBlock skyblock) {
this.skyblock = skyblock;
this.scoreboardStorage = new HashMap<>();
this.teamNames = new ArrayList<>();
this.objectiveNames = new ArrayList<>();
this.runTaskTimer(skyblock, 20, 40);
}
@ -49,45 +39,7 @@ public class ScoreboardManager extends BukkitRunnable {
public void run() {
if (runTicks++ == 0) {
IslandManager islandManager = skyblock.getIslandManager();
FileManager fileManager = skyblock.getFileManager();
if (fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Scoreboard.Enable")) {
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
for (Player all : Bukkit.getOnlinePlayers()) {
Scoreboard scoreboard = new Scoreboard(skyblock, all);
Island island = islandManager.getIsland(all);
if (island == null) {
scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getFileConfiguration().getString("Scoreboard.Tutorial.Displayname")));
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Tutorial.Displaylines"));
} else {
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"));
}
}
}
scoreboard.run();
storeScoreboard(all, scoreboard);
}
}
updateScoreboards(true);
return;
}
@ -112,7 +64,6 @@ public class ScoreboardManager extends BukkitRunnable {
final Objective objective = board.getObjective(name);
if (objective != null) objective.unregister();
}
for (String name : teamNames) {
@ -123,7 +74,6 @@ public class ScoreboardManager extends BukkitRunnable {
if (team != null) team.unregister();
}
}
/*
@ -152,7 +102,8 @@ public class ScoreboardManager extends BukkitRunnable {
Objective obj = playerBoard.getObjective(primaryObjective.getName());
if (obj == null) obj = playerBoard.registerNewObjective(primaryObjective.getName(), primaryObjective.getCriteria());
if (obj == null)
obj = playerBoard.registerNewObjective(primaryObjective.getName(), primaryObjective.getCriteria());
obj.setDisplayName(primaryObjective.getDisplayName());
obj.setDisplaySlot(primaryObjective.getDisplaySlot());
@ -182,62 +133,73 @@ public class ScoreboardManager extends BukkitRunnable {
obj.setOption(option, primaryTeam.getOption(option));
}
}
}
}
}
public void resendScoreboard() {
IslandManager islandManager = skyblock.getIslandManager();
public void updateScoreboards(boolean createNew) {
FileManager fileManager = skyblock.getFileManager();
if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Scoreboard.Enable")) return;
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Scoreboard.Enable"))
return;
for (Player all : Bukkit.getOnlinePlayers()) {
if (!hasScoreboard(all)) continue;
Scoreboard scoreboard = getScoreboard(all);
boolean store = false;
Scoreboard scoreboard = null;
if (hasScoreboard(all))
scoreboard = getScoreboard(all);
else {
if (createNew) {
scoreboard = new Scoreboard(skyblock, all);
store = true;
}
}
if (scoreboard == null) continue;
IslandManager islandManager = skyblock.getIslandManager();
Config language = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"));
Island island = islandManager.getIsland(all);
if (island == null) {
scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getFileConfiguration().getString("Scoreboard.Tutorial.Displayname")));
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Tutorial.Displaylines"));
scoreboard.setDisplayName(color(language.getFileConfiguration().getString("Scoreboard.Tutorial.Displayname")));
scoreboard.setDisplayList(language.getFileConfiguration().getStringList("Scoreboard.Tutorial.Displaylines"));
} else {
if (island.getRole(IslandRole.Member).size() == 0 && island.getRole(IslandRole.Operator).size() == 0) {
scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getFileConfiguration().getString("Scoreboard.Island.Solo.Displayname")));
scoreboard.setDisplayName(color(language.getFileConfiguration().getString("Scoreboard.Island.Solo.Displayname")));
if (islandManager.getVisitorsAtIsland(island).size() == 0) {
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Empty.Displaylines"));
scoreboard.setDisplayList(language.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Empty.Displaylines"));
} else {
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Occupied.Displaylines"));
scoreboard.setDisplayList(language.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Occupied.Displaylines"));
}
} else {
scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getFileConfiguration().getString("Scoreboard.Island.Team.Displayname")));
scoreboard.setDisplayName(color(language.getFileConfiguration().getString("Scoreboard.Island.Team.Displayname")));
if (islandManager.getVisitorsAtIsland(island).size() == 0) {
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Team.Empty.Displaylines"));
scoreboard.setDisplayList(language.getFileConfiguration().getStringList("Scoreboard.Island.Team.Empty.Displaylines"));
} else {
scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Team.Occupied.Displaylines"));
scoreboard.setDisplayList(language.getFileConfiguration().getStringList("Scoreboard.Island.Team.Occupied.Displaylines"));
}
}
}
scoreboard.run();
if (store) storeScoreboard(all, scoreboard);
}
}
private String color(String str) {
return str != null ? ChatColor.translateAlternateColorCodes('&', str) : null;
}
public void storeScoreboard(Player player, Scoreboard scoreboard) {
scoreboardStorage.put(player.getUniqueId(), scoreboard);
}
public void unloadPlayer(Player player) {
scoreboardStorage.remove(player.getUniqueId());
}
public Scoreboard getScoreboard(Player player) {
if (scoreboardStorage.containsKey(player.getUniqueId())) {
return scoreboardStorage.get(player.getUniqueId());
@ -249,4 +211,4 @@ public class ScoreboardManager extends BukkitRunnable {
public boolean hasScoreboard(Player player) {
return scoreboardStorage.containsKey(player.getUniqueId());
}
}
}