Convert the HologramManager into a task.

This commit is contained in:
Brianna 2020-04-11 07:24:28 -04:00
parent 85c49242be
commit 42b4d09294
7 changed files with 53 additions and 38 deletions

View File

@ -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() {

View File

@ -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"));

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -18,6 +18,6 @@ public class LeaderboardTask extends BukkitRunnable {
leaderboardManager.resetLeaderboard();
leaderboardManager.setupLeaderHeads();
skyblock.getHologramManager().updateHologram();
skyblock.getHologramTask().updateHologram();
}
}

View File

@ -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<Hologram> hologramStorage = new ArrayList<>();
private static HologramTask instance;
private static SkyBlock plugin;
public HologramManager(SkyBlock skyblock) {
this.skyblock = skyblock;
private final List<Hologram> 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<String> 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<String> hologramLines = new ArrayList<>();