mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2025-02-21 06:21:20 +01:00
Remove duplicate (re)loading code
This commit is contained in:
parent
0ff3b28fdd
commit
c17de21313
@ -15,8 +15,12 @@ import me.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import me.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerTracker;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.ProtocolLibHook;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandManager;
|
||||
import me.filoghost.holographicdisplays.commands.Messages;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||
import me.filoghost.holographicdisplays.disk.HologramConfig;
|
||||
import me.filoghost.holographicdisplays.disk.HologramLoadException;
|
||||
import me.filoghost.holographicdisplays.disk.upgrade.LegacySymbolsUpgrader;
|
||||
import me.filoghost.holographicdisplays.listener.ChunkListener;
|
||||
import me.filoghost.holographicdisplays.listener.MainListener;
|
||||
@ -27,17 +31,18 @@ import me.filoghost.holographicdisplays.nms.interfaces.NMSManager;
|
||||
import me.filoghost.holographicdisplays.nms.interfaces.PacketController;
|
||||
import me.filoghost.holographicdisplays.object.APIHologram;
|
||||
import me.filoghost.holographicdisplays.object.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.placeholder.AnimationsRegister;
|
||||
import me.filoghost.holographicdisplays.placeholder.PlaceholdersManager;
|
||||
import me.filoghost.holographicdisplays.task.BungeeCleanupTask;
|
||||
import me.filoghost.holographicdisplays.task.StartupLoadHologramsTask;
|
||||
import me.filoghost.holographicdisplays.task.WorldPlayerCounterTask;
|
||||
import me.filoghost.holographicdisplays.util.NMSVersion;
|
||||
import org.bstats.bukkit.MetricsLite;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@ -45,6 +50,7 @@ public class HolographicDisplays extends FCommonsPlugin implements PacketControl
|
||||
|
||||
private static HolographicDisplays instance;
|
||||
|
||||
private ConfigManager configManager;
|
||||
private InternalHologramManager internalHologramManager;
|
||||
private APIHologramManager apiHologramManager;
|
||||
|
||||
@ -88,9 +94,9 @@ public class HolographicDisplays extends FCommonsPlugin implements PacketControl
|
||||
throw new PluginEnableException(e, "Couldn't initialize the NMS manager.");
|
||||
}
|
||||
|
||||
configManager = new ConfigManager(getDataFolder().toPath());
|
||||
internalHologramManager = new InternalHologramManager(nmsManager);
|
||||
apiHologramManager = new APIHologramManager(nmsManager);
|
||||
ConfigManager configManager = new ConfigManager(getDataFolder().toPath());
|
||||
|
||||
// Run only once at startup, before anything else.
|
||||
try {
|
||||
@ -98,29 +104,13 @@ public class HolographicDisplays extends FCommonsPlugin implements PacketControl
|
||||
} catch (ConfigException e) {
|
||||
Log.warning("Couldn't convert symbols file", e);
|
||||
}
|
||||
|
||||
// Load placeholders.yml.
|
||||
configManager.reloadCustomPlaceholders();
|
||||
|
||||
// Load the configuration.
|
||||
configManager.reloadMainConfig();
|
||||
|
||||
// ProtocolLib check.
|
||||
load(null, true);
|
||||
|
||||
ProtocolLibHook.setup(this, nmsManager);
|
||||
|
||||
// Load animation files and the placeholder manager.
|
||||
PlaceholdersManager.load(this);
|
||||
try {
|
||||
AnimationsRegister.loadAnimations(configManager);
|
||||
} catch (Exception e) {
|
||||
Log.warning("Failed to load animation files!", e);
|
||||
}
|
||||
|
||||
// Initialize other static classes.
|
||||
configManager.reloadHologramDatabase();
|
||||
BungeeServerTracker.restartTask(Configuration.bungeeRefreshSeconds);
|
||||
|
||||
// Start repeating tasks.
|
||||
PlaceholdersManager.startRefreshTask(this);
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new BungeeCleanupTask(), 5 * 60 * 20, 5 * 60 * 20);
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new WorldPlayerCounterTask(), 0L, 3 * 20);
|
||||
|
||||
@ -141,13 +131,53 @@ public class HolographicDisplays extends FCommonsPlugin implements PacketControl
|
||||
new MetricsLite(this, pluginID);
|
||||
|
||||
updateNotificationListener.runAsyncUpdateCheck();
|
||||
|
||||
// Holograms are loaded later, when the worlds are ready.
|
||||
Bukkit.getScheduler().runTask(this, new StartupLoadHologramsTask(
|
||||
internalHologramManager,
|
||||
configManager.getHologramDatabase().getHolograms()));
|
||||
}
|
||||
|
||||
public void load(CommandSender sender, boolean deferHologramLoad) {
|
||||
configManager.reloadCustomPlaceholders();
|
||||
configManager.reloadMainConfig();
|
||||
configManager.reloadHologramDatabase();
|
||||
try {
|
||||
AnimationsRegister.loadAnimations(configManager);
|
||||
} catch (Exception e) {
|
||||
Log.warning("Failed to load animation files!", e);
|
||||
}
|
||||
|
||||
BungeeServerTracker.resetTrackedServers();
|
||||
BungeeServerTracker.restartTask(Configuration.bungeeRefreshSeconds);
|
||||
|
||||
PlaceholdersManager.untrackAll();
|
||||
internalHologramManager.clearAll();
|
||||
|
||||
if (deferHologramLoad) {
|
||||
// For the initial load: holograms are loaded later, when the worlds are ready
|
||||
Bukkit.getScheduler().runTask(this, () -> createHolograms(sender));
|
||||
} else {
|
||||
createHolograms(sender);
|
||||
}
|
||||
}
|
||||
|
||||
private void createHolograms(CommandSender sender) {
|
||||
// Create all the holograms
|
||||
for (HologramConfig hologramConfig : configManager.getHologramDatabase().getHolograms()) {
|
||||
try {
|
||||
hologramConfig.createHologram(internalHologramManager);
|
||||
} catch (HologramLoadException e) {
|
||||
if (sender != null) {
|
||||
Messages.sendWarning(sender, Utils.formatExceptionMessage(e));
|
||||
} else {
|
||||
Log.warning(Utils.formatExceptionMessage(e));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.warning("Unexpected exception while loading the hologram \"" + hologramConfig.getName() + "\".", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Then trigger a refresh for all of them
|
||||
for (BaseHologram hologram : internalHologramManager.getHolograms()) {
|
||||
hologram.refreshAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
@ -71,7 +71,7 @@ public class HologramCommandManager extends SubCommandManager {
|
||||
subCommands.add(new MovehereCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new AlignCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new CopyCommand(internalHologramManager, configManager));
|
||||
subCommands.add(new ReloadCommand(configManager, internalHologramManager));
|
||||
subCommands.add(new ReloadCommand());
|
||||
|
||||
subCommands.add(new RemovelineCommand(this, internalHologramManager, configManager));
|
||||
subCommands.add(new SetlineCommand(this, internalHologramManager, configManager));
|
||||
|
@ -6,68 +6,23 @@
|
||||
package me.filoghost.holographicdisplays.commands.subs;
|
||||
|
||||
import me.filoghost.fcommons.command.sub.SubCommandContext;
|
||||
import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.Colors;
|
||||
import me.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerTracker;
|
||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import me.filoghost.holographicdisplays.commands.HologramSubCommand;
|
||||
import me.filoghost.holographicdisplays.commands.Messages;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||
import me.filoghost.holographicdisplays.disk.HologramConfig;
|
||||
import me.filoghost.holographicdisplays.disk.HologramLoadException;
|
||||
import me.filoghost.holographicdisplays.event.HolographicDisplaysReloadEvent;
|
||||
import me.filoghost.holographicdisplays.object.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.object.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.placeholder.AnimationsRegister;
|
||||
import me.filoghost.holographicdisplays.placeholder.PlaceholdersManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class ReloadCommand extends HologramSubCommand {
|
||||
|
||||
private final ConfigManager configManager;
|
||||
private final InternalHologramManager internalHologramManager;
|
||||
|
||||
public ReloadCommand(ConfigManager configManager, InternalHologramManager internalHologramManager) {
|
||||
public ReloadCommand() {
|
||||
super("reload");
|
||||
setDescription("Reloads the holograms from the database.");
|
||||
|
||||
this.configManager = configManager;
|
||||
this.internalHologramManager = internalHologramManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, SubCommandContext context) {
|
||||
configManager.reloadCustomPlaceholders();
|
||||
configManager.reloadMainConfig();
|
||||
|
||||
BungeeServerTracker.resetTrackedServers();
|
||||
BungeeServerTracker.restartTask(Configuration.bungeeRefreshSeconds);
|
||||
|
||||
configManager.reloadHologramDatabase();
|
||||
try {
|
||||
AnimationsRegister.loadAnimations(configManager);
|
||||
} catch (Exception e) {
|
||||
Log.warning("Failed to load animation files!", e);
|
||||
}
|
||||
|
||||
PlaceholdersManager.untrackAll();
|
||||
internalHologramManager.clearAll();
|
||||
|
||||
// Create all the holograms
|
||||
for (HologramConfig hologramConfig : configManager.getHologramDatabase().getHolograms()) {
|
||||
try {
|
||||
hologramConfig.createHologram(internalHologramManager);
|
||||
} catch (HologramLoadException e) {
|
||||
Messages.sendWarning(sender, Utils.formatExceptionMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
// Then trigger a refresh for all of them
|
||||
for (BaseHologram hologram : internalHologramManager.getHolograms()) {
|
||||
hologram.refreshAll();
|
||||
}
|
||||
HolographicDisplays.getInstance().load(sender, false);
|
||||
|
||||
sender.sendMessage(Colors.PRIMARY + "Configuration reloaded successfully.");
|
||||
Bukkit.getPluginManager().callEvent(new HolographicDisplaysReloadEvent());
|
||||
|
@ -46,7 +46,7 @@ public class PlaceholdersManager {
|
||||
}
|
||||
|
||||
|
||||
public static void load(Plugin plugin) {
|
||||
public static void startRefreshTask(Plugin plugin) {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
|
||||
for (Placeholder placeholder : PlaceholdersRegister.getPlaceholders()) {
|
||||
|
Loading…
Reference in New Issue
Block a user