-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved everything to world.bentobox.challenges package
- Loading branch information
1 parent
5009729
commit 8f51ddb
Showing
32 changed files
with
4,574 additions
and
1 deletion.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
src/main/java/world/bentobox/challenges/ChallengesAddon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package world.bentobox.challenges; | ||
|
||
import org.bukkit.Bukkit; | ||
|
||
import world.bentobox.challenges.commands.ChallengesCommand; | ||
import world.bentobox.challenges.commands.admin.Challenges; | ||
import world.bentobox.challenges.listeners.ResetListener; | ||
import world.bentobox.challenges.listeners.SaveListener; | ||
import world.bentobox.bentobox.api.addons.Addon; | ||
import world.bentobox.bentobox.api.commands.CompositeCommand; | ||
|
||
/** | ||
* Add-on to BSkyBlock that enables challenges | ||
* @author tastybento | ||
* | ||
*/ | ||
public class ChallengesAddon extends Addon { | ||
|
||
private ChallengesManager challengesManager; | ||
private String permissionPrefix = "addon"; | ||
private FreshSqueezedChallenges importManager; | ||
private boolean hooked; | ||
|
||
@Override | ||
public void onLoad() { | ||
// Save default config.yml | ||
saveDefaultConfig(); | ||
} | ||
|
||
@Override | ||
public void onEnable() { | ||
// Check if it is enabled - it might be loaded, but not enabled. | ||
if (getPlugin() == null || !getPlugin().isEnabled()) { | ||
Bukkit.getLogger().severe("BentoBox is not available or disabled!"); | ||
this.setState(State.DISABLED); | ||
return; | ||
} | ||
|
||
// Challenges Manager | ||
challengesManager = new ChallengesManager(this); | ||
// Challenge import setup | ||
importManager = new FreshSqueezedChallenges(this); | ||
|
||
// Register commands - run one tick later to allow all addons to load | ||
// AcidIsland hook in | ||
getPlugin().getAddonsManager().getAddonByName("AcidIsland").ifPresent(a -> { | ||
CompositeCommand acidIslandCmd = getPlugin().getCommandsManager().getCommand("ai"); | ||
if (acidIslandCmd != null) { | ||
new ChallengesCommand(this, acidIslandCmd); | ||
CompositeCommand acidCmd = getPlugin().getCommandsManager().getCommand("acid"); | ||
new Challenges(this, acidCmd); | ||
hooked = true; | ||
} | ||
}); | ||
getPlugin().getAddonsManager().getAddonByName("BSkyBlock").ifPresent(a -> { | ||
// BSkyBlock hook in | ||
CompositeCommand bsbIslandCmd = getPlugin().getCommandsManager().getCommand("island"); | ||
if (bsbIslandCmd != null) { | ||
new ChallengesCommand(this, bsbIslandCmd); | ||
CompositeCommand bsbAdminCmd = getPlugin().getCommandsManager().getCommand("bsbadmin"); | ||
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!"); | ||
this.setState(State.DISABLED); | ||
return; | ||
} | ||
// 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!"); | ||
} | ||
// Register the reset listener | ||
this.registerListener(new ResetListener(this)); | ||
// Register the autosave listener. | ||
this.registerListener(new SaveListener(this)); | ||
// Done | ||
} | ||
|
||
@Override | ||
public void onDisable(){ | ||
if (challengesManager != null) { | ||
challengesManager.save(false); | ||
} | ||
} | ||
|
||
public ChallengesManager getChallengesManager() { | ||
return challengesManager; | ||
} | ||
|
||
@Override | ||
public String getPermissionPrefix() { | ||
return permissionPrefix ; | ||
} | ||
|
||
/** | ||
* @return the importManager | ||
*/ | ||
public FreshSqueezedChallenges getImportManager() { | ||
return importManager; | ||
} | ||
|
||
} |
Oops, something went wrong.