From 067cbd4da80305ab5142ab2ffa820043fdba9e71 Mon Sep 17 00:00:00 2001 From: Brianna Date: Wed, 8 Apr 2020 12:28:42 -0400 Subject: [PATCH] Holograms now use either Holographic Displays, Holograms, or CMI. --- .../java/com/songoda/skyblock/SkyBlock.java | 3 + .../admin/RefreshHologramsCommand.java | 2 +- .../command/commands/admin/ReloadCommand.java | 2 +- .../commands/admin/RemoveHologramCommand.java | 5 +- .../commands/admin/SetHologramCommand.java | 6 +- .../songoda/skyblock/hologram/Hologram.java | 67 +--- .../skyblock/hologram/HologramManager.java | 290 +++++------------- .../skyblock/leaderboard/LeaderboardTask.java | 2 +- src/main/resources/language.yml | 4 +- src/main/resources/plugin.yml | 2 +- 10 files changed, 96 insertions(+), 287 deletions(-) diff --git a/src/main/java/com/songoda/skyblock/SkyBlock.java b/src/main/java/com/songoda/skyblock/SkyBlock.java index dd1aa9fe..78cc06db 100644 --- a/src/main/java/com/songoda/skyblock/SkyBlock.java +++ b/src/main/java/com/songoda/skyblock/SkyBlock.java @@ -100,6 +100,9 @@ public class SkyBlock extends SongodaPlugin { // Load Economy EconomyManager.load(); + // Load Holograms + com.songoda.core.hooks.HologramManager.load(this); + fileManager = new FileManager(this); localizationManager = new LocalizationManager(); worldManager = new WorldManager(this); diff --git a/src/main/java/com/songoda/skyblock/command/commands/admin/RefreshHologramsCommand.java b/src/main/java/com/songoda/skyblock/command/commands/admin/RefreshHologramsCommand.java index a15b2c0f..7b0854a6 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/admin/RefreshHologramsCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/admin/RefreshHologramsCommand.java @@ -41,7 +41,7 @@ public class RefreshHologramsCommand extends SubCommand { leaderboardManager.resetLeaderboard(); leaderboardManager.setupLeaderHeads(); - Bukkit.getScheduler().runTask(skyblock, () -> skyblock.getHologramManager().resetHologram()); + Bukkit.getScheduler().runTask(skyblock, () -> skyblock.getHologramManager().updateHologram()); }); messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.RefreshHolograms.Refreshed.Message")); 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 a917c2d0..8e53a582 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 @@ -93,7 +93,7 @@ public class ReloadCommand extends SubCommand { leaderboardManager.resetLeaderboard(); leaderboardManager.setupLeaderHeads(); - Bukkit.getScheduler().runTask(skyblock, () -> skyblock.getHologramManager().resetHologram()); + Bukkit.getScheduler().runTask(skyblock, () -> skyblock.getHologramManager().updateHologram()); }); limitHandler.reloadAll(); diff --git a/src/main/java/com/songoda/skyblock/command/commands/admin/RemoveHologramCommand.java b/src/main/java/com/songoda/skyblock/command/commands/admin/RemoveHologramCommand.java index f2225263..76740ee0 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/admin/RemoveHologramCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/admin/RemoveHologramCommand.java @@ -76,9 +76,8 @@ public class RemoveHologramCommand extends SubCommand { HologramType hologramType1 = HologramType.valueOf(WordUtils.capitalize(args[0].toLowerCase())); Hologram hologram = hologramManager.getHologram(hologramType1); - if (hologram != null) { - hologramManager.removeHologram(hologram); - } + if (hologram != null) + hologram.remove(); }); messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.RemoveHologram.Removed.Message").replace("%type", hologramType.name())); diff --git a/src/main/java/com/songoda/skyblock/command/commands/admin/SetHologramCommand.java b/src/main/java/com/songoda/skyblock/command/commands/admin/SetHologramCommand.java index c2b96ca6..2593afe1 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/admin/SetHologramCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/admin/SetHologramCommand.java @@ -9,7 +9,6 @@ import com.songoda.skyblock.hologram.HologramManager; import com.songoda.skyblock.hologram.HologramType; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.sound.SoundManager; - import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; import org.bukkit.command.ConsoleCommandSender; @@ -55,9 +54,8 @@ public class SetHologramCommand extends SubCommand { .valueOf(WordUtils.capitalize(args[0].toLowerCase())); Hologram hologram = hologramManager.getHologram(hologramType1); - if (hologram != null) { - hologramManager.removeHologram(hologram); - } + if (hologram != null) + hologram.remove(); hologramManager.spawnHologram(hologramType1); }); diff --git a/src/main/java/com/songoda/skyblock/hologram/Hologram.java b/src/main/java/com/songoda/skyblock/hologram/Hologram.java index 2f4c1a76..051b6ff7 100644 --- a/src/main/java/com/songoda/skyblock/hologram/Hologram.java +++ b/src/main/java/com/songoda/skyblock/hologram/Hologram.java @@ -1,5 +1,6 @@ package com.songoda.skyblock.hologram; +import com.songoda.core.hooks.HologramManager; import com.songoda.skyblock.utils.version.NMSUtil; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -11,70 +12,30 @@ import java.util.List; public class Hologram { - private List holograms = new ArrayList<>(); - private HologramType type; private Location location; public Hologram(HologramType type, Location location, List lines) { this.type = type; this.location = location; - - for (String lineList : lines) { - addLine(lineList); - } - } - - public void addLine(String text) { - ArmorStand as = (ArmorStand) location.getWorld().spawnEntity( - location.clone().add(0.0D, getHeight() + getHeightIncrement(), 0.0D), EntityType.ARMOR_STAND); - int NMSVersion = NMSUtil.getVersionNumber(); - as.setVisible(false); - if (NMSVersion > 8) - as.setMarker(false); - as.setGravity(false); - as.setCustomName(ChatColor.translateAlternateColorCodes('&', text)); - as.setCustomNameVisible(true); - - holograms.add(as); - } - - public void setLine(int index, String text) { - if (index < holograms.size()) { - ArmorStand as = holograms.get(index); - - if (!as.isDead()) { - as.setCustomName(ChatColor.translateAlternateColorCodes('&', text)); - as.setCustomNameVisible(true); - } - } - } - - public void removeLine(int index) { - if (index < holograms.size()) { - ArmorStand as = holograms.get(index); - - if (!as.isDead()) { - as.remove(); - } - - holograms.remove(index); - } - } - - public double getHeight() { - return -2.0D + (holograms.size() * getHeightIncrement()); - } - - public double getHeightIncrement() { - return 0.35; + HologramManager.createHologram(location, lines); } public HologramType getType() { return type; } - public List getHolograms() { - return holograms; + + public Location getLocation() { + return location; + } + + public void remove() { + HologramManager.removeHologram(location); + } + + public void update(List lines) { + HologramManager.updateHologram(location, lines); + } } diff --git a/src/main/java/com/songoda/skyblock/hologram/HologramManager.java b/src/main/java/com/songoda/skyblock/hologram/HologramManager.java index af625219..e7de74b8 100644 --- a/src/main/java/com/songoda/skyblock/hologram/HologramManager.java +++ b/src/main/java/com/songoda/skyblock/hologram/HologramManager.java @@ -1,5 +1,6 @@ package com.songoda.skyblock.hologram; +import com.songoda.core.utils.TextUtils; import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager.Config; @@ -9,21 +10,14 @@ import com.songoda.skyblock.leaderboard.LeaderboardManager; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.utils.NumberUtil; import com.songoda.skyblock.utils.player.OfflinePlayer; -import com.songoda.skyblock.utils.world.LocationUtil; import com.songoda.skyblock.visit.Visit; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Location; -import org.bukkit.World; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import java.io.File; import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; import java.util.List; public class HologramManager { @@ -37,8 +31,6 @@ public class HologramManager { FileManager fileManager = skyblock.getFileManager(); Bukkit.getServer().getScheduler().runTaskLater(skyblock, () -> { - removeWorldHolograms(); - for (HologramType hologramTypeList : HologramType.values()) { if (hologramTypeList == HologramType.Votes) { if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")) @@ -61,143 +53,89 @@ public class HologramManager { } public void spawnHologram(HologramType type) { - LeaderboardManager leaderboardManager = skyblock.getLeaderboardManager(); - MessageManager messageManager = skyblock.getMessageManager(); FileManager fileManager = skyblock.getFileManager(); Config locationsConfig = fileManager.getConfig(new File(skyblock.getDataFolder(), "locations.yml")); FileConfiguration locationsConfigLoad = locationsConfig.getFileConfiguration(); + + if (locationsConfigLoad.getString("Location.Hologram.Leaderboard." + type) != null) + spawnHologram(type, skyblock.getFileManager().getLocation(locationsConfig, + "Location.Hologram.Leaderboard." + type, true), getHologramLines(type)); + } + + private List getHologramLines(HologramType type) { + FileManager fileManager = skyblock.getFileManager(); + LeaderboardManager leaderboardManager = skyblock.getLeaderboardManager(); + MessageManager messageManager = skyblock.getMessageManager(); + FileConfiguration languageConfigLoad = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")) .getFileConfiguration(); - if (locationsConfigLoad.getString("Location.Hologram.Leaderboard." + type) != null) { - List hologramLines = new ArrayList<>(); - Leaderboard.Type leaderboardType = null; + List hologramLines = new ArrayList<>(); + Leaderboard.Type leaderboardType = null; - switch (type) { - case Level: - leaderboardType = Leaderboard.Type.Level; - break; - case Bank: - leaderboardType = Leaderboard.Type.Bank; - break; - case Votes: - leaderboardType = Leaderboard.Type.Votes; - break; - } - - hologramLines.add(messageManager.replaceMessage(null, - languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Header"))); - - for (int i = 0; i < 10; i++) { - Leaderboard leaderboard = leaderboardManager.getLeaderboardFromPosition(leaderboardType, i); - - if (leaderboard == null) { - hologramLines.add(messageManager.replaceMessage(null, - languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Unclaimed") - .replace("%position", "" + (i + 1)))); - } else { - 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(); - } - - if (type == HologramType.Level) { - IslandLevel level = visit.getLevel(); - hologramLines.add(ChatColor.translateAlternateColorCodes('&', - languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Claimed") - .replace("%position", "" + (i + 1)) - .replace("%player", islandOwnerName) - .replace("%level", NumberUtil.formatNumberByDecimal(level.getLevel())) - .replace("%points", NumberUtil.formatNumberByDecimal(level.getPoints())))); - } else if (type == HologramType.Bank) { - hologramLines.add(ChatColor.translateAlternateColorCodes('&', - languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Claimed") - .replace("%position", "" + (i + 1)) - .replace("%player", islandOwnerName) - .replace("%balance", - "" + NumberUtil.formatNumberByDecimal(visit.getBankBalance())))); - } else if (type == HologramType.Votes) { - hologramLines.add(ChatColor.translateAlternateColorCodes('&', - languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Claimed") - .replace("%position", "" + (i + 1)) - .replace("%player", islandOwnerName) - .replace("%votes", - "" + NumberUtil.formatNumberByDecimal(visit.getVoters().size())))); - } - } - } - - String hologramFooter = languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Footer"); - - if (!hologramFooter.isEmpty()) { - hologramLines.add(messageManager.replaceMessage(null, hologramFooter)); - } - - Collections.reverse(hologramLines); - - spawnHologram(type, skyblock.getFileManager().getLocation(locationsConfig, - "Location.Hologram.Leaderboard." + type, true), hologramLines); + switch (type) { + case Level: + leaderboardType = Leaderboard.Type.Level; + break; + case Bank: + leaderboardType = Leaderboard.Type.Bank; + break; + case Votes: + leaderboardType = Leaderboard.Type.Votes; + break; } - } - public void removeHologram(Hologram hologram) { - if (hologramStorage.contains(hologram)) { - List holograms = hologram.getHolograms(); + hologramLines.add(TextUtils.formatText( + languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Header"))); - for (Iterator it = holograms.iterator(); it.hasNext(); ) { - it.next().remove(); + for (int i = 0; i < 10; i++) { + Leaderboard leaderboard = leaderboardManager.getLeaderboardFromPosition(leaderboardType, i); + + if (leaderboard == null) continue; + + Visit visit = leaderboard.getVisit(); + + Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); + String islandOwnerName = targetPlayer == null + ? new OfflinePlayer(visit.getOwnerUUID()).getName() : targetPlayer.getName(); + + if (type == HologramType.Level) { + IslandLevel level = visit.getLevel(); + hologramLines.add(TextUtils.formatText( + languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Claimed") + .replace("%position", "" + (i + 1)) + .replace("%player", islandOwnerName) + .replace("%level", NumberUtil.formatNumberByDecimal(level.getLevel())) + .replace("%points", NumberUtil.formatNumberByDecimal(level.getPoints())))); + } else if (type == HologramType.Bank) { + hologramLines.add(TextUtils.formatText( + languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Claimed") + .replace("%position", "" + (i + 1)) + .replace("%player", islandOwnerName) + .replace("%balance", + "" + NumberUtil.formatNumberByDecimal(visit.getBankBalance())))); + } else if (type == HologramType.Votes) { + hologramLines.add(TextUtils.formatText( + languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Claimed") + .replace("%position", "" + (i + 1)) + .replace("%player", islandOwnerName) + .replace("%votes", + "" + NumberUtil.formatNumberByDecimal(visit.getVoters().size())))); } - - hologramStorage.remove(hologram); } + + String hologramFooter = languageConfigLoad.getString("Hologram.Leaderboard." + type.name() + ".Footer"); + + if (!hologramFooter.isEmpty()) + hologramLines.add(TextUtils.formatText(hologramFooter)); + + return hologramLines; } public void removeHolograms() { for (Hologram hologramList : hologramStorage) { - List holograms = hologramList.getHolograms(); - - for (Iterator it = holograms.iterator(); it.hasNext(); ) { - it.next().remove(); - } - } - } - - public void removeWorldHolograms() { - FileManager fileManager = skyblock.getFileManager(); - - List locations = new ArrayList<>(); - - Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "locations.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); - - for (HologramType hologramTypeList : HologramType.values()) { - if (configLoad.getString("Location.Hologram.Leaderboard." + hologramTypeList.name()) != null) { - locations.add(fileManager.getLocation(config, - "Location.Hologram.Leaderboard." + hologramTypeList.name(), true)); - } - } - - for (World worldList : Bukkit.getWorlds()) { - List entities = worldList.getEntities(); - - for (Iterator it = entities.iterator(); it.hasNext(); ) { - Entity entity = it.next(); - - if (entity instanceof ArmorStand) { - for (Location locationList : locations) { - if (LocationUtil.isLocationAtLocationRadius(entity.getLocation(), locationList, 1)) { - entity.remove(); - } - } - } - } + hologramList.remove(); } } @@ -211,99 +149,9 @@ public class HologramManager { return null; } - public boolean hasHologram(HologramType type) { + public void updateHologram() { for (Hologram hologramList : hologramStorage) { - if (hologramList.getType() == type) { - return true; - } - } - - return false; - } - - public void resetHologram() { - LeaderboardManager leaderboardManager = skyblock.getLeaderboardManager(); - MessageManager messageManager = skyblock.getMessageManager(); - FileManager fileManager = skyblock.getFileManager(); - - FileConfiguration configLoad = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration(); - - for (HologramType hologramTypeList : HologramType.values()) { - if (hologramTypeList == HologramType.Votes) { - if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() - .getBoolean("Island.Visitor.Vote")) { - continue; - } - } - - Hologram hologram; - - if (hasHologram(hologramTypeList)) { - hologram = getHologram(hologramTypeList); - } else { - continue; - } - - Leaderboard.Type leaderboardType = null; - - switch (hologramTypeList) { - case Level: - leaderboardType = Leaderboard.Type.Level; - break; - case Bank: - leaderboardType = Leaderboard.Type.Bank; - break; - case Votes: - leaderboardType = Leaderboard.Type.Votes; - break; - } - - for (int i = 0; i < 10; i++) { - Leaderboard leaderboard = leaderboardManager.getLeaderboardFromPosition(leaderboardType, i); - int hologramLine = 10 - i; - - if (leaderboard == null) { - hologram.setLine(hologramLine, messageManager.replaceMessage(null, - configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Unclaimed") - .replace("%position", "" + (i + 1)))); - } else { - 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(); - } - - if (hologramTypeList == HologramType.Level) { - IslandLevel level = visit.getLevel(); - hologram.setLine(hologramLine, ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Claimed") - .replace("%position", "" + (i + 1)) - .replace("%player", islandOwnerName) - .replace("%level", NumberUtil.formatNumberByDecimal(level.getLevel())) - .replace("%points", NumberUtil.formatNumberByDecimal(level.getPoints())))); - } else if (hologramTypeList == HologramType.Bank) { - hologram.setLine(hologramLine, ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Claimed") - .replace("%position", "" + (i + 1)) - .replace("%player", islandOwnerName) - .replace("%balance", - "" + NumberUtil.formatNumberByDecimal(visit.getBankBalance())))); - } else if (hologramTypeList == HologramType.Votes) { - hologram.setLine(hologramLine, ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Claimed") - .replace("%position", "" + (i + 1)) - .replace("%player", islandOwnerName) - .replace("%votes", - "" + NumberUtil.formatNumberByDecimal(visit.getVoters().size())))); - } - } - } + hologramList.update(getHologramLines(hologramList.getType())); } } } diff --git a/src/main/java/com/songoda/skyblock/leaderboard/LeaderboardTask.java b/src/main/java/com/songoda/skyblock/leaderboard/LeaderboardTask.java index 0fdc117f..fade015c 100644 --- a/src/main/java/com/songoda/skyblock/leaderboard/LeaderboardTask.java +++ b/src/main/java/com/songoda/skyblock/leaderboard/LeaderboardTask.java @@ -18,6 +18,6 @@ public class LeaderboardTask extends BukkitRunnable { leaderboardManager.resetLeaderboard(); leaderboardManager.setupLeaderHeads(); - skyblock.getHologramManager().resetHologram(); + skyblock.getHologramManager().updateHologram(); } } diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 39fbf0f9..66feccbd 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -295,7 +295,7 @@ Command: Set: Message: '&bSkyBlock &8| &aInfo&8: &eThe ''&b%type&e'' hologram has been set to your location.' Invalid: - Message: '&bSkyBlock &8| &cError&8: &eInvalid: /island admin sethologram ' + Message: '&bSkyBlock &8| &cError&8: &eInvalid: /island admin sethologram ' Info: Message: '&f&oSets the location of a hologram.' Settings: @@ -316,7 +316,7 @@ Command: Message: '&f&oManage generators for cobblestone generators.' RemoveHologram: Invalid: - Message: '&bSkyBlock &8| &cError&8: &eInvalid: /island admin removehologram ' + Message: '&bSkyBlock &8| &cError&8: &eInvalid: /island admin removehologram ' Set: Message: '&bSkyBlock &8| &cError&8: &eA location for that hologram has not been set.' Info: diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c50f8a86..e299881c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ version: maven-version-number api-version: 1.13 description: A unique SkyBlock plugin author: Songoda -softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, Vault, Reserve, LeaderHeads, EpicSpawners, WildStacker, UltimateStacker, WorldEdit] +softdepend: [HolographicDisplays, Holograms, CMI, PlaceholderAPI, MVdWPlaceholderAPI, Vault, Reserve, LeaderHeads, EpicSpawners, WildStacker, UltimateStacker, WorldEdit] loadbefore: [Multiverse-Core] commands: island: