diff --git a/src/main/java/com/songoda/skyblock/SkyBlock.java b/src/main/java/com/songoda/skyblock/SkyBlock.java index 78cc06db..2ee4b4e1 100644 --- a/src/main/java/com/songoda/skyblock/SkyBlock.java +++ b/src/main/java/com/songoda/skyblock/SkyBlock.java @@ -15,7 +15,7 @@ import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.confirmation.ConfirmationTask; import com.songoda.skyblock.cooldown.CooldownManager; import com.songoda.skyblock.generator.GeneratorManager; -import com.songoda.skyblock.hologram.HologramManager; +import com.songoda.skyblock.tasks.HologramTask; import com.songoda.skyblock.invite.InviteManager; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.reward.RewardManager; @@ -77,7 +77,7 @@ public class SkyBlock extends SongodaPlugin { private LeaderboardManager leaderboardManager; private PlaceholderManager placeholderManager; private MessageManager messageManager; - private HologramManager hologramManager; + private HologramTask hologramTask; private LimitationInstanceHandler limitationHandler; private LocalizationManager localizationManager; private RewardManager rewardManager; @@ -142,7 +142,6 @@ public class SkyBlock extends SongodaPlugin { placeholderManager.registerPlaceholders(); messageManager = new MessageManager(this); - hologramManager = new HologramManager(this); rewardManager = new RewardManager(this); rewardManager.loadRewards(); @@ -151,6 +150,9 @@ public class SkyBlock extends SongodaPlugin { new VisitTask(playerDataManager).runTaskTimerAsynchronously(this, 0L, 20L); new ConfirmationTask(playerDataManager).runTaskTimerAsynchronously(this, 0L, 20L); + // Start Tasks + hologramTask = HologramTask.startTask(this); + PluginManager pluginManager = getServer().getPluginManager(); pluginManager.registerEvents(new Join(this), this); pluginManager.registerEvents(new Quit(this), this); @@ -220,8 +222,8 @@ public class SkyBlock extends SongodaPlugin { this.cooldownManager.onDisable(); } - if (this.hologramManager != null) { - this.hologramManager.onDisable(); + if (this.hologramTask != null) { + this.hologramTask.onDisable(); } if (this.fabledChallenge != null) { @@ -333,8 +335,8 @@ public class SkyBlock extends SongodaPlugin { return messageManager; } - public HologramManager getHologramManager() { - return hologramManager; + public HologramTask getHologramTask() { + return hologramTask; } public StackableManager getStackableManager() { 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 7b0854a6..17002a3c 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().updateHologram()); + Bukkit.getScheduler().runTask(skyblock, () -> skyblock.getHologramTask().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 8e53a582..f3f2de4f 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().updateHologram()); + Bukkit.getScheduler().runTask(skyblock, () -> skyblock.getHologramTask().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 76740ee0..ee6dfd39 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 @@ -5,7 +5,7 @@ import com.songoda.skyblock.command.SubCommand; import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.hologram.Hologram; -import com.songoda.skyblock.hologram.HologramManager; +import com.songoda.skyblock.tasks.HologramTask; import com.songoda.skyblock.hologram.HologramType; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.sound.SoundManager; @@ -33,7 +33,7 @@ public class RemoveHologramCommand extends SubCommand { } public void onCommand(CommandSender sender, String[] args) { - HologramManager hologramManager = skyblock.getHologramManager(); + HologramTask hologramManager = skyblock.getHologramTask(); MessageManager messageManager = skyblock.getMessageManager(); SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); 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 2593afe1..6d066755 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 @@ -5,7 +5,7 @@ import com.songoda.skyblock.command.SubCommand; import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.hologram.Hologram; -import com.songoda.skyblock.hologram.HologramManager; +import com.songoda.skyblock.tasks.HologramTask; import com.songoda.skyblock.hologram.HologramType; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.sound.SoundManager; @@ -21,7 +21,7 @@ public class SetHologramCommand extends SubCommand { @Override public void onCommandByPlayer(Player player, String[] args) { - HologramManager hologramManager = skyblock.getHologramManager(); + HologramTask hologramManager = skyblock.getHologramTask(); MessageManager messageManager = skyblock.getMessageManager(); SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); diff --git a/src/main/java/com/songoda/skyblock/leaderboard/LeaderboardTask.java b/src/main/java/com/songoda/skyblock/leaderboard/LeaderboardTask.java index fade015c..b3334236 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().updateHologram(); + skyblock.getHologramTask().updateHologram(); } } diff --git a/src/main/java/com/songoda/skyblock/hologram/HologramManager.java b/src/main/java/com/songoda/skyblock/tasks/HologramTask.java similarity index 76% rename from src/main/java/com/songoda/skyblock/hologram/HologramManager.java rename to src/main/java/com/songoda/skyblock/tasks/HologramTask.java index e7de74b8..9f0b85c8 100644 --- a/src/main/java/com/songoda/skyblock/hologram/HologramManager.java +++ b/src/main/java/com/songoda/skyblock/tasks/HologramTask.java @@ -1,9 +1,11 @@ -package com.songoda.skyblock.hologram; +package com.songoda.skyblock.tasks; import com.songoda.core.utils.TextUtils; import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager.Config; +import com.songoda.skyblock.hologram.Hologram; +import com.songoda.skyblock.hologram.HologramType; import com.songoda.skyblock.island.IslandLevel; import com.songoda.skyblock.leaderboard.Leaderboard; import com.songoda.skyblock.leaderboard.LeaderboardManager; @@ -15,33 +17,45 @@ import org.bukkit.Bukkit; import org.bukkit.Location; 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; -public class HologramManager { +public class HologramTask extends BukkitRunnable { - private final SkyBlock skyblock; - private List hologramStorage = new ArrayList<>(); + private static HologramTask instance; + private static SkyBlock plugin; - public HologramManager(SkyBlock skyblock) { - this.skyblock = skyblock; + private final List hologramStorage = new ArrayList<>(); - FileManager fileManager = skyblock.getFileManager(); + public HologramTask(SkyBlock plug) { + plugin = plug; + } - Bukkit.getServer().getScheduler().runTaskLater(skyblock, () -> { - for (HologramType hologramTypeList : HologramType.values()) { - if (hologramTypeList == HologramType.Votes) { - if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")) - .getFileConfiguration().getBoolean("Island.Visitor.Vote")) { - continue; - } + public static HologramTask startTask(SkyBlock plug) { + plugin = plug; + if (instance == null) { + instance = new HologramTask(plugin); + instance.runTaskTimerAsynchronously(plugin, 0, 20 * 15); + } + + return instance; + } + + @Override + public void run() { + FileManager fileManager = plugin.getFileManager(); + for (HologramType hologramTypeList : HologramType.values()) { + if (hologramTypeList == HologramType.Votes) { + if (!fileManager.getConfig(new File(plugin.getDataFolder(), "config.yml")) + .getFileConfiguration().getBoolean("Island.Visitor.Vote")) { + continue; } - - spawnHologram(hologramTypeList); } - }, 200L); + spawnHologram(hologramTypeList); + } } public void onDisable() { @@ -53,22 +67,21 @@ public class HologramManager { } public void spawnHologram(HologramType type) { - FileManager fileManager = skyblock.getFileManager(); + FileManager fileManager = plugin.getFileManager(); - Config locationsConfig = fileManager.getConfig(new File(skyblock.getDataFolder(), "locations.yml")); + Config locationsConfig = fileManager.getConfig(new File(plugin.getDataFolder(), "locations.yml")); FileConfiguration locationsConfigLoad = locationsConfig.getFileConfiguration(); if (locationsConfigLoad.getString("Location.Hologram.Leaderboard." + type) != null) - spawnHologram(type, skyblock.getFileManager().getLocation(locationsConfig, + spawnHologram(type, plugin.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(); + FileManager fileManager = plugin.getFileManager(); + LeaderboardManager leaderboardManager = plugin.getLeaderboardManager(); - FileConfiguration languageConfigLoad = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")) + FileConfiguration languageConfigLoad = fileManager.getConfig(new File(plugin.getDataFolder(), "language.yml")) .getFileConfiguration(); List hologramLines = new ArrayList<>();