From f6aea23057ebac591b6260ac4d334d8b218a6159 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Wed, 16 Dec 2020 06:00:37 -0500 Subject: [PATCH] Add objective update API events, part 1. See #1501 --- .../me/blackvein/quests/CustomObjective.java | 17 +- .../java/me/blackvein/quests/Quester.java | 339 ++++++++++++++---- .../blackvein/quests/enums/ObjectiveType.java | 79 ++++ .../quester/QuesterPostChangeStageEvent.java | 2 +- .../QuesterPostCompleteQuestEvent.java | 2 +- .../quester/QuesterPostFailQuestEvent.java | 2 +- .../quester/QuesterPostStartQuestEvent.java | 2 +- .../quester/QuesterPreChangeStageEvent.java | 2 +- .../quester/QuesterPreCompleteQuestEvent.java | 2 +- .../quester/QuesterPreFailQuestEvent.java | 2 +- .../quester/QuesterPreStartQuestEvent.java | 2 +- 11 files changed, 366 insertions(+), 85 deletions(-) create mode 100644 main/src/main/java/me/blackvein/quests/enums/ObjectiveType.java diff --git a/main/src/main/java/me/blackvein/quests/CustomObjective.java b/main/src/main/java/me/blackvein/quests/CustomObjective.java index cf7ca8a9c..a2f2d0e43 100644 --- a/main/src/main/java/me/blackvein/quests/CustomObjective.java +++ b/main/src/main/java/me/blackvein/quests/CustomObjective.java @@ -23,6 +23,10 @@ import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; +import me.blackvein.quests.enums.ObjectiveType; +import me.blackvein.quests.events.quester.QuesterPostUpdateObjectiveEvent; +import me.blackvein.quests.events.quester.QuesterPreUpdateObjectiveEvent; + public abstract class CustomObjective implements Listener { private final Quests plugin = Quests.getPlugin(Quests.class); @@ -173,20 +177,29 @@ public abstract class CustomObjective implements Listener { } } if (index > -1) { + final ObjectiveType type = ObjectiveType.CUSTOM; + final QuesterPreUpdateObjectiveEvent preEvent + = new QuesterPreUpdateObjectiveEvent(quester, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final int goal = quester.getCurrentStage(quest).customObjectiveCounts.get(index); if (quester.getQuestData(quest).customObjectiveCounts.get(obj.getName()) >= goal) { - quester.finishObjective(quest, "customObj", new ItemStack(Material.AIR, 1), + quester.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, goal), null, null, null, null, null, null, null, obj); // Multiplayer quester.dispatchMultiplayerObjectives(quest, quester.getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).customObjectiveCounts.put(obj.getName(), quester.getQuestData(quest).customObjectiveCounts.get(obj.getName())); - q.finishObjective(quest, "customObj", new ItemStack(Material.AIR, 1), + q.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, goal), null, null, null, null, null, null, null, obj); return null; }); } + + final QuesterPostUpdateObjectiveEvent postEvent + = new QuesterPostUpdateObjectiveEvent(quester, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } } } diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index 4bec79412..6dd9cffb8 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -53,10 +53,13 @@ import com.gmail.nossr50.util.player.UserManager; import de.erethon.dungeonsxl.player.DGroup; import me.blackvein.quests.conditions.Condition; +import me.blackvein.quests.enums.ObjectiveType; import me.blackvein.quests.events.quest.QuestTakeEvent; import me.blackvein.quests.events.quester.QuesterPostStartQuestEvent; +import me.blackvein.quests.events.quester.QuesterPostUpdateObjectiveEvent; 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.storage.Storage; import me.blackvein.quests.tasks.StageTimer; @@ -1325,6 +1328,10 @@ public class Quester implements Comparable { */ @SuppressWarnings("deprecation") public void breakBlock(final Quest quest, final ItemStack m) { + final ObjectiveType type = ObjectiveType.BREAK_BLOCK; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final ItemStack temp = m; temp.setAmount(0); ItemStack broken = temp; @@ -1397,7 +1404,7 @@ public class Quester implements Comparable { if (getQuestData(quest).blocksBroken.contains(broken)) { getQuestData(quest).blocksBroken.set(getQuestData(quest).blocksBroken.indexOf(broken), newBroken); if (broken.getAmount() == toBreak.getAmount()) { - finishObjective(quest, "breakBlock", m, toBreak, null, null, null, null, null, null, null, null); + finishObjective(quest, type, m, toBreak, null, null, null, null, null, null, null, null); // Multiplayer final ItemStack finalBroken = broken; @@ -1405,13 +1412,16 @@ public class Quester implements Comparable { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).blocksBroken.set(getQuestData(quest).blocksBroken .indexOf(finalBroken), newBroken); - q.finishObjective(quest, "breakBlock", m, finalToBreak, null, null, null, null, null, null, + q.finishObjective(quest, type, m, finalToBreak, null, null, null, null, null, null, null, null); return null; }); } } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -1422,6 +1432,10 @@ public class Quester implements Comparable { */ @SuppressWarnings("deprecation") public void damageBlock(final Quest quest, final ItemStack m) { + final ObjectiveType type = ObjectiveType.DAMAGE_BLOCK; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final ItemStack temp = m; temp.setAmount(0); ItemStack damaged = temp; @@ -1474,7 +1488,7 @@ public class Quester implements Comparable { if (getQuestData(quest).blocksDamaged.contains(damaged)) { getQuestData(quest).blocksDamaged.set(getQuestData(quest).blocksDamaged.indexOf(damaged), newDamaged); if (damaged.getAmount() == toDamage.getAmount()) { - finishObjective(quest, "damageBlock", m, toDamage, null, null, null, null, null, null, null, null); + finishObjective(quest, type, m, toDamage, null, null, null, null, null, null, null, null); // Multiplayer final ItemStack finalDamaged = damaged; @@ -1482,13 +1496,16 @@ public class Quester implements Comparable { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).blocksDamaged.set(getQuestData(quest).blocksDamaged .indexOf(finalDamaged), newDamaged); - q.finishObjective(quest, "damageBlock", m, finalToDamage, null, null, null, null, null, null, + q.finishObjective(quest, type, m, finalToDamage, null, null, null, null, null, null, null, null); return null; }); } } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -1499,6 +1516,10 @@ public class Quester implements Comparable { */ @SuppressWarnings("deprecation") public void placeBlock(final Quest quest, final ItemStack m) { + final ObjectiveType type = ObjectiveType.PLACE_BLOCK; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final ItemStack temp = m; temp.setAmount(0); ItemStack placed = temp; @@ -1551,7 +1572,7 @@ public class Quester implements Comparable { if (getQuestData(quest).blocksPlaced.contains(placed)) { getQuestData(quest).blocksPlaced.set(getQuestData(quest).blocksPlaced.indexOf(placed), newplaced); if (placed.getAmount() == toPlace.getAmount()) { - finishObjective(quest, "placeBlock", m, toPlace, null, null, null, null, null, null, null, null); + finishObjective(quest, type, m, toPlace, null, null, null, null, null, null, null, null); // Multiplayer final ItemStack finalPlaced = placed; @@ -1559,13 +1580,16 @@ public class Quester implements Comparable { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).blocksPlaced.set(getQuestData(quest).blocksPlaced .indexOf(finalPlaced), newplaced); - q.finishObjective(quest, "placeBlock", m, finalToPlace, null, null, null, null, null, null, + q.finishObjective(quest, type, m, finalToPlace, null, null, null, null, null, null, null, null); return null; }); } } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -1576,6 +1600,10 @@ public class Quester implements Comparable { */ @SuppressWarnings("deprecation") public void useBlock(final Quest quest, final ItemStack m) { + final ObjectiveType type = ObjectiveType.USE_BLOCK; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final ItemStack temp = m; temp.setAmount(0); ItemStack used = temp; @@ -1628,7 +1656,7 @@ public class Quester implements Comparable { if (getQuestData(quest).blocksUsed.contains(used)) { getQuestData(quest).blocksUsed.set(getQuestData(quest).blocksUsed.indexOf(used), newUsed); if (used.getAmount() == toUse.getAmount()) { - finishObjective(quest, "useBlock", m, toUse, null, null, null, null, null, null, null, null); + finishObjective(quest, type, m, toUse, null, null, null, null, null, null, null, null); // Multiplayer final ItemStack finalUsed = used; @@ -1636,13 +1664,16 @@ public class Quester implements Comparable { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).blocksUsed.set(getQuestData(quest).blocksUsed .indexOf(finalUsed), newUsed); - q.finishObjective(quest, "useBlock", m, finalToUse, null, null, null, null, null, null, null, + q.finishObjective(quest, type, m, finalToUse, null, null, null, null, null, null, null, null); return null; }); } } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -1653,6 +1684,10 @@ public class Quester implements Comparable { */ @SuppressWarnings("deprecation") public void cutBlock(final Quest quest, final ItemStack m) { + final ObjectiveType type = ObjectiveType.CUT_BLOCK; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final ItemStack temp = m; temp.setAmount(0); ItemStack cut = temp; @@ -1705,20 +1740,23 @@ public class Quester implements Comparable { if (getQuestData(quest).blocksCut.contains(cut)) { getQuestData(quest).blocksCut.set(getQuestData(quest).blocksCut.indexOf(cut), newCut); if (cut.getAmount() == toCut.getAmount()) { - finishObjective(quest, "cutBlock", m, toCut, null, null, null, null, null, null, null, null); + finishObjective(quest, type, m, toCut, null, null, null, null, null, null, null, null); // Multiplayer final ItemStack finalCut = cut; final ItemStack finalToCut = toCut; dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).blocksCut.set(getQuestData(quest).blocksCut.indexOf(finalCut), newCut); - q.finishObjective(quest, "cutBlock", m, finalToCut, null, null, null, null, null, null, null, + q.finishObjective(quest, type, m, finalToCut, null, null, null, null, null, null, null, null); return null; }); } } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -1728,6 +1766,10 @@ public class Quester implements Comparable { * @param i The item being crafted */ public void craftItem(final Quest quest, final ItemStack i) { + final ObjectiveType type = ObjectiveType.CRAFT_ITEM; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final Player player = getPlayer(); ItemStack found = null; for (final ItemStack is : getQuestData(quest).itemsCrafted.keySet()) { @@ -1754,14 +1796,14 @@ public class Quester implements Comparable { if (amount < req) { if ((i.getAmount() + amount) >= req) { getQuestData(quest).itemsCrafted.put(found, req); - finishObjective(quest, "craftItem", new ItemStack(m, 1), found, null, null, null, null, null, null, + finishObjective(quest, type, new ItemStack(m, 1), found, null, null, null, null, null, null, null, null); // Multiplayer final ItemStack finalFound = found; dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).itemsCrafted.put(finalFound, req); - q.finishObjective(quest, "craftItem", new ItemStack(m, 1), finalFound, null, null, null, null, + q.finishObjective(quest, type, new ItemStack(m, 1), finalFound, null, null, null, null, null, null, null, null); return null; }); @@ -1770,6 +1812,9 @@ public class Quester implements Comparable { } } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -1779,6 +1824,10 @@ public class Quester implements Comparable { * @param i The item being smelted */ public void smeltItem(final Quest quest, final ItemStack i) { + final ObjectiveType type = ObjectiveType.SMELT_ITEM; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final Player player = getPlayer(); ItemStack found = null; for (final ItemStack is : getQuestData(quest).itemsSmelted.keySet()) { @@ -1804,14 +1853,14 @@ public class Quester implements Comparable { if (amount < req) { if ((i.getAmount() + amount) >= req) { getQuestData(quest).itemsSmelted.put(found, req); - finishObjective(quest, "smeltItem", new ItemStack(m, 1), found, null, null, null, null, null, null, + finishObjective(quest, type, new ItemStack(m, 1), found, null, null, null, null, null, null, null, null); // Multiplayer final ItemStack finalFound = found; dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).itemsSmelted.put(finalFound, req); - q.finishObjective(quest, "smeltItem", new ItemStack(m, 1), finalFound, null, null, null, null, + q.finishObjective(quest, type, new ItemStack(m, 1), finalFound, null, null, null, null, null, null, null, null); return null; }); @@ -1820,6 +1869,9 @@ public class Quester implements Comparable { } } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -1829,6 +1881,10 @@ public class Quester implements Comparable { * @param i The item being enchanted */ public void enchantItem(final Quest quest, final ItemStack i) { + final ObjectiveType type = ObjectiveType.ENCHANT_ITEM; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final Player player = getPlayer(); ItemStack found = null; for (final ItemStack is : getQuestData(quest).itemsEnchanted.keySet()) { @@ -1854,14 +1910,14 @@ public class Quester implements Comparable { if (amount < req) { if ((i.getAmount() + amount) >= req) { getQuestData(quest).itemsEnchanted.put(found, req); - finishObjective(quest, "enchItem", new ItemStack(m, 1), found, null, null, null, null, null, null, + finishObjective(quest, type, new ItemStack(m, 1), found, null, null, null, null, null, null, null, null); // Multiplayer final ItemStack finalFound = found; dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).itemsEnchanted.put(finalFound, req); - q.finishObjective(quest, "enchItem", new ItemStack(m, 1), finalFound, null, null, null, null, + q.finishObjective(quest, type, new ItemStack(m, 1), finalFound, null, null, null, null, null, null, null, null); return null; }); @@ -1870,6 +1926,9 @@ public class Quester implements Comparable { } } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -1879,6 +1938,10 @@ public class Quester implements Comparable { * @param i The item being brewed */ public void brewItem(final Quest quest, final ItemStack i) { + final ObjectiveType type = ObjectiveType.BREW_ITEM; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final Player player = getPlayer(); ItemStack found = null; for (final ItemStack is : getQuestData(quest).itemsBrewed.keySet()) { @@ -1904,14 +1967,14 @@ public class Quester implements Comparable { if (amount < req) { if ((i.getAmount() + amount) >= req) { getQuestData(quest).itemsBrewed.put(found, req); - finishObjective(quest, "brewItem", new ItemStack(m, 1), found, null, null, null, null, null, null, + finishObjective(quest, type, new ItemStack(m, 1), found, null, null, null, null, null, null, null, null); // Multiplayer final ItemStack finalFound = found; dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).itemsBrewed.put(finalFound, req); - q.finishObjective(quest, "brewItem", new ItemStack(m, 1), finalFound, null, null, null, null, + q.finishObjective(quest, type, new ItemStack(m, 1), finalFound, null, null, null, null, null, null, null, null); return null; }); @@ -1920,6 +1983,9 @@ public class Quester implements Comparable { } } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -1929,6 +1995,10 @@ public class Quester implements Comparable { * @param i The item being consumed */ public void consumeItem(final Quest quest, final ItemStack i) { + final ObjectiveType type = ObjectiveType.CONSUME_ITEM; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final Player player = getPlayer(); ItemStack found = null; for (final ItemStack is : getQuestData(quest).itemsConsumed.keySet()) { @@ -1954,14 +2024,14 @@ public class Quester implements Comparable { if (amount < req) { if ((i.getAmount() + amount) >= req) { getQuestData(quest).itemsConsumed.put(found, req); - finishObjective(quest, "consumeItem", new ItemStack(m, 1), found, null, null, null, null, null, null, + finishObjective(quest, type, new ItemStack(m, 1), found, null, null, null, null, null, null, null, null); // Multiplayer final ItemStack finalFound = found; dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).itemsConsumed.put(finalFound, req); - q.finishObjective(quest, "consumeItem", new ItemStack(m, 1), finalFound, null, null, null, null, + q.finishObjective(quest, type, new ItemStack(m, 1), finalFound, null, null, null, null, null, null, null, null); return null; }); @@ -1970,6 +2040,9 @@ public class Quester implements Comparable { } } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -1978,23 +2051,30 @@ public class Quester implements Comparable { * @param quest The quest for which the fish is being caught */ public void milkCow(final Quest quest) { + final ObjectiveType type = ObjectiveType.MILK_COW; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final int cowsToMilk = getCurrentStage(quest).cowsToMilk; if (getQuestData(quest).getCowsMilked() < cowsToMilk) { getQuestData(quest).setCowsMilked(getQuestData(quest).getCowsMilked() + 1); if (getQuestData(quest).getCowsMilked() == cowsToMilk) { - finishObjective(quest, "milkCow", new ItemStack(Material.AIR, 1), + finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, cowsToMilk), null, null, null, null, null, null, null, null); // Multiplayer dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).setCowsMilked(cowsToMilk); - q.finishObjective(quest, "milkCow", new ItemStack(Material.AIR, 1), + q.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, cowsToMilk), null, null, null, null, null, null, null, null); return null; }); } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -2003,23 +2083,30 @@ public class Quester implements Comparable { * @param quest The quest for which the fish is being caught */ public void catchFish(final Quest quest) { + final ObjectiveType type = ObjectiveType.CATCH_FISH; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final int fishToCatch = getCurrentStage(quest).fishToCatch; if (getQuestData(quest).getFishCaught() < fishToCatch) { getQuestData(quest).setFishCaught(getQuestData(quest).getFishCaught() + 1); if (getQuestData(quest).getFishCaught() == fishToCatch) { - finishObjective(quest, "catchFish", new ItemStack(Material.AIR, 1), + finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, fishToCatch), null, null, null, null, null, null, null, null); // Multiplayer dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).setFishCaught(fishToCatch); - q.finishObjective(quest, "catchFish", new ItemStack(Material.AIR, 1), + q.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, fishToCatch), null, null, null, null, null, null, null, null); return null; }); } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -2038,6 +2125,10 @@ public class Quester implements Comparable { if (currentStage.mobsToKill.contains(e) == false) { return; } + final ObjectiveType type = ObjectiveType.KILL_MOB; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final int indexOfMobKilled = questData.mobsKilled.indexOf(e); final int numberOfSpecificMobKilled = questData.mobNumKilled.get(indexOfMobKilled); final int numberOfSpecificMobNeedsToBeKilledInCurrentStage = currentStage.mobNumToKill.get(indexOfMobKilled); @@ -2066,20 +2157,23 @@ public class Quester implements Comparable { final int newNumberOfSpecificMobKilled = numberOfSpecificMobKilled + 1; questData.mobNumKilled.set(indexOfMobKilled, newNumberOfSpecificMobKilled); if (newNumberOfSpecificMobKilled == numberOfSpecificMobNeedsToBeKilledInCurrentStage) { - finishObjective(quest, "killMob", new ItemStack(Material.AIR, 1), + finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, numberOfSpecificMobNeedsToBeKilledInCurrentStage), null, e, null, null, null, null, null, null); // Multiplayer dispatchMultiplayerObjectives(quest, currentStage, (final Quester q) -> { q.getQuestData(quest).mobNumKilled.set(indexOfMobKilled, newNumberOfSpecificMobKilled); - q.finishObjective(quest, "killMob", new ItemStack(Material.AIR, 1), + q.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, numberOfSpecificMobNeedsToBeKilledInCurrentStage), null, e, null, null, null, null, null, null); return null; }); } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -2089,22 +2183,29 @@ public class Quester implements Comparable { * @param player The player to be killed */ public void killPlayer(final Quest quest, final Player player) { + final ObjectiveType type = ObjectiveType.KILL_PLAYER; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + final int playersToKill = getCurrentStage(quest).playersToKill; if (getQuestData(quest).getPlayersKilled() < playersToKill) { getQuestData(quest).setPlayersKilled(getQuestData(quest).getPlayersKilled() + 1); if (getQuestData(quest).getPlayersKilled() == playersToKill) { - finishObjective(quest, "killPlayer", new ItemStack(Material.AIR, 1), + finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, playersToKill), null, null, null, null, null, null, null, null); // Multiplayer dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).setPlayersKilled(getQuestData(quest).getPlayersKilled()); - q.finishObjective(quest, "killPlayer", new ItemStack(Material.AIR, 1), + q.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, playersToKill), null, null, null, null, null, null, null, null); return null; }); } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -2119,6 +2220,10 @@ public class Quester implements Comparable { if (n == null) { return; } + final ObjectiveType type = ObjectiveType.DELIVER_ITEM; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + int currentIndex = -1; final LinkedList matches = new LinkedList(); for (final ItemStack is : getQuestData(quest).itemsDelivered) { @@ -2159,13 +2264,13 @@ public class Quester implements Comparable { player.getInventory().setItem(index, null); } player.updateInventory(); - finishObjective(quest, "deliverItem", new ItemStack(m, 1), found, null, null, null, null, null, + finishObjective(quest, type, new ItemStack(m, 1), found, null, null, null, null, null, null, null, null); // Multiplayer dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).itemsDelivered.set(items.indexOf(found), newStack); - q.finishObjective(quest, "deliverItem", new ItemStack(m, 1), found, null, null, null, null, + q.finishObjective(quest, type, new ItemStack(m, 1), found, null, null, null, null, null, null, null, null); return null; }); @@ -2184,6 +2289,9 @@ public class Quester implements Comparable { } } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -2193,22 +2301,29 @@ public class Quester implements Comparable { * @param n The NPC being interacted with */ public void interactWithNPC(final Quest quest, final NPC n) { + final ObjectiveType type = ObjectiveType.TALK_TO_NPC; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + if (getQuestData(quest).citizensInteracted.containsKey(n.getId())) { final Boolean b = getQuestData(quest).citizensInteracted.get(n.getId()); if (b != null && !b) { getQuestData(quest).citizensInteracted.put(n.getId(), true); - finishObjective(quest, "talkToNPC", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), + finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), null, null, null, n, null, null, null, null); // Multiplayer dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).citizensInteracted.put(n.getId(), true); - q.finishObjective(quest, "talkToNPC", new ItemStack(Material.AIR, 1), + q.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), null, null, null, n, null, null, null, null); return null; }); } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -2218,26 +2333,33 @@ public class Quester implements Comparable { * @param n The NPC being killed */ public void killNPC(final Quest quest, final NPC n) { + final ObjectiveType type = ObjectiveType.KILL_NPC; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + if (getQuestData(quest).citizensKilled.contains(n.getId())) { final int index = getQuestData(quest).citizensKilled.indexOf(n.getId()); final int npcsToKill = getCurrentStage(quest).citizenNumToKill.get(index); if (getQuestData(quest).citizenNumKilled.get(index) < npcsToKill) { getQuestData(quest).citizenNumKilled.set(index, getQuestData(quest).citizenNumKilled.get(index) + 1); if (getQuestData(quest).citizenNumKilled.get(index).equals(npcsToKill)) { - finishObjective(quest, "killNPC", new ItemStack(Material.AIR, 1), + finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, npcsToKill), null, null, null, n, null, null, null, null); // Multiplayer dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).citizenNumKilled.set(index, getQuestData(quest).citizenNumKilled .get(index)); - q.finishObjective(quest, "killNPC", new ItemStack(Material.AIR, 1), + q.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, npcsToKill), null, null, null, n, null, null, null, null); return null; }); } } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -2250,6 +2372,10 @@ public class Quester implements Comparable { if (getQuestData(quest) == null || getQuestData(quest).locationsReached == null) { return; } + final ObjectiveType type = ObjectiveType.REACH_LOCATION; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + int index = 0; for (final Location location : getQuestData(quest).locationsReached) { try { @@ -2272,12 +2398,12 @@ public class Quester implements Comparable { // TODO - Find proper cause of Github issues #646 and #825 and #1191 if (getQuestData(quest).hasReached.size() <= index) { getQuestData(quest).hasReached.add(true); - finishObjective(quest, "reachLocation", new ItemStack(Material.AIR, 1), + finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), null, null, null, null, location, null, null, null); } else if (getQuestData(quest).hasReached.get(index) == false) { getQuestData(quest).hasReached.set(index, true); - finishObjective(quest, "reachLocation", new ItemStack(Material.AIR, 1), + finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), null, null, null, null, location, null, null, null); } @@ -2287,12 +2413,12 @@ public class Quester implements Comparable { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { if (finalIndex >= getQuestData(quest).hasReached.size()) { q.getQuestData(quest).hasReached.add(true); - q.finishObjective(quest, "reachLocation", new ItemStack(Material.AIR, 1), + q.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), null, null, null, null, location, null, null, null); } else { q.getQuestData(quest).hasReached.set(finalIndex, true); - q.finishObjective(quest, "reachLocation", new ItemStack(Material.AIR, 1), + q.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), null, null, null, null, location, null, null, null); } @@ -2312,6 +2438,9 @@ public class Quester implements Comparable { e.printStackTrace(); } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -2321,22 +2450,29 @@ public class Quester implements Comparable { * @param entity The mob being tamed */ public void tameMob(final Quest quest, final EntityType entity) { + final ObjectiveType type = ObjectiveType.TAME_MOB; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + if (getQuestData(quest).mobsTamed.containsKey(entity)) { getQuestData(quest).mobsTamed.put(entity, (getQuestData(quest).mobsTamed.get(entity) + 1)); final int mobsToTame = getCurrentStage(quest).mobsToTame.get(entity); if (getQuestData(quest).mobsTamed.get(entity).equals(mobsToTame)) { - finishObjective(quest, "tameMob", new ItemStack(Material.AIR, 1), + finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, mobsToTame), null, entity, null, null, null, null, null, null); // Multiplayer dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).mobsTamed.put(entity, getQuestData(quest).mobsTamed.get(entity)); - q.finishObjective(quest, "tameMob", new ItemStack(Material.AIR, 1), + q.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, mobsToTame), null, entity, null, null, null, null, null, null); return null; }); } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -2346,22 +2482,29 @@ public class Quester implements Comparable { * @param color The wool color of the sheep being sheared */ public void shearSheep(final Quest quest, final DyeColor color) { + final ObjectiveType type = ObjectiveType.SHEAR_SHEEP; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + if (getQuestData(quest).sheepSheared.containsKey(color)) { getQuestData(quest).sheepSheared.put(color, (getQuestData(quest).sheepSheared.get(color) + 1)); final int sheepToShear = getCurrentStage(quest).sheepToShear.get(color); if (getQuestData(quest).sheepSheared.get(color).equals(sheepToShear)) { - finishObjective(quest, "shearSheep", new ItemStack(Material.AIR, 1), + finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, sheepToShear), null, null, null, null, null, color, null, null); // Multiplayer dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).sheepSheared.put(color, getQuestData(quest).sheepSheared.get(color)); - q.finishObjective(quest, "shearSheep", new ItemStack(Material.AIR, 1), + q.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, sheepToShear), null, null, null, null, null, color, null, null); return null; }); } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } /** @@ -2371,24 +2514,28 @@ public class Quester implements Comparable { * @param evt The event during which the password was entered */ public void sayPassword(final Quest quest, final AsyncPlayerChatEvent evt) { + final ObjectiveType type = ObjectiveType.PASSWORD; + final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(preEvent); + boolean done; for (final LinkedList passes : getCurrentStage(quest).passwordPhrases) { done = false; for (final String pass : passes) { if (pass.equalsIgnoreCase(evt.getMessage())) { evt.setCancelled(true); - final String display = getCurrentStage(quest).passwordDisplays.get(getCurrentStage(quest).passwordPhrases - .indexOf(passes)); + final String display = getCurrentStage(quest).passwordDisplays.get(getCurrentStage(quest) + .passwordPhrases.indexOf(passes)); getQuestData(quest).passwordsSaid.put(display, true); done = true; plugin.getServer().getScheduler().runTask(plugin, () -> { - finishObjective(quest, "password", new ItemStack(Material.AIR, 1), + finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), null, null, null, null, null, null, display, null); // Multiplayer dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { q.getQuestData(quest).passwordsSaid.put(display, true); - q.finishObjective(quest, "password", new ItemStack(Material.AIR, 1), + q.finishObjective(quest, type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), null, null, null, null, null, null, display, null); return null; }); @@ -2400,15 +2547,18 @@ public class Quester implements Comparable { break; } } + + final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type); + plugin.getServer().getPluginManager().callEvent(postEvent); } - + /** * Complete quest objective * * @param quest * Quest containing the objective * @param objective - * Type of objective, e.g. "password" or "damageBlock" + * Type of objective * @param increment * Final amount material being applied * @param goal @@ -2431,9 +2581,9 @@ public class Quester implements Comparable { * See CustomObjective class */ @SuppressWarnings("deprecation") - public void finishObjective(final Quest quest, final String objective, final ItemStack increment, final ItemStack goal, - final Enchantment enchantment, final EntityType mob, final String extra, final NPC npc, final Location location, final DyeColor color, - final String pass, final CustomObjective co) { + public void finishObjective(final Quest quest, final ObjectiveType objective, final ItemStack increment, + final ItemStack goal, final Enchantment enchantment, final EntityType mob, final String extra, + final NPC npc, final Location location, final DyeColor color, final String pass, final CustomObjective co) { final Player p = getPlayer(); if (getCurrentStage(quest).objectiveOverrides.isEmpty() == false) { for (final String s: getCurrentStage(quest).objectiveOverrides) { @@ -2444,10 +2594,10 @@ public class Quester implements Comparable { } p.sendMessage(message); } - } else if (objective.equalsIgnoreCase("password")) { + } else if (objective.equals(ObjectiveType.PASSWORD)) { final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + pass; p.sendMessage(message); - } else if (objective.equalsIgnoreCase("breakBlock")) { + } else if (objective.equals(ObjectiveType.BREAK_BLOCK)) { String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "break") + " "; message = message + " " + goal.getAmount() + "/" + goal.getAmount(); if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta() @@ -2456,7 +2606,7 @@ public class Quester implements Comparable { } else { p.sendMessage(message.replace("", ItemUtil.getName(increment))); } - } else if (objective.equalsIgnoreCase("damageBlock")) { + } else if (objective.equals(ObjectiveType.DAMAGE_BLOCK)) { String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "damage") + " "; message = message + " " + goal.getAmount() + "/" + goal.getAmount(); @@ -2466,7 +2616,7 @@ public class Quester implements Comparable { } else { p.sendMessage(message.replace("", ItemUtil.getName(increment))); } - } else if (objective.equalsIgnoreCase("placeBlock")) { + } else if (objective.equals(ObjectiveType.PLACE_BLOCK)) { String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "place") + " "; message = message + " " + goal.getAmount() + "/" + goal.getAmount(); if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta() @@ -2475,7 +2625,7 @@ public class Quester implements Comparable { } else { p.sendMessage(message.replace("", ItemUtil.getName(increment))); } - } else if (objective.equalsIgnoreCase("useBlock")) { + } else if (objective.equals(ObjectiveType.USE_BLOCK)) { String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "use") + " "; message = message + " " + goal.getAmount() + "/" + goal.getAmount(); if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta() @@ -2484,7 +2634,7 @@ public class Quester implements Comparable { } else { p.sendMessage(message.replace("", ItemUtil.getName(increment))); } - } else if (objective.equalsIgnoreCase("cutBlock")) { + } else if (objective.equals(ObjectiveType.CUT_BLOCK)) { String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "cut") + " "; message = message + " " + goal.getAmount() + "/" + goal.getAmount(); if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta() @@ -2493,7 +2643,7 @@ public class Quester implements Comparable { } else { p.sendMessage(message.replace("", ItemUtil.getName(increment))); } - } else if (objective.equalsIgnoreCase("craftItem")) { + } else if (objective.equals(ObjectiveType.CRAFT_ITEM)) { final ItemStack is = getCurrentStage(quest).itemsToCraft.get(getCurrentStage(quest).itemsToCraft.indexOf(goal)); final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "craftItem") + " " + is.getAmount() + "/" + is.getAmount(); @@ -2503,7 +2653,7 @@ public class Quester implements Comparable { } else { p.sendMessage(message.replace("", ItemUtil.getName(is))); } - } else if (objective.equalsIgnoreCase("smeltItem")) { + } else if (objective.equals(ObjectiveType.SMELT_ITEM)) { final ItemStack is = getCurrentStage(quest).itemsToSmelt.get(getCurrentStage(quest).itemsToSmelt.indexOf(goal)); final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "smeltItem") + " " + is.getAmount() + "/" + is.getAmount(); @@ -2513,7 +2663,7 @@ public class Quester implements Comparable { } else { p.sendMessage(message.replace("", ItemUtil.getName(is))); } - } else if (objective.equalsIgnoreCase("enchantItem")) { + } else if (objective.equals(ObjectiveType.ENCHANT_ITEM)) { final ItemStack is = getCurrentStage(quest).itemsToEnchant.get(getCurrentStage(quest).itemsToEnchant.indexOf(goal)); final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "enchItem") + " " + is.getAmount() + "/" + is.getAmount(); @@ -2523,7 +2673,7 @@ public class Quester implements Comparable { } else { p.sendMessage(message.replace("", ItemUtil.getName(is))); } - } else if (objective.equalsIgnoreCase("brewItem")) { + } else if (objective.equals(ObjectiveType.BREW_ITEM)) { final ItemStack is = getCurrentStage(quest).itemsToBrew.get(getCurrentStage(quest).itemsToBrew.indexOf(goal)); final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "brewItem") + " " + is.getAmount() + "/" + is.getAmount(); @@ -2534,7 +2684,7 @@ public class Quester implements Comparable { } else { p.sendMessage(message.replace("", ItemUtil.getName(is))); } - } else if (objective.equalsIgnoreCase("consumeItem")) { + } else if (objective.equals(ObjectiveType.CONSUME_ITEM)) { final ItemStack is = getCurrentStage(quest).itemsToConsume.get(getCurrentStage(quest).itemsToConsume .indexOf(goal)); final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "consumeItem") @@ -2545,7 +2695,7 @@ public class Quester implements Comparable { } else { p.sendMessage(message.replace("", ItemUtil.getName(is))); } - } else if (objective.equalsIgnoreCase("deliverItem")) { + } else if (objective.equals(ObjectiveType.DELIVER_ITEM)) { String obj = Lang.get(p, "deliver"); obj = obj.replace("", plugin.getDependencies().getNPCName(getCurrentStage(quest).itemDeliveryTargets .get(getCurrentStage(quest).itemsToDeliver.indexOf(goal)))); @@ -2558,51 +2708,51 @@ public class Quester implements Comparable { } else { p.sendMessage(message.replace("", ItemUtil.getName(is))); } - } else if (objective.equalsIgnoreCase("milkCow")) { + } else if (objective.equals(ObjectiveType.MILK_COW)) { String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "milkCow") + " "; message = message + " " + goal.getAmount() + "/" + goal.getAmount(); p.sendMessage(message); - } else if (objective.equalsIgnoreCase("catchFish")) { + } else if (objective.equals(ObjectiveType.CATCH_FISH)) { String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "catchFish") + " "; message = message + " " + goal.getAmount() + "/" + goal.getAmount(); p.sendMessage(message); - } else if (objective.equalsIgnoreCase("killMob")) { + } else if (objective.equals(ObjectiveType.KILL_MOB)) { String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "kill") + " "; message = message + " " + goal.getAmount() + "/" + goal.getAmount(); if (plugin.getSettings().canTranslateNames()) { plugin.getLocaleQuery().sendMessage(p, message, mob, extra); } else { - p.sendMessage(message.replace("", MiscUtil.getProperMobName(mob))); + p.sendMessage(message.replace("", MiscUtil.snakeCaseToUpperCamelCase(mob.name()))); } - } else if (objective.equalsIgnoreCase("killPlayer")) { + } else if (objective.equals(ObjectiveType.KILL_PLAYER)) { String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "killPlayer"); message = message + " " + goal.getAmount() + "/" + goal.getAmount(); p.sendMessage(message); - } else if (objective.equalsIgnoreCase("talkToNPC")) { + } else if (objective.equals(ObjectiveType.TALK_TO_NPC)) { String obj = Lang.get(p, "talkTo"); obj = obj.replace("", plugin.getDependencies().getNPCName(npc.getId())); final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + obj; p.sendMessage(message); - } else if (objective.equalsIgnoreCase("killNPC")) { + } else if (objective.equals(ObjectiveType.KILL_NPC)) { String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "kill") + " " + npc.getName(); message = message + " " + goal.getAmount() + "/" + goal.getAmount(); p.sendMessage(message); - } else if (objective.equalsIgnoreCase("tameMob")) { + } else if (objective.equals(ObjectiveType.TAME_MOB)) { String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "tame") + " "; message = message + " " + goal.getAmount() + "/" + goal.getAmount(); if (plugin.getSettings().canTranslateNames()) { plugin.getLocaleQuery().sendMessage(p, message, mob, extra); } else { - p.sendMessage(message.replace("", MiscUtil.getProperMobName(mob))); + p.sendMessage(message.replace("", MiscUtil.snakeCaseToUpperCamelCase(mob.name()))); } - } else if (objective.equalsIgnoreCase("shearSheep")) { + } else if (objective.equals(ObjectiveType.SHEAR_SHEEP)) { String obj = Lang.get(p, "shearSheep"); obj = obj.replace("", color.name().toLowerCase()); String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + obj; message = message + " " + goal.getAmount() + "/" + goal.getAmount(); p.sendMessage(message); - } else if (objective.equalsIgnoreCase("reachLocation")) { + } else if (objective.equals(ObjectiveType.REACH_LOCATION)) { String obj = Lang.get(p, "goTo"); try { obj = obj.replace("", getCurrentStage(quest).locationNames.get(getCurrentStage(quest) @@ -2642,6 +2792,45 @@ public class Quester implements Comparable { quest.nextStage(this, true); } } + + /** + * Complete quest objective + * + * @deprecated Use {@link #finishObjective(Quest, ObjectiveType, ItemStack, ItemStack, Enchantment, EntityType, + * String, NPC, Location, DyeColor, String, CustomObjective)} + * + * @param quest + * Quest containing the objective + * @param objective + * Type of objective, e.g. "password" or "damageBlock" + * @param increment + * Final amount material being applied + * @param goal + * Total required amount of material + * @param enchantment + * Enchantment being applied by user + * @param mob + * Mob being killed or tamed + * @param extra + * Extra mob enum like career or ocelot type + * @param npc + * NPC being talked to or killed + * @param location + * Location for user to reach + * @param color + * Shear color + * @param pass + * Password + * @param co + * See CustomObjective class + */ + @Deprecated + public void finishObjective(final Quest quest, final String objective, final ItemStack increment, + final ItemStack goal, final Enchantment enchantment, final EntityType mob, final String extra, + final NPC npc, final Location location, final DyeColor color, final String pass, final CustomObjective co) { + finishObjective(quest, ObjectiveType.fromName(objective), increment, goal, enchantment, mob, extra, npc, + location, color, pass, co); + } /** * Check whether this Quester has completed all objectives for their current stage @@ -2650,7 +2839,7 @@ public class Quester implements Comparable { * @return true if all stage objectives are marked complete */ public boolean testComplete(final Quest quest) { - for (final String s : getObjectives(quest, true)) { + for (final String s : getCurrentObjectives(quest, true)) { if (s.startsWith(ChatColor.GREEN.toString())) { return false; } diff --git a/main/src/main/java/me/blackvein/quests/enums/ObjectiveType.java b/main/src/main/java/me/blackvein/quests/enums/ObjectiveType.java new file mode 100644 index 000000000..89ab6f536 --- /dev/null +++ b/main/src/main/java/me/blackvein/quests/enums/ObjectiveType.java @@ -0,0 +1,79 @@ +/******************************************************************************************************* + * Continued by PikaMug (formerly HappyPikachu) with permission from _Blackvein_. 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.enums; + +import java.util.HashMap; +import java.util.Map; + +public enum ObjectiveType { + + BREAK_BLOCK(1, "BreakBlock"), + DAMAGE_BLOCK(2, "DamageBlock"), + PLACE_BLOCK(3, "PlaceBlock"), + USE_BLOCK(4, "UseBlock"), + CUT_BLOCK(5, "CutBlock"), + CRAFT_ITEM(6, "CraftItem"), + SMELT_ITEM(7, "SmeltItem"), + ENCHANT_ITEM(8, "EnchantItem"), + BREW_ITEM(9, "BrewItem"), + CONSUME_ITEM(10, "ConsumeItem"), + DELIVER_ITEM(11, "DeliverItem"), + MILK_COW(12, "MilkCow"), + CATCH_FISH(13, "CatchFish"), + KILL_MOB(14, "KillMob"), + KILL_PLAYER(15, "KillPlayer"), + TALK_TO_NPC(16, "TalkToNPC"), + KILL_NPC(17, "KillNPC"), + TAME_MOB(18, "TameMob"), + SHEAR_SHEEP(19, "ShearSheep"), + REACH_LOCATION(20, "ReachLocation"), + PASSWORD(21, "Password"), + CUSTOM(127, "Custom"); + + private String name; + private byte typeId; + + private static final Map NAME_MAP = new HashMap(); + private static final Map ID_MAP = new HashMap(); + + static { + for (final ObjectiveType type : values()) { + if (type.name != null) { + NAME_MAP.put(type.name.toLowerCase(), type); + } + if (type.typeId > 0) { + ID_MAP.put(type.typeId, type); + } + } + } + + private ObjectiveType(final int typeId, final String name) { + this.typeId = (byte) typeId; + // Capitalize first letter for legacy reasons + this.name = name.substring(0, 1).toUpperCase() + name.substring(1); + } + + public static ObjectiveType fromName(final String name) { + if (name == null) { + return null; + } + return NAME_MAP.get(name.toLowerCase()); + } + + public static ObjectiveType fromId(final int id) { + if (id > Byte.MAX_VALUE) { + return null; + } + return ID_MAP.get((byte) id); + } +} diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostChangeStageEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostChangeStageEvent.java index ec7f2dfda..7a2ea68a0 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostChangeStageEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostChangeStageEvent.java @@ -37,7 +37,7 @@ public class QuesterPostChangeStageEvent extends QuesterEvent { /** * Returns the quest involved in this event * - * @return Quest who is involved in this event + * @return Quest which is involved in this event */ public Quest getQuest() { return quest; diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostCompleteQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostCompleteQuestEvent.java index 5a652e0f7..4f8d46eea 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostCompleteQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostCompleteQuestEvent.java @@ -32,7 +32,7 @@ public class QuesterPostCompleteQuestEvent extends QuesterEvent { /** * Returns the quest involved in this event * - * @return Quest who is involved in this event + * @return Quest which is involved in this event */ public Quest getQuest() { return quest; diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostFailQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostFailQuestEvent.java index 7639ddcf6..30e000627 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostFailQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostFailQuestEvent.java @@ -32,7 +32,7 @@ public class QuesterPostFailQuestEvent extends QuesterEvent { /** * Returns the quest involved in this event * - * @return Quest who is involved in this event + * @return Quest which is involved in this event */ public Quest getQuest() { return quest; diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostStartQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostStartQuestEvent.java index 06fc059f9..7489ce9aa 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostStartQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostStartQuestEvent.java @@ -32,7 +32,7 @@ public class QuesterPostStartQuestEvent extends QuesterEvent { /** * Returns the quest involved in this event * - * @return Quest who is involved in this event + * @return Quest which is involved in this event */ public Quest getQuest() { return quest; diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreChangeStageEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreChangeStageEvent.java index 58be089f3..cbef24d61 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreChangeStageEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreChangeStageEvent.java @@ -39,7 +39,7 @@ public class QuesterPreChangeStageEvent extends QuesterEvent implements Cancella /** * Returns the quest involved in this event * - * @return Quest who is involved in this event + * @return Quest which is involved in this event */ public Quest getQuest() { return quest; diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreCompleteQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreCompleteQuestEvent.java index 426152d5d..804903628 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreCompleteQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreCompleteQuestEvent.java @@ -34,7 +34,7 @@ public class QuesterPreCompleteQuestEvent extends QuesterEvent implements Cancel /** * Returns the quest involved in this event * - * @return Quest who is involved in this event + * @return Quest which is involved in this event */ public Quest getQuest() { return quest; diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreFailQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreFailQuestEvent.java index c10c56185..b4a63dec2 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreFailQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreFailQuestEvent.java @@ -34,7 +34,7 @@ public class QuesterPreFailQuestEvent extends QuesterEvent implements Cancellabl /** * Returns the quest involved in this event * - * @return Quest who is involved in this event + * @return Quest which is involved in this event */ public Quest getQuest() { return quest; diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreStartQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreStartQuestEvent.java index a073e37c4..3ad1a40cb 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreStartQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreStartQuestEvent.java @@ -34,7 +34,7 @@ public class QuesterPreStartQuestEvent extends QuesterEvent implements Cancellab /** * Returns the quest involved in this event * - * @return Quest who is involved in this event + * @return Quest which is involved in this event */ public Quest getQuest() { return quest;