Skip to content

Commit

Permalink
Remove all references to GitHubWebAPI4Java and use lambda instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
BONNe authored and BuildTools committed Sep 2, 2019
1 parent b719b88 commit 747c12f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 32 deletions.
12 changes: 0 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@
<version>${vault.version}</version>
<scope>provided</scope>
</dependency>
<!-- Shaded APIs -->
<dependency>
<groupId>com.github.TheBusyBiscuit</groupId>
<artifactId>GitHubWebAPI4Java</artifactId>
<version>d5f5e0bbd8</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -265,12 +259,6 @@
<version>3.2.1</version>
<configuration>
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>io.github.TheBusyBiscuit.GitHubWebAPI4Java</pattern>
<shadedPattern>world.bentobox.bentobox.api.github</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
Expand Down
31 changes: 11 additions & 20 deletions src/main/java/world/bentobox/challenges/web/WebManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.nio.charset.StandardCharsets;
import java.util.*;

import io.github.TheBusyBiscuit.GitHubWebAPI4Java.GitHubWebAPI;
import io.github.TheBusyBiscuit.GitHubWebAPI4Java.objects.repositories.GitHubRepository;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.challenges.ChallengesAddon;
Expand Down Expand Up @@ -40,15 +38,15 @@ public WebManager(ChallengesAddon addon)
// If below 0, it means we shouldn't run this as a repeating task.
this.plugin.getServer().getScheduler().runTaskLaterAsynchronously(this.plugin,
() -> this.requestCatalogGitHubData(true),
20L);
600L);
}
else
{
// Set connection interval to be at least 60 minutes.
connectionInterval = Math.max(connectionInterval, 60 * 20 * 60L);
this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin,
() -> this.requestCatalogGitHubData(true),
20L,
600L,
connectionInterval);
}
}
Expand All @@ -61,21 +59,21 @@ public WebManager(ChallengesAddon addon)
*/
public void requestCatalogGitHubData(boolean clearCache)
{
this.plugin.getWebManager().getGitHub().ifPresent(gh ->
this.plugin.getWebManager().getGitHub().ifPresent(gitHubWebAPI ->
{
if (this.plugin.getSettings().isLogGithubDownloadData())
{
this.plugin.log("Downloading data from GitHub...");
}

GitHubRepository repo = new GitHubRepository(gh, "BentoBoxWorld/weblink");

String catalogContent = "";

// Downloading the data
try
{
catalogContent = repo.getContent("challenges/catalog.json").getContent().replaceAll("\\n", "");
catalogContent = gitHubWebAPI.getRepository("BentoBoxWorld", "weblink").
getContent("challenges/catalog.json").
getContent().replaceAll("\\n", "");
}
catch (IllegalAccessException e)
{
Expand Down Expand Up @@ -125,26 +123,22 @@ public void requestCatalogGitHubData(boolean clearCache)
* @param entry Entry that contains information about requested object.
* @return {@code true} if request was successful, {@code false} otherwise.
*/
public boolean requestEntryGitHubData(User user, World world, LibraryEntry entry)
public void requestEntryGitHubData(User user, World world, LibraryEntry entry)
{
Optional<GitHubWebAPI> gitAPI = this.plugin.getWebManager().getGitHub();

if (gitAPI.isPresent())
this.plugin.getWebManager().getGitHub().ifPresent(gitHubWebAPI ->
{
if (this.plugin.getSettings().isLogGithubDownloadData())
{
this.plugin.log("Downloading data from GitHub...");
}

GitHubRepository repo = new GitHubRepository(gitAPI.get(), "BentoBoxWorld/weblink");

String challengeLibrary = "";

// Downloading the data
try
{

challengeLibrary = repo.getContent("challenges/library/" + entry.getRepository() + ".json").
challengeLibrary = gitHubWebAPI.getRepository("BentoBoxWorld", "weblink").
getContent("challenges/library/" + entry.getRepository() + ".json").
getContent().
replaceAll("\\n", "");
}
Expand Down Expand Up @@ -177,11 +171,8 @@ public boolean requestEntryGitHubData(User user, World world, LibraryEntry entry
if (!challengeLibrary.isEmpty())
{
this.addon.getImportManager().loadDownloadedChallenges(user, world, challengeLibrary);
return true;
}
}

return false;
});
}


Expand Down

0 comments on commit 747c12f

Please sign in to comment.