Added 'web.github.download-data' in config

This commit is contained in:
Florian CUNY 2019-02-21 10:53:01 +01:00
parent e041107df9
commit 1bdb919734
2 changed files with 25 additions and 5 deletions

View File

@ -169,6 +169,13 @@ public class Settings implements DataObject {
@ConfigEntry(path = "web.metrics")
private boolean metrics = true;
@ConfigComment("Toggle whether BentoBox can connect to GitHub to get data about updates and addons.")
@ConfigComment("Disabling this will result in the deactivation of the update checker and of some other")
@ConfigComment("features that rely on the data downloaded from the GitHub API.")
@ConfigComment("It does not send any data.")
@ConfigEntry(path = "web.github.download-data", since = "1.3.0")
private boolean githubDownloadData = true;
//---------------------------------------------------------------------------------------/
@ConfigComment("These settings should not be edited")
private String uniqueId = "config";
@ -445,4 +452,12 @@ public class Settings implements DataObject {
public void setResetCooldownOnCreate(boolean resetCooldownOnCreate) {
this.resetCooldownOnCreate = resetCooldownOnCreate;
}
public boolean isGithubDownloadData() {
return githubDownloadData;
}
public void setGithubDownloadData(boolean githubDownloadData) {
this.githubDownloadData = githubDownloadData;
}
}

View File

@ -6,6 +6,7 @@ import java.util.Map;
import org.bukkit.Bukkit;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.github.GitHubConnector;
@ -19,13 +20,15 @@ import world.bentobox.bentobox.api.github.GitHubConnector;
public class WebManager {
private @NonNull BentoBox plugin;
private @NonNull GitHubConnector bentoBoxGitHubConnector;
private @Nullable 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();
if (plugin.getSettings().isGithubDownloadData()) {
this.bentoBoxGitHubConnector = new GitHubConnector("BentoBoxWorld/BentoBox");
setupAddonsGitHubConnectors();
}
}
/**
@ -41,7 +44,9 @@ public class WebManager {
* 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));
if (plugin.getSettings().isGithubDownloadData()) {
Bukkit.getScheduler().runTask(plugin, () -> bentoBoxGitHubConnector.connect());
gitHubConnectors.values().forEach(gitHubConnector -> Bukkit.getScheduler().runTask(plugin, gitHubConnector::connect));
}
}
}