diff --git a/src/main/java/me/blackvein/quests/Quests.java b/src/main/java/me/blackvein/quests/Quests.java index 776324bb0..87b94599e 100644 --- a/src/main/java/me/blackvein/quests/Quests.java +++ b/src/main/java/me/blackvein/quests/Quests.java @@ -142,18 +142,24 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, private static Quests instance = null; public static final String validVersion = "1.7.9-R0.2"; + @SuppressWarnings("serial") + class StageFailedException extends Exception { } + + @SuppressWarnings("serial") + class SkipQuest extends Exception { } + @Override public void onEnable() { /*if(getServer().getBukkitVersion().equalsIgnoreCase(validVersion) == false) { - + log.severe("[Quests] Your current version of CraftBukkit is " + getServer().getBukkitVersion() + ", this version of Quests is built for version " + validVersion); log.severe("[Quests] Disabling..."); getServer().getPluginManager().disablePlugin(this); return; - - } */ - + + } */ + pListener = new PlayerListener(this); effListener = new NpcEffectThread(this); npcListener = new NpcListener(this); @@ -177,7 +183,123 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, questFactory = new QuestFactory(this); eventFactory = new EventFactory(this); - try { + linkOtherPlugins(); + + defaultConfigFile(); + + loadConfig(); + loadModules(); + + defaultLangFile(); + defaultQuestsFile(); + defaultEventsFile(); + defaultDataFile(); + + getServer().getPluginManager().registerEvents(pListener, this); + if (npcEffects) { + getServer().getScheduler().scheduleSyncRepeatingTask(this, effListener, 20, 20); + } + printInfo("[Quests] Enabled."); + + delayLoadQuestInfo(); + } + + private void defaultLangFile() { + lang = new Lang(this); + lang.initPhrases(); + if (new File(this.getDataFolder(), "/lang/en.yml").exists() == false) { + printInfo("[Quests] Translation data not found, writing defaults to file."); + lang.saveNewLang(); + } else { + lang.loadLang(); + } + } + + private void delayLoadQuestInfo() { + getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + @Override + public void run() { + loadQuests(); + loadEvents(); + log.log(Level.INFO, "[Quests] " + quests.size() + " Quest(s) loaded."); + log.log(Level.INFO, "[Quests] " + events.size() + " Event(s) loaded."); + log.log(Level.INFO, "[Quests] " + Lang.getPhrases() + " Phrase(s) loaded."); + questers.putAll(getOnlineQuesters()); + if (snoop) { + snoop(); + } + } + }, 5L); + } + + private void defaultDataFile() { + if (new File(this.getDataFolder(), "data.yml").exists() == false) { + printInfo("[Quests] Data file not found, writing default to file."); + FileConfiguration data = new YamlConfiguration(); + data.options().copyHeader(true); + data.options().copyDefaults(true); + try { + data.save(new File(this.getDataFolder(), "data.yml")); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + loadData(); + } + } + + private void defaultEventsFile() { + if (new File(this.getDataFolder(), "events.yml").exists() == false) { + printInfo("[Quests] Events data not found, writing defaults to file."); + FileConfiguration data = new YamlConfiguration(); + data.options().copyHeader(true); + data.options().copyDefaults(true); + try { + data.load(this.getResource("events.yml")); + data.save(new File(this.getDataFolder(), "events.yml")); + } catch (IOException e) { + e.printStackTrace(); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + } + } + + private void defaultQuestsFile() { + if (new File(this.getDataFolder(), "quests.yml").exists() == false) { + + printInfo("[Quests] Quest data not found, writing defaults to file."); + FileConfiguration data = new YamlConfiguration(); + try { + data.load(this.getResource("quests.yml")); + data.set("events", null); + data.save(new File(this.getDataFolder(), "quests.yml")); + } catch (IOException e) { + e.printStackTrace(); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + + } + } + + private void defaultConfigFile() { + if (new File(this.getDataFolder(), "config.yml").exists() == false) { + printInfo("[Quests] Config not found, writing default to file."); + FileConfiguration config = new YamlConfiguration(); + try { + config.load(this.getResource("config.yml")); + config.save(new File(this.getDataFolder(), "config.yml")); + } catch (IOException e) { + e.printStackTrace(); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + } + } + + private void linkOtherPlugins() { + try { if (getServer().getPluginManager().getPlugin("Citizens") != null) { citizens = (CitizensPlugin) getServer().getPluginManager().getPlugin("Citizens"); } @@ -203,7 +325,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, if (getServer().getPluginManager().getPlugin("Heroes") != null) { heroes = (Heroes) getServer().getPluginManager().getPlugin("Heroes"); } - + if (getServer().getPluginManager().getPlugin("PhatLoots") != null) { phatLoots = (PhatLoots) getServer().getPluginManager().getPlugin("PhatLoots"); } @@ -217,100 +339,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, } vault = (Vault) getServer().getPluginManager().getPlugin("Vault"); - - if (new File(this.getDataFolder(), "config.yml").exists() == false) { - printInfo("[Quests] Config not found, writing default to file."); - FileConfiguration config = new YamlConfiguration(); - try { - config.load(this.getResource("config.yml")); - config.save(new File(this.getDataFolder(), "config.yml")); - } catch (IOException e) { - e.printStackTrace(); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } - - } - - loadConfig(); - loadModules(); - lang = new Lang(this); - lang.initPhrases(); - if(new File(this.getDataFolder(), "/lang/en.yml").exists() == false) { - printInfo("[Quests] Translation data not found, writing defaults to file."); - lang.saveNewLang(); - }else - lang.loadLang(); - - if (new File(this.getDataFolder(), "quests.yml").exists() == false) { - - printInfo("[Quests] Quest data not found, writing defaults to file."); - FileConfiguration data = new YamlConfiguration(); - try { - data.load(this.getResource("quests.yml")); - data.set("events", null); - data.save(new File(this.getDataFolder(), "quests.yml")); - } catch (IOException e) { - e.printStackTrace(); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } - - } - - if (new File(this.getDataFolder(), "events.yml").exists() == false) { - printInfo("[Quests] Events data not found, writing defaults to file."); - FileConfiguration data = new YamlConfiguration(); - data.options().copyHeader(true); - data.options().copyDefaults(true); - try { - data.load(this.getResource("events.yml")); - data.save(new File(this.getDataFolder(), "events.yml")); - } catch (IOException e) { - e.printStackTrace(); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } - - } - - if (new File(this.getDataFolder(), "data.yml").exists() == false) { - printInfo("[Quests] Data file not found, writing default to file."); - FileConfiguration data = new YamlConfiguration(); - data.options().copyHeader(true); - data.options().copyDefaults(true); - try { - data.save(new File(this.getDataFolder(), "data.yml")); - } catch (IOException e) { - e.printStackTrace(); - } - - } else { - loadData(); - } - - getServer().getPluginManager().registerEvents(pListener, this); - if (npcEffects) { - getServer().getScheduler().scheduleSyncRepeatingTask(this, effListener, 20, 20); - } - printInfo("[Quests] Enabled."); - - getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { - @Override - public void run() { - loadQuests(); - loadEvents(); - log.log(Level.INFO, "[Quests] " + quests.size() + " Quest(s) loaded."); - log.log(Level.INFO, "[Quests] " + events.size() + " Event(s) loaded."); - log.log(Level.INFO, "[Quests] " + Lang.getPhrases() + " Phrase(s) loaded."); - questers.putAll(getOnlineQuesters()); - if (snoop) { - snoop(); - } - } - }, 5L); - - } + } @Override public void onDisable() { @@ -456,10 +485,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, } public void loadData() { - + YamlConfiguration config = new YamlConfiguration(); File dataFile = new File(this.getDataFolder(), "data.yml"); - + try { config.load(dataFile); } catch (Exception e) { @@ -467,15 +496,15 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, } if(config.contains("npc-gui")) { - + List ids = config.getIntegerList("npc-gui"); questNPCGUIs.clear(); questNPCGUIs.addAll(ids); - + } - + } - + public void loadModules() { File f = new File(this.getDataFolder(), "modules"); @@ -501,7 +530,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, try { JarFile jarFile = new JarFile(jar); - Enumeration e = jarFile.entries(); + Enumeration e = jarFile.entries(); URL[] urls = {new URL("jar:file:" + jar.getPath() + "!/")}; @@ -517,9 +546,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, String className = je.getName().substring(0, je.getName().length() - 6); className = className.replace('/', '.'); Class c = Class.forName(className, true, cl); - + if(CustomRequirement.class.isAssignableFrom(c)){ - + Class requirementClass = c.asSubclass(CustomRequirement.class); Constructor cstrctr = requirementClass.getConstructor(); CustomRequirement requirement = cstrctr.newInstance(); @@ -527,9 +556,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, String name = requirement.getName() == null ? "[" + jar.getName() + "]" : requirement.getName(); String author = requirement.getAuthor() == null ? "[Unknown]" : requirement.getAuthor(); printInfo("[Quests] Loaded Module: " + name + " by " + author); - + }else if(CustomReward.class.isAssignableFrom(c)){ - + Class rewardClass = c.asSubclass(CustomReward.class); Constructor cstrctr = rewardClass.getConstructor(); CustomReward reward = cstrctr.newInstance(); @@ -537,9 +566,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, String name = reward.getName() == null ? "[" + jar.getName() + "]" : reward.getName(); String author = reward.getAuthor() == null ? "[Unknown]" : reward.getAuthor(); printInfo("[Quests] Loaded Module: " + name + " by " + author); - + }else if(CustomObjective.class.isAssignableFrom(c)){ - + Class objectiveClass = c.asSubclass(CustomObjective.class); Constructor cstrctr = objectiveClass.getConstructor(); CustomObjective objective = cstrctr.newInstance(); @@ -547,7 +576,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, String name = objective.getName() == null ? "[" + jar.getName() + "]" : objective.getName(); String author = objective.getAuthor() == null ? "[Unknown]" : objective.getAuthor(); printInfo("[Quests] Loaded Module: " + name + " by " + author); - + }else{ printSevere("[Quests] Error: Unable to load module from file: " + jar.getName() + ", jar file is not a valid module!"); } @@ -620,1334 +649,15 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, if (cmd.getName().equalsIgnoreCase("quest")) { - if (cs instanceof Player) { - - if (((Player) cs).hasPermission("quests.quest")) { - - if (args.length == 0) { - - if (getQuester(cs.getName()).currentQuest != null) { - - if (getQuester(cs.getName()).delayStartTime == 0) { - cs.sendMessage(GOLD + Lang.get("questObjectivesTitle")); - } - - for (String s : getQuester(cs.getName()).getObjectivesReal()) { - - cs.sendMessage(s); - - } - - } else { - - cs.sendMessage(YELLOW + Lang.get("noActiveQuest")); - return true; - - } - - } else { - - if (((Player) cs).hasPermission("quests.questinfo")) { - - String name = ""; - - if (args.length == 1) { - name = args[0].toLowerCase(); - } else { - - int index = 0; - for (String s : args) { - - if (index == (args.length - 1)) { - name = name + s.toLowerCase(); - } else { - name = name + s.toLowerCase() + " "; - } - - index++; - - } - } - - Quest quest = findQuest(name); - - if (quest != null) { - - Player player = (Player) cs; - Quester quester = getQuester(player.getName()); - - cs.sendMessage(GOLD + "- " + quest.name + " -"); - cs.sendMessage(" "); - if (quest.redoDelay > -1) { - - if (quest.redoDelay == 0) { - cs.sendMessage(DARKAQUA + Lang.get("readoable")); - } else { - String msg = Lang.get("redoableEvery"); - msg = msg.replaceAll("