diff --git a/src/main/java/world/bentobox/bentobox/BentoBox.java b/src/main/java/world/bentobox/bentobox/BentoBox.java index 7765900ac..8d38ee990 100644 --- a/src/main/java/world/bentobox/bentobox/BentoBox.java +++ b/src/main/java/world/bentobox/bentobox/BentoBox.java @@ -36,6 +36,7 @@ import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.managers.SchemsManager; +import world.bentobox.bentobox.managers.WebManager; import world.bentobox.bentobox.util.heads.HeadGetter; import world.bentobox.bentobox.versions.ServerCompatibility; @@ -61,6 +62,7 @@ public class BentoBox extends JavaPlugin { private HooksManager hooksManager; private PlaceholdersManager placeholdersManager; private IslandDeletionManager islandDeletionManager; + private WebManager webManager; // Settings private Settings settings; @@ -177,6 +179,9 @@ public class BentoBox extends JavaPlugin { hooksManager.registerHook(new MultiverseCoreHook()); islandWorldManager.registerWorldsToMultiverse(); + webManager = new WebManager(this); + webManager.requestGitHubData(); + // Show banner User.getInstance(Bukkit.getConsoleSender()).sendMessage("successfully-loaded", TextVariables.VERSION, instance.getDescription().getVersion(), diff --git a/src/main/java/world/bentobox/bentobox/managers/WebManager.java b/src/main/java/world/bentobox/bentobox/managers/WebManager.java new file mode 100644 index 000000000..d186dddd0 --- /dev/null +++ b/src/main/java/world/bentobox/bentobox/managers/WebManager.java @@ -0,0 +1,46 @@ +package world.bentobox.bentobox.managers; + +import org.bukkit.Bukkit; +import org.eclipse.jdt.annotation.NonNull; +import world.bentobox.bentobox.BentoBox; +import world.bentobox.bentobox.api.addons.Addon; +import world.bentobox.bentobox.api.github.GitHubConnector; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Handles web-related stuff. + * Should be instantiated after all addons are loaded. + * @author Poslovitch + * @since 1.3.0 + */ +public class WebManager { + + private @NonNull BentoBox plugin; + private @NonNull GitHubConnector bentoBoxGitHubConnector; + private @NonNull Map<@NonNull Addon, @NonNull GitHubConnector> gitHubConnectors = new LinkedHashMap<>(); + + public WebManager(@NonNull BentoBox plugin) { + this.plugin = plugin; + this.bentoBoxGitHubConnector = new GitHubConnector("BentoBoxWorld/BentoBox"); + setupAddonsGitHubConnectors(); + } + + /** + * Setups the {@code GitHubConnector} instances for each addons. + */ + private void setupAddonsGitHubConnectors() { + plugin.getAddonsManager().getEnabledAddons().stream() + .filter(addon -> !addon.getDescription().getRepository().isEmpty()) + .forEach(addon -> gitHubConnectors.put(addon, new GitHubConnector(addon.getDescription().getRepository()))); + } + + /** + * Connects all the {@link GitHubConnector} to GitHub to retrieve data. + */ + public void requestGitHubData() { + Bukkit.getScheduler().runTask(plugin, () -> bentoBoxGitHubConnector.connect()); + gitHubConnectors.values().forEach(gitHubConnector -> Bukkit.getScheduler().runTask(plugin, gitHubConnector::connect)); + } +}