mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-21 18:15:32 +01:00
Refactor current quests method
This commit is contained in:
parent
f5f872bd25
commit
19c6f02cc8
@ -130,7 +130,7 @@ public interface Quester extends Comparable<Quester> {
|
||||
|
||||
LinkedList<String> getCurrentRequirements(final Quest quest, final boolean ignoreOverrides);
|
||||
|
||||
LinkedList<String> getCurrentObjectives(final Quest quest, final boolean ignoreOverrides);
|
||||
LinkedList<Objective> getCurrentObjectives(final Quest quest, final boolean ignoreOverrides, final boolean formatNames);
|
||||
|
||||
void showCurrentObjectives(final Quest quest, final Quester quester, final boolean ignoreOverrides);
|
||||
|
||||
|
@ -10,11 +10,11 @@
|
||||
|
||||
package me.pikamug.quests.item;
|
||||
|
||||
import me.pikamug.quests.player.BukkitQuester;
|
||||
import me.pikamug.quests.BukkitQuestsPlugin;
|
||||
import me.pikamug.quests.player.Quester;
|
||||
import me.pikamug.quests.quests.components.BukkitObjective;
|
||||
import me.pikamug.quests.quests.Quest;
|
||||
import me.pikamug.quests.quests.components.Objective;
|
||||
import me.pikamug.quests.util.BukkitItemUtil;
|
||||
import me.pikamug.quests.util.BukkitLang;
|
||||
import me.pikamug.quests.util.BukkitMiscUtil;
|
||||
@ -72,17 +72,18 @@ public class BukkitQuestJournal {
|
||||
title.setColor(net.md_5.bungee.api.ChatColor.DARK_PURPLE);
|
||||
title.setBold(true);
|
||||
final BookUtil.PageBuilder builder = new BookUtil.PageBuilder().add(title).newLine();
|
||||
for (final BukkitObjective obj : ((BukkitQuester)owner).getCurrentObjectivesTemp(quest, false, false)) {
|
||||
for (final Objective obj : owner.getCurrentObjectives(quest, false, false)) {
|
||||
final BukkitObjective objective = (BukkitObjective) obj;
|
||||
if (!plugin.getConfigSettings().canShowCompletedObjs()
|
||||
&& obj.getMessage().startsWith(ChatColor.GRAY.toString())) {
|
||||
&& objective.getMessage().startsWith(ChatColor.GRAY.toString())) {
|
||||
continue;
|
||||
}
|
||||
if (obj.getMessage() != null) {
|
||||
if (objective.getMessage() != null) {
|
||||
String[] split = null;
|
||||
if (obj.getMessage().contains("<item>") && obj.getGoalAsItem() != null) {
|
||||
split = obj.getMessage().split("<item>");
|
||||
if (objective.getMessage().contains("<item>") && objective.getGoalAsItem() != null) {
|
||||
split = objective.getMessage().split("<item>");
|
||||
builder.add(split[0]);
|
||||
final ItemStack goal = obj.getGoalAsItem();
|
||||
final ItemStack goal = objective.getGoalAsItem();
|
||||
if (goal.getItemMeta() != null && goal.getItemMeta().hasDisplayName()) {
|
||||
builder.add("" + ChatColor.DARK_AQUA + ChatColor.ITALIC
|
||||
+ goal.getItemMeta().getDisplayName());
|
||||
@ -98,21 +99,21 @@ public class BukkitQuestJournal {
|
||||
}
|
||||
builder.add(split[1]).newLine();
|
||||
}
|
||||
if (obj.getMessage().contains("<mob>") && obj.getGoalAsMob() != null) {
|
||||
split = obj.getMessage().split("<mob>");
|
||||
if (objective.getMessage().contains("<mob>") && objective.getGoalAsMob() != null) {
|
||||
split = objective.getMessage().split("<mob>");
|
||||
builder.add(split[0]);
|
||||
if (plugin.getConfigSettings().canTranslateNames()) {
|
||||
final TranslatableComponent tc = new TranslatableComponent(plugin.getLocaleManager()
|
||||
.queryEntityType(obj.getGoalAsMob().getEntityType(), null)); // TODO extra data
|
||||
.queryEntityType(objective.getGoalAsMob().getEntityType(), null)); // TODO extra data
|
||||
tc.setColor(net.md_5.bungee.api.ChatColor.DARK_RED);
|
||||
builder.add(tc);
|
||||
} else {
|
||||
builder.add(BukkitMiscUtil.snakeCaseToUpperCamelCase(obj.getGoalAsMob().getEntityType().name()));
|
||||
builder.add(BukkitMiscUtil.snakeCaseToUpperCamelCase(objective.getGoalAsMob().getEntityType().name()));
|
||||
}
|
||||
builder.add(split[1]).newLine();
|
||||
}
|
||||
if (split == null) {
|
||||
builder.add(obj.getMessage()).newLine();
|
||||
builder.add(objective.getMessage()).newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1135,479 +1135,6 @@ public class BukkitQuester implements Quester {
|
||||
current.addAll(finishedRequirements);
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current objectives for a quest, both finished and unfinished
|
||||
*
|
||||
* @param quest The quest to get objectives of
|
||||
* @param ignoreOverrides Whether to ignore objective-overrides
|
||||
* @return List of detailed objectives
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public LinkedList<String> getCurrentObjectives(final Quest quest, final boolean ignoreOverrides) {
|
||||
if (quest == null) {
|
||||
plugin.getLogger().severe("Quest was null when getting objectives for " + getLastKnownName());
|
||||
return new LinkedList<>();
|
||||
}
|
||||
if (getQuestDataOrDefault(quest) == null) {
|
||||
plugin.getLogger().warning("Quest data was null when getting objectives for " + quest.getName());
|
||||
return new LinkedList<>();
|
||||
}
|
||||
if (getCurrentStage(quest) == null) {
|
||||
//plugin.getLogger().warning("Current stage was null when getting objectives for " + quest.getName());
|
||||
return new LinkedList<>();
|
||||
}
|
||||
final BukkitDependencies depends = plugin.getDependencies();
|
||||
if (!ignoreOverrides && !getCurrentStage(quest).getObjectiveOverrides().isEmpty()) {
|
||||
final LinkedList<String> objectives = new LinkedList<>();
|
||||
for (final String s: getCurrentStage(quest).getObjectiveOverrides()) {
|
||||
String message = ChatColor.GREEN + BukkitConfigUtil.parseString(s, quest, getPlayer());
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message);
|
||||
}
|
||||
return objectives;
|
||||
}
|
||||
final BukkitQuestProgress data = (BukkitQuestProgress) getQuestDataOrDefault(quest);
|
||||
final BukkitStage stage = (BukkitStage) getCurrentStage(quest);
|
||||
final LinkedList<String> objectives = new LinkedList<>();
|
||||
for (final ItemStack e : stage.getBlocksToBreak()) {
|
||||
for (final ItemStack e2 : data.blocksBroken) {
|
||||
if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) {
|
||||
final ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "break");
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + e2.getAmount() + "/" + e.getAmount());
|
||||
} else {
|
||||
// Legacy
|
||||
message += " <item>" + color + color + ": " + e2.getAmount() + "/" + e.getAmount();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message.replace("<item>", BukkitItemUtil.getName(e2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final ItemStack e : stage.getBlocksToDamage()) {
|
||||
for (final ItemStack e2 : data.blocksDamaged) {
|
||||
if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) {
|
||||
final ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "damage");
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + e2.getAmount() + "/" + e.getAmount());
|
||||
} else {
|
||||
// Legacy
|
||||
message += " <item>" + color + color + ": " + e2.getAmount() + "/" + e.getAmount();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message.replace("<item>", BukkitItemUtil.getName(e2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final ItemStack e : stage.getBlocksToPlace()) {
|
||||
for (final ItemStack e2 : data.blocksPlaced) {
|
||||
final ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "place");
|
||||
if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) {
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + e2.getAmount() + "/" + e.getAmount());
|
||||
} else {
|
||||
// Legacy
|
||||
message += " <item>" + color + color + ": " + e2.getAmount() + "/" + e.getAmount();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message.replace("<item>", BukkitItemUtil.getName(e2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final ItemStack e : stage.getBlocksToUse()) {
|
||||
for (final ItemStack e2 : data.blocksUsed) {
|
||||
final ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "use");
|
||||
if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) {
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + e2.getAmount() + "/" + e.getAmount());
|
||||
} else {
|
||||
// Legacy
|
||||
message += " <item>" + color + ": " + e2.getAmount() + "/" + e.getAmount();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message.replace("<item>", BukkitItemUtil.getName(e2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final ItemStack e : stage.getBlocksToCut()) {
|
||||
for (final ItemStack e2 : data.blocksCut) {
|
||||
final ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "cut");
|
||||
if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) {
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + e2.getAmount() + "/" + e.getAmount());
|
||||
} else {
|
||||
// Legacy
|
||||
message += " <item>" + color + ": " + e2.getAmount() + "/" + e.getAmount();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message.replace("<item>", BukkitItemUtil.getName(e2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
int craftIndex = 0;
|
||||
for (final ItemStack is : stage.getItemsToCraft()) {
|
||||
int crafted = 0;
|
||||
if (data.itemsCrafted.size() > craftIndex) {
|
||||
crafted = data.itemsCrafted.get(craftIndex).getAmount();
|
||||
}
|
||||
final int toCraft = is.getAmount();
|
||||
final ChatColor color = crafted < toCraft ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "craftItem");
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + crafted + "/" + toCraft);
|
||||
} else {
|
||||
// Legacy
|
||||
message += color + ": " + crafted + "/" + is.getAmount();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message.replace("<item>", BukkitItemUtil.getName(is)));
|
||||
craftIndex++;
|
||||
}
|
||||
int smeltIndex = 0;
|
||||
for (final ItemStack is : stage.getItemsToSmelt()) {
|
||||
int smelted = 0;
|
||||
if (data.itemsSmelted.size() > smeltIndex) {
|
||||
smelted = data.itemsSmelted.get(smeltIndex).getAmount();
|
||||
}
|
||||
final int toSmelt = is.getAmount();
|
||||
final ChatColor color = smelted < toSmelt ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "smeltItem");
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + smelted + "/" + toSmelt);
|
||||
} else {
|
||||
// Legacy
|
||||
message += color + ": " + smelted + "/" + is.getAmount();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message.replace("<item>", BukkitItemUtil.getName(is)));
|
||||
smeltIndex++;
|
||||
}
|
||||
int enchantIndex = 0;
|
||||
for (final ItemStack is : stage.getItemsToEnchant()) {
|
||||
int enchanted = 0;
|
||||
if (data.itemsEnchanted.size() > enchantIndex) {
|
||||
enchanted = data.itemsEnchanted.get(enchantIndex).getAmount();
|
||||
}
|
||||
final int toEnchant = is.getAmount();
|
||||
final ChatColor color = enchanted < toEnchant ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "enchItem");
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + enchanted + "/" + toEnchant);
|
||||
} else {
|
||||
// Legacy
|
||||
message += color + ": " + enchanted + "/" + is.getAmount();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
if (is.getEnchantments().isEmpty()) {
|
||||
objectives.add(message.replace("<item>", BukkitItemUtil.getName(is))
|
||||
.replace("<enchantment>", "")
|
||||
.replace("<level>", "")
|
||||
.replaceAll("\\s+", " "));
|
||||
} else {
|
||||
for (final Entry<Enchantment, Integer> e : is.getEnchantments().entrySet()) {
|
||||
objectives.add(message.replace("<item>", BukkitItemUtil.getName(is))
|
||||
.replace("<enchantment>", BukkitItemUtil.getPrettyEnchantmentName(e.getKey()))
|
||||
.replace("<level>", RomanNumeral.getNumeral(e.getValue())));
|
||||
}
|
||||
}
|
||||
enchantIndex++;
|
||||
}
|
||||
int brewIndex = 0;
|
||||
for (final ItemStack is : stage.getItemsToBrew()) {
|
||||
int brewed = 0;
|
||||
if (data.itemsBrewed.size() > brewIndex) {
|
||||
brewed = data.itemsBrewed.get(brewIndex).getAmount();
|
||||
}
|
||||
final int toBrew = is.getAmount();
|
||||
final ChatColor color = brewed < toBrew ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "brewItem");
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + brewed + "/" + toBrew);
|
||||
} else {
|
||||
// Legacy
|
||||
message += color + ": " + brewed + "/" + is.getAmount();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message.replace("<item>", BukkitItemUtil.getName(is)));
|
||||
brewIndex++;
|
||||
}
|
||||
int consumeIndex = 0;
|
||||
for (final ItemStack is : stage.getItemsToConsume()) {
|
||||
int consumed = 0;
|
||||
if (data.itemsConsumed.size() > consumeIndex) {
|
||||
consumed = data.itemsConsumed.get(consumeIndex).getAmount();
|
||||
}
|
||||
final int toConsume = is.getAmount();
|
||||
final ChatColor color = consumed < toConsume ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "consumeItem");
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + consumed + "/" + toConsume);
|
||||
} else {
|
||||
// Legacy
|
||||
message += color + ": " + consumed + "/" + is.getAmount();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message.replace("<item>", BukkitItemUtil.getName(is)));
|
||||
consumeIndex++;
|
||||
}
|
||||
int deliverIndex = 0;
|
||||
for (final ItemStack is : stage.getItemsToDeliver()) {
|
||||
int delivered = 0;
|
||||
if (data.itemsDelivered.size() > deliverIndex) {
|
||||
delivered = data.itemsDelivered.get(deliverIndex).getAmount();
|
||||
}
|
||||
final int toDeliver = is.getAmount();
|
||||
final UUID npc = stage.getItemDeliveryTargets().get(deliverIndex);
|
||||
final ChatColor color = delivered < toDeliver ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "deliver").replace("<npc>", depends.getNpcName(npc));
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + delivered + "/" + toDeliver);
|
||||
} else {
|
||||
// Legacy
|
||||
message += color + ": " + delivered + "/" + toDeliver;
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message.replace("<item>", BukkitItemUtil.getName(is)));
|
||||
deliverIndex++;
|
||||
}
|
||||
int interactIndex = 0;
|
||||
for (final UUID n : stage.getNpcsToInteract()) {
|
||||
boolean interacted = false;
|
||||
if (data.npcsInteracted.size() > interactIndex) {
|
||||
interacted = data.npcsInteracted.get(interactIndex);
|
||||
}
|
||||
final ChatColor color = !interacted ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "talkTo")
|
||||
.replace("<npc>", depends.getNpcName(n));
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message);
|
||||
interactIndex++;
|
||||
}
|
||||
int npcKillIndex = 0;
|
||||
for (final UUID n : stage.getNpcsToKill()) {
|
||||
int npcKilled = 0;
|
||||
if (data.npcsNumKilled.size() > npcKillIndex) {
|
||||
npcKilled = data.npcsNumKilled.get(npcKillIndex);
|
||||
}
|
||||
final int toNpcKill = stage.getNpcNumToKill().get(npcKillIndex);
|
||||
final ChatColor color = npcKilled < toNpcKill ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "kill");
|
||||
if (message.contains("<mob>")) {
|
||||
message = message.replace("<mob>", depends.getNpcName(n));
|
||||
} else {
|
||||
message += " " + depends.getNpcName(n);
|
||||
}
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + npcKilled + "/" + toNpcKill);
|
||||
} else {
|
||||
// Legacy
|
||||
message += color + ": " + npcKilled + "/" + toNpcKill;
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message);
|
||||
npcKillIndex++;
|
||||
}
|
||||
int mobKillIndex = 0;
|
||||
for (final EntityType e : stage.getMobsToKill()) {
|
||||
int mobKilled = 0;
|
||||
if (data.mobNumKilled.size() > mobKillIndex) {
|
||||
mobKilled = data.mobNumKilled.get(mobKillIndex);
|
||||
}
|
||||
final int toMobKill = stage.getMobNumToKill().get(mobKillIndex);
|
||||
final ChatColor color = mobKilled < toMobKill ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + "";
|
||||
if (stage.getLocationsToKillWithin().isEmpty()) {
|
||||
message += BukkitLang.get(getPlayer(), "kill");
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + mobKilled + "/" + toMobKill);
|
||||
} else {
|
||||
// Legacy
|
||||
message += ChatColor.AQUA + " <mob>" + color + ": " + mobKilled + "/" + toMobKill;
|
||||
}
|
||||
} else {
|
||||
message += BukkitLang.get(getPlayer(), "killAtLocation").replace("<location>",
|
||||
stage.getKillNames().get(stage.getMobsToKill().indexOf(e)));
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + mobKilled + "/" + toMobKill);
|
||||
} else {
|
||||
message += color + ": " + mobKilled + "/" + toMobKill;
|
||||
}
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message.replace("<mob>", BukkitMiscUtil.snakeCaseToUpperCamelCase(e.name())));
|
||||
mobKillIndex++;
|
||||
}
|
||||
int tameIndex = 0;
|
||||
for (final int toTame : stage.getMobNumToTame()) {
|
||||
int tamed = 0;
|
||||
if (data.mobsTamed.size() > tameIndex) {
|
||||
tamed = data.mobsTamed.get(tameIndex);
|
||||
}
|
||||
final ChatColor color = tamed < toTame ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "tame");
|
||||
if (!message.contains("<mob>")) {
|
||||
message += " <mob>";
|
||||
}
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + tamed + "/" + toTame);
|
||||
} else {
|
||||
// Legacy
|
||||
message += color + ": " + tamed + "/" + toTame;
|
||||
}
|
||||
objectives.add(message.replace("<mob>",
|
||||
BukkitMiscUtil.snakeCaseToUpperCamelCase(stage.getMobsToTame().get(tameIndex).name())));
|
||||
tameIndex++;
|
||||
}
|
||||
if (stage.getFishToCatch() != null) {
|
||||
final ChatColor color = data.getFishCaught() < stage.getFishToCatch() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "catchFish");
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + data.getFishCaught() + "/" + stage.getFishToCatch());
|
||||
} else {
|
||||
// Legacy
|
||||
message += color + ": " + data.getFishCaught() + "/" + stage.getFishToCatch();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message);
|
||||
}
|
||||
if (stage.getCowsToMilk() != null) {
|
||||
final ChatColor color = data.getCowsMilked() < stage.getCowsToMilk() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "milkCow");
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + data.getCowsMilked() + "/" + stage.getCowsToMilk());
|
||||
} else {
|
||||
// Legacy
|
||||
message += color + ": " + data.getCowsMilked() + "/" + stage.getCowsToMilk();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message);
|
||||
}
|
||||
int shearIndex = 0;
|
||||
for (final int toShear : stage.getSheepNumToShear()) {
|
||||
int sheared = 0;
|
||||
if (data.sheepSheared.size() > shearIndex) {
|
||||
sheared = data.sheepSheared.get(shearIndex);
|
||||
}
|
||||
final ChatColor color = sheared < toShear ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "shearSheep");
|
||||
message = message.replace("<color>", BukkitMiscUtil.getPrettyDyeColorName(stage.getSheepToShear()
|
||||
.get(shearIndex)));
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + sheared + "/" + toShear);
|
||||
} else {
|
||||
// Legacy
|
||||
message += color + ": " + sheared + "/" + toShear;
|
||||
}
|
||||
objectives.add(message);
|
||||
shearIndex++;
|
||||
}
|
||||
if (stage.getPlayersToKill() != null) {
|
||||
final ChatColor color = data.getPlayersKilled() < stage.getPlayersToKill() ? ChatColor.GREEN
|
||||
: ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "killPlayer");
|
||||
if (message.contains("<count>")) {
|
||||
message = message.replace("<count>", "" + color + data.getPlayersKilled() + "/"
|
||||
+ stage.getPlayersToKill());
|
||||
} else {
|
||||
// Legacy
|
||||
message += color + ": " + data.getPlayersKilled() + "/" + stage.getPlayersToKill();
|
||||
}
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
|
||||
}
|
||||
objectives.add(message);
|
||||
}
|
||||
for (int i = 0 ; i < stage.getLocationsToReach().size(); i++) {
|
||||
if (i < data.locationsReached.size()) {
|
||||
final ChatColor color = !data.locationsReached.get(i) ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + BukkitLang.get(getPlayer(), "goTo");
|
||||
message = message.replace("<location>", stage.getLocationNames().get(i));
|
||||
objectives.add(message);
|
||||
}
|
||||
}
|
||||
int passIndex = 0;
|
||||
for (final String s : stage.getPasswordDisplays()) {
|
||||
boolean said = false;
|
||||
if (data.passwordsSaid.size() > passIndex) {
|
||||
said = data.passwordsSaid.get(passIndex);
|
||||
}
|
||||
final ChatColor color = !said ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
objectives.add(color + s);
|
||||
passIndex++;
|
||||
}
|
||||
int customIndex = 0;
|
||||
for (final CustomObjective co : stage.getCustomObjectives()) {
|
||||
int cleared = 0;
|
||||
if (data.customObjectiveCounts.size() > customIndex) {
|
||||
cleared = data.customObjectiveCounts.get(customIndex);
|
||||
}
|
||||
final int toClear = stage.getCustomObjectiveCounts().get(customIndex);
|
||||
final ChatColor color = cleared < toClear ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + co.getDisplay();
|
||||
for (final Entry<String,Object> prompt : co.getData()) {
|
||||
final String replacement = "%" + prompt.getKey() + "%";
|
||||
try {
|
||||
for (final Entry<String, Object> e : stage.getCustomObjectiveData()) {
|
||||
if (e.getKey().equals(prompt.getKey())) {
|
||||
if (message.contains(replacement)) {
|
||||
message = message.replace(replacement, ((String) e.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final NullPointerException ne) {
|
||||
plugin.getLogger().severe("Unable to gather display for " + co.getName() + " on "
|
||||
+ quest.getName());
|
||||
ne.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (co.canShowCount()) {
|
||||
message = message.replace("%count%", cleared + "/" + toClear);
|
||||
}
|
||||
objectives.add(BukkitConfigUtil.parseString(message));
|
||||
customIndex++;
|
||||
}
|
||||
return objectives;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current objectives for a quest, both finished and unfinished
|
||||
@ -1618,8 +1145,8 @@ public class BukkitQuester implements Quester {
|
||||
* @return List of detailed objectives
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public LinkedList<BukkitObjective> getCurrentObjectivesTemp(final Quest quest, final boolean ignoreOverrides,
|
||||
final boolean formatNames) {
|
||||
public LinkedList<Objective> getCurrentObjectives(final Quest quest, final boolean ignoreOverrides,
|
||||
final boolean formatNames) {
|
||||
if (quest == null) {
|
||||
plugin.getLogger().severe("Quest was null when getting objectives for " + getLastKnownName());
|
||||
return new LinkedList<>();
|
||||
@ -1635,7 +1162,7 @@ public class BukkitQuester implements Quester {
|
||||
}
|
||||
final BukkitDependencies depends = plugin.getDependencies();
|
||||
if (!ignoreOverrides && !stage.getObjectiveOverrides().isEmpty()) {
|
||||
final LinkedList<BukkitObjective> objectives = new LinkedList<>();
|
||||
final LinkedList<Objective> objectives = new LinkedList<>();
|
||||
for (final String s: stage.getObjectiveOverrides()) {
|
||||
String message = ChatColor.GREEN + BukkitConfigUtil.parseString(s, quest, getPlayer());
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
@ -1647,7 +1174,7 @@ public class BukkitQuester implements Quester {
|
||||
return objectives;
|
||||
}
|
||||
final BukkitQuestProgress data = (BukkitQuestProgress) getQuestDataOrDefault(quest);
|
||||
final LinkedList<BukkitObjective> objectives = new LinkedList<>();
|
||||
final LinkedList<Objective> objectives = new LinkedList<>();
|
||||
for (final ItemStack goal : stage.getBlocksToBreak()) {
|
||||
for (final ItemStack progress : data.blocksBroken) {
|
||||
if (progress.getType().equals(goal.getType()) && progress.getDurability() == goal.getDurability()) {
|
||||
@ -2175,7 +1702,8 @@ public class BukkitQuester implements Quester {
|
||||
settings.setTranslateNames(false);
|
||||
plugin.getLogger().severe("Problem with locale manager! Item name translation disabled.");
|
||||
}
|
||||
for (final BukkitObjective objective : q.getCurrentObjectivesTemp(quest, false, false)) {
|
||||
for (final Objective obj : q.getCurrentObjectives(quest, false, false)) {
|
||||
final BukkitObjective objective = (BukkitObjective) obj;
|
||||
final String message = "- " + objective.getMessage();
|
||||
if (objective.getProgressAsItem() != null && objective.getGoalAsItem() != null) {
|
||||
final ItemStack progress = objective.getProgressAsItem();
|
||||
@ -4249,8 +3777,8 @@ public class BukkitQuester implements Quester {
|
||||
* @return true if all stage objectives are marked complete
|
||||
*/
|
||||
public boolean testComplete(final Quest quest) {
|
||||
for (final String s : getCurrentObjectives(quest, true)) {
|
||||
if (s.startsWith(ChatColor.GREEN.toString())) {
|
||||
for (final Objective objective : getCurrentObjectives(quest, true, false)) {
|
||||
if (objective.getProgress() < objective.getGoal()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user