Added WebManager

This commit is contained in:
Florian CUNY 2019-02-12 16:24:51 +01:00
parent 3fb60480ff
commit 7e0ea8d945
2 changed files with 51 additions and 0 deletions

View File

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

View File

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