diff --git a/src/main/java/me/blackvein/quests/Planner.java b/src/main/java/me/blackvein/quests/Planner.java new file mode 100644 index 000000000..31988b3d1 --- /dev/null +++ b/src/main/java/me/blackvein/quests/Planner.java @@ -0,0 +1,33 @@ +package me.blackvein.quests; + +public class Planner { + public String start = null; + public String end = null; + public long repeat = -1; + public long cooldown = -1; + + public String getStart() { + return start; + } + public void setStart(String start) { + this.start = start; + } + public String getEnd() { + return end; + } + public void setEnd(String end) { + this.end = end; + } + public long getRepeat() { + return repeat; + } + public void setRepeat(long repeat) { + this.repeat = repeat; + } + public long getCooldown() { + return cooldown; + } + public void setCooldown(long cooldown) { + this.cooldown = cooldown; + } +} \ No newline at end of file diff --git a/src/main/java/me/blackvein/quests/Quest.java b/src/main/java/me/blackvein/quests/Quest.java index 33b1b6deb..3f2d3eb69 100644 --- a/src/main/java/me/blackvein/quests/Quest.java +++ b/src/main/java/me/blackvein/quests/Quest.java @@ -12,10 +12,8 @@ package me.blackvein.quests; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; -import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -56,31 +54,22 @@ public class Quest { protected NPC npcStart; protected Location blockStart; protected Event initialEvent; - // Planner - public String startPlanner = null; - public String endPlanner = null; - public long repeatPlanner = -1; - public long cooldownPlanner = -1; - // Rewards - int moneyReward = 0; - int questPoints = 0; - int exp = 0; - List commands = new LinkedList(); - List permissions = new LinkedList(); - LinkedList itemRewards = new LinkedList(); - List mcmmoSkills = new LinkedList(); - List mcmmoAmounts = new LinkedList(); - List heroesClasses = new LinkedList(); - List heroesAmounts = new LinkedList(); - List phatLootRewards = new LinkedList(); - Map> customRewards = new HashMap>(); - private Requirements reqs = new Requirements(); + private Planner pln = new Planner(); + private Rewards rews = new Rewards(); public Requirements getRequirements() { return reqs; } + public Planner getPlanner() { + return pln; + } + + public Rewards getRewards() { + return rews; + } + public String getName() { return name; } @@ -413,11 +402,11 @@ public class Quest { } } }, 40); - if (moneyReward > 0 && Quests.economy != null) { - Quests.economy.depositPlayer(q.getOfflinePlayer(), moneyReward); + if (rews.getMoney() > 0 && Quests.economy != null) { + Quests.economy.depositPlayer(q.getOfflinePlayer(), rews.getMoney()); none = null; } - if (cooldownPlanner > -1) { + if (pln.getCooldown() > -1) { q.completedTimes.put(this.name, System.currentTimeMillis()); if (q.amountsCompleted.containsKey(this.name)) { q.amountsCompleted.put(this.name, q.amountsCompleted.get(this.name) + 1); @@ -425,7 +414,7 @@ public class Quest { q.amountsCompleted.put(this.name, 1); } } - for (ItemStack i : itemRewards) { + for (ItemStack i : rews.getItems()) { try { Quests.addItem(player, i); } catch (Exception e) { @@ -436,7 +425,7 @@ public class Quest { } none = null; } - for (String s : commands) { + for (String s : rews.getCommands()) { final String command = s.replace("", player.getName()); if (Bukkit.isPrimaryThread()) { Bukkit.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command); @@ -451,25 +440,25 @@ public class Quest { } none = null; } - for (String s : permissions) { + for (String s : rews.getPermissions()) { if (Quests.permission != null) { Quests.permission.playerAdd(player, s); } none = null; } - for (String s : mcmmoSkills) { - UserManager.getPlayer(player).getProfile().addLevels(Quests.getMcMMOSkill(s), mcmmoAmounts.get(mcmmoSkills.indexOf(s))); + for (String s : rews.getMcmmoSkills()) { + UserManager.getPlayer(player).getProfile().addLevels(Quests.getMcMMOSkill(s), rews.getMcmmoAmounts().get(rews.getMcmmoSkills().indexOf(s))); none = null; } - for (String s : heroesClasses) { + for (String s : rews.getHeroesClasses()) { Hero hero = plugin.getHero(player.getUniqueId()); - hero.addExp(heroesAmounts.get(heroesClasses.indexOf(s)), Quests.heroes.getClassManager().getClass(s), player.getLocation()); + hero.addExp(rews.getHeroesAmounts().get(rews.getHeroesClasses().indexOf(s)), Quests.heroes.getClassManager().getClass(s), player.getLocation()); none = null; } LinkedList phatLootItems = new LinkedList(); int phatLootExp = 0; LinkedList phatLootMessages = new LinkedList(); - for (String s : phatLootRewards) { + for (String s : rews.getPhatLoots()) { LootBundle lb = PhatLootsAPI.getPhatLoot(s).rollForLoot(); if (lb.getExp() > 0) { phatLootExp += lb.getExp(); @@ -502,8 +491,8 @@ public class Quest { phatLootMessages.addAll(lb.getMessageList()); } } - if (exp > 0) { - player.giveExp(exp); + if (rews.getExp() > 0) { + player.giveExp(rews.getExp()); none = null; } String complete = Lang.get(player, "questCompleteTitle"); @@ -516,12 +505,12 @@ public class Quest { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "title " + player.getName() + " subtitle " + "{\"text\":\"" + name + "\",\"color\":\"yellow\"}"); } - if (questPoints > 0) { - player.sendMessage("- " + ChatColor.DARK_GREEN + questPoints + " " + Lang.get(player, "questPoints")); - q.questPoints += questPoints; + if (rews.getQuestPoints() > 0) { + player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getQuestPoints() + " " + Lang.get(player, "questPoints")); + q.questPoints += rews.getQuestPoints(); none = null; } - for (ItemStack i : itemRewards) { + for (ItemStack i : rews.getItems()) { String text = "error"; if (i.hasItemMeta() && i.getItemMeta().hasDisplayName()) { if (i.getEnchantments().isEmpty()) { @@ -585,27 +574,27 @@ public class Quest { } none = null; } - if (moneyReward > 1) { - player.sendMessage("- " + ChatColor.DARK_GREEN + moneyReward + " " + ChatColor.DARK_PURPLE + Quests.getCurrency(true)); + if (rews.getMoney() > 1) { + player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getMoney() + " " + ChatColor.DARK_PURPLE + Quests.getCurrency(true)); none = null; - } else if (moneyReward == 1) { - player.sendMessage("- " + ChatColor.DARK_GREEN + moneyReward + " " + ChatColor.DARK_PURPLE + Quests.getCurrency(false)); + } else if (rews.getMoney() == 1) { + player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getMoney() + " " + ChatColor.DARK_PURPLE + Quests.getCurrency(false)); none = null; } - if (exp > 0 || phatLootExp > 0) { - int tot = exp + phatLootExp; + if (rews.getExp() > 0 || phatLootExp > 0) { + int tot = rews.getExp() + phatLootExp; player.sendMessage("- " + ChatColor.DARK_GREEN + tot + ChatColor.DARK_PURPLE + " " + Lang.get(player, "experience")); none = null; } - if (mcmmoSkills.isEmpty() == false) { - for (String s : mcmmoSkills) { - player.sendMessage("- " + ChatColor.DARK_GREEN + mcmmoAmounts.get(mcmmoSkills.indexOf(s)) + " " + ChatColor.DARK_PURPLE + s + " " + Lang.get(player, "experience")); + if (rews.getMcmmoSkills().isEmpty() == false) { + for (String s : rews.getMcmmoSkills()) { + player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getMcmmoAmounts().get(rews.getMcmmoSkills().indexOf(s)) + " " + ChatColor.DARK_PURPLE + s + " " + Lang.get(player, "experience")); } none = null; } - if (heroesClasses.isEmpty() == false) { - for (String s : heroesClasses) { - player.sendMessage("- " + ChatColor.AQUA + heroesAmounts.get(heroesClasses.indexOf(s)) + " " + ChatColor.BLUE + s + " " + Lang.get(player, "experience")); + if (rews.getHeroesClasses().isEmpty() == false) { + for (String s : rews.getHeroesClasses()) { + player.sendMessage("- " + ChatColor.AQUA + rews.getHeroesAmounts().get(rews.getHeroesClasses().indexOf(s)) + " " + ChatColor.BLUE + s + " " + Lang.get(player, "experience")); } none = null; } @@ -615,7 +604,7 @@ public class Quest { } none = null; } - for (String s : customRewards.keySet()) { + for (String s : rews.getCustomRewards().keySet()) { CustomReward found = null; for (CustomReward cr : plugin.customRewards) { if (cr.getName().equalsIgnoreCase(s)) { @@ -624,7 +613,7 @@ public class Quest { } } if (found != null) { - Map datamap = customRewards.get(found.getName()); + Map datamap = rews.getCustomRewards().get(found.getName()); String message = found.getRewardName(); if (message != null) { for (String key : datamap.keySet()) { @@ -634,7 +623,7 @@ public class Quest { } else { plugin.getLogger().warning("Failed to notify player: Custom Reward does not have an assigned name"); } - found.giveReward(player, customRewards.get(s)); + found.giveReward(player, rews.getCustomRewards().get(s)); } else { plugin.getLogger().warning("Quester \"" + player.getName() + "\" completed the Quest \"" + name + "\", but the Custom Reward \"" + s + "\" could not be found. Does it still exist?"); } diff --git a/src/main/java/me/blackvein/quests/QuestFactory.java b/src/main/java/me/blackvein/quests/QuestFactory.java index 3a9e3b0ff..2e382a148 100644 --- a/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/src/main/java/me/blackvein/quests/QuestFactory.java @@ -1312,7 +1312,6 @@ public class QuestFactory implements ConversationAbandonedListener { if (q.guiDisplay != null) { cc.setSessionData(CK.Q_GUIDISPLAY, q.guiDisplay); } - // Requirements Requirements reqs = q.getRequirements(); if (reqs.getMoney() != 0) { cc.setSessionData(CK.REQ_MONEY, reqs.getMoney()); @@ -1356,58 +1355,52 @@ public class QuestFactory implements ConversationAbandonedListener { cc.setSessionData(CK.REQ_CUSTOM, list); cc.setSessionData(CK.REQ_CUSTOM_DATA, datamapList); } - // - // Rewards - if (q.moneyReward != 0) { - cc.setSessionData(CK.REW_MONEY, q.moneyReward); + Rewards rews = q.getRewards(); + if (rews.getMoney() != 0) { + cc.setSessionData(CK.REW_MONEY, rews.getMoney()); } - if (q.questPoints != 0) { - cc.setSessionData(CK.REW_QUEST_POINTS, q.questPoints); + if (rews.getQuestPoints() != 0) { + cc.setSessionData(CK.REW_QUEST_POINTS, rews.getQuestPoints()); } - if (q.exp != 0) { - cc.setSessionData(CK.REW_EXP, q.exp); + if (rews.getExp() != 0) { + cc.setSessionData(CK.REW_EXP, rews.getExp()); } - if (q.itemRewards.isEmpty() == false) { - cc.setSessionData(CK.REW_ITEMS, q.itemRewards); + if (rews.getItems().isEmpty() == false) { + cc.setSessionData(CK.REW_ITEMS, reqs.getItems()); } - if (q.commands.isEmpty() == false) { - cc.setSessionData(CK.REW_COMMAND, q.commands); + if (rews.getCommands().isEmpty() == false) { + cc.setSessionData(CK.REW_COMMAND, rews.getCommands()); } - if (q.permissions.isEmpty() == false) { - cc.setSessionData(CK.REW_PERMISSION, q.permissions); + if (rews.getPermissions().isEmpty() == false) { + cc.setSessionData(CK.REW_PERMISSION, rews.getPermissions()); } - if (q.mcmmoSkills.isEmpty() == false) { - cc.setSessionData(CK.REW_MCMMO_SKILLS, q.mcmmoSkills); - cc.setSessionData(CK.REW_MCMMO_AMOUNTS, q.mcmmoAmounts); + if (rews.getMcmmoSkills().isEmpty() == false) { + cc.setSessionData(CK.REW_MCMMO_SKILLS, rews.getMcmmoSkills()); + cc.setSessionData(CK.REW_MCMMO_AMOUNTS, rews.getMcmmoAmounts()); } - if (q.heroesClasses.isEmpty() == false) { - cc.setSessionData(CK.REW_HEROES_CLASSES, q.heroesClasses); - cc.setSessionData(CK.REW_HEROES_AMOUNTS, q.heroesAmounts); + if (rews.getHeroesClasses().isEmpty() == false) { + cc.setSessionData(CK.REW_HEROES_CLASSES, rews.getHeroesClasses()); + cc.setSessionData(CK.REW_HEROES_AMOUNTS, rews.getHeroesAmounts()); } - if (q.heroesClasses.isEmpty() == false) { - cc.setSessionData(CK.REW_HEROES_CLASSES, q.heroesClasses); - cc.setSessionData(CK.REW_HEROES_AMOUNTS, q.heroesAmounts); + if (rews.getPhatLoots().isEmpty() == false) { + cc.setSessionData(CK.REW_PHAT_LOOTS, rews.getPhatLoots()); } - if (q.phatLootRewards.isEmpty() == false) { - cc.setSessionData(CK.REW_PHAT_LOOTS, q.phatLootRewards); + if (rews.getCustomRewards().isEmpty() == false) { + cc.setSessionData(CK.REW_CUSTOM, new LinkedList(rews.getCustomRewards().keySet())); + cc.setSessionData(CK.REW_CUSTOM_DATA, new LinkedList(rews.getCustomRewards().values())); } - if (q.customRewards.isEmpty() == false) { - cc.setSessionData(CK.REW_CUSTOM, new LinkedList(q.customRewards.keySet())); - cc.setSessionData(CK.REW_CUSTOM_DATA, new LinkedList(q.customRewards.values())); + Planner pln = q.getPlanner(); + if (pln.getStart() != null) { + cc.setSessionData(CK.PLN_START_DATE, pln.getStart()); } - // - //Planner - if (q.startPlanner != null) { - cc.setSessionData(CK.PLN_START_DATE, q.startPlanner); + if (pln.getEnd() != null) { + cc.setSessionData(CK.PLN_END_DATE, pln.getEnd()); } - if (q.endPlanner != null) { - cc.setSessionData(CK.PLN_END_DATE, q.endPlanner); + if (pln.getRepeat() != -1) { + cc.setSessionData(CK.PLN_REPEAT_CYCLE, pln.getRepeat()); } - if (q.repeatPlanner != -1) { - cc.setSessionData(CK.PLN_REPEAT_CYCLE, q.repeatPlanner); - } - if (q.cooldownPlanner != -1) { - cc.setSessionData(CK.PLN_COOLDOWN, q.cooldownPlanner); + if (pln.getCooldown() != -1) { + cc.setSessionData(CK.PLN_COOLDOWN, pln.getCooldown()); } // // Stages diff --git a/src/main/java/me/blackvein/quests/Quester.java b/src/main/java/me/blackvein/quests/Quester.java index 76c97a987..6520679f5 100644 --- a/src/main/java/me/blackvein/quests/Quester.java +++ b/src/main/java/me/blackvein/quests/Quester.java @@ -315,28 +315,29 @@ public class Quester { return; } Player player = getPlayer(); + Planner pln = q.getPlanner(); long start = -1; long end = -1; - if (q.startPlanner != null) { + if (pln.getStart() != null) { Calendar cal = Calendar.getInstance(); - String[] s = q.startPlanner.split(":"); + String[] s = pln.getStart().split(":"); cal.set(Integer.valueOf(s[2]), Integer.valueOf(s[1]), Integer.valueOf(s[0]), Integer.valueOf(s[3]), Integer.valueOf(s[4]), Integer.valueOf(s[5])); start = cal.getTimeInMillis(); } - if (q.endPlanner != null) { + if (pln.getEnd() != null) { Calendar cal = Calendar.getInstance(); - String[] s = q.endPlanner.split(":"); + String[] s = pln.getEnd().split(":"); cal.set(Integer.valueOf(s[2]), Integer.valueOf(s[1]), Integer.valueOf(s[0]), Integer.valueOf(s[3]), Integer.valueOf(s[4]), Integer.valueOf(s[5])); end = cal.getTimeInMillis(); } if (start > -1 && end > -1) { - if (q.repeatPlanner > -1) { + if (pln.getRepeat() > -1) { long questLength = end - start; long nextStart = start; while (System.currentTimeMillis() >= nextStart) { - nextStart += questLength + q.repeatPlanner; + nextStart += questLength + pln.getRepeat(); } long nextEnd = nextStart + questLength; if (System.currentTimeMillis() < nextStart) { @@ -361,7 +362,7 @@ public class Quester { } } } - if (q.startPlanner != null) { + if (pln.getStart() != null) { if (System.currentTimeMillis() < start) { String early = Lang.get("plnTooEarly"); early = early.replace("", ChatColor.AQUA + q.getName() + ChatColor.YELLOW); @@ -372,7 +373,7 @@ public class Quester { } } //TODO - should this even be reported? - if (q.endPlanner != null) { + if (pln.getEnd() != null) { if (System.currentTimeMillis() > end) { String late = Lang.get("plnTooLate"); late = late.replace("", ChatColor.AQUA + q.getName() + ChatColor.RED); @@ -1761,7 +1762,7 @@ public class Quester { } } - public long getDifference(Quest q) { + public long getCooldownDifference(Quest q) { long currentTime = System.currentTimeMillis(); long lastTime; if (completedTimes.containsKey(q.getName()) == false) { @@ -1770,7 +1771,7 @@ public class Quester { } else { lastTime = completedTimes.get(q.getName()); } - long comparator = q.cooldownPlanner; + long comparator = q.getPlanner().getCooldown(); long difference = (comparator - (currentTime - lastTime)); return difference; } diff --git a/src/main/java/me/blackvein/quests/Quests.java b/src/main/java/me/blackvein/quests/Quests.java index eba4629f7..c80b62caf 100644 --- a/src/main/java/me/blackvein/quests/Quests.java +++ b/src/main/java/me/blackvein/quests/Quests.java @@ -93,9 +93,9 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import me.blackvein.listeners.NpcListener; -import me.blackvein.listeners.PlayerListener; import me.blackvein.quests.exceptions.InvalidStageException; +import me.blackvein.quests.listeners.NpcListener; +import me.blackvein.quests.listeners.PlayerListener; import me.blackvein.quests.prompts.QuestAcceptPrompt; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; @@ -1617,7 +1617,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } else if (quester.currentQuests.containsKey(q)) { String msg = Lang.get(player, "questAlreadyOn"); player.sendMessage(ChatColor.YELLOW + msg); - } else if (quester.completedQuests.contains(q.getName()) && q.cooldownPlanner < 0) { + } else if (quester.completedQuests.contains(q.getName()) && q.getPlanner().getCooldown() < 0) { String msg = Lang.get(player, "questAlreadyCompleted"); msg = msg.replace("", ChatColor.DARK_PURPLE + q.getName() + ChatColor.YELLOW); player.sendMessage(ChatColor.YELLOW + msg); @@ -1632,10 +1632,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } else { boolean takeable = true; if (quester.completedQuests.contains(q.getName())) { - if (quester.getDifference(q) > 0) { + if (quester.getCooldownDifference(q) > 0) { String early = Lang.get(player, "questTooEarly"); early = early.replace("", ChatColor.AQUA + q.getName() + ChatColor.YELLOW); - early = early.replace("