mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-09 08:51:40 +01:00
Should fix NPE when setting up connection to GitHub
This commit is contained in:
parent
4eae5fada0
commit
d9dc337de9
@ -59,36 +59,27 @@ public class WebManager {
|
|||||||
if (plugin.getSettings().isLogGithubDownloadData()) {
|
if (plugin.getSettings().isLogGithubDownloadData()) {
|
||||||
plugin.log("Downloading data from GitHub...");
|
plugin.log("Downloading data from GitHub...");
|
||||||
}
|
}
|
||||||
GitHubRepository repo = new GitHubRepository(gh, "BentoBoxWorld/weblink");
|
GitHubRepository repo;
|
||||||
|
try {
|
||||||
|
repo = new GitHubRepository(gh, "BentoBoxWorld/weblink");
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.logError("An unhandled exception occurred when trying to connect to GitHub...");
|
||||||
|
plugin.logStacktrace(e);
|
||||||
|
|
||||||
String tagsContent = "";
|
// Stop the execution of the method right away.
|
||||||
String topicsContent = "";
|
return;
|
||||||
String catalogContent = "";
|
}
|
||||||
|
|
||||||
// Downloading the data
|
// Downloading the data
|
||||||
try {
|
String tagsContent = getContent(repo, "catalog/tags.json");
|
||||||
tagsContent = repo.getContent("catalog/tags.json").getContent().replaceAll("\\n", "");
|
String topicsContent = getContent(repo, "catalog/topics.json");
|
||||||
topicsContent = repo.getContent("catalog/topics.json").getContent().replaceAll("\\n", "");
|
String catalogContent = getContent(repo, "catalog/catalog.json");
|
||||||
catalogContent = repo.getContent("catalog/catalog.json").getContent().replaceAll("\\n", "");
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
if (plugin.getSettings().isLogGithubDownloadData()) {
|
|
||||||
plugin.log("Could not connect to GitHub.");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
plugin.logError("An unhandled exception occurred when downloading data from GitHub...");
|
|
||||||
plugin.logStacktrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// People were concerned that the download took ages, so we need to tell them it's over now.
|
// People were concerned that the download took ages, so we need to tell them it's over now.
|
||||||
if (plugin.getSettings().isLogGithubDownloadData()) {
|
if (plugin.getSettings().isLogGithubDownloadData()) {
|
||||||
plugin.log("Successfully downloaded data from GitHub.");
|
plugin.log("Successfully downloaded data from GitHub.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decoding the Base64 encoded contents
|
|
||||||
tagsContent = new String(Base64.getDecoder().decode(tagsContent), StandardCharsets.UTF_8);
|
|
||||||
topicsContent = new String(Base64.getDecoder().decode(topicsContent), StandardCharsets.UTF_8);
|
|
||||||
catalogContent = new String(Base64.getDecoder().decode(catalogContent), StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
/* Parsing the data */
|
/* Parsing the data */
|
||||||
|
|
||||||
// Register the tags translations in the locales
|
// Register the tags translations in the locales
|
||||||
@ -140,6 +131,29 @@ public class WebManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param repo
|
||||||
|
* @param fileName
|
||||||
|
* @return
|
||||||
|
* @since 1.8.0
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
private String getContent(@NonNull GitHubRepository repo, String fileName) {
|
||||||
|
try {
|
||||||
|
String content = repo.getContent(fileName).getContent().replaceAll("\\n", "");
|
||||||
|
return new String(Base64.getDecoder().decode(content), StandardCharsets.UTF_8);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
if (plugin.getSettings().isLogGithubDownloadData()) {
|
||||||
|
plugin.log("Could not connect to GitHub.");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.logError("An unhandled exception occurred when downloading '" + fileName + "' from GitHub...");
|
||||||
|
plugin.logStacktrace(e);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the contents of the addons catalog (may be an empty list).
|
* Returns the contents of the addons catalog (may be an empty list).
|
||||||
* @return the contents of the addons catalog.
|
* @return the contents of the addons catalog.
|
||||||
|
Loading…
Reference in New Issue
Block a user