mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-23 08:41:29 +01:00
Attempt to initialize dependencies more aggressively, fixes #1246
This commit is contained in:
parent
77bc015340
commit
6f6c2ebac8
@ -22,8 +22,8 @@ public class DenizenTrigger {
|
||||
if (scriptName == null) {
|
||||
return false;
|
||||
}
|
||||
if (plugin.getDependencies().getDenizenAPI().containsScript(scriptName)) {
|
||||
plugin.getDependencies().getDenizenAPI().runTaskScript(scriptName, quester.getPlayer());
|
||||
if (plugin.getDependencies().getDenizenApi().containsScript(scriptName)) {
|
||||
plugin.getDependencies().getDenizenApi().runTaskScript(scriptName, quester.getPlayer());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ import de.erethon.dungeonsxl.DungeonsXL;
|
||||
|
||||
public class Dependencies {
|
||||
|
||||
private Quests plugin;
|
||||
private final Quests plugin;
|
||||
private static Economy economy = null;
|
||||
private static Permission permission = null;
|
||||
private static WorldGuardAPI worldGuardApi = null;
|
||||
@ -61,43 +61,77 @@ public class Dependencies {
|
||||
}
|
||||
|
||||
public Economy getVaultEconomy() {
|
||||
if (economy == null && isPluginAvailable("Vault")) {
|
||||
if (!setupEconomy()) {
|
||||
plugin.getLogger().warning("Economy not found.");
|
||||
}
|
||||
}
|
||||
return economy;
|
||||
}
|
||||
|
||||
public Permission getVaultPermission() {
|
||||
if (permission == null && isPluginAvailable("Vault")) {
|
||||
if (!setupPermissions()) {
|
||||
plugin.getLogger().warning("Permissions not found.");
|
||||
}
|
||||
}
|
||||
return permission;
|
||||
}
|
||||
|
||||
public WorldGuardAPI getWorldGuardApi() {
|
||||
if (worldGuardApi == null && isPluginAvailable("WorldGuard")) {
|
||||
worldGuardApi = new WorldGuardAPI(plugin.getServer().getPluginManager().getPlugin("WorldGuard"));
|
||||
}
|
||||
return worldGuardApi;
|
||||
}
|
||||
|
||||
public mcMMO getMcmmoClassic() {
|
||||
if (mcmmo == null && isPluginAvailable("Heroes")) {
|
||||
try {
|
||||
Class.forName("com.gmail.nossr50.datatypes.skills.SkillType");
|
||||
mcmmo = (mcMMO) plugin.getServer().getPluginManager().getPlugin("mcMMO");
|
||||
} catch (Exception e) {
|
||||
// Unsupported version
|
||||
}
|
||||
}
|
||||
return mcmmo;
|
||||
}
|
||||
|
||||
public Heroes getHeroes() {
|
||||
if (heroes == null && isPluginAvailable("Heroes")) {
|
||||
heroes = (Heroes) plugin.getServer().getPluginManager().getPlugin("Heroes");
|
||||
}
|
||||
return heroes;
|
||||
}
|
||||
|
||||
public PhatLoots getPhatLoots() {
|
||||
if (phatLoots == null && isPluginAvailable("PhatLoots")) {
|
||||
try {
|
||||
phatLoots = (PhatLoots) plugin.getServer().getPluginManager().getPlugin("PhatLoots");
|
||||
plugin.getLogger().info("Sucessfully linked Quests with PhatLoots "
|
||||
+ phatLoots.getDescription().getVersion());
|
||||
} catch (NoClassDefFoundError e) {
|
||||
plugin.getLogger().warning("Unofficial version of PhatLoots found. PhatLoots in Quests not enabled.");
|
||||
}
|
||||
}
|
||||
return phatLoots;
|
||||
}
|
||||
|
||||
public PlaceholderAPIPlugin getPlaceholderApi() {
|
||||
if (placeholder == null && isPluginAvailable("PlaceholderAPI")) {
|
||||
placeholder = (PlaceholderAPIPlugin) plugin.getServer().getPluginManager().getPlugin("PlaceholderAPI");
|
||||
}
|
||||
return placeholder;
|
||||
}
|
||||
|
||||
public CitizensPlugin getCitizens() {
|
||||
if (citizens == null) {
|
||||
if (isPluginAvailable("Citizens")) {
|
||||
try {
|
||||
citizens = (CitizensPlugin) plugin.getServer().getPluginManager().getPlugin("Citizens");
|
||||
plugin.getLogger().info("Sucessfully linked Quests with Citizens "
|
||||
+ citizens.getDescription().getVersion());
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("Legacy version of Citizens found. Citizens in Quests not enabled.");
|
||||
}
|
||||
if (citizens == null && isPluginAvailable("Citizens")) {
|
||||
try {
|
||||
citizens = (CitizensPlugin) plugin.getServer().getPluginManager().getPlugin("Citizens");
|
||||
plugin.getLogger().info("Sucessfully linked Quests with Citizens "
|
||||
+ citizens.getDescription().getVersion());
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("Legacy version of Citizens found. Citizens in Quests not enabled.");
|
||||
}
|
||||
}
|
||||
return citizens;
|
||||
@ -107,19 +141,37 @@ public class Dependencies {
|
||||
citizens = null;
|
||||
}
|
||||
|
||||
public DenizenAPI getDenizenAPI() {
|
||||
public DenizenAPI getDenizenApi() {
|
||||
if (denizenApi == null && isPluginAvailable("Denizen")) {
|
||||
denizenApi = new DenizenAPI();
|
||||
}
|
||||
return denizenApi;
|
||||
}
|
||||
|
||||
public CitizensBooksAPI getCitizensBooksApi() {
|
||||
if (citizensBooks == null && isPluginAvailable("CitizensBooks")) {
|
||||
citizensBooks = ((CitizensBooksPlugin) plugin.getServer().getPluginManager().getPlugin("CitizensBooks"))
|
||||
.getAPI();
|
||||
}
|
||||
return citizensBooks;
|
||||
}
|
||||
|
||||
public DungeonsXL getDungeonsApi() {
|
||||
if (dungeons == null && isPluginAvailable("DungeonsXL")) {
|
||||
dungeons = DungeonsXL.getInstance();
|
||||
}
|
||||
return dungeons;
|
||||
}
|
||||
|
||||
public PartiesAPI getPartiesApi() {
|
||||
if (parties == null && isPluginAvailable("Parties")) {
|
||||
try {
|
||||
Class.forName("com.alessiodp.parties.api.Parties");
|
||||
parties = Parties.getApi();
|
||||
} catch (Exception e) {
|
||||
// Unsupported version
|
||||
}
|
||||
}
|
||||
return parties;
|
||||
}
|
||||
|
||||
@ -136,63 +188,18 @@ public class Dependencies {
|
||||
}
|
||||
|
||||
void init() {
|
||||
if (isPluginAvailable("Citizens")) {
|
||||
try {
|
||||
citizens = (CitizensPlugin) plugin.getServer().getPluginManager().getPlugin("Citizens");
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("Legacy version of Citizens found. Citizens in Quests not enabled.");
|
||||
}
|
||||
}
|
||||
if (isPluginAvailable("WorldGuard")) {
|
||||
worldGuardApi = new WorldGuardAPI(plugin.getServer().getPluginManager().getPlugin("WorldGuard"));
|
||||
}
|
||||
if (isPluginAvailable("Denizen")) {
|
||||
denizenApi = new DenizenAPI();
|
||||
}
|
||||
if (isPluginAvailable("mcMMO")) {
|
||||
try {
|
||||
Class.forName("com.gmail.nossr50.datatypes.skills.SkillType");
|
||||
mcmmo = (mcMMO) plugin.getServer().getPluginManager().getPlugin("mcMMO");
|
||||
} catch (Exception e) {
|
||||
// Unsupported version
|
||||
}
|
||||
}
|
||||
if (isPluginAvailable("Heroes")) {
|
||||
heroes = (Heroes) plugin.getServer().getPluginManager().getPlugin("Heroes");
|
||||
}
|
||||
if (isPluginAvailable("PhatLoots")) {
|
||||
try {
|
||||
phatLoots = (PhatLoots) plugin.getServer().getPluginManager().getPlugin("PhatLoots");
|
||||
} catch (NoClassDefFoundError e) {
|
||||
plugin.getLogger().warning("Unofficial version of PhatLoots found. PhatLoots in Quests not enabled.");
|
||||
}
|
||||
}
|
||||
if (isPluginAvailable("PlaceholderAPI")) {
|
||||
placeholder = (PlaceholderAPIPlugin) plugin.getServer().getPluginManager().getPlugin("PlaceholderAPI");
|
||||
}
|
||||
if (isPluginAvailable("CitizensBooks")) {
|
||||
citizensBooks = ((CitizensBooksPlugin) plugin.getServer().getPluginManager().getPlugin("CitizensBooks"))
|
||||
.getAPI();
|
||||
}
|
||||
if (isPluginAvailable("DungeonsXL")) {
|
||||
dungeons = DungeonsXL.getInstance();
|
||||
}
|
||||
if (isPluginAvailable("Parties")) {
|
||||
try {
|
||||
Class.forName("com.alessiodp.parties.api.Parties");
|
||||
parties = Parties.getApi();
|
||||
} catch (Exception e) {
|
||||
// Unsupported version
|
||||
}
|
||||
}
|
||||
if (isPluginAvailable("Vault")) {
|
||||
if (!setupEconomy()) {
|
||||
plugin.getLogger().warning("Economy not found.");
|
||||
}
|
||||
if (!setupPermissions()) {
|
||||
plugin.getLogger().warning("Permissions not found.");
|
||||
}
|
||||
}
|
||||
getCitizens();
|
||||
getWorldGuardApi();
|
||||
getDenizenApi();
|
||||
getMcmmoClassic();
|
||||
getHeroes();
|
||||
getPhatLoots();
|
||||
getPlaceholderApi();
|
||||
getCitizensBooksApi();
|
||||
getDungeonsApi();
|
||||
getPartiesApi();
|
||||
getVaultEconomy();
|
||||
getVaultPermission();
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
|
@ -1946,7 +1946,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
List<Integer> npcAmountsToKill = new LinkedList<Integer>();
|
||||
// Legacy Denizen script load
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".script-to-run")) {
|
||||
if (getDependencies().getDenizenAPI().containsScript(config.getString("quests." + questKey
|
||||
if (getDependencies().getDenizenApi().containsScript(config.getString("quests." + questKey
|
||||
+ ".stages.ordered." + stageNum + ".script-to-run"))) {
|
||||
oStage.script = config.getString("quests." + questKey + ".stages.ordered." + stageNum
|
||||
+ ".script-to-run");
|
||||
|
@ -74,7 +74,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
if (plugin.getDependencies().getDenizenAPI() == null) {
|
||||
if (plugin.getDependencies().getDenizenApi() == null) {
|
||||
return ChatColor.GRAY;
|
||||
} else {
|
||||
return ChatColor.BLUE;
|
||||
@ -105,7 +105,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
|
||||
case 6:
|
||||
return ChatColor.YELLOW + Lang.get("eventEditorSetMobSpawns");
|
||||
case 7:
|
||||
if (plugin.getDependencies().getDenizenAPI() == null) {
|
||||
if (plugin.getDependencies().getDenizenApi() == null) {
|
||||
return ChatColor.GRAY + Lang.get("stageEditorDenizenScript");
|
||||
} else {
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorDenizenScript");
|
||||
@ -146,7 +146,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
|
||||
return text;
|
||||
}
|
||||
case 7:
|
||||
if (plugin.getDependencies().getDenizenAPI() == null) {
|
||||
if (plugin.getDependencies().getDenizenApi() == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")";
|
||||
} else {
|
||||
if (context.getSessionData(CK.E_DENIZEN) == null) {
|
||||
@ -692,7 +692,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
String text = ChatColor.DARK_AQUA + "- " + Lang.get("stageEditorDenizenScript") + " -\n";
|
||||
for (String s : plugin.getDependencies().getDenizenAPI().getScriptNames()) {
|
||||
for (String s : plugin.getDependencies().getDenizenApi().getScriptNames()) {
|
||||
text += ChatColor.AQUA + "- " + s + "\n";
|
||||
}
|
||||
return text + ChatColor.YELLOW + Lang.get("stageEditorScriptPrompt");
|
||||
@ -703,7 +703,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
|
||||
Player player = (Player) context.getForWhom();
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false
|
||||
&& input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
|
||||
if (plugin.getDependencies().getDenizenAPI().containsScript(input)) {
|
||||
if (plugin.getDependencies().getDenizenApi().containsScript(input)) {
|
||||
context.setSessionData(CK.E_DENIZEN, input.toUpperCase());
|
||||
return new ActionMainPrompt(context);
|
||||
} else {
|
||||
|
@ -30,7 +30,7 @@ import net.citizensnpcs.api.npc.NPC;
|
||||
public class DenizenAPI_1_0_9 {
|
||||
|
||||
private static Quests quests = (Quests) Bukkit.getPluginManager().getPlugin("Quests");
|
||||
private static DenizenAPI api = quests.getDependencies().getDenizenAPI();
|
||||
private static DenizenAPI api = quests.getDependencies().getDenizenApi();
|
||||
|
||||
@Nullable
|
||||
public static boolean containsScript(String input) {
|
||||
|
@ -34,7 +34,7 @@ import net.citizensnpcs.api.npc.NPC;
|
||||
public class DenizenAPI_1_1_0 {
|
||||
|
||||
private static Quests quests = (Quests) Bukkit.getPluginManager().getPlugin("Quests");
|
||||
private static DenizenAPI api = quests.getDependencies().getDenizenAPI();
|
||||
private static DenizenAPI api = quests.getDependencies().getDenizenApi();
|
||||
|
||||
@Nullable
|
||||
public static boolean containsScript(String input) {
|
||||
|
Loading…
Reference in New Issue
Block a user