Fixes issue with Level not being referenced correctly.

https://github.com/BentoBoxWorld/addon-challenges/issues/26
This commit is contained in:
tastybento 2018-11-12 10:24:18 -08:00
parent c70f5cf2f3
commit 1e07223d61
4 changed files with 14 additions and 35 deletions

31
pom.xml
View File

@ -63,11 +63,6 @@
<version>${powermock.version}</version> <version>${powermock.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.8.0</version>
</dependency>
<dependency> <dependency>
<groupId>world.bentobox</groupId> <groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId> <artifactId>bentobox</artifactId>
@ -209,30 +204,4 @@
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>sonar</id>
<properties>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.organization>tastybento-github</sonar.organization>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.4.1.1168</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View File

@ -17,6 +17,7 @@ public class ChallengesAddon extends Addon {
private ChallengesManager challengesManager; private ChallengesManager challengesManager;
private String permissionPrefix = "addon"; private String permissionPrefix = "addon";
private FreshSqueezedChallenges importManager; private FreshSqueezedChallenges importManager;
private boolean hooked;
@Override @Override
public void onLoad() { public void onLoad() {
@ -41,13 +42,14 @@ public class ChallengesAddon extends Addon {
// Register commands - run one tick later to allow all addons to load // Register commands - run one tick later to allow all addons to load
// AcidIsland hook in // AcidIsland hook in
getServer().getScheduler().runTask(getPlugin(), () -> { getServer().getScheduler().runTask(getPlugin(), () -> {
this.getPlugin().getAddonsManager().getAddonByName("AcidIsland").ifPresent(a -> { this.getPlugin().getAddonsManager().getAddonByName("AcidIsland").ifPresent(a -> {
CompositeCommand acidIslandCmd = getPlugin().getCommandsManager().getCommand("ai"); CompositeCommand acidIslandCmd = getPlugin().getCommandsManager().getCommand("ai");
if (acidIslandCmd != null) { if (acidIslandCmd != null) {
new ChallengesCommand(this, acidIslandCmd); new ChallengesCommand(this, acidIslandCmd);
CompositeCommand acidCmd = getPlugin().getCommandsManager().getCommand("acid"); CompositeCommand acidCmd = getPlugin().getCommandsManager().getCommand("acid");
new Challenges(this, acidCmd); new Challenges(this, acidCmd);
hooked = true;
} }
}); });
this.getPlugin().getAddonsManager().getAddonByName("BSkyBlock").ifPresent(a -> { this.getPlugin().getAddonsManager().getAddonByName("BSkyBlock").ifPresent(a -> {
@ -57,10 +59,18 @@ public class ChallengesAddon extends Addon {
new ChallengesCommand(this, bsbIslandCmd); new ChallengesCommand(this, bsbIslandCmd);
CompositeCommand bsbAdminCmd = getPlugin().getCommandsManager().getCommand("bsbadmin"); CompositeCommand bsbAdminCmd = getPlugin().getCommandsManager().getCommand("bsbadmin");
new Challenges(this, bsbAdminCmd); new Challenges(this, bsbAdminCmd);
hooked = true;
} }
}); });
}); });
// If the add-on never hooks in, then it is useless
if (!hooked) {
logError("Challenges could not hook into AcidIsland or BSkyBlock so will not do anything!");
}
// Try to find Level addon and if it does not exist, display a warning
if (!getAddonByName("Level").isPresent()) {
logWarning("Level add-on not found so level challenges will not work!");
}
// Done // Done
} }

View File

@ -151,7 +151,7 @@ public class TryToComplete {
private ChallengeResult checkLevel() { private ChallengeResult checkLevel() {
// Check if the level addon is installed or not // Check if the level addon is installed or not
long level = addon.getAddonByName("BentoBox-Level") long level = addon.getAddonByName("Level")
.map(l -> ((Level)l).getIslandLevel(world, user.getUniqueId())).orElse(0L); .map(l -> ((Level)l).getIslandLevel(world, user.getUniqueId())).orElse(0L);
if (level >= challenge.getReqIslandlevel()) { if (level >= challenge.getReqIslandlevel()) {
return new ChallengeResult().setMeetsRequirements(); return new ChallengeResult().setMeetsRequirements();

View File

@ -4,7 +4,7 @@ version: ${version}
authors: tastybento authors: tastybento
softdepend: AcidIsland, BSkyBlock softdepend: AcidIsland, BSkyBlock, Level
permissions: permissions:
bskyblock.challenges: bskyblock.challenges: