diff --git a/api/pom.xml b/api/pom.xml index 6925bda54..7786b58c3 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -5,7 +5,7 @@ me.blackvein.quests quests-parent - 4.2.4 + 4.3.0 quests-api diff --git a/api/src/main/java/me/blackvein/quests/player/IQuester.java b/api/src/main/java/me/blackvein/quests/player/IQuester.java index 2a7f24ed1..5aade9158 100644 --- a/api/src/main/java/me/blackvein/quests/player/IQuester.java +++ b/api/src/main/java/me/blackvein/quests/player/IQuester.java @@ -143,8 +143,6 @@ public interface IQuester extends Comparable { LinkedList getCurrentObjectives(final IQuest quest, final boolean ignoreOverrides); - LinkedList getCurrentObjectivesTemp(final IQuest quest, final boolean ignoreOverrides, final boolean formatItems); - LinkedList getObjectives(final IQuest quest, final boolean ignoreOverrides); boolean containsObjective(final IQuest quest, final String name); diff --git a/api/src/main/java/me/blackvein/quests/quests/Objective.java b/api/src/main/java/me/blackvein/quests/quests/Objective.java index 7b0dd4678..e5001b9ae 100644 --- a/api/src/main/java/me/blackvein/quests/quests/Objective.java +++ b/api/src/main/java/me/blackvein/quests/quests/Objective.java @@ -13,7 +13,7 @@ package me.blackvein.quests.quests; import me.blackvein.quests.enums.ObjectiveType; -import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; public interface Objective { ObjectiveType getType(); @@ -24,7 +24,7 @@ public interface Objective { int getGoal(); - ItemStack getItemProgress(); + @NotNull Object getProgressObject(); - ItemStack getItemGoal(); + @NotNull Object getGoalObject(); } diff --git a/core/pom.xml b/core/pom.xml index f6949f88d..09277c042 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -5,7 +5,7 @@ me.blackvein.quests quests-parent - 4.2.4 + 4.3.0 quests-core @@ -132,7 +132,7 @@ com.github.PikaMug LocaleLib - 5fb19ed10c + 35b50bfd53 xyz.upperlevel.spigot.book diff --git a/core/src/main/java/me/blackvein/quests/Quester.java b/core/src/main/java/me/blackvein/quests/Quester.java index 6c94d30b6..c2709a436 100644 --- a/core/src/main/java/me/blackvein/quests/Quester.java +++ b/core/src/main/java/me/blackvein/quests/Quester.java @@ -20,9 +20,9 @@ import me.blackvein.quests.conditions.ICondition; import me.blackvein.quests.config.ISettings; import me.blackvein.quests.convo.misc.QuestAbandonPrompt; import me.blackvein.quests.dependencies.IDependencies; -import me.blackvein.quests.events.quest.QuestQuitEvent; -import me.blackvein.quests.module.ICustomObjective; +import me.blackvein.quests.entity.CountableMob; import me.blackvein.quests.enums.ObjectiveType; +import me.blackvein.quests.events.quest.QuestQuitEvent; import me.blackvein.quests.events.quest.QuestTakeEvent; import me.blackvein.quests.events.quester.QuesterPostStartQuestEvent; import me.blackvein.quests.events.quester.QuesterPostUpdateObjectiveEvent; @@ -30,6 +30,7 @@ import me.blackvein.quests.events.quester.QuesterPreOpenGUIEvent; import me.blackvein.quests.events.quester.QuesterPreStartQuestEvent; import me.blackvein.quests.events.quester.QuesterPreUpdateObjectiveEvent; import me.blackvein.quests.item.QuestJournal; +import me.blackvein.quests.module.ICustomObjective; import me.blackvein.quests.nms.TitleProvider; import me.blackvein.quests.player.IQuester; import me.blackvein.quests.quests.BukkitObjective; @@ -1567,12 +1568,12 @@ public class Quester implements IQuester { * * @param quest The quest to get objectives of * @param ignoreOverrides Whether to ignore objective-overrides - * @param formatItems Whether to format item names, if applicable + * @param formatNames Whether to format item/entity names, if applicable * @return List of detailed objectives */ @SuppressWarnings("deprecation") - public LinkedList getCurrentObjectivesTemp(final IQuest quest, final boolean ignoreOverrides, - final boolean formatItems) { + public LinkedList getCurrentObjectivesTemp(final IQuest quest, final boolean ignoreOverrides, + final boolean formatNames) { if (quest == null) { plugin.getLogger().severe("Quest was null when getting objectives for " + getLastKnownName()); return new LinkedList<>(); @@ -1587,7 +1588,7 @@ public class Quester implements IQuester { } final IDependencies depends = plugin.getDependencies(); if (!ignoreOverrides && !getCurrentStage(quest).getObjectiveOverrides().isEmpty()) { - final LinkedList objectives = new LinkedList<>(); + final LinkedList objectives = new LinkedList<>(); for (final String s: getCurrentStage(quest).getObjectiveOverrides()) { String message = ChatColor.GREEN + ConfigUtil.parseString(s, quest, getPlayer()); if (depends.getPlaceholderApi() != null) { @@ -1600,7 +1601,7 @@ public class Quester implements IQuester { } final QuestData data = getQuestData(quest); final IStage stage = getCurrentStage(quest); - final LinkedList objectives = new LinkedList<>(); + final LinkedList 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()) { @@ -1616,7 +1617,7 @@ public class Quester implements IQuester { if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(getPlayer(), message); } - if (formatItems) { + if (formatNames) { message = message.replace("", ItemUtil.getName(progress)); } objectives.add(new BukkitObjective(ObjectiveType.BREAK_BLOCK, message, progress, goal)); @@ -1638,7 +1639,7 @@ public class Quester implements IQuester { if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(getPlayer(), message); } - if (formatItems) { + if (formatNames) { message = message.replace("", ItemUtil.getName(progress)); } objectives.add(new BukkitObjective(ObjectiveType.DAMAGE_BLOCK, message, progress, goal)); @@ -1660,7 +1661,7 @@ public class Quester implements IQuester { if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(getPlayer(), message); } - if (formatItems) { + if (formatNames) { message = message.replace("", ItemUtil.getName(progress)); } objectives.add(new BukkitObjective(ObjectiveType.PLACE_BLOCK, message, progress, goal)); @@ -1682,7 +1683,7 @@ public class Quester implements IQuester { if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(getPlayer(), message); } - if (formatItems) { + if (formatNames) { message = message.replace("", ItemUtil.getName(progress)); } objectives.add(new BukkitObjective(ObjectiveType.USE_BLOCK, message, progress, goal)); @@ -1704,7 +1705,7 @@ public class Quester implements IQuester { if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(getPlayer(), message); } - if (formatItems) { + if (formatNames) { message = message.replace("", ItemUtil.getName(progress)); } objectives.add(new BukkitObjective(ObjectiveType.CUT_BLOCK, message, progress, goal)); @@ -1728,7 +1729,7 @@ public class Quester implements IQuester { if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(getPlayer(), message); } - if (formatItems) { + if (formatNames) { message = message.replace("", ItemUtil.getName(goal)); } objectives.add(new BukkitObjective(ObjectiveType.CRAFT_ITEM, message, progress, goal)); @@ -1752,7 +1753,7 @@ public class Quester implements IQuester { if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(getPlayer(), message); } - if (formatItems) { + if (formatNames) { message = message.replace("", ItemUtil.getName(goal)); } objectives.add(new BukkitObjective(ObjectiveType.SMELT_ITEM, message, progress, goal)); @@ -1776,7 +1777,7 @@ public class Quester implements IQuester { if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(getPlayer(), message); } - if (formatItems) { + if (formatNames) { message = message.replace("", ItemUtil.getName(goal)); } if (goal.getEnchantments().isEmpty()) { @@ -1811,7 +1812,7 @@ public class Quester implements IQuester { if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(getPlayer(), message); } - if (formatItems) { + if (formatNames) { message = message.replace("", ItemUtil.getName(goal)); } objectives.add(new BukkitObjective(ObjectiveType.BREW_ITEM, message, progress, goal)); @@ -1835,7 +1836,7 @@ public class Quester implements IQuester { if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(getPlayer(), message); } - if (formatItems) { + if (formatNames) { message = message.replace("", ItemUtil.getName(goal)); } objectives.add(new BukkitObjective(ObjectiveType.CONSUME_ITEM, message, progress, goal)); @@ -1860,7 +1861,7 @@ public class Quester implements IQuester { if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(getPlayer(), message); } - if (formatItems) { + if (formatNames) { message = message.replace("", ItemUtil.getName(goal)); } objectives.add(new BukkitObjective(ObjectiveType.DELIVER_ITEM, message, progress, goal)); @@ -1937,16 +1938,20 @@ public class Quester implements IQuester { if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(getPlayer(), message); } - message = message.replace("", MiscUtil.getProperMobName(e)); - objectives.add(new BukkitObjective(ObjectiveType.KILL_MOB, message, mobKilled, toMobKill)); + if (formatNames) { + message = message.replace("", MiscUtil.getProperMobName(e)); + } + objectives.add(new BukkitObjective(ObjectiveType.KILL_MOB, message, + new CountableMob(e, mobKilled), new CountableMob(e, toMobKill))); mobKillIndex++; } int tameIndex = 0; - for (final int toTame : stage.getMobNumToTame()) { + for (final EntityType e : stage.getMobsToTame()) { int tamed = 0; if (data.mobsTamed.size() > tameIndex) { tamed = data.mobsTamed.get(tameIndex); } + final int toTame = stage.getMobNumToTame().get(tameIndex); final ChatColor color = tamed < toTame ? ChatColor.GREEN : ChatColor.GRAY; String message = color + Lang.get(getPlayer(), "tame"); if (!message.contains("")) { @@ -1958,8 +1963,11 @@ public class Quester implements IQuester { // Legacy message += color + ": " + tamed + "/" + toTame; } - message = message.replace("", MiscUtil.getProperMobName(stage.getMobsToTame().get(tameIndex))); - objectives.add(new BukkitObjective(ObjectiveType.TAME_MOB, message, tamed, toTame)); + if (formatNames) { + message = message.replace("", MiscUtil.getProperMobName(stage.getMobsToTame().get(tameIndex))); + } + objectives.add(new BukkitObjective(ObjectiveType.TAME_MOB, message, + new CountableMob(e, tamed), new CountableMob(e, toTame))); tameIndex++; } if (stage.getFishToCatch() != null) { @@ -3629,9 +3637,9 @@ public class Quester implements IQuester { } final Player p = getPlayer(); final ObjectiveType type = objective.getType(); - final ItemStack increment = objective.getItemProgress() != null ? objective.getItemProgress() + final ItemStack increment = objective.getGoalObject() instanceof ItemStack ? (ItemStack) objective : new ItemStack(Material.AIR, objective.getProgress()); - final ItemStack goal = objective.getItemGoal() != null ? objective.getItemGoal() + final ItemStack goal = objective.getGoalObject() instanceof ItemStack ? (ItemStack) objective : new ItemStack(Material.AIR, objective.getGoal()); if (!getCurrentStage(quest).getObjectiveOverrides().isEmpty()) { for (final String s: getCurrentStage(quest).getObjectiveOverrides()) { diff --git a/core/src/main/java/me/blackvein/quests/entity/CountableMob.java b/core/src/main/java/me/blackvein/quests/entity/CountableMob.java new file mode 100644 index 000000000..a0fb19aca --- /dev/null +++ b/core/src/main/java/me/blackvein/quests/entity/CountableMob.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2014 PikaMug and contributors. All rights reserved. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package me.blackvein.quests.entity; + +import org.bukkit.entity.EntityType; + +public class CountableMob { + + private EntityType entityType; + private int count; + + public CountableMob(EntityType entityType, int count) { + this.entityType = entityType; + this.count = count; + } + + public EntityType getEntityType() { + return entityType; + } + + public void setEntityType(final EntityType entityType) { + this.entityType = entityType; + } + + public int getCount() { + return count; + } + + public void setCount(final int count) { + this.count = count; + } +} diff --git a/core/src/main/java/me/blackvein/quests/item/QuestJournal.java b/core/src/main/java/me/blackvein/quests/item/QuestJournal.java index 6401711dd..11196b9e4 100644 --- a/core/src/main/java/me/blackvein/quests/item/QuestJournal.java +++ b/core/src/main/java/me/blackvein/quests/item/QuestJournal.java @@ -12,12 +12,14 @@ package me.blackvein.quests.item; +import me.blackvein.quests.Quester; import me.blackvein.quests.Quests; import me.blackvein.quests.player.IQuester; +import me.blackvein.quests.quests.BukkitObjective; import me.blackvein.quests.quests.IQuest; -import me.blackvein.quests.quests.Objective; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; +import me.blackvein.quests.util.MiscUtil; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TranslatableComponent; @@ -72,21 +74,38 @@ public class QuestJournal { 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 Objective obj : owner.getCurrentObjectivesTemp(quest, false, false)) { - if (obj.getMessage() != null && obj.getMessage().contains("")) { - final String[] split = obj.getMessage().split(""); - builder.add(split[0]); - if (plugin.getSettings().canTranslateNames() && obj.getItemGoal() != null) { - final TranslatableComponent tc = new TranslatableComponent(plugin.getLocaleManager() - .queryItemStack(obj.getItemGoal())); - tc.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA); - builder.add(tc); - } else { - builder.add(ItemUtil.getName(obj.getItemGoal())); + for (final BukkitObjective obj : ((Quester)owner).getCurrentObjectivesTemp(quest, false, false)) { + if (obj.getMessage() != null) { + String[] split = null; + if (obj.getMessage().contains("") && obj.getGoalAsItem() != null) { + split = obj.getMessage().split(""); + builder.add(split[0]); + if (plugin.getSettings().canTranslateNames()) { + final TranslatableComponent tc = new TranslatableComponent(plugin.getLocaleManager() + .queryItemStack(obj.getGoalAsItem())); + tc.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA); + builder.add(tc); + } else { + builder.add(ItemUtil.getName(obj.getGoalAsItem())); + } + builder.add(split[1]).newLine(); + } + if (obj.getMessage().contains("") && obj.getGoalAsMob() != null) { + split = obj.getMessage().split(""); + builder.add(split[0]); + if (plugin.getSettings().canTranslateNames()) { + final TranslatableComponent tc = new TranslatableComponent(plugin.getLocaleManager() + .queryEntityType(obj.getGoalAsMob().getEntityType(), null)); // TODO extra data + tc.setColor(net.md_5.bungee.api.ChatColor.DARK_RED); + builder.add(tc); + } else { + builder.add(MiscUtil.snakeCaseToUpperCamelCase(obj.getGoalAsMob().getEntityType().name())); + } + builder.add(split[1]).newLine(); + } + if (split == null) { + builder.add(obj.getMessage()).newLine(); } - builder.add(split[1]).newLine(); - } else { - builder.add(obj.getMessage()).newLine(); } } pages.add(builder.build()); diff --git a/core/src/main/java/me/blackvein/quests/quests/BukkitObjective.java b/core/src/main/java/me/blackvein/quests/quests/BukkitObjective.java index 43b7d749a..057e82928 100644 --- a/core/src/main/java/me/blackvein/quests/quests/BukkitObjective.java +++ b/core/src/main/java/me/blackvein/quests/quests/BukkitObjective.java @@ -12,17 +12,19 @@ package me.blackvein.quests.quests; -import org.bukkit.inventory.ItemStack; - +import me.blackvein.quests.entity.CountableMob; import me.blackvein.quests.enums.ObjectiveType; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class BukkitObjective implements Objective { private final ObjectiveType type; private final String message; private final int progress; private final int goal; - private final ItemStack progressStack; - private final ItemStack goalStack; + private final Object progressObj; + private final Object goalObj; /** * @deprecated Use {@link #BukkitObjective(ObjectiveType, String, int, int)} with null message @@ -32,61 +34,97 @@ public class BukkitObjective implements Objective { this.message = null; this.progress = progress; this.goal = goal; - this.progressStack = null; - this.goalStack = null; + this.progressObj = new Object(); + this.goalObj = new Object(); } /** - * @deprecated Use {@link #BukkitObjective(ObjectiveType, String, ItemStack, ItemStack)} with null message + * @deprecated Use {@link #BukkitObjective(ObjectiveType, String, Object, Object)} with null message */ public BukkitObjective(final ObjectiveType type, final ItemStack progress, final ItemStack goal) { this.type = type; this.message = null; this.progress = progress.getAmount(); this.goal = goal.getAmount(); - this.progressStack = progress; - this.goalStack = goal; + this.progressObj = progress; + this.goalObj = goal; } - public BukkitObjective(final ObjectiveType type, final String message, final int progress, final int goal) { + public BukkitObjective(final ObjectiveType type, @Nullable final String message, final int progress, + final int goal) { this.type = type; this.message = message; this.progress = progress; this.goal = goal; - this.progressStack = null; - this.goalStack = null; + this.progressObj = new Object(); + this.goalObj = new Object(); } - public BukkitObjective(final ObjectiveType type, final String message, final ItemStack progress, final ItemStack goal) { + public BukkitObjective(final ObjectiveType type, @Nullable final String message, final @NotNull Object progress, + final @NotNull Object goal) { this.type = type; this.message = message; - this.progress = progress.getAmount(); - this.goal = goal.getAmount(); - this.progressStack = progress; - this.goalStack = goal; + this.progressObj = progress; + this.goalObj = goal; + if (progressObj instanceof ItemStack) { + this.progress = ((ItemStack) progressObj).getAmount(); + } else if (progressObj instanceof CountableMob) { + this.progress = ((CountableMob) progressObj).getCount(); + } else { + this.progress = 0; + } + if (goalObj instanceof ItemStack) { + this.goal = ((ItemStack) goalObj).getAmount(); + } else if (goalObj instanceof CountableMob) { + this.goal = ((CountableMob) goalObj).getCount(); + } else { + this.goal = 0; + } } - + + @Override public ObjectiveType getType() { return type; } + @Override public String getMessage() { return message; } - + + @Override public int getProgress() { return progress; } - + + @Override public int getGoal() { return goal; } - - public ItemStack getItemProgress() { - return progressStack; + + @Override + public @NotNull Object getProgressObject() { + return progressObj; + } + + @Override + public @NotNull Object getGoalObject() { + return goalObj; } - public ItemStack getItemGoal() { - return goalStack; + public @Nullable ItemStack getProgressAsItem() { + return progressObj instanceof ItemStack ? (ItemStack) progressObj : null; + } + + public @Nullable ItemStack getGoalAsItem() { + return goalObj instanceof ItemStack ? (ItemStack) goalObj : null; + } + + public @Nullable CountableMob getProgressAsMob() { + return progressObj instanceof CountableMob ? (CountableMob) progressObj : null; + } + + public @Nullable CountableMob getGoalAsMob() { + return goalObj instanceof CountableMob ? (CountableMob) goalObj : null; } } diff --git a/dist/pom.xml b/dist/pom.xml index 3b54b3a13..ba4433d34 100644 --- a/dist/pom.xml +++ b/dist/pom.xml @@ -5,7 +5,7 @@ me.blackvein.quests quests-parent - 4.2.4 + 4.3.0 quests-dist pom diff --git a/pom.xml b/pom.xml index b32f7deec..249487ed4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,12 +6,12 @@ me.blackvein.quests quests-parent - 4.2.4 + 4.3.0 quests https://github.com/PikaMug/Quests/ - 4.2.4 + 4.3.0 UTF-8 1.8 1.8 diff --git a/v1_8_R1/pom.xml b/v1_8_R1/pom.xml index eddf70602..5fe46ca26 100644 --- a/v1_8_R1/pom.xml +++ b/v1_8_R1/pom.xml @@ -6,7 +6,7 @@ me.blackvein.quests quests-parent - 4.2.4 + 4.3.0 diff --git a/v1_8_R2/pom.xml b/v1_8_R2/pom.xml index 29085061e..094990698 100644 --- a/v1_8_R2/pom.xml +++ b/v1_8_R2/pom.xml @@ -6,7 +6,7 @@ me.blackvein.quests quests-parent - 4.2.4 + 4.3.0 diff --git a/v1_8_R3/pom.xml b/v1_8_R3/pom.xml index 5e9bdc679..8ae36b4ed 100644 --- a/v1_8_R3/pom.xml +++ b/v1_8_R3/pom.xml @@ -6,7 +6,7 @@ me.blackvein.quests quests-parent - 4.2.4 + 4.3.0