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