diff --git a/src/main/java/com/songoda/skyblock/SkyBlock.java b/src/main/java/com/songoda/skyblock/SkyBlock.java index c7633179..9a2fc3ae 100644 --- a/src/main/java/com/songoda/skyblock/SkyBlock.java +++ b/src/main/java/com/songoda/skyblock/SkyBlock.java @@ -253,6 +253,10 @@ public class SkyBlock extends SongodaPlugin { this.userCacheManager.onDisable(); } + if (this.scoreboardManager != null) { + this.scoreboardManager.disable(); + } + if (this.islandManager != null) { this.islandManager.onDisable(); } @@ -291,7 +295,6 @@ public class SkyBlock extends SongodaPlugin { private CoreProtectAPI loadCoreProtect() { Plugin plugin = getServer().getPluginManager().getPlugin("CoreProtect"); - if (plugin != null) { // Check before loading classes if (plugin instanceof CoreProtect) { // Check that CoreProtect is loaded CoreProtectAPI CoreProtect = ((CoreProtect) plugin).getAPI(); @@ -303,7 +306,6 @@ public class SkyBlock extends SongodaPlugin { } } return null; - } @Override diff --git a/src/main/java/com/songoda/skyblock/command/commands/admin/ReloadCommand.java b/src/main/java/com/songoda/skyblock/command/commands/admin/ReloadCommand.java index b04042a2..782ad1c8 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/admin/ReloadCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/admin/ReloadCommand.java @@ -68,7 +68,7 @@ public class ReloadCommand extends SubCommand { plugin.setScoreboardManager(new ScoreboardManager(plugin)); } } else { - plugin.getScoreboardManager().reloadScoreboards(false); + plugin.getScoreboardManager().reload(); } if (plugin.getGeneratorManager() == null) { diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/AcceptCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/AcceptCommand.java index f8f26401..baf485de 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/AcceptCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/AcceptCommand.java @@ -13,7 +13,6 @@ import com.songoda.skyblock.island.IslandRole; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; -import com.songoda.skyblock.scoreboard.Scoreboard; import com.songoda.skyblock.scoreboard.ScoreboardManager; import com.songoda.skyblock.sound.SoundManager; import org.bukkit.Bukkit; @@ -126,39 +125,25 @@ public class AcceptCommand extends SubCommand { plugin.getVisitManager().getIsland(invite.getOwnerUUID()) .removeVoter(player.getUniqueId()); - for (Player all : Bukkit.getOnlinePlayers()) { - if (!all.getUniqueId().equals(player.getUniqueId())) { - if (playerDataManager.hasPlayerData(all)) { - playerData = playerDataManager.getPlayerData(all); + for (Player loopPlayer : Bukkit.getOnlinePlayers()) { + if (!loopPlayer.getUniqueId().equals(player.getUniqueId())) { + if (playerDataManager.hasPlayerData(loopPlayer)) { + playerData = playerDataManager.getPlayerData(loopPlayer); if (playerData.getOwner() != null && playerData.getOwner().equals(island.getOwnerUUID())) { - all.sendMessage(ChatColor.translateAlternateColorCodes('&', + loopPlayer.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad .getString( "Command.Island.Accept.Accepted.Broadcast.Message") .replace("%player", player.getName()))); - soundManager.playSound(all, CompatibleSound.ENTITY_FIREWORK_ROCKET_BLAST.getSound(), 1.0F, + soundManager.playSound(loopPlayer, CompatibleSound.ENTITY_FIREWORK_ROCKET_BLAST.getSound(), 1.0F, 1.0F); if (scoreboardManager != null) { if (island.getRole(IslandRole.Member).size() == 1 && island.getRole(IslandRole.Operator).size() == 0) { - Scoreboard scoreboard = scoreboardManager.getScoreboard(all); - scoreboard.setDisplayName( - ChatColor.translateAlternateColorCodes('&', configLoad - .getString("Scoreboard.Island.Team.Displayname"))); - - if (islandManager.getVisitorsAtIsland(island).size() == 0) { - scoreboard.setDisplayList(configLoad.getStringList( - "Scoreboard.Island.Team.Empty.Displaylines")); - } else { - scoreboard.setDisplayList(configLoad.getStringList( - "Scoreboard.Island.Team.Occupied.Displaylines")); - } - - - scoreboard.run(); + scoreboardManager.updatePlayerScoreboardType(loopPlayer); } } } @@ -167,20 +152,7 @@ public class AcceptCommand extends SubCommand { } if (scoreboardManager != null) { - Scoreboard scoreboard = scoreboardManager.getScoreboard(player); - scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Scoreboard.Island.Team.Displayname", ""))); - - if (islandManager.getVisitorsAtIsland(island).size() == 0) { - scoreboard.setDisplayList( - configLoad.getStringList("Scoreboard.Island.Team.Empty.Displaylines")); - } else { - scoreboard.setDisplayList( - configLoad.getStringList("Scoreboard.Island.Team.Occupied.Displaylines")); - } - - - scoreboard.run(); + scoreboardManager.updatePlayerScoreboardType(player); } } } else { diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/KickCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/KickCommand.java index 97feb6af..8a3735cf 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/KickCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/KickCommand.java @@ -14,7 +14,6 @@ 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.Scoreboard; import com.songoda.skyblock.scoreboard.ScoreboardManager; import com.songoda.skyblock.sound.SoundManager; import com.songoda.skyblock.utils.player.OfflinePlayer; @@ -148,11 +147,7 @@ public class KickCommand extends SubCommand { } if (scoreboardManager != null) { - Scoreboard scoreboard = scoreboardManager.getScoreboard(targetPlayer); - scoreboard.setDisplayName( - ChatColor.translateAlternateColorCodes('&', languageConfig.getFileConfiguration().getString("Scoreboard.Tutorial.Displayname"))); - scoreboard.setDisplayList(languageConfig.getFileConfiguration().getStringList("Scoreboard.Tutorial.Displaylines")); - scoreboard.run(); + scoreboardManager.updatePlayerScoreboardType(targetPlayer); } playerData = playerDataManager.getPlayerData(targetPlayer); @@ -190,17 +185,7 @@ public class KickCommand extends SubCommand { if (scoreboardManager != null) { if (island.getRole(IslandRole.Member).size() == 0 && island.getRole(IslandRole.Operator).size() == 0) { - Scoreboard scoreboard = scoreboardManager.getScoreboard(player); - scoreboard.setDisplayName( - ChatColor.translateAlternateColorCodes('&', languageConfig.getFileConfiguration().getString("Scoreboard.Island.Solo.Displayname"))); - - if (islandManager.getVisitorsAtIsland(island).size() == 0) { - scoreboard.setDisplayList(languageConfig.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Empty.Displaylines")); - } else { - scoreboard.setDisplayList(languageConfig.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Occupied.Displaylines")); - } - - scoreboard.run(); + scoreboardManager.updatePlayerScoreboardType(player); } } } diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/LeaveCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/LeaveCommand.java index e1d5453b..98d6de8b 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/LeaveCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/LeaveCommand.java @@ -11,7 +11,6 @@ import com.songoda.skyblock.island.IslandRole; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; -import com.songoda.skyblock.scoreboard.Scoreboard; import com.songoda.skyblock.scoreboard.ScoreboardManager; import com.songoda.skyblock.sound.SoundManager; import com.songoda.skyblock.utils.world.LocationUtil; @@ -93,28 +92,22 @@ public class LeaveCommand extends SubCommand { // TODO Check if player has been teleported islandManager.unloadIsland(island, null); - for (Player all : Bukkit.getOnlinePlayers()) { - if (!all.getUniqueId().equals(player.getUniqueId())) { - if (island.hasRole(IslandRole.Member, all.getUniqueId()) - || island.hasRole(IslandRole.Operator, all.getUniqueId()) - || island.hasRole(IslandRole.Owner, all.getUniqueId())) { - all.sendMessage(ChatColor.translateAlternateColorCodes('&', + for (Player loopPlayer : Bukkit.getOnlinePlayers()) { + if (!loopPlayer.getUniqueId().equals(player.getUniqueId())) { + if (island.hasRole(IslandRole.Member, loopPlayer.getUniqueId()) + || island.hasRole(IslandRole.Operator, loopPlayer.getUniqueId()) + || island.hasRole(IslandRole.Owner, loopPlayer.getUniqueId())) { + loopPlayer.sendMessage(ChatColor.translateAlternateColorCodes('&', languageConfig.getFileConfiguration() .getString("Command.Island.Leave.Left.Broadcast.Message") .replace("%player", player.getName()))); - soundManager.playSound(all, CompatibleSound.ENTITY_IRON_GOLEM_ATTACK.getSound(), 5.0F, 5.0F); + soundManager.playSound(loopPlayer, CompatibleSound.ENTITY_IRON_GOLEM_ATTACK.getSound(), 5.0F, 5.0F); if (island.getRole(IslandRole.Member).size() == 0 && island.getRole(IslandRole.Operator).size() == 0) { if (scoreboardManager != null) { if (islandManager.getVisitorsAtIsland(island).size() != 0) { - Scoreboard scoreboard = scoreboardManager.getScoreboard(all); - scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', - languageConfig.getFileConfiguration() - .getString("Scoreboard.Island.Solo.Displayname"))); - scoreboard.setDisplayList(languageConfig.getFileConfiguration() - .getStringList("Scoreboard.Island.Solo.Occupied.Displaylines")); - scoreboard.run(); + scoreboardManager.updatePlayerScoreboardType(loopPlayer); } } @@ -129,12 +122,7 @@ public class LeaveCommand extends SubCommand { soundManager.playSound(player, CompatibleSound.ENTITY_IRON_GOLEM_ATTACK.getSound(), 5.0F, 5.0F); if (scoreboardManager != null) { - Scoreboard scoreboard = scoreboardManager.getScoreboard(player); - scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', - languageConfig.getFileConfiguration().getString("Scoreboard.Tutorial.Displayname"))); - scoreboard.setDisplayList( - languageConfig.getFileConfiguration().getStringList("Scoreboard.Tutorial.Displaylines")); - scoreboard.run(); + scoreboardManager.updatePlayerScoreboardType(player); } } } diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/ScoreboardCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/ScoreboardCommand.java index 5cceb97b..3107cb34 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/ScoreboardCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/ScoreboardCommand.java @@ -37,13 +37,13 @@ public class ScoreboardCommand extends SubCommand { soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); }else if (playerData.isScoreboard()) { playerData.setScoreboard(false); - scoreboardManager.removePlayer(player); - + scoreboardManager.addDisabledPlayer(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); + scoreboardManager.removeDisabledPlayer(player); messageManager.sendMessage(player, configLoad.getString("Command.Scoreboard.Enabled.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1.0F, 1.0F); diff --git a/src/main/java/com/songoda/skyblock/config/FileManager.java b/src/main/java/com/songoda/skyblock/config/FileManager.java index fe76ed74..3abd9501 100644 --- a/src/main/java/com/songoda/skyblock/config/FileManager.java +++ b/src/main/java/com/songoda/skyblock/config/FileManager.java @@ -11,6 +11,12 @@ import org.bukkit.configuration.file.YamlConfiguration; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.CopyOption; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; @@ -20,11 +26,13 @@ import java.util.logging.Level; public class FileManager { private final SkyBlock plugin; - private Map loadedConfigs = new HashMap<>(); + private final Map loadedConfigs = new HashMap<>(); public FileManager(SkyBlock plugin) { this.plugin = plugin; + backupIfNeeded(); + loadConfigs(); } @@ -56,6 +64,8 @@ public class FileManager { configFiles.put("upgrades.yml", new File(plugin.getDataFolder(), "upgrades.yml")); configFiles.put("biomes.yml", new File(plugin.getDataFolder(), "biomes.yml")); // configFiles.put("menus.yml", new File(skyblock.getDataFolder(), "menus.yml")); + configFiles.put("scoreboard.yml", new File(plugin.getDataFolder(), "scoreboard.yml")); + configFiles.put("placeholders.yml", new File(plugin.getDataFolder(), "placeholders.yml")); configFiles.put("generators.yml", new File(plugin.getDataFolder(), "generators.yml")); configFiles.put("stackables.yml", new File(plugin.getDataFolder(), "stackables.yml")); configFiles.put("structures.yml", new File(plugin.getDataFolder(), "structures.yml")); @@ -89,10 +99,15 @@ public class FileManager { } if (configFile.exists()) { - if (fileName.equals("config.yml") || fileName.equals("language.yml") || fileName.equals("worlds.yml") || fileName.equals("biomes.yml")) { + if (fileName.equals("config.yml") || + fileName.equals("language.yml") || + fileName.equals("worlds.yml") || + fileName.equals("biomes.yml") || + fileName.equals("scoreboard.yml") || + fileName.equals("placeholders.yml")) { FileChecker fileChecker; - if (fileName.equals("config.yml") || fileName.equals("biomes.yml")) { + if (fileName.equals("config.yml") || fileName.equals("biomes.yml") || fileName.equals("scoreboard.yml")) { fileChecker = new FileChecker(plugin, this, fileName, true); } else { fileChecker = new FileChecker(plugin, this, fileName, false); @@ -161,6 +176,35 @@ public class FileManager { ex.printStackTrace(); } } + + public void backupIfNeeded() { + File languageFile = new File(plugin.getDataFolder().toString() + "language.yml"); + File scoreboardFile = new File(plugin.getDataFolder().toString() + "scoreboard.yml"); + File placeholderFile = new File(plugin.getDataFolder().toString() + "placeholders.yml"); + if(languageFile.exists() && (!scoreboardFile.exists() || !placeholderFile.exists())) { + File backupDir = new File(plugin.getDataFolder().toString() + "/backup"); + if(!backupDir.exists()) { + backupDir.mkdir(); + } + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy-HH:mm:ss"); + LocalDateTime now = LocalDateTime.now(); + + + Path oldLanguagePath = languageFile.toPath(); + Path newLanguagePath = new File(plugin.getDataFolder().toString() + "/backup/language" + dtf.format(now) + ".yml").toPath(); + + CopyOption[] options = new CopyOption[]{ + StandardCopyOption.REPLACE_EXISTING, + StandardCopyOption.COPY_ATTRIBUTES + }; + + try { + Files.copy(oldLanguagePath, newLanguagePath, options); + } catch (IOException e) { + e.printStackTrace(); + } + } + } public Location getLocation(Config config, String path, boolean direction) { @@ -199,7 +243,6 @@ public class FileManager { } public Config getConfig(File configPath) { - Config cached = loadedConfigs.get(configPath.getPath()); if (cached != null) return cached; diff --git a/src/main/java/com/songoda/skyblock/island/IslandManager.java b/src/main/java/com/songoda/skyblock/island/IslandManager.java index ec249548..65926109 100644 --- a/src/main/java/com/songoda/skyblock/island/IslandManager.java +++ b/src/main/java/com/songoda/skyblock/island/IslandManager.java @@ -24,7 +24,6 @@ import com.songoda.skyblock.island.removal.ChunkDeleteSplitter; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; -import com.songoda.skyblock.scoreboard.Scoreboard; import com.songoda.skyblock.scoreboard.ScoreboardManager; import com.songoda.skyblock.sound.SoundManager; import com.songoda.skyblock.structure.Structure; @@ -264,12 +263,7 @@ public class IslandManager { data.setOwner(player.getUniqueId()); if (scoreboardManager != null) { - Config languageConfig = fileManager.getConfig(new File(plugin.getDataFolder(), "language.yml")); - - Scoreboard scoreboard = scoreboardManager.getScoreboard(player); - scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', languageConfig.getFileConfiguration().getString("Scoreboard.Island.Solo.Displayname"))); - scoreboard.setDisplayList(languageConfig.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Empty.Displaylines")); - scoreboard.run(); + scoreboardManager.updatePlayerScoreboardType(player); } Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { @@ -578,57 +572,52 @@ public class IslandManager { boolean cooldownCreationEnabled = configLoad.getBoolean("Island.Creation.Cooldown.Creation.Enable"); boolean cooldownDeletionEnabled = configLoad.getBoolean("Island.Creation.Cooldown.Deletion.Enable"); - config = fileManager.getConfig(new File(plugin.getDataFolder(), "language.yml")); - configLoad = config.getFileConfiguration(); - - for (Player all : Bukkit.getOnlinePlayers()) { - if ((island.hasRole(IslandRole.Member, all.getUniqueId()) || island.hasRole(IslandRole.Operator, all.getUniqueId()) || island.hasRole(IslandRole.Owner, all.getUniqueId())) && playerDataManager.hasPlayerData(all)) { - PlayerData playerData = playerDataManager.getPlayerData(all); + for (Player player : Bukkit.getOnlinePlayers()) { + if ((island.hasRole(IslandRole.Member, player.getUniqueId()) || + island.hasRole(IslandRole.Operator, player.getUniqueId()) || + island.hasRole(IslandRole.Owner, player.getUniqueId())) && + playerDataManager.hasPlayerData(player)) { + PlayerData playerData = playerDataManager.getPlayerData(player); playerData.setOwner(null); playerData.setMemberSince(null); playerData.setChat(false); playerData.save(); if (scoreboardManager != null) { - Scoreboard scoreboard = scoreboardManager.getScoreboard(all); - scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Scoreboard.Tutorial.Displayname"))); - scoreboard.setDisplayList(configLoad.getStringList("Scoreboard.Tutorial.Displaylines")); - scoreboard.run(); + scoreboardManager.updatePlayerScoreboardType(player); } - if (isPlayerAtIsland(island, all)) { - LocationUtil.teleportPlayerToSpawn(all); + if (isPlayerAtIsland(island, player)) { + LocationUtil.teleportPlayerToSpawn(player); } // TODO - Find a way to delete also offline players - if (plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration() - .getBoolean("Island.Deletion.ClearInventory", false)){ - all.getInventory().clear(); + if (configLoad.getBoolean("Island.Deletion.ClearInventory", false)){ + player.getInventory().clear(); } - if (plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration() - .getBoolean("Island.Deletion.ClearEnderChest", false)){ - all.getEnderChest().clear(); + if (configLoad.getBoolean("Island.Deletion.ClearEnderChest", false)){ + player.getEnderChest().clear(); } if (cooldownCreationEnabled) { - if (!all.hasPermission("fabledskyblock.bypass.cooldown") && !all.hasPermission("fabledskyblock.bypass.*") && !all.hasPermission("fabledskyblock.*")) { - plugin.getCooldownManager().createPlayer(CooldownType.Creation, all); + if (!player.hasPermission("fabledskyblock.bypass.cooldown") && !player.hasPermission("fabledskyblock.bypass.*") && !player.hasPermission("fabledskyblock.*")) { + plugin.getCooldownManager().createPlayer(CooldownType.Creation, player); } } if (cooldownDeletionEnabled) { - if (!all.hasPermission("fabledskyblock.bypass.cooldown") && !all.hasPermission("fabledskyblock.bypass.*") && !all.hasPermission("fabledskyblock.*")) { - plugin.getCooldownManager().createPlayer(CooldownType.Deletion, all); + if (!player.hasPermission("fabledskyblock.bypass.cooldown") && !player.hasPermission("fabledskyblock.bypass.*") && !player.hasPermission("fabledskyblock.*")) { + plugin.getCooldownManager().createPlayer(CooldownType.Deletion, player); } } } InviteManager inviteManager = plugin.getInviteManager(); - if (inviteManager.hasInvite(all.getUniqueId())) { - Invite invite = inviteManager.getInvite(all.getUniqueId()); + if (inviteManager.hasInvite(player.getUniqueId())) { + Invite invite = inviteManager.getInvite(player.getUniqueId()); if (invite.getOwnerUUID().equals(island.getOwnerUUID())) { - inviteManager.removeInvite(all.getUniqueId()); + inviteManager.removeInvite(player.getUniqueId()); } } } @@ -952,31 +941,20 @@ public class IslandManager { island.save(); - int islandMembers = island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() + 1, islandVisitors = getVisitorsAtIsland(island).size(); + int islandVisitors = getVisitorsAtIsland(island).size(); boolean unloadIsland = true; - for (Player all : Bukkit.getOnlinePlayers()) { - if (all == null || (player != null && player.getUniqueId().equals(all.getUniqueId()))) { + for (Player loopPlayer : Bukkit.getOnlinePlayers()) { + if (loopPlayer == null || (player != null && player.getUniqueId().equals(loopPlayer.getUniqueId()))) { continue; } - if (island.hasRole(IslandRole.Member, all.getUniqueId()) || island.hasRole(IslandRole.Operator, all.getUniqueId()) || island.hasRole(IslandRole.Owner, all.getUniqueId()) - || island.getCoopType(all.getUniqueId()) == IslandCoop.NORMAL) { + if (island.hasRole(IslandRole.Member, loopPlayer.getUniqueId()) || + island.hasRole(IslandRole.Operator, loopPlayer.getUniqueId()) || + island.hasRole(IslandRole.Owner, loopPlayer.getUniqueId()) || + island.getCoopType(loopPlayer.getUniqueId()) == IslandCoop.NORMAL) { if (scoreboardManager != null) { - try { - if (islandMembers == 1 && islandVisitors == 0) { - Scoreboard scoreboard = scoreboardManager.getScoreboard(all); - scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Scoreboard.Island.Solo.Displayname"))); - scoreboard.setDisplayList(configLoad.getStringList("Scoreboard.Island.Solo.Empty.Displaylines")); - scoreboard.run(); - } else if (islandVisitors == 0) { - Scoreboard scoreboard = scoreboardManager.getScoreboard(all); - scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Scoreboard.Island.Team.Displayname"))); - scoreboard.setDisplayList(configLoad.getStringList("Scoreboard.Island.Team.Empty.Displaylines")); - - scoreboard.run(); - } - } catch (Exception ignored) {} + scoreboardManager.updatePlayerScoreboardType(loopPlayer); } unloadIsland = false; @@ -1219,23 +1197,13 @@ public class IslandManager { int islandVisitors = getVisitorsAtIsland(island).size(), islandMembers = island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() + 1; if (islandVisitors == 0) { - for (Player all : Bukkit.getOnlinePlayers()) { - PlayerData targetPlayerData = plugin.getPlayerDataManager().getPlayerData(all); + for (Player loopPlayer : Bukkit.getOnlinePlayers()) { + PlayerData targetPlayerData = plugin.getPlayerDataManager().getPlayerData(loopPlayer); if (targetPlayerData != null && targetPlayerData.getOwner() != null && targetPlayerData.getOwner().equals(island.getOwnerUUID())) { - Scoreboard scoreboard = scoreboardManager.getScoreboard(all); - - if (islandMembers == 1) { - scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Scoreboard.Island.Solo.Displayname"))); - scoreboard.setDisplayList(configLoad.getStringList("Scoreboard.Island.Solo.Occupied.Displaylines")); - } else { - scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Scoreboard.Island.Team.Displayname"))); - scoreboard.setDisplayList(configLoad.getStringList("Scoreboard.Island.Team.Occupied.Displaylines")); - } - - scoreboard.run(); + scoreboardManager.updatePlayerScoreboardType(loopPlayer); } } } diff --git a/src/main/java/com/songoda/skyblock/listeners/Chat.java b/src/main/java/com/songoda/skyblock/listeners/Chat.java index 0e2bbd36..9cb2e19b 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Chat.java +++ b/src/main/java/com/songoda/skyblock/listeners/Chat.java @@ -47,19 +47,6 @@ public class Chat implements Listener { island = plugin.getIslandManager().getIsland(player); } - String messageFormat = event.getFormat(); - - for (String placeholderList : placeholderManager.getPlaceholders()) { - String placeholder = "{" + placeholderList + "}"; - - if (messageFormat.contains(placeholder)) { - messageFormat = messageFormat.replace(placeholder, - placeholderManager.getPlaceholder(player, placeholderList)); - } - } - - event.setFormat(messageFormat); - if (playerData.isChat() && island != null) { event.setCancelled(true); diff --git a/src/main/java/com/songoda/skyblock/listeners/Join.java b/src/main/java/com/songoda/skyblock/listeners/Join.java index 66ffa190..f716dbd9 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Join.java +++ b/src/main/java/com/songoda/skyblock/listeners/Join.java @@ -37,87 +37,85 @@ public class Join implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { - Player player = event.getPlayer(); + Player player = event.getPlayer(); - ScoreboardManager scoreboardManager = plugin.getScoreboardManager(); - PlayerDataManager playerDataManager = plugin.getPlayerDataManager(); - UserCacheManager userCacheManager = plugin.getUserCacheManager(); - CooldownManager cooldownManager = plugin.getCooldownManager(); - IslandManager islandManager = plugin.getIslandManager(); - FileManager fileManager = plugin.getFileManager(); + ScoreboardManager scoreboardManager = plugin.getScoreboardManager(); + PlayerDataManager playerDataManager = plugin.getPlayerDataManager(); + UserCacheManager userCacheManager = plugin.getUserCacheManager(); + CooldownManager cooldownManager = plugin.getCooldownManager(); + IslandManager islandManager = plugin.getIslandManager(); + FileManager fileManager = plugin.getFileManager(); - userCacheManager.addUser(player.getUniqueId(), player.getName()); - userCacheManager.saveAsync(); + userCacheManager.addUser(player.getUniqueId(), player.getName()); + userCacheManager.saveAsync(); + + try { + islandManager.loadIsland(player); + Island island = islandManager.getIsland(player); + boolean teleportedToIsland = false; + + Config config = fileManager.getConfig(new File(plugin.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + if (configLoad.getBoolean("Island.Join.Spawn")) { + LocationUtil.teleportPlayerToSpawn(player); + } else if (configLoad.getBoolean("Island.Join.Island") && island != null) { + Bukkit.getScheduler().runTask(plugin, () -> { + PaperLib.teleportAsync(player, island.getLocation(IslandWorld.Normal, IslandEnvironment.Main)); + player.setFallDistance(0.0F); + }); + teleportedToIsland = true; + } + + if (!teleportedToIsland) { + islandManager.loadPlayer(player); + } + } catch (Exception e) { + e.printStackTrace(); + } + + playerDataManager.loadPlayerData(player); + + if (playerDataManager.hasPlayerData(player)) { + String[] playerTexture; try { - islandManager.loadIsland(player); - Island island = islandManager.getIsland(player); - boolean teleportedToIsland = false; - - Config config = fileManager.getConfig(new File(plugin.getDataFolder(), "config.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); - - if (configLoad.getBoolean("Island.Join.Spawn")) { - LocationUtil.teleportPlayerToSpawn(player); - } else if (configLoad.getBoolean("Island.Join.Island") && island != null) { - Bukkit.getScheduler().runTask(plugin, () -> { - PaperLib.teleportAsync(player, island.getLocation(IslandWorld.Normal, IslandEnvironment.Main)); - player.setFallDistance(0.0F); - }); - teleportedToIsland = true; - } - - if (!teleportedToIsland) { - islandManager.loadPlayer(player); - } + Object entityPlayer = player.getClass().getMethod("getHandle").invoke(player); + Method getProfileMethod = entityPlayer.getClass().getMethod("getProfile"); + GameProfile gameProfile = (GameProfile) getProfileMethod.invoke(entityPlayer); + Property property = gameProfile.getProperties().get("textures").iterator().next(); + playerTexture = new String[]{property.getSignature(), property.getValue()}; } catch (Exception e) { - e.printStackTrace(); + playerTexture = new String[]{ + "K9P4tCIENYbNpDuEuuY0shs1x7iIvwXi4jUUVsATJfwsAIZGS+9OZ5T2HB0tWBoxRvZNi73Vr+syRdvTLUWPusVXIg+2fhXmQoaNEtnQvQVGQpjdQP0TkZtYG8PbvRxE6Z75ddq+DVx/65OSNHLWIB/D+Rg4vINh4ukXNYttn9QvauDHh1aW7/IkIb1Bc0tLcQyqxZQ3mdglxJfgIerqnlA++Lt7TxaLdag4y1NhdZyd3OhklF5B0+B9zw/qP8QCzsZU7VzJIcds1+wDWKiMUO7+60OSrIwgE9FPamxOQDFoDvz5BOULQEeNx7iFMB+eBYsapCXpZx0zf1bduppBUbbVC9wVhto/J4tc0iNyUq06/esHUUB5MHzdJ0Y6IZJAD/xIw15OLCUH2ntvs8V9/cy5/n8u3JqPUM2zhUGeQ2p9FubUGk4Q928L56l3omRpKV+5QYTrvF+AxFkuj2hcfGQG3VE2iYZO6omXe7nRPpbJlHkMKhE8Xvd1HP4PKpgivSkHBoZ92QEUAmRzZydJkp8CNomQrZJf+MtPiNsl/Q5RQM+8CQThg3+4uWptUfP5dDFWOgTnMdA0nIODyrjpp+bvIJnsohraIKJ7ZDnj4tIp4ObTNKDFC/8j8JHz4VCrtr45mbnzvB2DcK8EIB3JYT7ElJTHnc5BKMyLy5SKzuw=", + "eyJ0aW1lc3RhbXAiOjE1MjkyNTg0MTE4NDksInByb2ZpbGVJZCI6Ijg2NjdiYTcxYjg1YTQwMDRhZjU0NDU3YTk3MzRlZWQ3IiwicHJvZmlsZU5hbWUiOiJTdGV2ZSIsInNpZ25hdHVyZVJlcXVpcmVkIjp0cnVlLCJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZGMxYzc3Y2U4ZTU0OTI1YWI1ODEyNTQ0NmVjNTNiMGNkZDNkMGNhM2RiMjczZWI5MDhkNTQ4Mjc4N2VmNDAxNiJ9LCJDQVBFIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjc2N2Q0ODMyNWVhNTMyNDU2MTQwNmI4YzgyYWJiZDRlMjc1NWYxMTE1M2NkODVhYjA1NDVjYzIifX19"}; } + PlayerData playerData = playerDataManager.getPlayerData(player); + playerData.setTexture(playerTexture[0], playerTexture[1]); + Bukkit.getScheduler().runTaskAsynchronously(plugin, playerData::save); + } else { + playerDataManager.createPlayerData(player); playerDataManager.loadPlayerData(player); + } - if (playerDataManager.hasPlayerData(player)) { - String[] playerTexture; + playerDataManager.storeIsland(player); - try { - Object entityPlayer = player.getClass().getMethod("getHandle").invoke(player); - Method getProfileMethod = entityPlayer.getClass().getMethod("getProfile"); - GameProfile gameProfile = (GameProfile) getProfileMethod.invoke(entityPlayer); - Property property = gameProfile.getProperties().get("textures").iterator().next(); - playerTexture = new String[]{property.getSignature(), property.getValue()}; - } catch (Exception e) { - playerTexture = new String[]{ - "K9P4tCIENYbNpDuEuuY0shs1x7iIvwXi4jUUVsATJfwsAIZGS+9OZ5T2HB0tWBoxRvZNi73Vr+syRdvTLUWPusVXIg+2fhXmQoaNEtnQvQVGQpjdQP0TkZtYG8PbvRxE6Z75ddq+DVx/65OSNHLWIB/D+Rg4vINh4ukXNYttn9QvauDHh1aW7/IkIb1Bc0tLcQyqxZQ3mdglxJfgIerqnlA++Lt7TxaLdag4y1NhdZyd3OhklF5B0+B9zw/qP8QCzsZU7VzJIcds1+wDWKiMUO7+60OSrIwgE9FPamxOQDFoDvz5BOULQEeNx7iFMB+eBYsapCXpZx0zf1bduppBUbbVC9wVhto/J4tc0iNyUq06/esHUUB5MHzdJ0Y6IZJAD/xIw15OLCUH2ntvs8V9/cy5/n8u3JqPUM2zhUGeQ2p9FubUGk4Q928L56l3omRpKV+5QYTrvF+AxFkuj2hcfGQG3VE2iYZO6omXe7nRPpbJlHkMKhE8Xvd1HP4PKpgivSkHBoZ92QEUAmRzZydJkp8CNomQrZJf+MtPiNsl/Q5RQM+8CQThg3+4uWptUfP5dDFWOgTnMdA0nIODyrjpp+bvIJnsohraIKJ7ZDnj4tIp4ObTNKDFC/8j8JHz4VCrtr45mbnzvB2DcK8EIB3JYT7ElJTHnc5BKMyLy5SKzuw=", - "eyJ0aW1lc3RhbXAiOjE1MjkyNTg0MTE4NDksInByb2ZpbGVJZCI6Ijg2NjdiYTcxYjg1YTQwMDRhZjU0NDU3YTk3MzRlZWQ3IiwicHJvZmlsZU5hbWUiOiJTdGV2ZSIsInNpZ25hdHVyZVJlcXVpcmVkIjp0cnVlLCJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZGMxYzc3Y2U4ZTU0OTI1YWI1ODEyNTQ0NmVjNTNiMGNkZDNkMGNhM2RiMjczZWI5MDhkNTQ4Mjc4N2VmNDAxNiJ9LCJDQVBFIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjc2N2Q0ODMyNWVhNTMyNDU2MTQwNmI4YzgyYWJiZDRlMjc1NWYxMTE1M2NkODVhYjA1NDVjYzIifX19"}; - } + cooldownManager.addCooldownPlayer(CooldownType.Biome, cooldownManager.loadCooldownPlayer(CooldownType.Biome, player)); + cooldownManager.addCooldownPlayer(CooldownType.Creation, cooldownManager.loadCooldownPlayer(CooldownType.Creation, player)); + cooldownManager.addCooldownPlayer(CooldownType.Deletion, cooldownManager.loadCooldownPlayer(CooldownType.Deletion, player)); - PlayerData playerData = playerDataManager.getPlayerData(player); - playerData.setTexture(playerTexture[0], playerTexture[1]); - Bukkit.getScheduler().runTaskAsynchronously(plugin, playerData::save); - } else { - playerDataManager.createPlayerData(player); - playerDataManager.loadPlayerData(player); - } + if (scoreboardManager != null && playerDataManager.getPlayerData(player).isScoreboard()) { + scoreboardManager.updatePlayerScoreboardType(player); + } - playerDataManager.storeIsland(player); + Island island = islandManager.getIslandPlayerAt(player); + if (island != null) { + islandManager.updateBorder(island); + islandManager.updateFlight(player); + } - cooldownManager.addCooldownPlayer(CooldownType.Biome, cooldownManager.loadCooldownPlayer(CooldownType.Biome, player)); - cooldownManager.addCooldownPlayer(CooldownType.Creation, cooldownManager.loadCooldownPlayer(CooldownType.Creation, player)); - cooldownManager.addCooldownPlayer(CooldownType.Deletion, cooldownManager.loadCooldownPlayer(CooldownType.Deletion, player)); - - if (scoreboardManager != null && playerDataManager.getPlayerData(player).isScoreboard()) { - scoreboardManager.addPlayer(player); - } - - Island island = islandManager.getIslandPlayerAt(player); - if (island != null) { - islandManager.updateBorder(island); - islandManager.updateFlight(player); - } - - // Load Challenge - SkyBlock.getInstance().getFabledChallenge().getPlayerManager().loadPlayer(player.getUniqueId()); - }); + // Load Challenge + SkyBlock.getInstance().getFabledChallenge().getPlayerManager().loadPlayer(player.getUniqueId()); } } diff --git a/src/main/java/com/songoda/skyblock/listeners/Quit.java b/src/main/java/com/songoda/skyblock/listeners/Quit.java index bde39add..afc40f31 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Quit.java +++ b/src/main/java/com/songoda/skyblock/listeners/Quit.java @@ -14,6 +14,7 @@ import com.songoda.skyblock.island.IslandRole; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; +import com.songoda.skyblock.scoreboard.ScoreboardManager; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -37,132 +38,131 @@ public class Quit implements Listener { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { - Player player = event.getPlayer(); + Player player = event.getPlayer(); - PlayerDataManager playerDataManager = plugin.getPlayerDataManager(); - CooldownManager cooldownManager = plugin.getCooldownManager(); - MessageManager messageManager = plugin.getMessageManager(); - InviteManager inviteManager = plugin.getInviteManager(); - IslandManager islandManager = plugin.getIslandManager(); - PlayerManager challengePlayerManager = plugin.getFabledChallenge().getPlayerManager(); + PlayerDataManager playerDataManager = plugin.getPlayerDataManager(); + CooldownManager cooldownManager = plugin.getCooldownManager(); + MessageManager messageManager = plugin.getMessageManager(); + InviteManager inviteManager = plugin.getInviteManager(); + IslandManager islandManager = plugin.getIslandManager(); + ScoreboardManager scoreboardManager = plugin.getScoreboardManager(); + PlayerManager challengePlayerManager = plugin.getFabledChallenge().getPlayerManager(); - PlayerData playerData = playerDataManager.getPlayerData(player); + PlayerData playerData = playerDataManager.getPlayerData(player); - try { - playerData.setLastOnline(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date())); - } catch (Exception ignored) { - } + try { + playerData.setLastOnline(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date())); + } catch (Exception ignored) {} - Island island = islandManager.getIsland(player); + Island island = islandManager.getIsland(player); - if (island != null) { - Set islandMembersOnline = islandManager.getMembersOnline(island); + if (island != null) { + Set islandMembersOnline = islandManager.getMembersOnline(island); - if (islandMembersOnline.size() == 1) { - OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(island.getOwnerUUID()); - cooldownManager.setCooldownPlayer(CooldownType.Levelling, offlinePlayer); - cooldownManager.removeCooldownPlayer(CooldownType.Levelling, offlinePlayer); + if (islandMembersOnline.size() == 1) { + OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(island.getOwnerUUID()); + cooldownManager.setCooldownPlayer(CooldownType.Levelling, offlinePlayer); + cooldownManager.removeCooldownPlayer(CooldownType.Levelling, offlinePlayer); - cooldownManager.setCooldownPlayer(CooldownType.Ownership, offlinePlayer); - cooldownManager.removeCooldownPlayer(CooldownType.Ownership, offlinePlayer); - } else if (islandMembersOnline.size() == 2) { - for (UUID islandMembersOnlineList : islandMembersOnline) { - if (!islandMembersOnlineList.equals(player.getUniqueId())) { - Player targetPlayer = Bukkit.getServer().getPlayer(islandMembersOnlineList); - PlayerData targetPlayerData = playerDataManager.getPlayerData(targetPlayer); + cooldownManager.setCooldownPlayer(CooldownType.Ownership, offlinePlayer); + cooldownManager.removeCooldownPlayer(CooldownType.Ownership, offlinePlayer); + } else if (islandMembersOnline.size() == 2) { + for (UUID islandMembersOnlineList : islandMembersOnline) { + if (!islandMembersOnlineList.equals(player.getUniqueId())) { + Player targetPlayer = Bukkit.getServer().getPlayer(islandMembersOnlineList); + PlayerData targetPlayerData = playerDataManager.getPlayerData(targetPlayer); - if (targetPlayerData.isChat()) { - targetPlayerData.setChat(false); - messageManager.sendMessage(targetPlayer, - plugin.getFileManager() - .getConfig(new File(plugin.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Island.Chat.Untoggled.Message")); - } + if (targetPlayerData.isChat()) { + targetPlayerData.setChat(false); + messageManager.sendMessage(targetPlayer, + plugin.getFileManager() + .getConfig(new File(plugin.getDataFolder(), "language.yml")) + .getFileConfiguration().getString("Island.Chat.Untoggled.Message")); } } } + } + final Island is = island; + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> islandManager.unloadIsland(is, player)); + } + + cooldownManager.setCooldownPlayer(CooldownType.Biome, player); + cooldownManager.removeCooldownPlayer(CooldownType.Biome, player); + + cooldownManager.setCooldownPlayer(CooldownType.Creation, player); + cooldownManager.removeCooldownPlayer(CooldownType.Creation, player); + + cooldownManager.setCooldownPlayer(CooldownType.Deletion, player); + cooldownManager.removeCooldownPlayer(CooldownType.Deletion, player); + + playerDataManager.savePlayerData(player); + playerDataManager.unloadPlayerData(player); + + boolean offline = true; + if(island != null && plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration() + .getBoolean("Island.Challenge.PerIsland", false)){ + if(island.getRole(IslandRole.Member) != null){ + for(UUID uuid : island.getRole(IslandRole.Member)){ + if(Bukkit.getPlayer(uuid) != null && !Bukkit.getPlayer(uuid).isOnline()){ + offline = false; + } + } + } + if(offline && island.getRole(IslandRole.Operator) != null){ + for(UUID uuid : island.getRole(IslandRole.Operator)){ + if(Bukkit.getPlayer(uuid) != null && !Bukkit.getPlayer(uuid).isOnline()){ + offline = false; + } + } + } + if(offline && island.getRole(IslandRole.Owner) != null){ + for(UUID uuid : island.getRole(IslandRole.Owner)){ + if(Bukkit.getPlayer(uuid) != null && !Bukkit.getPlayer(uuid).isOnline()){ + offline = false; + } + } + } + } + + if(offline){ + challengePlayerManager.unloadPlayer(player.getUniqueId()); + } + + for (Island islandList : islandManager.getCoopIslands(player)) { + if (plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration() + .getBoolean("Island.Coop.Unload") || islandList.getCoopType(player.getUniqueId()) == IslandCoop.TEMP) { + islandList.removeCoopPlayer(player.getUniqueId()); + } + } + + if (playerData != null && playerData.getIsland() != null && islandManager.containsIsland(playerData.getIsland())) { + island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(playerData.getIsland())); + + if (!island.hasRole(IslandRole.Member, player.getUniqueId()) + && !island.hasRole(IslandRole.Operator, player.getUniqueId()) + && !island.hasRole(IslandRole.Owner, player.getUniqueId())) { final Island is = island; - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> islandManager.unloadIsland(is, player)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> islandManager.unloadIsland(is, null)); + } + } + + if (inviteManager.hasInvite(player.getUniqueId())) { + Invite invite = inviteManager.getInvite(player.getUniqueId()); + Player targetPlayer = Bukkit.getServer().getPlayer(invite.getOwnerUUID()); + + if (targetPlayer != null) { + messageManager.sendMessage(targetPlayer, + plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "language.yml")) + .getFileConfiguration() + .getString("Command.Island.Invite.Invited.Sender.Disconnected.Message") + .replace("%player", player.getName())); + plugin.getSoundManager().playSound(targetPlayer, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); } - cooldownManager.setCooldownPlayer(CooldownType.Biome, player); - cooldownManager.removeCooldownPlayer(CooldownType.Biome, player); - - cooldownManager.setCooldownPlayer(CooldownType.Creation, player); - cooldownManager.removeCooldownPlayer(CooldownType.Creation, player); - - cooldownManager.setCooldownPlayer(CooldownType.Deletion, player); - cooldownManager.removeCooldownPlayer(CooldownType.Deletion, player); - - playerDataManager.savePlayerData(player); - playerDataManager.unloadPlayerData(player); - - boolean offline = true; - if(island != null && plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration() - .getBoolean("Island.Challenge.PerIsland", false)){ - if(island.getRole(IslandRole.Member) != null){ - for(UUID uuid : island.getRole(IslandRole.Member)){ - if(Bukkit.getPlayer(uuid) != null && !Bukkit.getPlayer(uuid).isOnline()){ - offline = false; - } - } - } - if(offline && island.getRole(IslandRole.Operator) != null){ - for(UUID uuid : island.getRole(IslandRole.Operator)){ - if(Bukkit.getPlayer(uuid) != null && !Bukkit.getPlayer(uuid).isOnline()){ - offline = false; - } - } - } - if(offline && island.getRole(IslandRole.Owner) != null){ - for(UUID uuid : island.getRole(IslandRole.Owner)){ - if(Bukkit.getPlayer(uuid) != null && !Bukkit.getPlayer(uuid).isOnline()){ - offline = false; - } - } - } - } - - if(offline){ - challengePlayerManager.unloadPlayer(player.getUniqueId()); - } - - for (Island islandList : islandManager.getCoopIslands(player)) { - if (plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration() - .getBoolean("Island.Coop.Unload") || islandList.getCoopType(player.getUniqueId()) == IslandCoop.TEMP) { - islandList.removeCoopPlayer(player.getUniqueId()); - } - } - - if (playerData != null && playerData.getIsland() != null && islandManager.containsIsland(playerData.getIsland())) { - island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(playerData.getIsland())); - - if (!island.hasRole(IslandRole.Member, player.getUniqueId()) - && !island.hasRole(IslandRole.Operator, player.getUniqueId()) - && !island.hasRole(IslandRole.Owner, player.getUniqueId())) { - final Island is = island; - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> islandManager.unloadIsland(is, null)); - } - } - - if (inviteManager.hasInvite(player.getUniqueId())) { - Invite invite = inviteManager.getInvite(player.getUniqueId()); - Player targetPlayer = Bukkit.getServer().getPlayer(invite.getOwnerUUID()); - - if (targetPlayer != null) { - messageManager.sendMessage(targetPlayer, - plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "language.yml")) - .getFileConfiguration() - .getString("Command.Island.Invite.Invited.Sender.Disconnected.Message") - .replace("%player", player.getName())); - plugin.getSoundManager().playSound(targetPlayer, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); - } - - inviteManager.removeInvite(player.getUniqueId()); - } - }); + inviteManager.removeInvite(player.getUniqueId()); + } + scoreboardManager.unregisterPlayer(player); // Unload Challenge SkyBlock.getInstance().getFabledChallenge().getPlayerManager().unloadPlayer(event.getPlayer().getUniqueId()); } diff --git a/src/main/java/com/songoda/skyblock/placeholder/EZPlaceholder.java b/src/main/java/com/songoda/skyblock/placeholder/EZPlaceholder.java deleted file mode 100644 index 16655c31..00000000 --- a/src/main/java/com/songoda/skyblock/placeholder/EZPlaceholder.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.songoda.skyblock.placeholder; - -import com.songoda.skyblock.SkyBlock; -import com.songoda.skyblock.config.FileManager.Config; -import com.songoda.skyblock.island.IslandLevel; -import com.songoda.skyblock.leaderboard.Leaderboard; -import com.songoda.skyblock.leaderboard.LeaderboardManager; -import com.songoda.skyblock.utils.NumberUtil; -import com.songoda.skyblock.utils.player.OfflinePlayer; -import com.songoda.skyblock.visit.Visit; -import me.clip.placeholderapi.expansion.PlaceholderExpansion; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; - -import java.io.File; -import java.util.List; - -public class EZPlaceholder extends PlaceholderExpansion { - - private final SkyBlock plugin; - - public EZPlaceholder(SkyBlock plugin) { - this.plugin = plugin; - } - - public String getIdentifier() { - return "fabledskyblock"; - } - - public String getPlugin() { - return null; - } - - public String getAuthor() { - return plugin.getDescription().getAuthors().get(0); - } - - public String getVersion() { - return plugin.getDescription().getVersion(); - } - - public boolean persist() { - return true; - } - - public String onPlaceholderRequest(Player player, String identifier) { - PlaceholderManager placeholderManager = plugin.getPlaceholderManager(); - LeaderboardManager leaderboardManager = plugin.getLeaderboardManager(); - - Config config = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "language.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); - - List leaderboardLevelPlayers = leaderboardManager.getLeaderboard(Leaderboard.Type.Level); - List leaderboardBankPlayers = leaderboardManager.getLeaderboard(Leaderboard.Type.Bank); - List leaderboardVotesPlayers = leaderboardManager.getLeaderboard(Leaderboard.Type.Votes); - - - if (identifier.equalsIgnoreCase("islands")) { - return "" + plugin.getVisitManager().getIslands().size(); - } else { - for (int i = 0; i < 10; i++) { - if (identifier.equalsIgnoreCase("leaderboard_votes_" + (i + 1))) { - if (i < leaderboardVotesPlayers.size()) { - Leaderboard leaderboard = leaderboardVotesPlayers.get(i); - Visit visit = leaderboard.getVisit(); - - Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); - String islandOwnerName; - - if (targetPlayer == null) { - islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); - } else { - islandOwnerName = targetPlayer.getName(); - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_votes.Non-empty.Message") - .replace("%position", "" + (i + 1)).replace("%player", islandOwnerName) - .replace("%votes", NumberUtil.formatNumberByDecimal(visit.getVoters().size()))); - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_votes.Empty.Message")); - } else if (identifier.equalsIgnoreCase("leaderboard_bank_" + (i + 1))) { - if (i < leaderboardBankPlayers.size()) { - Leaderboard leaderboard = leaderboardBankPlayers.get(i); - Visit visit = leaderboard.getVisit(); - - Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); - String islandOwnerName; - - if (targetPlayer == null) { - islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); - } else { - islandOwnerName = targetPlayer.getName(); - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_bank.Non-empty.Message") - .replace("%position", "" + (i + 1)).replace("%player", islandOwnerName) - .replace("%balance", NumberUtil.formatNumberByDecimal(visit.getBankBalance()))); - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_bank.Empty.Message")); - } else if (identifier.equalsIgnoreCase("leaderboard_level_" + (i + 1))) { - if (i < leaderboardLevelPlayers.size()) { - Leaderboard leaderboard = leaderboardLevelPlayers.get(i); - Visit visit = leaderboard.getVisit(); - IslandLevel level = visit.getLevel(); - - Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); - String islandOwnerName; - - if (targetPlayer == null) { - islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); - } else { - islandOwnerName = targetPlayer.getName(); - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_level.Non-empty.Message") - .replace("%position", "" + (i + 1)).replace("%player", islandOwnerName) - .replace("%level", NumberUtil.formatNumberByDecimal(level.getLevel())) - .replace("%points", NumberUtil.formatNumberByDecimal(level.getPoints()))); - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_level.Empty.Message")); - } - } - } - - if (player == null) { - return ""; - } - - return placeholderManager.getPlaceholder(player, "fabledskyblock_" + identifier); - } - -} diff --git a/src/main/java/com/songoda/skyblock/placeholder/MVdWPlaceholder.java b/src/main/java/com/songoda/skyblock/placeholder/MVdWPlaceholder.java deleted file mode 100644 index 133e03e3..00000000 --- a/src/main/java/com/songoda/skyblock/placeholder/MVdWPlaceholder.java +++ /dev/null @@ -1,147 +0,0 @@ -package com.songoda.skyblock.placeholder; - -import be.maximvdw.placeholderapi.PlaceholderAPI; -import com.songoda.skyblock.SkyBlock; -import com.songoda.skyblock.config.FileManager.Config; -import com.songoda.skyblock.island.IslandLevel; -import com.songoda.skyblock.leaderboard.Leaderboard; -import com.songoda.skyblock.leaderboard.LeaderboardManager; -import com.songoda.skyblock.utils.NumberUtil; -import com.songoda.skyblock.utils.player.OfflinePlayer; -import com.songoda.skyblock.visit.Visit; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; - -import java.io.File; -import java.util.List; -import java.util.logging.Level; - -public class MVdWPlaceholder { - - private final SkyBlock plugin; - - public MVdWPlaceholder(SkyBlock plugin) { - this.plugin = plugin; - } - - public void register() { - PlaceholderManager placeholderManager = plugin.getPlaceholderManager(); - LeaderboardManager leaderboardManager = plugin.getLeaderboardManager(); - - Config config = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "language.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); - - List leaderboardLevelPlayers = leaderboardManager.getLeaderboard(Leaderboard.Type.Level); - List leaderboardBankPlayers = leaderboardManager.getLeaderboard(Leaderboard.Type.Bank); - List leaderboardVotesPlayers = leaderboardManager.getLeaderboard(Leaderboard.Type.Votes); - - PlaceholderAPI.registerPlaceholder(plugin, "fabledskyblock_islands", event -> "" + plugin.getVisitManager().getIslands().size()); - - for (int i = 0; i < 10; i++) { - PlaceholderAPI.registerPlaceholder(plugin, "fabledskyblock_leaderboard_votes_" + (i + 1), - event -> { - int index = Integer.valueOf(event.getPlaceholder().replace("fabledskyblock_leaderboard_votes_", "")); - - if (index < leaderboardVotesPlayers.size()) { - Leaderboard leaderboard = leaderboardVotesPlayers.get(index); - Visit visit = leaderboard.getVisit(); - - Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); - String islandOwnerName; - - if (targetPlayer == null) { - islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); - } else { - islandOwnerName = targetPlayer.getName(); - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_votes.Non-empty.Message") - .replace("%position", "" + (index + 1)) - .replace("%player", islandOwnerName) - .replace("%votes", NumberUtil.formatNumberByDecimal(visit.getVoters().size()))); - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_votes.Empty.Message")); - }); - - PlaceholderAPI.registerPlaceholder(plugin, "fabledskyblock_leaderboard_bank_" + (i + 1), - event -> { - int index = Integer.valueOf(event.getPlaceholder().replace("fabledskyblock_leaderboard_bank_", "")); - - if (index < leaderboardBankPlayers.size()) { - Leaderboard leaderboard = leaderboardBankPlayers.get(index); - Visit visit = leaderboard.getVisit(); - - Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); - String islandOwnerName; - - if (targetPlayer == null) { - islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); - } else { - islandOwnerName = targetPlayer.getName(); - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_bank.Non-empty.Message") - .replace("%position", "" + (index + 1)) - .replace("%player", islandOwnerName) - .replace("%balance", NumberUtil.formatNumberByDecimal(visit.getBankBalance()))); - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_bank.Empty.Message")); - }); - - PlaceholderAPI.registerPlaceholder(plugin, "fabledskyblock_leaderboard_level_" + (i + 1), - event -> { - int index = Integer.valueOf(event.getPlaceholder().replace("fabledskyblock_leaderboard_level_", "")); - - if (index < leaderboardLevelPlayers.size()) { - Leaderboard leaderboard = leaderboardLevelPlayers.get(index); - Visit visit = leaderboard.getVisit(); - IslandLevel level = visit.getLevel(); - - Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); - String islandOwnerName; - - if (targetPlayer == null) { - islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); - } else { - islandOwnerName = targetPlayer.getName(); - } - - return ChatColor.translateAlternateColorCodes('&', configLoad - .getString("Placeholder.fabledskyblock_leaderboard_level.Non-empty.Message") - .replace("%position", "" + (index + 1)).replace("%player", islandOwnerName) - .replace("%level", NumberUtil.formatNumberByDecimal(level.getLevel())) - .replace("%points", NumberUtil.formatNumberByDecimal(level.getPoints()))); - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_leaderboard_level.Empty.Message")); - }); - } - - for (String placeholderList : placeholderManager.getPlaceholders()) { - PlaceholderAPI.registerPlaceholder(plugin, placeholderList, event -> { - try { - Player player = event.getPlayer(); - - if (player == null) { - return null; - } - - return placeholderManager.getPlaceholder(player, event.getPlaceholder()); - } catch (Exception ex) { - Bukkit.getLogger().log(Level.WARNING, "[FabledSkyBlock] Exception while retrieving placeholder {}:", event.getPlaceholder()); - Bukkit.getLogger().log(Level.WARNING, "", ex); - return event.getPlaceholder(); - } - }); - } - } -} diff --git a/src/main/java/com/songoda/skyblock/placeholder/PlaceholderManager.java b/src/main/java/com/songoda/skyblock/placeholder/PlaceholderManager.java index 7091d8a5..b9e65053 100644 --- a/src/main/java/com/songoda/skyblock/placeholder/PlaceholderManager.java +++ b/src/main/java/com/songoda/skyblock/placeholder/PlaceholderManager.java @@ -1,452 +1,41 @@ package com.songoda.skyblock.placeholder; -import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.skyblock.SkyBlock; -import com.songoda.skyblock.config.FileManager.Config; -import com.songoda.skyblock.invite.Invite; -import com.songoda.skyblock.island.Island; -import com.songoda.skyblock.island.IslandManager; -import com.songoda.skyblock.island.IslandRole; -import com.songoda.skyblock.island.IslandStatus; -import com.songoda.skyblock.leaderboard.Leaderboard; -import com.songoda.skyblock.leaderboard.LeaderboardManager; -import com.songoda.skyblock.levelling.IslandLevelManager; -import com.songoda.skyblock.upgrade.Upgrade; -import com.songoda.skyblock.upgrade.Upgrade.Type; -import com.songoda.skyblock.utils.NumberUtil; -import com.songoda.skyblock.visit.VisitManager; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; +import com.songoda.skyblock.manager.Manager; +import com.songoda.skyblock.placeholder.hook.PlaceholderAPI; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -public class PlaceholderManager { - - private final SkyBlock plugin; - - private boolean PlaceholderAPI = false; - private boolean MVdWPlaceholderAPI = false; - +public class PlaceholderManager extends Manager { + + private boolean PlaceholderAPIEnabled = false; + public PlaceholderManager(SkyBlock plugin) { - this.plugin = plugin; - + super(plugin); + PluginManager pluginManager = plugin.getServer().getPluginManager(); - + if (pluginManager.getPlugin("PlaceholderAPI") != null) { - PlaceholderAPI = true; - } - - if (pluginManager.getPlugin("MVdWPlaceholderAPI") != null) { - MVdWPlaceholderAPI = true; + PlaceholderAPIEnabled = true; } } - + public void registerPlaceholders() { - if (PlaceholderAPI) { - new EZPlaceholder(plugin).register(); - } - - if (MVdWPlaceholderAPI) { - new MVdWPlaceholder(plugin).register(); + if (PlaceholderAPIEnabled) { + new PlaceholderAPI(plugin).register(); } } - + public boolean isPlaceholderAPIEnabled() { - return PlaceholderAPI; + return PlaceholderAPIEnabled; } - - public boolean isMVdWPlaceholderAPIEnabled() { - return MVdWPlaceholderAPI; - } - - public String getPlaceholder(Player player, String placeholder) { - IslandManager islandManager = plugin.getIslandManager(); - VisitManager visitManager = plugin.getVisitManager(); - IslandLevelManager levellingManager = plugin.getLevellingManager(); - - Island island = islandManager.getIsland(player); - - Config config = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "language.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); - - if (placeholder.equalsIgnoreCase("fabledskyblock_island_exists")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_exists.Not-exists.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_exists.Exists.Message")); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_isopen")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_isopen.Empty.Message")); - } else { - if (island.getStatus().equals(IslandStatus.OPEN)) { // TODO Update to Status - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_isopen.Open.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_isopen.Closed.Message")); - } - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_size")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_size.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_size.Non-empty.Message") - .replace("%placeholder", "" + island.getSize())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_radius")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_radius.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_radius.Non-empty.Message") - .replace("%placeholder", "" + island.getRadius())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_level")) { - return island == null || island.getLevel() == null ? "0": Long.toString(island.getLevel().getLevel()); - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_level_formatted")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_level_formatted.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_level_formatted.Non-empty.Message").replace( - "%placeholder", "" + NumberUtil.formatNumberBySuffix(island.getLevel().getLevel()))); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_points")) { - return island == null ? "0": Long.toString(island.getLevel().getPoints()); - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_votes")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_votes.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_votes.Non-empty.Message") - .replace("%placeholder", "" + visitManager.getIslands().get(player.getUniqueId()).getVoters().size())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_role")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_role.Empty.Message")); - } else { - for (IslandRole roleList : IslandRole.values()) { - if (island.hasRole(roleList, player.getUniqueId())) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_role.Non-empty.Message") - .replace("%placeholder", plugin.getLocalizationManager().getLocalizationFor(IslandRole.class).getLocale(roleList))); - } - } - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_owner")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_owner.Empty.Message")); - } else { - UUID islandOwnerUUID = island.getOwnerUUID(); - Player targetPlayer = Bukkit.getServer().getPlayer(islandOwnerUUID); - - if (targetPlayer == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_owner.Non-empty.Other.Message").replace( - "%placeholder", Bukkit.getServer().getOfflinePlayer(islandOwnerUUID).getName())); - } else { - if (targetPlayer.getName().equals(player.getName())) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_owner.Non-empty.Yourself.Message") - .replace("%placeholder", targetPlayer.getName())); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_owner.Non-empty.Other.Message") - .replace("%placeholder", targetPlayer.getName())); - } - } - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_biome")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_biome.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_biome.Non-empty.Message") - .replace("%placeholder", island.getBiomeName())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_time")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_time.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_time.Non-empty.Message") - .replace("%placeholder", "" + island.getTime())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_weather")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_weather.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_weather.Non-empty.Message") - .replace("%placeholder", "" + island.getWeatherName())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_bans")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_bans.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_bans.Non-empty.Message") - .replace("%placeholder", "" + island.getBan().getBans().size())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_members_total")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_members_total.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_members_total.Non-empty.Message") - .replace("%placeholder", "" + (island.getRole(IslandRole.Member).size() - + island.getRole(IslandRole.Operator).size() + 1))); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_members")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_members.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_members.Non-empty.Message") - .replace("%placeholder", "" + island.getRole(IslandRole.Member).size())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_maxmembers")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_maxmembers.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_maxmembers.Non-empty.Message") - .replace("%placeholder", "" + island.getMaxMembers())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_operators")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_operators.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_operators.Non-empty.Message") - .replace("%placeholder", "" + island.getRole(IslandRole.Operator).size())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_coops")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_coops.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_coops.Non-empty.Message") - .replace("%placeholder", "" + islandManager.getCoopPlayersAtIsland(island).size())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_coops_total")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_coops_total.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_coops_total.Non-empty.Message") - .replace("%placeholder", "" + island.getCoopPlayers().size())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_visitors")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_visitors.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_visitors.Non-empty.Message") - .replace("%placeholder", "" + islandManager.getVisitorsAtIsland(island).size())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_invites")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_invites.Empty.Message")); - } else { - Map invites = plugin.getInviteManager().getInvites(); - int invitedPlayers = 0; - - for (int i = 0; i < invites.size(); i++) { - UUID uuid = (UUID) invites.keySet().toArray()[i]; - Invite invite = invites.get(uuid); - - if (invite.getOwnerUUID().equals(island.getOwnerUUID())) { - invitedPlayers++; - } - } - - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_invites.Non-empty.Message") - .replace("%placeholder", "" + invitedPlayers)); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_bank_balance")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_bank_balance.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_bank_balance.Non-empty.Message")) - .replace("%placeholder", "" + NumberUtil.formatNumberByDecimal(island.getBankBalance())); - } - } else if (placeholder.equalsIgnoreCase("fabledskyblock_island_bank_balance_formatted")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_bank_balance_formatted.Empty.Message")); - } else { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_bank_balance_formatted.Non-empty.Message")) - .replace("%placeholder", "" + NumberUtil.formatNumberBySuffix((long) island.getBankBalance())); - } - } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_leaderboard_level_rank")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_level_rank.Empty.Message")); - } else { - LeaderboardManager leaderboardManager = plugin.getLeaderboardManager(); - int rank = leaderboardManager.getPlayerIslandLeaderboardPosition(player, Leaderboard.Type.Level); - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_level_rank.Non-empty.Message") - .replace("%placeholder", "" + rank)); - } - } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_leaderboard_bank_rank")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_bank_rank.Empty.Message")); - } else { - LeaderboardManager leaderboardManager = plugin.getLeaderboardManager(); - int rank = leaderboardManager.getPlayerIslandLeaderboardPosition(player, Leaderboard.Type.Bank); - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_bank_rank.Non-empty.Message") - .replace("%placeholder", "" + rank)); - } - } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_leaderboard_votes_rank")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_votes_rank.Empty.Message")); - } else { - LeaderboardManager leaderboardManager = plugin.getLeaderboardManager(); - int rank = leaderboardManager.getPlayerIslandLeaderboardPosition(player, Leaderboard.Type.Votes); - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_leaderboard_votes_rank.Non-empty.Message") - .replace("%placeholder", "" + rank)); - } - } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_level_block_count_")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_level_block_count.Empty.Message")); - } else { - String materialName = placeholder.replace("fabledskyblock_island_level_block_count_", "").toUpperCase(); - CompatibleMaterial materials = CompatibleMaterial.getMaterial(materialName); - if (materials == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_level_block_count.Invalid.Message")); - } else { - long blockCount = island.getLevel().getMaterialAmount(materials.name()); - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_level_block_count.Non-empty.Message") - .replace("%placeholder", NumberUtil.formatNumberByDecimal(blockCount))); - } - } - } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_level_block_points_")) { - if (island == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_level_block_points.Empty.Message")); - } else { - String materialName = placeholder.replace("fabledskyblock_island_level_block_points_", "").toUpperCase(); - CompatibleMaterial materials = CompatibleMaterial.getMaterial(materialName); - if (materials == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_level_block_points.Invalid.Message")); - } else { - long blockPoints = island.getLevel().getMaterialPoints(materials.name()); - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_island_level_block_points.Non-empty.Message") - .replace("%placeholder", NumberUtil.formatNumberByDecimal(blockPoints))); - } - } - } else if (placeholder.toLowerCase().startsWith("fabledskyblock_level_block_value_")) { - String materialName = placeholder.replace("fabledskyblock_level_block_value_", "").toUpperCase(); - CompatibleMaterial materials = CompatibleMaterial.getMaterial(materialName); - if (materials == null) { - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_level_block_value.Invalid.Message")); - } else { - double blockValue = levellingManager.getWorth(materials); - return ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Placeholder.fabledskyblock_level_block_value.Non-empty.Message") - .replace("%placeholder", NumberUtil.formatNumberByDecimal(blockValue))); - } - } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_has_upgrade_")) { - Type type; - - final String lower = placeholder.replace("fabledskyblock_island_has_upgrade_", "").toLowerCase(); - - if (lower.isEmpty()) return ""; - - final String toParse = lower.substring(0, 1).toUpperCase() + lower.substring(1); - - try { - type = Upgrade.Type.valueOf(toParse); - } catch (IllegalArgumentException ignored) { - type = null; - } - - if (type == null) return "Invalid type '" + toParse + "'"; - - return Boolean.toString(island.hasUpgrade(type)); + + public String parsePlaceholders(Player player, String message) { + String retValue = ""; + + if(PlaceholderAPIEnabled) { + retValue = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, message); } - - return ""; - } - - public List getPlaceholders() { - List placeholders = new ArrayList<>(25); - placeholders.add("fabledskyblock_island_exists"); - placeholders.add("fabledskyblock_island_isopen"); - placeholders.add("fabledskyblock_island_size"); - placeholders.add("fabledskyblock_island_radius"); - placeholders.add("fabledskyblock_island_level"); - placeholders.add("fabledskyblock_island_level_formatted"); - placeholders.add("fabledskyblock_island_points"); - placeholders.add("fabledskyblock_island_votes"); - placeholders.add("fabledskyblock_island_role"); - placeholders.add("fabledskyblock_island_owner"); - placeholders.add("fabledskyblock_island_biome"); - placeholders.add("fabledskyblock_island_time"); - placeholders.add("fabledskyblock_island_weather"); - placeholders.add("fabledskyblock_island_bans"); - placeholders.add("fabledskyblock_island_members_total"); - placeholders.add("fabledskyblock_island_members"); - placeholders.add("fabledskyblock_island_maxmembers"); - placeholders.add("fabledskyblock_island_operators"); - placeholders.add("fabledskyblock_island_coops"); - placeholders.add("fabledskyblock_island_coops_total"); - placeholders.add("fabledskyblock_island_visitors"); - placeholders.add("fabledskyblock_island_invites"); - placeholders.add("fabledskyblock_island_bank_balance"); - placeholders.add("fabledskyblock_island_leaderboard_level_rank"); - placeholders.add("fabledskyblock_island_leaderboard_bank_rank"); - placeholders.add("fabledskyblock_island_leaderboard_votes_rank"); - //placeholders.add("fabledskyblock_island_level_block_count_"); - //placeholders.add("fabledskyblock_island_level_block_points_"); - //placeholders.add("fabledskyblock_level_block_value_"); - - return placeholders; + return retValue; } } diff --git a/src/main/java/com/songoda/skyblock/placeholder/PlaceholderProcessor.java b/src/main/java/com/songoda/skyblock/placeholder/PlaceholderProcessor.java new file mode 100644 index 00000000..6ffb3e1f --- /dev/null +++ b/src/main/java/com/songoda/skyblock/placeholder/PlaceholderProcessor.java @@ -0,0 +1,417 @@ +package com.songoda.skyblock.placeholder; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.config.FileManager; +import com.songoda.skyblock.invite.Invite; +import com.songoda.skyblock.island.Island; +import com.songoda.skyblock.island.IslandManager; +import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.island.IslandStatus; +import com.songoda.skyblock.leaderboard.Leaderboard; +import com.songoda.skyblock.leaderboard.LeaderboardManager; +import com.songoda.skyblock.levelling.IslandLevelManager; +import com.songoda.skyblock.upgrade.Upgrade; +import com.songoda.skyblock.utils.NumberUtil; +import com.songoda.skyblock.visit.VisitManager; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +import java.io.File; +import java.util.Map; +import java.util.UUID; + +public class PlaceholderProcessor { + + public String processPlaceholder(Player player, String placeholder) { + SkyBlock plugin = SkyBlock.getInstance(); + IslandManager islandManager = plugin.getIslandManager(); + VisitManager visitManager = plugin.getVisitManager(); + IslandLevelManager levellingManager = plugin.getLevellingManager(); + + FileManager fileManager = plugin.getFileManager(); + FileConfiguration placeholdersLoad = fileManager.getConfig( + new File(plugin.getDataFolder(), "placeholders.yml")).getFileConfiguration(); + + if(placeholdersLoad == null) { + Bukkit.broadcastMessage("ABC"); + return "Error"; + } + + Island island = islandManager.getIsland(player); + + String returnValue = null; + + if(player == null || placeholder == null) { + return ""; + } + + switch (placeholder.toLowerCase()) { + case "fabledskyblock_island_exists": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_exists.Not-exists.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_exists.Exists.Message")); + } + break; + case "fabledskyblock_island_isopen": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_isopen.Empty.Message")); + } else { + if (island.getStatus().equals(IslandStatus.OPEN)) { // TODO Update to Status + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_isopen.Open.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_isopen.Closed.Message")); + } + } + break; + case "fabledskyblock_island_size": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_size.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_size.Non-empty.Message") + .replace("%placeholder", "" + island.getSize())); + } + break; + case "fabledskyblock_island_radius": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_radius.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_radius.Non-empty.Message") + .replace("%placeholder", "" + island.getRadius())); + } + break; + case "fabledskyblock_island_level": + returnValue = island == null || island.getLevel() == null ? "0" : Long.toString(island.getLevel().getLevel()); + break; + case "fabledskyblock_island_level_formatted": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_level_formatted.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_level_formatted.Non-empty.Message").replace( + "%placeholder", "" + NumberUtil.formatNumberBySuffix(island.getLevel().getLevel()))); + } + break; + case "fabledskyblock_island_points": + returnValue = island == null ? "0" : Long.toString(island.getLevel().getPoints()); + break; + case "fabledskyblock_island_votes": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_votes.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_votes.Non-empty.Message") + .replace("%placeholder", "" + visitManager.getIslands().get(player.getUniqueId()).getVoters().size())); + } + break; + case "fabledskyblock_island_role": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_role.Empty.Message")); + } else { + for (IslandRole roleList : IslandRole.values()) { + if (island.hasRole(roleList, player.getUniqueId())) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_role.Non-empty.Message") + .replace("%placeholder", plugin.getLocalizationManager().getLocalizationFor(IslandRole.class).getLocale(roleList))); + } + } + } + break; + case "fabledskyblock_island_owner": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_owner.Empty.Message")); + } else { + UUID islandOwnerUUID = island.getOwnerUUID(); + Player targetPlayer = Bukkit.getServer().getPlayer(islandOwnerUUID); + + if (targetPlayer == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_owner.Non-empty.Other.Message").replace( + "%placeholder", Bukkit.getServer().getOfflinePlayer(islandOwnerUUID).getName())); + } else { + if (targetPlayer.getName().equals(player.getName())) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_owner.Non-empty.Yourself.Message") + .replace("%placeholder", targetPlayer.getName())); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_owner.Non-empty.Other.Message") + .replace("%placeholder", targetPlayer.getName())); + } + } + } + break; + case "fabledskyblock_island_biome": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_biome.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_biome.Non-empty.Message") + .replace("%placeholder", island.getBiomeName())); + } + break; + case "fabledskyblock_island_time": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_time.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_time.Non-empty.Message") + .replace("%placeholder", "" + island.getTime())); + } + break; + case "fabledskyblock_island_weather": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_weather.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_weather.Non-empty.Message") + .replace("%placeholder", "" + island.getWeatherName())); + } + break; + case "fabledskyblock_island_bans": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_bans.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_bans.Non-empty.Message") + .replace("%placeholder", "" + island.getBan().getBans().size())); + } + break; + case "fabledskyblock_island_members_total": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_members_total.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_members_total.Non-empty.Message") + .replace("%placeholder", "" + (island.getRole(IslandRole.Member).size() + + island.getRole(IslandRole.Operator).size() + 1))); + } + break; + case "fabledskyblock_island_members": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_members.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_members.Non-empty.Message") + .replace("%placeholder", "" + island.getRole(IslandRole.Member).size())); + } + break; + case "fabledskyblock_island_maxmembers": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_maxmembers.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_maxmembers.Non-empty.Message") + .replace("%placeholder", "" + island.getMaxMembers())); + } + break; + case "fabledskyblock_island_operators": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_operators.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_operators.Non-empty.Message") + .replace("%placeholder", "" + island.getRole(IslandRole.Operator).size())); + } + break; + case "fabledskyblock_island_coops": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_coops.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_coops.Non-empty.Message") + .replace("%placeholder", "" + islandManager.getCoopPlayersAtIsland(island).size())); + } + break; + case "fabledskyblock_island_coops_total": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_coops_total.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_coops_total.Non-empty.Message") + .replace("%placeholder", "" + island.getCoopPlayers().size())); + } + break; + case "fabledskyblock_island_visitors": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_visitors.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_visitors.Non-empty.Message") + .replace("%placeholder", "" + islandManager.getVisitorsAtIsland(island).size())); + } + break; + case "fabledskyblock_island_invites": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_invites.Empty.Message")); + } else { + Map invites = plugin.getInviteManager().getInvites(); + int invitedPlayers = 0; + + for (int i = 0; i < invites.size(); i++) { + UUID uuid = (UUID) invites.keySet().toArray()[i]; + Invite invite = invites.get(uuid); + + if (invite.getOwnerUUID().equals(island.getOwnerUUID())) { + invitedPlayers++; + } + } + + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_invites.Non-empty.Message") + .replace("%placeholder", "" + invitedPlayers)); + } + break; + case "fabledskyblock_island_bank_balance": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_bank_balance.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_bank_balance.Non-empty.Message")) + .replace("%placeholder", "" + NumberUtil.formatNumberByDecimal(island.getBankBalance())); + } + break; + case "fabledskyblock_island_bank_balance_formatted": + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_bank_balance_formatted.Empty.Message")); + } else { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholders.fabledskyblock_island_bank_balance_formatted.Non-empty.Message")) + .replace("%placeholder", "" + NumberUtil.formatNumberBySuffix((long) island.getBankBalance())); + } + break; + } + + if(returnValue == null) { + if (placeholder.toLowerCase().startsWith("fabledskyblock_island_leaderboard_level_rank")) { + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_leaderboard_level_rank.Empty.Message")); + } else { + LeaderboardManager leaderboardManager = plugin.getLeaderboardManager(); + int rank = leaderboardManager.getPlayerIslandLeaderboardPosition(player, Leaderboard.Type.Level); + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_leaderboard_level_rank.Non-empty.Message") + .replace("%placeholder", "" + rank)); + } + } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_leaderboard_bank_rank")) { + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_leaderboard_bank_rank.Empty.Message")); + } else { + LeaderboardManager leaderboardManager = plugin.getLeaderboardManager(); + int rank = leaderboardManager.getPlayerIslandLeaderboardPosition(player, Leaderboard.Type.Bank); + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_leaderboard_bank_rank.Non-empty.Message") + .replace("%placeholder", "" + rank)); + } + } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_leaderboard_votes_rank")) { + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_leaderboard_votes_rank.Empty.Message")); + } else { + LeaderboardManager leaderboardManager = plugin.getLeaderboardManager(); + int rank = leaderboardManager.getPlayerIslandLeaderboardPosition(player, Leaderboard.Type.Votes); + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_leaderboard_votes_rank.Non-empty.Message") + .replace("%placeholder", "" + rank)); + } + } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_level_block_count_")) { + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_level_block_count.Empty.Message")); + } else { + String materialName = placeholder.replace("fabledskyblock_island_level_block_count_", "").toUpperCase(); + CompatibleMaterial materials = CompatibleMaterial.getMaterial(materialName); + if (materials == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_level_block_count.Invalid.Message")); + } else { + long blockCount = island.getLevel().getMaterialAmount(materials.name()); + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_level_block_count.Non-empty.Message") + .replace("%placeholder", NumberUtil.formatNumberByDecimal(blockCount))); + } + } + } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_level_block_points_")) { + if (island == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_level_block_points.Empty.Message")); + } else { + String materialName = placeholder.replace("fabledskyblock_island_level_block_points_", "").toUpperCase(); + CompatibleMaterial materials = CompatibleMaterial.getMaterial(materialName); + if (materials == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_level_block_points.Invalid.Message")); + } else { + long blockPoints = island.getLevel().getMaterialPoints(materials.name()); + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_island_level_block_points.Non-empty.Message") + .replace("%placeholder", NumberUtil.formatNumberByDecimal(blockPoints))); + } + } + } else if (placeholder.toLowerCase().startsWith("fabledskyblock_level_block_value_")) { + String materialName = placeholder.replace("fabledskyblock_level_block_value_", "").toUpperCase(); + CompatibleMaterial materials = CompatibleMaterial.getMaterial(materialName); + if (materials == null) { + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_level_block_value.Invalid.Message")); + } else { + double blockValue = levellingManager.getWorth(materials); + returnValue = ChatColor.translateAlternateColorCodes('&', + placeholdersLoad.getString("Placeholder.fabledskyblock_level_block_value.Non-empty.Message") + .replace("%placeholder", NumberUtil.formatNumberByDecimal(blockValue))); + } + } else if (placeholder.toLowerCase().startsWith("fabledskyblock_island_has_upgrade_")) { + Upgrade.Type type; + + final String lower = placeholder.replace("fabledskyblock_island_has_upgrade_", "").toLowerCase(); + + if (!lower.isEmpty()) { + final String toParse = lower.substring(0, 1).toUpperCase() + lower.substring(1); + + try { + type = Upgrade.Type.valueOf(toParse); + returnValue = Boolean.toString(island.hasUpgrade(type)); + } catch (IllegalArgumentException ignored) { + returnValue = "Invalid type '" + toParse + "'"; + } + } else { + returnValue = ""; + } + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/songoda/skyblock/placeholder/wip/hook/PlaceholderAPI.java b/src/main/java/com/songoda/skyblock/placeholder/hook/PlaceholderAPI.java similarity index 73% rename from src/main/java/com/songoda/skyblock/placeholder/wip/hook/PlaceholderAPI.java rename to src/main/java/com/songoda/skyblock/placeholder/hook/PlaceholderAPI.java index f11fb13b..cddb05f3 100644 --- a/src/main/java/com/songoda/skyblock/placeholder/wip/hook/PlaceholderAPI.java +++ b/src/main/java/com/songoda/skyblock/placeholder/hook/PlaceholderAPI.java @@ -1,22 +1,25 @@ -package com.songoda.skyblock.placeholder.wip.hook; +package com.songoda.skyblock.placeholder.hook; import com.songoda.skyblock.SkyBlock; -import com.songoda.skyblock.placeholder.wip.PlaceholderProcessor; +import com.songoda.skyblock.placeholder.PlaceholderProcessor; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import org.bukkit.entity.Player; public class PlaceholderAPI extends PlaceholderExpansion { private final SkyBlock plugin; + private final PlaceholderProcessor placeholderProcessor; public PlaceholderAPI(SkyBlock plugin) { this.plugin = plugin; + this.placeholderProcessor = new PlaceholderProcessor(); } public String getIdentifier() { return "fabledskyblock"; } + @Deprecated public String getPlugin() { return null; } @@ -35,6 +38,6 @@ public class PlaceholderAPI extends PlaceholderExpansion { public String onPlaceholderRequest(Player player, String identifier) { - return PlaceholderProcessor.processPlaceholder(player, "fabledskyblock_" + identifier); + return placeholderProcessor.processPlaceholder(player, "fabledskyblock_" + identifier); } } diff --git a/src/main/java/com/songoda/skyblock/placeholder/wip/Placeholder.java b/src/main/java/com/songoda/skyblock/placeholder/wip/Placeholder.java deleted file mode 100644 index 6debe567..00000000 --- a/src/main/java/com/songoda/skyblock/placeholder/wip/Placeholder.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.songoda.skyblock.placeholder.wip; - -public class Placeholder { - - private final String placeholder; - private final String result; - - public Placeholder(String placeholder, String result) { - this.placeholder = placeholder; - this.result = result; - } - - public String getPlaceholder() { - return placeholder; - } - - public String getResult() { - return result; - } -} \ No newline at end of file diff --git a/src/main/java/com/songoda/skyblock/placeholder/wip/PlaceholderManager.java b/src/main/java/com/songoda/skyblock/placeholder/wip/PlaceholderManager.java deleted file mode 100644 index b3c6ec20..00000000 --- a/src/main/java/com/songoda/skyblock/placeholder/wip/PlaceholderManager.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.songoda.skyblock.placeholder.wip; - -import com.songoda.skyblock.SkyBlock; -import com.songoda.skyblock.manager.Manager; -import org.bukkit.entity.Player; - -public class PlaceholderManager extends Manager { - - public PlaceholderManager(SkyBlock plugin) { - super(plugin); - } - - public String parsePlaceholders(Player player, String message) { - return ""; - } -} diff --git a/src/main/java/com/songoda/skyblock/placeholder/wip/PlaceholderProcessor.java b/src/main/java/com/songoda/skyblock/placeholder/wip/PlaceholderProcessor.java deleted file mode 100644 index dda79fd7..00000000 --- a/src/main/java/com/songoda/skyblock/placeholder/wip/PlaceholderProcessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.songoda.skyblock.placeholder.wip; - -import org.bukkit.entity.Player; - -public class PlaceholderProcessor { - - public static String processPlaceholder(Player player, String placeholder) { - if(player == null || placeholder == null) { - return ""; - } - return "To be implemented"; - } -} diff --git a/src/main/java/com/songoda/skyblock/placeholder/wip/hook/MVdWPlaceholder.java b/src/main/java/com/songoda/skyblock/placeholder/wip/hook/MVdWPlaceholder.java deleted file mode 100644 index 24ef95db..00000000 --- a/src/main/java/com/songoda/skyblock/placeholder/wip/hook/MVdWPlaceholder.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.songoda.skyblock.placeholder.wip.hook; - -public class MVdWPlaceholder { -} diff --git a/src/main/java/com/songoda/skyblock/playerdata/PlayerDataManager.java b/src/main/java/com/songoda/skyblock/playerdata/PlayerDataManager.java index e8ce4783..d1e43d31 100644 --- a/src/main/java/com/songoda/skyblock/playerdata/PlayerDataManager.java +++ b/src/main/java/com/songoda/skyblock/playerdata/PlayerDataManager.java @@ -8,7 +8,6 @@ import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.*; import com.songoda.skyblock.message.MessageManager; -import com.songoda.skyblock.scoreboard.Scoreboard; import com.songoda.skyblock.scoreboard.ScoreboardManager; import com.songoda.skyblock.utils.player.OfflinePlayer; import com.songoda.skyblock.utils.world.LocationUtil; @@ -193,23 +192,12 @@ public class PlayerDataManager { ScoreboardManager scoreboardManager = plugin.getScoreboardManager(); if (scoreboardManager != null) { - for (Player all : Bukkit.getOnlinePlayers()) { - PlayerData targetPlayerData = getPlayerData(all); + for (Player loopPlayer : Bukkit.getOnlinePlayers()) { + PlayerData targetPlayerData = getPlayerData(loopPlayer); - if (targetPlayerData.getOwner() != null && targetPlayerData.getOwner().equals(island.getOwnerUUID())) { - Scoreboard scoreboard = scoreboardManager.getScoreboard(all); - - if ((island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() + 1) == 1) { - scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Scoreboard.Island.Solo.Displayname"))); - scoreboard.setDisplayList(configLoad.getStringList("Scoreboard.Island.Solo.Occupied.Displaylines")); - } else { - scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Scoreboard.Island.Team.Displayname"))); - scoreboard.setDisplayList(configLoad.getStringList("Scoreboard.Island.Team.Occupied.Displaylines")); - - - } - - scoreboard.run(); + if (targetPlayerData.getOwner() != null && + targetPlayerData.getOwner().equals(island.getOwnerUUID())) { + scoreboardManager.updatePlayerScoreboardType(loopPlayer); } } } diff --git a/src/main/java/com/songoda/skyblock/scoreboard/Board.java b/src/main/java/com/songoda/skyblock/scoreboard/Board.java new file mode 100644 index 00000000..bb50c5a9 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/scoreboard/Board.java @@ -0,0 +1,118 @@ +package com.songoda.skyblock.scoreboard; + +import com.songoda.core.compatibility.ServerVersion; +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.placeholder.PlaceholderManager; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; + +import java.util.HashMap; + +class Board { + + private final Player player; + private final SkyBlock plugin; + public Scoreboard board; + private final Objective objective; + + private final HashMap cache = new HashMap<>(); + + public Board(SkyBlock plugin, Player player, int lineCount) { + this.player = player; + this.plugin = plugin; + this.board = this.plugin.getServer().getScoreboardManager().getNewScoreboard(); + this.objective = this.board.registerNewObjective("sb1", "sb2"); + this.objective.setDisplaySlot(DisplaySlot.SIDEBAR); + this.objective.setDisplayName("..."); + + for(int i = 0; i < lineCount;i++) { + Team t = this.board.registerNewTeam(i + ""); + t.addEntry(ChatColor.values()[i] + ""); + + this.objective.getScore(ChatColor.values()[i] + "").setScore(lineCount - i); + } + + //this.player.setScoreboard(this.board); + } + + public void setTitle(String string) { + PlaceholderManager placeholderManager = plugin.getPlaceholderManager(); + + if(string == null) string = ""; + string = placeholderManager.parsePlaceholders(player, string); + + if (!cache.containsKey(-1) || !cache.get(-1).equals(string)) { + cache.remove(-1); + cache.put(-1, string); + objective.setDisplayName(string); + } + } + + public void setLine(int line, String string) { + Team t = board.getTeam(String.valueOf(line)); + if(string == null) string = ""; + + if ((!cache.containsKey(line) || !cache.get(line).equals(string)) && t != null) { + cache.remove(line); + cache.put(line, string); + + ScoreboardLine parts; + + if (ServerVersion.isServerVersionAbove(ServerVersion.V1_8)) { + parts = convertIntoPieces(string, 16); + } else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)){ + parts = convertIntoPieces(string, 64); + } else { + parts = convertIntoPieces(string, 8); + } + + t.setPrefix(parts.getPrefix()); + t.setSuffix(parts.getSuffix()); + } + } + + private ScoreboardLine convertIntoPieces(String line, int allowed_line_size) { + String prefixLine = line.substring(0, Math.min(line.length(), allowed_line_size)); + String suffixLine = ""; + if(line.length() > allowed_line_size) { + suffixLine = line.substring(allowed_line_size); + } + + if (prefixLine.endsWith(String.valueOf(ChatColor.COLOR_CHAR))) { + prefixLine = ChatColor.translateAlternateColorCodes( + ChatColor.COLOR_CHAR, prefixLine.substring(0, prefixLine.length() - 1)); + suffixLine = ChatColor.translateAlternateColorCodes( + ChatColor.COLOR_CHAR, ChatColor.COLOR_CHAR + suffixLine); + } else { + String lastColorCodes; + + if (prefixLine.contains(String.valueOf(ChatColor.COLOR_CHAR))) { + String[] colorCodes = prefixLine.split(String.valueOf(ChatColor.COLOR_CHAR)); + String lastColorCodeText = colorCodes[colorCodes.length - 1]; + lastColorCodes = ChatColor.COLOR_CHAR + + lastColorCodeText.substring(0, Math.min(lastColorCodeText.length(), 1)); + + if ((colorCodes.length >= 2) && + (lastColorCodes.equals(String.valueOf(ChatColor.BOLD)) || + lastColorCodes.equals(String.valueOf(ChatColor.STRIKETHROUGH)) || + lastColorCodes.equals(String.valueOf(ChatColor.UNDERLINE)) || + lastColorCodes.equals(String.valueOf(ChatColor.ITALIC)) || + lastColorCodes.equals(String.valueOf(ChatColor.MAGIC)))) { + lastColorCodeText = colorCodes[colorCodes.length - 2]; + lastColorCodes = ChatColor.COLOR_CHAR + + lastColorCodeText.substring(0, Math.min(lastColorCodeText.length(), 1)) + lastColorCodes; + } + } else { + lastColorCodes = ChatColor.WHITE.toString(); + } + + prefixLine = ChatColor.translateAlternateColorCodes(ChatColor.COLOR_CHAR, prefixLine); + suffixLine = ChatColor.translateAlternateColorCodes(ChatColor.COLOR_CHAR, lastColorCodes + suffixLine); + } + return new ScoreboardLine(prefixLine, suffixLine); + } +} diff --git a/src/main/java/com/songoda/skyblock/scoreboard/Driver.java b/src/main/java/com/songoda/skyblock/scoreboard/Driver.java new file mode 100644 index 00000000..7742f8bc --- /dev/null +++ b/src/main/java/com/songoda/skyblock/scoreboard/Driver.java @@ -0,0 +1,92 @@ +package com.songoda.skyblock.scoreboard; + +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.config.FileManager; +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +class Driver extends BukkitRunnable { + + private final SkyBlock plugin; + + private final Row title; + private final List rows; + private final List holders; + private final ScoreboardType boardType; + + public Driver(SkyBlock plugin, ScoreboardType boardType) { + this.plugin = plugin; + FileManager fileManager = plugin.getFileManager(); + FileConfiguration scoreboardLoad = fileManager.getConfig( + new File(plugin.getDataFolder(), "scoreboard.yml")).getFileConfiguration(); + + rows = new ArrayList<>(); + holders = new ArrayList<>(); + this.boardType = boardType; + + ConfigurationSection config = scoreboardLoad.getConfigurationSection(boardType.getConfigSection()); + + if(config != null) { + List lines = config.getStringList("Title.Content"); + int interval = config.getInt("Title.Interval"); + title = new Row(lines, interval); + + for(int i = 1; i<16; i++) { + List rowLines = config.getStringList("Rows." + i + ".Content"); + if(!rowLines.isEmpty()) { + Row row = new Row(rowLines, config.getInt("Interval")); + rows.add(row); + } + } + } else { + title = new Row(new ArrayList<>(), 0); + } + } + + public List getRows() { + return rows; + } + + public Row getTitle() { + return title; + } + + public void registerHolder(Holder holder) { + holders.add(holder); + } + + public void unregisterHolder(Holder holder) { + holders.remove(holder); + } + + public void unregisterHolder(Player player) { + for(Holder holder : holders) + if(holder.player.equals(player)) { + holders.remove(holder); + break; + } + } + + @Override + public void run() { + title.update(); + for(Row row : rows) { + row.update(); + } + + for(Holder holder : holders) { + holder.update(); + } + } + + public ScoreboardType getBoardType() { + return boardType; + } +} diff --git a/src/main/java/com/songoda/skyblock/scoreboard/Holder.java b/src/main/java/com/songoda/skyblock/scoreboard/Holder.java new file mode 100644 index 00000000..a06df835 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/scoreboard/Holder.java @@ -0,0 +1,48 @@ +package com.songoda.skyblock.scoreboard; + +import com.songoda.skyblock.SkyBlock; +import com.songoda.skyblock.placeholder.PlaceholderManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +class Holder { + + private final SkyBlock plugin; + + private final Driver driver; + public final Player player; + + private final Board board; + + public Holder(SkyBlock plugin, Driver driver, Player player) { + this.plugin = plugin; + this.driver = driver; + this.player = player; + + board = new Board(plugin, player, driver.getRows().size()); + update(); + } + + public void update() { + PlaceholderManager placeholderManager = plugin.getPlaceholderManager(); + ScoreboardManager scoreboardManager = plugin.getScoreboardManager(); + + if(scoreboardManager != null) { + if (!scoreboardManager.isPlayerDisabled(player)) { + board.setTitle(driver.getTitle().getLine()); + + int count = 0; + for(Row row : driver.getRows()) { + String line = placeholderManager.parsePlaceholders(player, row.getLine()); + board.setLine(count, line); + count++; + } + + this.player.setScoreboard(board.board); + } else { + this.player.setScoreboard(plugin.getServer().getScoreboardManager().getNewScoreboard()); + } + } + } + +} diff --git a/src/main/java/com/songoda/skyblock/scoreboard/Row.java b/src/main/java/com/songoda/skyblock/scoreboard/Row.java new file mode 100644 index 00000000..a9e7803e --- /dev/null +++ b/src/main/java/com/songoda/skyblock/scoreboard/Row.java @@ -0,0 +1,54 @@ +package com.songoda.skyblock.scoreboard; + +import com.songoda.core.utils.TextUtils; + +import java.util.List; + +class Row { + + private final int interval; + private final List lines; + private String line; + private int current; + private int count; + + public boolean static_line; + + public Row(List lines, int interval) { + this.lines = lines; + this.interval = interval; + this.current = 1; + this.count = 0; + + if(interval < 0) { + static_line = true; + } else { + static_line = false; + } + + if(lines.isEmpty()) { + line = ""; + } else { + line = TextUtils.formatText(lines.get(0)); + } + } + + public void update() { + if (!static_line && !lines.isEmpty()) { + if (count >= interval) { + count = 0; + current++; + if (current >= lines.size()) + current = 0; + line = TextUtils.formatText(lines.get(current)); + } else { + count++; + } + } + } + + public String getLine() { + return this.line; + } + +} diff --git a/src/main/java/com/songoda/skyblock/scoreboard/Scoreboard.java b/src/main/java/com/songoda/skyblock/scoreboard/Scoreboard.java deleted file mode 100644 index 134d2588..00000000 --- a/src/main/java/com/songoda/skyblock/scoreboard/Scoreboard.java +++ /dev/null @@ -1,224 +0,0 @@ -package com.songoda.skyblock.scoreboard; - -import com.songoda.core.compatibility.ServerVersion; -import com.songoda.skyblock.SkyBlock; -import com.songoda.skyblock.island.Island; -import com.songoda.skyblock.island.IslandLevel; -import com.songoda.skyblock.island.IslandManager; -import com.songoda.skyblock.island.IslandRole; -import com.songoda.skyblock.localization.type.Localization; -import com.songoda.skyblock.placeholder.PlaceholderManager; -import com.songoda.skyblock.utils.NumberUtil; -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.scheduler.BukkitTask; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Team; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class Scoreboard { - - private final SkyBlock plugin; - private final Player player; - - private String displayName; - private List displayList; - - private BukkitTask scheduler; - - public Scoreboard(SkyBlock plugin, Player player) { - this.plugin = plugin; - this.player = player; - displayList = new ArrayList<>(); - } - - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - - public void setDisplayList(List displayList) { - this.displayList = displayList; - } - - public void run() { - if (scheduler != null) scheduler.cancel(); - - new BukkitRunnable() { - @Override - public void run() { - final org.bukkit.scoreboard.Scoreboard scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); - - new BukkitRunnable() { - @Override - @SuppressWarnings("deprecation") - public void run() { - String ranStr = UUID.randomUUID().toString().split("-")[0]; - Objective obj; - - if (scoreboard.getObjective(player.getName()) != null) { - obj = scoreboard.getObjective(player.getName()); - } else { - obj = scoreboard.registerNewObjective(player.getName(), "dummy"); - } - - obj.setDisplaySlot(DisplaySlot.SIDEBAR); - - String formattedDisplayName = ChatColor.translateAlternateColorCodes('&', replaceDisplayName(displayName)); - int max; - if(ServerVersion.isServerVersion(ServerVersion.V1_8)) { - max = 16; - } else { - max = 32; - } - if (formattedDisplayName.length() > max) { - obj.setDisplayName(ChatColor.RED + "Too long..."); - } else { - obj.setDisplayName(formattedDisplayName); - } - - for (int i = 0; i < ChatColor.values().length; i++) { - if (i == displayList.size()) { - break; - } - - ChatColor chatColor = ChatColor.values()[i]; - Team team = scoreboard.registerNewTeam(ranStr + i); - team.addEntry(chatColor.toString()); - obj.getScore(chatColor.toString()).setScore(i); - } - - scheduler = new BukkitRunnable() { - int i1 = displayList.size(); - - @Override - public void run() { - if (!player.isOnline()) cancel(); - - try { - String formattedDisplayName = ChatColor.translateAlternateColorCodes('&', replaceDisplayName(displayName)); - - if (formattedDisplayName.length() > max) { - obj.setDisplayName(ChatColor.RED + "Too long..."); - } else { - obj.setDisplayName(formattedDisplayName); - } - - for (String displayLine : displayList) { - i1--; - - displayLine = replaceDisplayLine(displayLine); - - if (displayLine.length() > 32) { - displayLine = "&cLine too long..."; - } - - if (displayLine.length() >= 16) { - String prefixLine = displayLine.substring(0, Math.min(displayLine.length(), 16)); - String suffixLine = displayLine.substring(16); - - if (prefixLine.endsWith("&")) { - prefixLine = ChatColor.translateAlternateColorCodes('&', prefixLine.substring(0, prefixLine.length() - 1)); - suffixLine = ChatColor.translateAlternateColorCodes('&', "&" + suffixLine); - } else { - String lastColorCodes; - - if (prefixLine.contains("&")) { - String[] colorCodes = prefixLine.split("&"); - String lastColorCodeText = colorCodes[colorCodes.length - 1]; - lastColorCodes = "&" + lastColorCodeText.substring(0, Math.min(lastColorCodeText.length(), 1)); - - if ((colorCodes.length >= 2) && (lastColorCodes.equals("&l") || lastColorCodes.equals("&m") || lastColorCodes.equals("&n") || lastColorCodes.equals("&o"))) { - lastColorCodeText = colorCodes[colorCodes.length - 2]; - lastColorCodes = "&" + lastColorCodeText.substring(0, Math.min(lastColorCodeText.length(), 1)) + lastColorCodes; - } - } else { - lastColorCodes = "&f"; - } - - prefixLine = ChatColor.translateAlternateColorCodes('&', prefixLine); - suffixLine = ChatColor.translateAlternateColorCodes('&', lastColorCodes + suffixLine); - } - - scoreboard.getTeam(ranStr + i1).setPrefix(prefixLine); - scoreboard.getTeam(ranStr + i1).setSuffix(suffixLine); - } else { - scoreboard.getTeam(ranStr + i1).setPrefix(ChatColor.translateAlternateColorCodes('&', displayLine)); - } - } - - i1 = displayList.size(); - } catch (Exception e) { - cancel(); - } - } - }.runTaskTimerAsynchronously(plugin, 0L, 20L); - - player.setScoreboard(scoreboard); - } - }.runTaskAsynchronously(plugin); - } - }.runTask(plugin); - } - - private String replaceDisplayName(String displayName) { - displayName = displayName.replace("%players_online", "" + Bukkit.getServer().getOnlinePlayers().size()).replace("%players_max", "" + Bukkit.getServer().getMaxPlayers()); - - return displayName; - } - - private String replaceDisplayLine(String displayLine) { - SkyBlock plugin = SkyBlock.getInstance(); - - IslandManager islandManager = plugin.getIslandManager(); - - displayLine = displayLine.replace("%players_online", String.valueOf(Bukkit.getServer().getOnlinePlayers().size())); - displayLine = displayLine.replace("%players_max", String.valueOf(Bukkit.getServer().getMaxPlayers())); - - Island island = islandManager.getIsland(player); - - if (island != null) { - IslandLevel level = island.getLevel(); - - if (island.getRole(IslandRole.Member).size() == 0 && island.getRole(IslandRole.Operator).size() == 0) { - displayLine = displayLine.replace("%island_level", "" + NumberUtil.formatNumberByDecimal(level.getLevel())).replace("%island_members", ChatColor.RED + "0").replace("%island_role", ChatColor.RED + "null") - .replace("%island_visitors", "" + islandManager.getVisitorsAtIsland(island).size()).replace("%island_size", "" + island.getSize()).replace("%island_radius", "" + island.getRadius()); - } else { - int islandMembers = 1 + island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size(); - String islandRole = ""; - - - Localization locale = plugin.getLocalizationManager().getLocalizationFor(IslandRole.class); - - if (island.hasRole(IslandRole.Owner, player.getUniqueId())) { - islandRole = locale.getLocale(IslandRole.Owner); - } else if (island.hasRole(IslandRole.Operator, player.getUniqueId())) { - islandRole = locale.getLocale(IslandRole.Operator); - } else if (island.hasRole(IslandRole.Member, player.getUniqueId())) { - islandRole = locale.getLocale(IslandRole.Member);; - } - - displayLine = displayLine.replace("%island_points", "" + NumberUtil.formatNumberByDecimal(level.getPoints())).replace("%island_level", "" + NumberUtil.formatNumberByDecimal(level.getLevel())) - .replace("%island_members", "" + islandMembers).replace("%island_role", islandRole).replace("%island_visitors", "" + islandManager.getVisitorsAtIsland(island).size()) - .replace("%island_size", "" + island.getSize()).replace("%island_radius", "" + island.getRadius()); - } - } else { - displayLine = displayLine.replace("%island_points", ChatColor.RED + "0").replace("%island_level", ChatColor.RED + "0").replace("%island_members", ChatColor.RED + "0").replace("%island_role", ChatColor.RED + "null") - .replace("%island_size", ChatColor.RED + "0").replace("%island_radius", ChatColor.RED + "0"); - } - - PlaceholderManager placeholderManager = plugin.getPlaceholderManager(); - - if (placeholderManager.isPlaceholderAPIEnabled()) { - displayLine = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, displayLine); - } - - return displayLine.replace(String.valueOf(ChatColor.COLOR_CHAR), "&"); // Returning unformatted line to avoid issues in next step - } -} diff --git a/src/main/java/com/songoda/skyblock/scoreboard/ScoreboardLine.java b/src/main/java/com/songoda/skyblock/scoreboard/ScoreboardLine.java new file mode 100644 index 00000000..758fa921 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/scoreboard/ScoreboardLine.java @@ -0,0 +1,20 @@ +package com.songoda.skyblock.scoreboard; + +class ScoreboardLine { + + private final String prefix; + private final String suffix; + + public ScoreboardLine(String prefix, String suffix) { + this.prefix = prefix; + this.suffix = suffix; + } + + public String getPrefix() { + return prefix; + } + + public String getSuffix() { + return suffix; + } +} diff --git a/src/main/java/com/songoda/skyblock/scoreboard/ScoreboardManager.java b/src/main/java/com/songoda/skyblock/scoreboard/ScoreboardManager.java index 6b73bd82..92a7e36a 100644 --- a/src/main/java/com/songoda/skyblock/scoreboard/ScoreboardManager.java +++ b/src/main/java/com/songoda/skyblock/scoreboard/ScoreboardManager.java @@ -1,275 +1,139 @@ package com.songoda.skyblock.scoreboard; -import com.songoda.core.compatibility.ServerVersion; import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.config.FileManager; -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.IslandManager; -import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.manager.Manager; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; +import com.songoda.skyblock.visit.Visit; +import io.netty.util.internal.ConcurrentSet; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Team; -import org.bukkit.scoreboard.Team.Option; import java.io.File; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -public class ScoreboardManager { - - private final SkyBlock plugin; - private final Map scoreboardStorage = new ConcurrentHashMap<>(); - - private final PlayerDataManager playerDataManager; +public class ScoreboardManager extends Manager { - private final List teamNames = new ArrayList<>(); - private final List objectiveNames = new ArrayList<>(); + private final List drivers; + private final Set disabledPlayers; public ScoreboardManager(SkyBlock plugin) { - this.plugin = plugin; - this.playerDataManager = plugin.getPlayerDataManager(); - Bukkit.getScheduler().runTask(plugin, () -> reloadScoreboards(true)); - Bukkit.getScheduler().runTaskTimer(plugin, this::updateScoreboards, 20L, 40L); + super(plugin); + this.drivers = new ArrayList<>(); + this.disabledPlayers = new ConcurrentSet<>(); + + for(ScoreboardType type : ScoreboardType.values()) { + newDriver(type); + } + + updateOnlinePlayers(); } - private synchronized void updateScoreboards() { - final org.bukkit.scoreboard.Scoreboard primary = Bukkit.getScoreboardManager().getMainScoreboard(); - final Set objectives = primary.getObjectives(); - final Set teams = primary.getTeams(); - - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { - /* - * Unregister all teams or objectives that are no longer present in the main - * scoreboard. - */ - for (UUID uuid : scoreboardStorage.keySet()) { - Player player = Bukkit.getPlayer(uuid); - if(player != null) { - final org.bukkit.scoreboard.Scoreboard board = player.getScoreboard(); - - for (String name : objectiveNames) { - - if (primary.getObjective(name) != null) continue; - - final Objective objective = board.getObjective(name); - - if (objective != null) objective.unregister(); - } - - for (String name : teamNames) { - - if (primary.getTeam(name) != null) continue; - - final Team team = board.getTeam(name); - - if (team != null) team.unregister(); - } - } - } - - /* - * Update the objective/team names. - */ - - objectiveNames.clear(); - teamNames.clear(); - - for(Objective objective : objectives) { - if (primary.getObjective(objective.getName()) != null) { - objectiveNames.add(objective.getName()); - } - } - - for(Team team : teams) { - if (primary.getTeam(team.getName()) != null) { - teamNames.add(team.getName()); - } - } - - /* - * Update or add any missing information to the player's scoreboard. - */ - - for (UUID uuid : scoreboardStorage.keySet()) { - Player player = Bukkit.getPlayer(uuid); - if(player != null) { - PlayerData pd = playerDataManager.getPlayerData(player); - if(pd != null && pd.isScoreboard()){ - final org.bukkit.scoreboard.Scoreboard playerBoard = player.getScoreboard(); - - for (Objective primaryObjective : objectives) { - - Objective obj = playerBoard.getObjective(primaryObjective.getName()); - - if (obj == null) - obj = playerBoard.registerNewObjective(primaryObjective.getName(), primaryObjective.getCriteria()); - - obj.setDisplayName(primaryObjective.getDisplayName()); - obj.setDisplaySlot(primaryObjective.getDisplaySlot()); - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) 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 (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) 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 (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) { - for (Option option : Option.values()) { - obj.setOption(option, primaryTeam.getOption(option)); - } - } - } - } - } - } - }); + @Override + public void disable() { + clearDrivers(); } - public synchronized void reloadScoreboards(boolean createNew) { + @Override + public void reload() { + disable(); + updateOnlinePlayers(); + } - FileManager fileManager = plugin.getFileManager(); - - if (!fileManager.getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Scoreboard.Enable")) - return; - - for (Player all : Bukkit.getOnlinePlayers()) { - - boolean store = false; - - Scoreboard scoreboard = null; - if (hasScoreboard(all)) - scoreboard = getScoreboard(all); - else { - if (createNew) { - scoreboard = new Scoreboard(plugin, all); - store = true; - } - } - - if (scoreboard == null) continue; - - IslandManager islandManager = plugin.getIslandManager(); - Config language = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "language.yml")); - Island island = islandManager.getIsland(all); - - if (island == null) { - 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(color(language.getFileConfiguration().getString("Scoreboard.Island.Solo.Displayname"))); - - if (islandManager.getVisitorsAtIsland(island).size() == 0) { - scoreboard.setDisplayList(language.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Empty.Displaylines")); - } else { - scoreboard.setDisplayList(language.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Occupied.Displaylines")); - } - } else { - scoreboard.setDisplayName(color(language.getFileConfiguration().getString("Scoreboard.Island.Team.Displayname"))); - - if (islandManager.getVisitorsAtIsland(island).size() == 0) { - scoreboard.setDisplayList(language.getFileConfiguration().getStringList("Scoreboard.Island.Team.Empty.Displaylines")); - } else { - scoreboard.setDisplayList(language.getFileConfiguration().getStringList("Scoreboard.Island.Team.Occupied.Displaylines")); - } - } - } - - scoreboard.run(); - if (store) storeScoreboard(all, scoreboard); + public void updateOnlinePlayers() { + for(Player player : plugin.getServer().getOnlinePlayers()) { + updatePlayerScoreboardType(player); } } - private String color(String str) { - return str != null ? ChatColor.translateAlternateColorCodes('&', str) : null; - } - - public synchronized void storeScoreboard(Player player, Scoreboard scoreboard) { - scoreboardStorage.put(player.getUniqueId(), scoreboard); - } - - public synchronized Scoreboard getScoreboard(Player player) { - if (scoreboardStorage.containsKey(player.getUniqueId())) { - return scoreboardStorage.get(player.getUniqueId()); - } - - return null; - } - - public synchronized boolean hasScoreboard(Player player) { - return scoreboardStorage.containsKey(player.getUniqueId()); - } - - public synchronized Map getScoreboardStorage() { - return this.scoreboardStorage; - } - - public synchronized void addPlayer(Player player){ - CooldownManager cooldownManager = plugin.getCooldownManager(); - FileManager fileManager = plugin.getFileManager(); + public void updatePlayerScoreboardType(Player player) { + PlayerDataManager playerDataManager = plugin.getPlayerDataManager(); IslandManager islandManager = plugin.getIslandManager(); - - Config config = fileManager.getConfig(new File(plugin.getDataFolder(), "language.yml")); - Scoreboard scoreboard = new Scoreboard(plugin, 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")); + + PlayerData playerData = playerDataManager.getPlayerData(player); + Island island = islandManager.getIslandByPlayer(player); + + if(playerData.isScoreboard()) { + ScoreboardType type; + if(island != null) { + Visit islandVisit = island.getVisit(); + boolean hasVisitors = islandVisit.getVisitors().size() > 1; + boolean hasMembers = islandVisit.getMembers() > 1; + + if(hasMembers) { + if(hasVisitors) { + type = ScoreboardType.ISLAND_SOLO_VISITORS; + } else { + type = ScoreboardType.ISLAND_SOLO_EMPTY; + } } else { - scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Island.Solo.Occupied.Displaylines")); + if(hasVisitors) { + type = ScoreboardType.ISLAND_TEAM_VISITORS; + } else { + type = ScoreboardType.ISLAND_TEAM_EMPTY; + } } } 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")); - } - + type = ScoreboardType.NOISLAND; } - } else { - scoreboard.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getFileConfiguration().getString("Scoreboard.Tutorial.Displayname"))); - scoreboard.setDisplayList(config.getFileConfiguration().getStringList("Scoreboard.Tutorial.Displaylines")); + + setPlayerScoreboard(player, type); + Bukkit.broadcastMessage(type.toString()); } - - scoreboard.run(); - this.storeScoreboard(player, scoreboard); + } + + public void unregisterPlayer(Player player) { + for(Driver driver : drivers) { + driver.unregisterHolder(player); + } + } + + public void addDisabledPlayer(Player player) { + disabledPlayers.add(player); + } + + public void removeDisabledPlayer(Player player) { + disabledPlayers.remove(player); + } + + public boolean isPlayerDisabled(Player player) { + return disabledPlayers.contains(player); } - public synchronized void removePlayer(Player player){ - player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()); - this.scoreboardStorage.remove(player.getUniqueId()); + private void newDriver(ScoreboardType board) { + FileManager fileManager = plugin.getFileManager(); + FileConfiguration scoreboardLoad = fileManager.getConfig( + new File(plugin.getDataFolder(), "scoreboard.yml")).getFileConfiguration(); + + Driver driver = new Driver(plugin, board); + if(scoreboardLoad.getBoolean("Settings.Async", true)) { + driver.runTaskTimerAsynchronously(plugin, 1L, 1L); + } else { + driver.runTaskTimer(plugin, 1L, 1L); + } + drivers.add(driver); + Bukkit.broadcastMessage("G " + drivers.size()); } -} \ No newline at end of file + + public void clearDrivers() { + for(Driver driver : drivers) + driver.cancel(); + drivers.clear(); + } + + public void setPlayerScoreboard(Player player, ScoreboardType type) { + for(Driver driver : drivers) { + if(driver.getBoardType().equals(type)) { + Bukkit.broadcastMessage("F"); + driver.registerHolder(new Holder(plugin, driver, player)); + } else { + driver.unregisterHolder(player); + } + } + Bukkit.broadcastMessage(drivers.size() + ""); + } +} diff --git a/src/main/java/com/songoda/skyblock/scoreboard/ScoreboardType.java b/src/main/java/com/songoda/skyblock/scoreboard/ScoreboardType.java new file mode 100644 index 00000000..5848ff7d --- /dev/null +++ b/src/main/java/com/songoda/skyblock/scoreboard/ScoreboardType.java @@ -0,0 +1,21 @@ +package com.songoda.skyblock.scoreboard; + +import javax.annotation.Nonnull; + +enum ScoreboardType { + NOISLAND("Scoreboards.NoIsland"), + ISLAND_SOLO_EMPTY("Scoreboards.Island.Solo.Empty"), + ISLAND_SOLO_VISITORS("Scoreboards.Island.Solo.Occupied"), + ISLAND_TEAM_EMPTY("Scoreboards.Island.Team.Empty"), + ISLAND_TEAM_VISITORS("Scoreboards.Island.Team.Occupied"); + + private final String configSection; + + ScoreboardType(@Nonnull String configSection) { + this.configSection = configSection; + } + + public @Nonnull String getConfigSection() { + return this.configSection; + } +} diff --git a/src/main/java/com/songoda/skyblock/scoreboard/wip/Board.java b/src/main/java/com/songoda/skyblock/scoreboard/wip/Board.java deleted file mode 100644 index 59a8c178..00000000 --- a/src/main/java/com/songoda/skyblock/scoreboard/wip/Board.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.songoda.skyblock.scoreboard.wip; - -public class Board { -} diff --git a/src/main/java/com/songoda/skyblock/scoreboard/wip/Driver.java b/src/main/java/com/songoda/skyblock/scoreboard/wip/Driver.java deleted file mode 100644 index bc52b8f8..00000000 --- a/src/main/java/com/songoda/skyblock/scoreboard/wip/Driver.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.songoda.skyblock.scoreboard.wip; - -import org.bukkit.scheduler.BukkitRunnable; - -public class Driver extends BukkitRunnable { - public Driver(String board) { - } - - @Override - public void run() { - - } - - public void setDefault(boolean isDefault) { - } -} diff --git a/src/main/java/com/songoda/skyblock/scoreboard/wip/Manager.java b/src/main/java/com/songoda/skyblock/scoreboard/wip/Manager.java deleted file mode 100644 index 91054545..00000000 --- a/src/main/java/com/songoda/skyblock/scoreboard/wip/Manager.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.songoda.skyblock.scoreboard.wip; - -import com.songoda.skyblock.SkyBlock; - -import java.util.Map; - -public class Manager { - - Map drivers; - - public void newDriver(String board, boolean isDefault) { - Driver driver = new Driver(board); - driver.runTaskTimerAsynchronously(SkyBlock.getInstance(), 1L, 1L); - drivers.put(board, driver); - driver.setDefault(isDefault); - } - - public void clearDrivers() - { - for(Driver driver : drivers.values()) - driver.cancel(); - drivers.clear(); - } -} diff --git a/src/main/java/com/songoda/skyblock/scoreboard/wip/Row.java b/src/main/java/com/songoda/skyblock/scoreboard/wip/Row.java deleted file mode 100644 index 1a430b8c..00000000 --- a/src/main/java/com/songoda/skyblock/scoreboard/wip/Row.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.songoda.skyblock.scoreboard.wip; - -public class Row { -} diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index e85b5a83..3ab56c7b 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -1133,83 +1133,6 @@ Command: Message: '&bSkyBlock &8| &cError&8: &eYou don''t have permission to perform that command.' Island: Message: '&bSkyBlock &8| &cError&8: &eYou don''t have permission to perform that command.' -Scoreboard: - Tutorial: - Displaylines: - - '' - - '&bIsland&f:' - - '&cYou do not own an Island.' - - ' &8- &7/island create' - - '' - - '&bProfile&f:' - - ' &8- &7Rank&8: &fDefault' - - ' &8- &7Balance&8: &f$0' - - '' - - '&ewww.example.net' - Displayname: '&b&lSkyBlock' - Island: - Solo: - Empty: - Displaylines: - - '' - - '&bIsland&f:' - - ' &8- &7Level&8: &f%island_level' - - ' &8- &7Size&8: &f%island_size&7x&f%island_size' - - '' - - '&bProfile&f:' - - ' &8- &7Rank&8: &fDefault' - - ' &8- &7Balance&8: &f$0' - - '' - - '&ewww.example.net' - Occupied: - Displaylines: - - '' - - '&bIsland&f:' - - ' &8- &7Level&8: &f%island_level' - - ' &8- &7Visitors&8: &f%island_visitors' - - ' &8- &7Size&8: &f%island_size&7x&f%island_size' - - '' - - '&bProfile&f:' - - ' &8- &7Rank&8: &fDefault' - - ' &8- &7Balance&8: &f$0' - - '' - - '&ewww.example.net' - Displayname: '&b&lSkyBlock' - Team: - Word: - Owner: Owner - Operator: Operator - Member: Member - Empty: - Displaylines: - - '' - - '&bIsland&f:' - - ' &8- &7Role&8: &f%island_role' - - ' &8- &7Members&8: &f%island_members' - - ' &8- &7Level&8: &f%island_level' - - ' &8- &7Size&8: &f%island_size&7x&f%island_size' - - '' - - '&bProfile&f:' - - ' &8- &7Rank&8: &fDefault' - - ' &8- &7Balance&8: &f$0' - - '' - - '&ewww.example.net' - Occupied: - Displaylines: - - '' - - '&bIsland&f:' - - ' &8- &7Role&8: &f%island_role' - - ' &8- &7Members&8: &f%island_members' - - ' &8- &7Level&8: &f%island_level' - - ' &8- &7Visitors&8: &f%island_visitors' - - ' &8- &7Size&8: &f%island_size&7x&f%island_size' - - '' - - '&bProfile&f:' - - ' &8- &7Rank&8: &fDefault' - - ' &8- &7Balance&8: &f$0' - - '' - - '&ewww.example.net' - Displayname: '&b&lSkyBlock' Menu: Settings: Default: @@ -3454,171 +3377,6 @@ Menu: Exit: Displayname: '&cExit' Lore: '&7Exits the Menu' -Placeholder: - fabledskyblock_leaderboard_votes: - Empty: - Message: 'Unclaimed' - Non-empty: - Message: '[%position] %player [%votes]' - fabledskyblock_leaderboard_bank: - Empty: - Message: 'Unclaimed' - Non-empty: - Message: '[%position] %player [$%balance]' - fabledskyblock_island_exists: - Exists: - Message: 'true' - Not-exists: - Message: 'false' - fabledskyblock_island_members: - Non-empty: - Message: '%placeholder' - Empty: - Message: '0' - fabledskyblock_island_coops: - Empty: - Message: '0' - Non-empty: - Message: '%placeholder' - fabledskyblock_leaderboard_level: - Empty: - Message: 'Unclaimed' - Non-empty: - Message: '[%position] %player [%level]' - fabledskyblock_island_visitors: - Non-empty: - Message: '%placeholder' - Empty: - Message: '0' - fabledskyblock_island_size: - Empty: - Message: '0' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_maxmembers: - Empty: - Message: '0' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_time: - Non-empty: - Message: '%placeholder' - Empty: - Message: '0' - fabledskyblock_island_bank_balance_formatted: - Empty: - Message: '0' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_owner: - Non-empty: - Yourself: - Message: 'You' - Other: - Message: '%placeholder' - Empty: - Message: '&oNone' - fabledskyblock_island_leaderboard_bank_rank: - Non-empty: - Message: '%placeholder' - Empty: - Message: '0' - fabledskyblock_island_bans: - Non-empty: - Message: '%placeholder' - Empty: - Message: '0' - fabledskyblock_island_coops_total: - Non-empty: - Message: '%placeholder' - Empty: - Message: '0' - fabledskyblock_island_invites: - Non-empty: - Message: '%placeholder' - Empty: - Message: '0' - fabledskyblock_island_level_block_count: - Invalid: - Message: 'Invalid Type' - Non-empty: - Message: '%placeholder' - Empty: - Message: '0' - fabledskyblock_island_weather: - Empty: - Message: '0' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_role: - Empty: - Message: '&oNone' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_operators: - Empty: - Message: '0' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_bank_balance: - Empty: - Message: '0' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_biome: - Empty: - Message: '&oNone' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_level_formatted: - Empty: - Message: '0' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_members_total: - Non-empty: - Message: '%placeholder' - Empty: - Message: '0' - fabledskyblock_island_level_block_points: - Empty: - Message: '0' - Invalid: - Message: 'Invalid Type' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_isopen: - Closed: - Message: 'false' - Open: - Message: 'true' - Empty: - Message: 'false' - fabledskyblock_island_votes: - Empty: - Message: '0' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_radius: - Empty: - Message: '0' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_leaderboard_votes_rank: - Non-empty: - Message: '%placeholder' - Empty: - Message: '0' - fabledskyblock_level_block_value: - Invalid: - Message: 'Invalid Type' - Non-empty: - Message: '%placeholder' - fabledskyblock_island_leaderboard_level_rank: - Empty: - Message: '0' - Non-empty: - Message: '%placeholder' Island: Limit: Block: diff --git a/src/main/resources/placeholders.yml b/src/main/resources/placeholders.yml new file mode 100644 index 00000000..46d2d601 --- /dev/null +++ b/src/main/resources/placeholders.yml @@ -0,0 +1,165 @@ +Placeholders: + fabledskyblock_leaderboard_votes: + Empty: + Message: 'Unclaimed' + Non-empty: + Message: '[%position] %player [%votes]' + fabledskyblock_leaderboard_bank: + Empty: + Message: 'Unclaimed' + Non-empty: + Message: '[%position] %player [$%balance]' + fabledskyblock_island_exists: + Exists: + Message: 'true' + Not-exists: + Message: 'false' + fabledskyblock_island_members: + Non-empty: + Message: '%placeholder' + Empty: + Message: '0' + fabledskyblock_island_coops: + Empty: + Message: '0' + Non-empty: + Message: '%placeholder' + fabledskyblock_leaderboard_level: + Empty: + Message: 'Unclaimed' + Non-empty: + Message: '[%position] %player [%level]' + fabledskyblock_island_visitors: + Non-empty: + Message: '%placeholder' + Empty: + Message: '0' + fabledskyblock_island_size: + Empty: + Message: '0' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_maxmembers: + Empty: + Message: '0' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_time: + Non-empty: + Message: '%placeholder' + Empty: + Message: '0' + fabledskyblock_island_bank_balance_formatted: + Empty: + Message: '0' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_owner: + Non-empty: + Yourself: + Message: 'You' + Other: + Message: '%placeholder' + Empty: + Message: '&oNone' + fabledskyblock_island_leaderboard_bank_rank: + Non-empty: + Message: '%placeholder' + Empty: + Message: '0' + fabledskyblock_island_bans: + Non-empty: + Message: '%placeholder' + Empty: + Message: '0' + fabledskyblock_island_coops_total: + Non-empty: + Message: '%placeholder' + Empty: + Message: '0' + fabledskyblock_island_invites: + Non-empty: + Message: '%placeholder' + Empty: + Message: '0' + fabledskyblock_island_level_block_count: + Invalid: + Message: 'Invalid Type' + Non-empty: + Message: '%placeholder' + Empty: + Message: '0' + fabledskyblock_island_weather: + Empty: + Message: '0' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_role: + Empty: + Message: '&oNone' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_operators: + Empty: + Message: '0' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_bank_balance: + Empty: + Message: '0' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_biome: + Empty: + Message: '&oNone' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_level_formatted: + Empty: + Message: '0' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_members_total: + Non-empty: + Message: '%placeholder' + Empty: + Message: '0' + fabledskyblock_island_level_block_points: + Empty: + Message: '0' + Invalid: + Message: 'Invalid Type' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_isopen: + Closed: + Message: 'false' + Open: + Message: 'true' + Empty: + Message: 'false' + fabledskyblock_island_votes: + Empty: + Message: '0' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_radius: + Empty: + Message: '0' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_leaderboard_votes_rank: + Non-empty: + Message: '%placeholder' + Empty: + Message: '0' + fabledskyblock_level_block_value: + Invalid: + Message: 'Invalid Type' + Non-empty: + Message: '%placeholder' + fabledskyblock_island_leaderboard_level_rank: + Empty: + Message: '0' + Non-empty: + Message: '%placeholder' \ No newline at end of file diff --git a/src/main/resources/scoreboard.yml b/src/main/resources/scoreboard.yml new file mode 100644 index 00000000..ca925c49 --- /dev/null +++ b/src/main/resources/scoreboard.yml @@ -0,0 +1,339 @@ +Settings: + Async: true +Scoreboards: + NoIsland: + Title: + Interval: 3 + Content: + - '&b&lSkyBlock' + - '&a&lS&b&lkyBlock' + - '&a&lSk&b&lyBlock' + - '&a&lSky&b&lBlock' + - '&a&lSkyB&b&llock' + - '&a&lSkyBl&b&lock' + - '&a&lSkyBlo&b&lck' + - '&a&lSkyBloc&b&lk' + - '&a&lSkyBlock' + - '&b&lS&a&lkyBlock' + - '&b&lSk&a&lyBlock' + - '&b&lSky&a&lBlock' + - '&b&lSkyB&a&llock' + - '&b&lSkyBl&a&lock' + - '&b&lSkyBlo&a&lck' + - '&b&lSkyBloc&a&lk' + Rows: + 1: + Interval: -1 + Content: + - '' + 2: + Interval: -1 + Content: + - '&bIsland&f:' + 3: + Interval: 5 + Content: + - '&cYou do not own an Island.' + 4: + Interval: 20 + Content: + - ' &8- &7/island create' + 5: + Interval: -1 + Content: + - '' + 6: + Interval: 5 + Content: + - '&bProfile&f:' + 7: + Interval: 20 + Content: + - ' &8- &7Rank&8: &fDefault' + '8': + Interval: 5 + Content: + - ' &8- &7Balance&8: &f$0' + '9': + Interval: -1 + Content: + - '' + 10: + Interval: -1 + Content: + - '&ewww.songoda.com' + Island: + Solo: + Empty: + Title: + Interval: 3 + Content: + - '&b&lSkyBlock' + - '&a&lS&b&lkyBlock' + - '&a&lSk&b&lyBlock' + - '&a&lSky&b&lBlock' + - '&a&lSkyB&b&llock' + - '&a&lSkyBl&b&lock' + - '&a&lSkyBlo&b&lck' + - '&a&lSkyBloc&b&lk' + - '&a&lSkyBlock' + - '&b&lS&a&lkyBlock' + - '&b&lSk&a&lyBlock' + - '&b&lSky&a&lBlock' + - '&b&lSkyB&a&llock' + - '&b&lSkyBl&a&lock' + - '&b&lSkyBlo&a&lck' + - '&b&lSkyBloc&a&lk' + Rows: + 1: + Interval: -1 + Content: + - '' + 2: + Interval: -1 + Content: + - '&bIsland&f:' + 3: + Interval: 5 + Content: + - ' &8- &7Level&8: &f%island_level%' + 4: + Interval: 20 + Content: + - ' &8- &7Size&8: &f%island_size%&7x&f%island_size%' + 5: + Interval: -1 + Content: + - '' + 6: + Interval: 5 + Content: + - '&bProfile&f:' + 7: + Interval: 20 + Content: + - ' &8- &7Rank&8: &fDefault' + '8': + Interval: 5 + Content: + - ' &8- &7Balance&8: &f$0' + '9': + Interval: -1 + Content: + - '' + 10: + Interval: -1 + Content: + - '&ewww.songoda.com' + Occupied: + Title: + Interval: 3 + Content: + - '&b&lSkyBlock' + - '&a&lS&b&lkyBlock' + - '&a&lSk&b&lyBlock' + - '&a&lSky&b&lBlock' + - '&a&lSkyB&b&llock' + - '&a&lSkyBl&b&lock' + - '&a&lSkyBlo&b&lck' + - '&a&lSkyBloc&b&lk' + - '&a&lSkyBlock' + - '&b&lS&a&lkyBlock' + - '&b&lSk&a&lyBlock' + - '&b&lSky&a&lBlock' + - '&b&lSkyB&a&llock' + - '&b&lSkyBl&a&lock' + - '&b&lSkyBlo&a&lck' + - '&b&lSkyBloc&a&lk' + Rows: + 1: + Interval: -1 + Content: + - '' + 2: + Interval: -1 + Content: + - '&bIsland&f:' + 3: + Interval: 5 + Content: + - ' &8- &7Level&8: &f%island_level%' + 4: + Interval: 5 + Content: + - ' &8- &7Visitors&8: &f%island_visitors%' + 5: + Interval: 20 + Content: + - ' &8- &7Size&8: &f%island_size%&7x&f%island_size%' + 6: + Interval: -1 + Content: + - '' + 7: + Interval: 5 + Content: + - '&bProfile&f:' + 8: + Interval: 20 + Content: + - ' &8- &7Rank&8: &fDefault' + '9': + Interval: 5 + Content: + - ' &8- &7Balance&8: &f$0' + '10': + Interval: -1 + Content: + - '' + 11: + Interval: -1 + Content: + - '&ewww.songoda.com' + Team: + Word: + Owner: 'Owner' + Operator: 'Operator' + Member: 'Member' + Empty: + Title: + Interval: 3 + Content: + - '&b&lSkyBlock' + - '&a&lS&b&lkyBlock' + - '&a&lSk&b&lyBlock' + - '&a&lSky&b&lBlock' + - '&a&lSkyB&b&llock' + - '&a&lSkyBl&b&lock' + - '&a&lSkyBlo&b&lck' + - '&a&lSkyBloc&b&lk' + - '&a&lSkyBlock' + - '&b&lS&a&lkyBlock' + - '&b&lSk&a&lyBlock' + - '&b&lSky&a&lBlock' + - '&b&lSkyB&a&llock' + - '&b&lSkyBl&a&lock' + - '&b&lSkyBlo&a&lck' + - '&b&lSkyBloc&a&lk' + Rows: + 1: + Interval: -1 + Content: + - '' + 2: + Interval: -1 + Content: + - '&bIsland&f:' + 3: + Interval: 20 + Content: + - ' &8- &7Role&8: &f%island_role%' + 4: + Interval: 20 + Content: + - ' &8- &7Members&8: &f%island_members%' + 5: + Interval: 5 + Content: + - ' &8- &7Level&8: &f%island_level%' + 6: + Interval: 20 + Content: + - ' &8- &7Size&8: &f%island_size%&7x&f%island_size%' + 7: + Interval: -1 + Content: + - '' + 8: + Interval: 5 + Content: + - '&bProfile&f:' + 9: + Interval: 20 + Content: + - ' &8- &7Rank&8: &fDefault' + '10': + Interval: 5 + Content: + - ' &8- &7Balance&8: &f$0' + '11': + Interval: -1 + Content: + - '' + 12: + Interval: -1 + Content: + - '&ewww.songoda.com' + Occupied: + Title: + Interval: 3 + Content: + - '&b&lSkyBlock' + - '&a&lS&b&lkyBlock' + - '&a&lSk&b&lyBlock' + - '&a&lSky&b&lBlock' + - '&a&lSkyB&b&llock' + - '&a&lSkyBl&b&lock' + - '&a&lSkyBlo&b&lck' + - '&a&lSkyBloc&b&lk' + - '&a&lSkyBlock' + - '&b&lS&a&lkyBlock' + - '&b&lSk&a&lyBlock' + - '&b&lSky&a&lBlock' + - '&b&lSkyB&a&llock' + - '&b&lSkyBl&a&lock' + - '&b&lSkyBlo&a&lck' + - '&b&lSkyBloc&a&lk' + Rows: + 1: + Interval: -1 + Content: + - '' + 2: + Interval: -1 + Content: + - '&bIsland&f:' + 3: + Interval: 20 + Content: + - ' &8- &7Role&8: &f%island_role%' + 4: + Interval: 20 + Content: + - ' &8- &7Members&8: &f%island_members%' + 5: + Interval: 5 + Content: + - ' &8- &7Level&8: &f%island_level%' + 6: + Interval: 5 + Content: + - ' &8- &7Visitors&8: &f%island_visitors%' + 7: + Interval: 20 + Content: + - ' &8- &7Size&8: &f%island_size%&7x&f%island_size%' + 8: + Interval: -1 + Content: + - '' + 9: + Interval: 5 + Content: + - '&bProfile&f:' + 10: + Interval: 20 + Content: + - ' &8- &7Rank&8: &fDefault' + '11': + Interval: 5 + Content: + - ' &8- &7Balance&8: &f$0' + '12': + Interval: -1 + Content: + - '' + 13: + Interval: -1 + Content: + - '&ewww.songoda.com' \ No newline at end of file