Add objective update API events, part 1. See #1501

This commit is contained in:
PikaMug 2020-12-16 06:00:37 -05:00
parent 8558ddc11d
commit f6aea23057
11 changed files with 366 additions and 85 deletions

View File

@ -23,6 +23,10 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack; 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 { public abstract class CustomObjective implements Listener {
private final Quests plugin = Quests.getPlugin(Quests.class); private final Quests plugin = Quests.getPlugin(Quests.class);
@ -173,20 +177,29 @@ public abstract class CustomObjective implements Listener {
} }
} }
if (index > -1) { 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); final int goal = quester.getCurrentStage(quest).customObjectiveCounts.get(index);
if (quester.getQuestData(quest).customObjectiveCounts.get(obj.getName()) >= goal) { 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); new ItemStack(Material.AIR, goal), null, null, null, null, null, null, null, obj);
// Multiplayer // Multiplayer
quester.dispatchMultiplayerObjectives(quest, quester.getCurrentStage(quest), (final Quester q) -> { quester.dispatchMultiplayerObjectives(quest, quester.getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).customObjectiveCounts.put(obj.getName(), q.getQuestData(quest).customObjectiveCounts.put(obj.getName(),
quester.getQuestData(quest).customObjectiveCounts.get(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); new ItemStack(Material.AIR, goal), null, null, null, null, null, null, null, obj);
return null; return null;
}); });
} }
final QuesterPostUpdateObjectiveEvent postEvent
= new QuesterPostUpdateObjectiveEvent(quester, quest, type);
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
} }
} }

View File

@ -53,10 +53,13 @@ import com.gmail.nossr50.util.player.UserManager;
import de.erethon.dungeonsxl.player.DGroup; import de.erethon.dungeonsxl.player.DGroup;
import me.blackvein.quests.conditions.Condition; import me.blackvein.quests.conditions.Condition;
import me.blackvein.quests.enums.ObjectiveType;
import me.blackvein.quests.events.quest.QuestTakeEvent; import me.blackvein.quests.events.quest.QuestTakeEvent;
import me.blackvein.quests.events.quester.QuesterPostStartQuestEvent; 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.QuesterPreOpenGUIEvent;
import me.blackvein.quests.events.quester.QuesterPreStartQuestEvent; import me.blackvein.quests.events.quester.QuesterPreStartQuestEvent;
import me.blackvein.quests.events.quester.QuesterPreUpdateObjectiveEvent;
import me.blackvein.quests.item.QuestJournal; import me.blackvein.quests.item.QuestJournal;
import me.blackvein.quests.storage.Storage; import me.blackvein.quests.storage.Storage;
import me.blackvein.quests.tasks.StageTimer; import me.blackvein.quests.tasks.StageTimer;
@ -1325,6 +1328,10 @@ public class Quester implements Comparable<Quester> {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void breakBlock(final Quest quest, final ItemStack m) { 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; final ItemStack temp = m;
temp.setAmount(0); temp.setAmount(0);
ItemStack broken = temp; ItemStack broken = temp;
@ -1397,7 +1404,7 @@ public class Quester implements Comparable<Quester> {
if (getQuestData(quest).blocksBroken.contains(broken)) { if (getQuestData(quest).blocksBroken.contains(broken)) {
getQuestData(quest).blocksBroken.set(getQuestData(quest).blocksBroken.indexOf(broken), newBroken); getQuestData(quest).blocksBroken.set(getQuestData(quest).blocksBroken.indexOf(broken), newBroken);
if (broken.getAmount() == toBreak.getAmount()) { 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 // Multiplayer
final ItemStack finalBroken = broken; final ItemStack finalBroken = broken;
@ -1405,13 +1412,16 @@ public class Quester implements Comparable<Quester> {
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).blocksBroken.set(getQuestData(quest).blocksBroken q.getQuestData(quest).blocksBroken.set(getQuestData(quest).blocksBroken
.indexOf(finalBroken), newBroken); .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); null, null);
return 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<Quester> {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void damageBlock(final Quest quest, final ItemStack m) { 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; final ItemStack temp = m;
temp.setAmount(0); temp.setAmount(0);
ItemStack damaged = temp; ItemStack damaged = temp;
@ -1474,7 +1488,7 @@ public class Quester implements Comparable<Quester> {
if (getQuestData(quest).blocksDamaged.contains(damaged)) { if (getQuestData(quest).blocksDamaged.contains(damaged)) {
getQuestData(quest).blocksDamaged.set(getQuestData(quest).blocksDamaged.indexOf(damaged), newDamaged); getQuestData(quest).blocksDamaged.set(getQuestData(quest).blocksDamaged.indexOf(damaged), newDamaged);
if (damaged.getAmount() == toDamage.getAmount()) { 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 // Multiplayer
final ItemStack finalDamaged = damaged; final ItemStack finalDamaged = damaged;
@ -1482,13 +1496,16 @@ public class Quester implements Comparable<Quester> {
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).blocksDamaged.set(getQuestData(quest).blocksDamaged q.getQuestData(quest).blocksDamaged.set(getQuestData(quest).blocksDamaged
.indexOf(finalDamaged), newDamaged); .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); null, null);
return 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<Quester> {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void placeBlock(final Quest quest, final ItemStack m) { 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; final ItemStack temp = m;
temp.setAmount(0); temp.setAmount(0);
ItemStack placed = temp; ItemStack placed = temp;
@ -1551,7 +1572,7 @@ public class Quester implements Comparable<Quester> {
if (getQuestData(quest).blocksPlaced.contains(placed)) { if (getQuestData(quest).blocksPlaced.contains(placed)) {
getQuestData(quest).blocksPlaced.set(getQuestData(quest).blocksPlaced.indexOf(placed), newplaced); getQuestData(quest).blocksPlaced.set(getQuestData(quest).blocksPlaced.indexOf(placed), newplaced);
if (placed.getAmount() == toPlace.getAmount()) { 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 // Multiplayer
final ItemStack finalPlaced = placed; final ItemStack finalPlaced = placed;
@ -1559,13 +1580,16 @@ public class Quester implements Comparable<Quester> {
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).blocksPlaced.set(getQuestData(quest).blocksPlaced q.getQuestData(quest).blocksPlaced.set(getQuestData(quest).blocksPlaced
.indexOf(finalPlaced), newplaced); .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); null, null);
return 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<Quester> {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void useBlock(final Quest quest, final ItemStack m) { 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; final ItemStack temp = m;
temp.setAmount(0); temp.setAmount(0);
ItemStack used = temp; ItemStack used = temp;
@ -1628,7 +1656,7 @@ public class Quester implements Comparable<Quester> {
if (getQuestData(quest).blocksUsed.contains(used)) { if (getQuestData(quest).blocksUsed.contains(used)) {
getQuestData(quest).blocksUsed.set(getQuestData(quest).blocksUsed.indexOf(used), newUsed); getQuestData(quest).blocksUsed.set(getQuestData(quest).blocksUsed.indexOf(used), newUsed);
if (used.getAmount() == toUse.getAmount()) { 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 // Multiplayer
final ItemStack finalUsed = used; final ItemStack finalUsed = used;
@ -1636,13 +1664,16 @@ public class Quester implements Comparable<Quester> {
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).blocksUsed.set(getQuestData(quest).blocksUsed q.getQuestData(quest).blocksUsed.set(getQuestData(quest).blocksUsed
.indexOf(finalUsed), newUsed); .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); null);
return 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<Quester> {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void cutBlock(final Quest quest, final ItemStack m) { 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; final ItemStack temp = m;
temp.setAmount(0); temp.setAmount(0);
ItemStack cut = temp; ItemStack cut = temp;
@ -1705,20 +1740,23 @@ public class Quester implements Comparable<Quester> {
if (getQuestData(quest).blocksCut.contains(cut)) { if (getQuestData(quest).blocksCut.contains(cut)) {
getQuestData(quest).blocksCut.set(getQuestData(quest).blocksCut.indexOf(cut), newCut); getQuestData(quest).blocksCut.set(getQuestData(quest).blocksCut.indexOf(cut), newCut);
if (cut.getAmount() == toCut.getAmount()) { 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 // Multiplayer
final ItemStack finalCut = cut; final ItemStack finalCut = cut;
final ItemStack finalToCut = toCut; final ItemStack finalToCut = toCut;
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).blocksCut.set(getQuestData(quest).blocksCut.indexOf(finalCut), newCut); 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); null);
return 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<Quester> {
* @param i The item being crafted * @param i The item being crafted
*/ */
public void craftItem(final Quest quest, final ItemStack i) { 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(); final Player player = getPlayer();
ItemStack found = null; ItemStack found = null;
for (final ItemStack is : getQuestData(quest).itemsCrafted.keySet()) { for (final ItemStack is : getQuestData(quest).itemsCrafted.keySet()) {
@ -1754,14 +1796,14 @@ public class Quester implements Comparable<Quester> {
if (amount < req) { if (amount < req) {
if ((i.getAmount() + amount) >= req) { if ((i.getAmount() + amount) >= req) {
getQuestData(quest).itemsCrafted.put(found, 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); null, null);
// Multiplayer // Multiplayer
final ItemStack finalFound = found; final ItemStack finalFound = found;
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).itemsCrafted.put(finalFound, req); 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); null, null, null, null);
return null; return null;
}); });
@ -1770,6 +1812,9 @@ public class Quester implements Comparable<Quester> {
} }
} }
} }
final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type);
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
/** /**
@ -1779,6 +1824,10 @@ public class Quester implements Comparable<Quester> {
* @param i The item being smelted * @param i The item being smelted
*/ */
public void smeltItem(final Quest quest, final ItemStack i) { 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(); final Player player = getPlayer();
ItemStack found = null; ItemStack found = null;
for (final ItemStack is : getQuestData(quest).itemsSmelted.keySet()) { for (final ItemStack is : getQuestData(quest).itemsSmelted.keySet()) {
@ -1804,14 +1853,14 @@ public class Quester implements Comparable<Quester> {
if (amount < req) { if (amount < req) {
if ((i.getAmount() + amount) >= req) { if ((i.getAmount() + amount) >= req) {
getQuestData(quest).itemsSmelted.put(found, 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); null, null);
// Multiplayer // Multiplayer
final ItemStack finalFound = found; final ItemStack finalFound = found;
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).itemsSmelted.put(finalFound, req); 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); null, null, null, null);
return null; return null;
}); });
@ -1820,6 +1869,9 @@ public class Quester implements Comparable<Quester> {
} }
} }
} }
final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type);
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
/** /**
@ -1829,6 +1881,10 @@ public class Quester implements Comparable<Quester> {
* @param i The item being enchanted * @param i The item being enchanted
*/ */
public void enchantItem(final Quest quest, final ItemStack i) { 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(); final Player player = getPlayer();
ItemStack found = null; ItemStack found = null;
for (final ItemStack is : getQuestData(quest).itemsEnchanted.keySet()) { for (final ItemStack is : getQuestData(quest).itemsEnchanted.keySet()) {
@ -1854,14 +1910,14 @@ public class Quester implements Comparable<Quester> {
if (amount < req) { if (amount < req) {
if ((i.getAmount() + amount) >= req) { if ((i.getAmount() + amount) >= req) {
getQuestData(quest).itemsEnchanted.put(found, 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); null, null);
// Multiplayer // Multiplayer
final ItemStack finalFound = found; final ItemStack finalFound = found;
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).itemsEnchanted.put(finalFound, req); 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); null, null, null, null);
return null; return null;
}); });
@ -1870,6 +1926,9 @@ public class Quester implements Comparable<Quester> {
} }
} }
} }
final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type);
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
/** /**
@ -1879,6 +1938,10 @@ public class Quester implements Comparable<Quester> {
* @param i The item being brewed * @param i The item being brewed
*/ */
public void brewItem(final Quest quest, final ItemStack i) { 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(); final Player player = getPlayer();
ItemStack found = null; ItemStack found = null;
for (final ItemStack is : getQuestData(quest).itemsBrewed.keySet()) { for (final ItemStack is : getQuestData(quest).itemsBrewed.keySet()) {
@ -1904,14 +1967,14 @@ public class Quester implements Comparable<Quester> {
if (amount < req) { if (amount < req) {
if ((i.getAmount() + amount) >= req) { if ((i.getAmount() + amount) >= req) {
getQuestData(quest).itemsBrewed.put(found, 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); null, null);
// Multiplayer // Multiplayer
final ItemStack finalFound = found; final ItemStack finalFound = found;
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).itemsBrewed.put(finalFound, req); 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); null, null, null, null);
return null; return null;
}); });
@ -1920,6 +1983,9 @@ public class Quester implements Comparable<Quester> {
} }
} }
} }
final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type);
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
/** /**
@ -1929,6 +1995,10 @@ public class Quester implements Comparable<Quester> {
* @param i The item being consumed * @param i The item being consumed
*/ */
public void consumeItem(final Quest quest, final ItemStack i) { 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(); final Player player = getPlayer();
ItemStack found = null; ItemStack found = null;
for (final ItemStack is : getQuestData(quest).itemsConsumed.keySet()) { for (final ItemStack is : getQuestData(quest).itemsConsumed.keySet()) {
@ -1954,14 +2024,14 @@ public class Quester implements Comparable<Quester> {
if (amount < req) { if (amount < req) {
if ((i.getAmount() + amount) >= req) { if ((i.getAmount() + amount) >= req) {
getQuestData(quest).itemsConsumed.put(found, 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); null, null);
// Multiplayer // Multiplayer
final ItemStack finalFound = found; final ItemStack finalFound = found;
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).itemsConsumed.put(finalFound, req); 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); null, null, null, null);
return null; return null;
}); });
@ -1970,6 +2040,9 @@ public class Quester implements Comparable<Quester> {
} }
} }
} }
final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type);
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
/** /**
@ -1978,23 +2051,30 @@ public class Quester implements Comparable<Quester> {
* @param quest The quest for which the fish is being caught * @param quest The quest for which the fish is being caught
*/ */
public void milkCow(final Quest quest) { 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; final int cowsToMilk = getCurrentStage(quest).cowsToMilk;
if (getQuestData(quest).getCowsMilked() < cowsToMilk) { if (getQuestData(quest).getCowsMilked() < cowsToMilk) {
getQuestData(quest).setCowsMilked(getQuestData(quest).getCowsMilked() + 1); getQuestData(quest).setCowsMilked(getQuestData(quest).getCowsMilked() + 1);
if (getQuestData(quest).getCowsMilked() == cowsToMilk) { 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); new ItemStack(Material.AIR, cowsToMilk), null, null, null, null, null, null, null, null);
// Multiplayer // Multiplayer
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).setCowsMilked(cowsToMilk); 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); new ItemStack(Material.AIR, cowsToMilk), null, null, null, null, null, null, null, null);
return 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<Quester> {
* @param quest The quest for which the fish is being caught * @param quest The quest for which the fish is being caught
*/ */
public void catchFish(final Quest quest) { 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; final int fishToCatch = getCurrentStage(quest).fishToCatch;
if (getQuestData(quest).getFishCaught() < fishToCatch) { if (getQuestData(quest).getFishCaught() < fishToCatch) {
getQuestData(quest).setFishCaught(getQuestData(quest).getFishCaught() + 1); getQuestData(quest).setFishCaught(getQuestData(quest).getFishCaught() + 1);
if (getQuestData(quest).getFishCaught() == fishToCatch) { 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); new ItemStack(Material.AIR, fishToCatch), null, null, null, null, null, null, null, null);
// Multiplayer // Multiplayer
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).setFishCaught(fishToCatch); 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); new ItemStack(Material.AIR, fishToCatch), null, null, null, null, null, null, null, null);
return 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<Quester> {
if (currentStage.mobsToKill.contains(e) == false) { if (currentStage.mobsToKill.contains(e) == false) {
return; 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 indexOfMobKilled = questData.mobsKilled.indexOf(e);
final int numberOfSpecificMobKilled = questData.mobNumKilled.get(indexOfMobKilled); final int numberOfSpecificMobKilled = questData.mobNumKilled.get(indexOfMobKilled);
final int numberOfSpecificMobNeedsToBeKilledInCurrentStage = currentStage.mobNumToKill.get(indexOfMobKilled); final int numberOfSpecificMobNeedsToBeKilledInCurrentStage = currentStage.mobNumToKill.get(indexOfMobKilled);
@ -2066,20 +2157,23 @@ public class Quester implements Comparable<Quester> {
final int newNumberOfSpecificMobKilled = numberOfSpecificMobKilled + 1; final int newNumberOfSpecificMobKilled = numberOfSpecificMobKilled + 1;
questData.mobNumKilled.set(indexOfMobKilled, newNumberOfSpecificMobKilled); questData.mobNumKilled.set(indexOfMobKilled, newNumberOfSpecificMobKilled);
if (newNumberOfSpecificMobKilled == numberOfSpecificMobNeedsToBeKilledInCurrentStage) { 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, new ItemStack(Material.AIR, numberOfSpecificMobNeedsToBeKilledInCurrentStage), null, e, null,
null, null, null, null, null); null, null, null, null, null);
// Multiplayer // Multiplayer
dispatchMultiplayerObjectives(quest, currentStage, (final Quester q) -> { dispatchMultiplayerObjectives(quest, currentStage, (final Quester q) -> {
q.getQuestData(quest).mobNumKilled.set(indexOfMobKilled, newNumberOfSpecificMobKilled); 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, new ItemStack(Material.AIR, numberOfSpecificMobNeedsToBeKilledInCurrentStage), null, e,
null, null, null, null, null, null); null, null, null, null, null, null);
return 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<Quester> {
* @param player The player to be killed * @param player The player to be killed
*/ */
public void killPlayer(final Quest quest, final Player player) { 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; final int playersToKill = getCurrentStage(quest).playersToKill;
if (getQuestData(quest).getPlayersKilled() < playersToKill) { if (getQuestData(quest).getPlayersKilled() < playersToKill) {
getQuestData(quest).setPlayersKilled(getQuestData(quest).getPlayersKilled() + 1); getQuestData(quest).setPlayersKilled(getQuestData(quest).getPlayersKilled() + 1);
if (getQuestData(quest).getPlayersKilled() == playersToKill) { 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); new ItemStack(Material.AIR, playersToKill), null, null, null, null, null, null, null, null);
// Multiplayer // Multiplayer
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).setPlayersKilled(getQuestData(quest).getPlayersKilled()); 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); new ItemStack(Material.AIR, playersToKill), null, null, null, null, null, null, null, null);
return 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<Quester> {
if (n == null) { if (n == null) {
return; return;
} }
final ObjectiveType type = ObjectiveType.DELIVER_ITEM;
final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type);
plugin.getServer().getPluginManager().callEvent(preEvent);
int currentIndex = -1; int currentIndex = -1;
final LinkedList<Integer> matches = new LinkedList<Integer>(); final LinkedList<Integer> matches = new LinkedList<Integer>();
for (final ItemStack is : getQuestData(quest).itemsDelivered) { for (final ItemStack is : getQuestData(quest).itemsDelivered) {
@ -2159,13 +2264,13 @@ public class Quester implements Comparable<Quester> {
player.getInventory().setItem(index, null); player.getInventory().setItem(index, null);
} }
player.updateInventory(); 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); null, null, null);
// Multiplayer // Multiplayer
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).itemsDelivered.set(items.indexOf(found), newStack); 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); null, null, null, null);
return null; return null;
}); });
@ -2184,6 +2289,9 @@ public class Quester implements Comparable<Quester> {
} }
} }
} }
final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type);
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
/** /**
@ -2193,22 +2301,29 @@ public class Quester implements Comparable<Quester> {
* @param n The NPC being interacted with * @param n The NPC being interacted with
*/ */
public void interactWithNPC(final Quest quest, final NPC n) { 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())) { if (getQuestData(quest).citizensInteracted.containsKey(n.getId())) {
final Boolean b = getQuestData(quest).citizensInteracted.get(n.getId()); final Boolean b = getQuestData(quest).citizensInteracted.get(n.getId());
if (b != null && !b) { if (b != null && !b) {
getQuestData(quest).citizensInteracted.put(n.getId(), true); 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); null, null, null, n, null, null, null, null);
// Multiplayer // Multiplayer
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).citizensInteracted.put(n.getId(), true); 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); new ItemStack(Material.AIR, 1), null, null, null, n, null, null, null, null);
return 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<Quester> {
* @param n The NPC being killed * @param n The NPC being killed
*/ */
public void killNPC(final Quest quest, final NPC n) { 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())) { if (getQuestData(quest).citizensKilled.contains(n.getId())) {
final int index = getQuestData(quest).citizensKilled.indexOf(n.getId()); final int index = getQuestData(quest).citizensKilled.indexOf(n.getId());
final int npcsToKill = getCurrentStage(quest).citizenNumToKill.get(index); final int npcsToKill = getCurrentStage(quest).citizenNumToKill.get(index);
if (getQuestData(quest).citizenNumKilled.get(index) < npcsToKill) { if (getQuestData(quest).citizenNumKilled.get(index) < npcsToKill) {
getQuestData(quest).citizenNumKilled.set(index, getQuestData(quest).citizenNumKilled.get(index) + 1); getQuestData(quest).citizenNumKilled.set(index, getQuestData(quest).citizenNumKilled.get(index) + 1);
if (getQuestData(quest).citizenNumKilled.get(index).equals(npcsToKill)) { 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); new ItemStack(Material.AIR, npcsToKill), null, null, null, n, null, null, null, null);
// Multiplayer // Multiplayer
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).citizenNumKilled.set(index, getQuestData(quest).citizenNumKilled q.getQuestData(quest).citizenNumKilled.set(index, getQuestData(quest).citizenNumKilled
.get(index)); .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); new ItemStack(Material.AIR, npcsToKill), null, null, null, n, null, null, null, null);
return 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<Quester> {
if (getQuestData(quest) == null || getQuestData(quest).locationsReached == null) { if (getQuestData(quest) == null || getQuestData(quest).locationsReached == null) {
return; return;
} }
final ObjectiveType type = ObjectiveType.REACH_LOCATION;
final QuesterPreUpdateObjectiveEvent preEvent = new QuesterPreUpdateObjectiveEvent(this, quest, type);
plugin.getServer().getPluginManager().callEvent(preEvent);
int index = 0; int index = 0;
for (final Location location : getQuestData(quest).locationsReached) { for (final Location location : getQuestData(quest).locationsReached) {
try { try {
@ -2272,12 +2398,12 @@ public class Quester implements Comparable<Quester> {
// TODO - Find proper cause of Github issues #646 and #825 and #1191 // TODO - Find proper cause of Github issues #646 and #825 and #1191
if (getQuestData(quest).hasReached.size() <= index) { if (getQuestData(quest).hasReached.size() <= index) {
getQuestData(quest).hasReached.add(true); 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, new ItemStack(Material.AIR, 1), null, null, null, null, location, null,
null, null); null, null);
} else if (getQuestData(quest).hasReached.get(index) == false) { } else if (getQuestData(quest).hasReached.get(index) == false) {
getQuestData(quest).hasReached.set(index, true); 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, new ItemStack(Material.AIR, 1), null, null, null, null, location, null,
null, null); null, null);
} }
@ -2287,12 +2413,12 @@ public class Quester implements Comparable<Quester> {
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
if (finalIndex >= getQuestData(quest).hasReached.size()) { if (finalIndex >= getQuestData(quest).hasReached.size()) {
q.getQuestData(quest).hasReached.add(true); 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, new ItemStack(Material.AIR, 1), null, null, null, null, location, null,
null, null); null, null);
} else { } else {
q.getQuestData(quest).hasReached.set(finalIndex, true); 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, new ItemStack(Material.AIR, 1), null, null, null, null, location, null,
null, null); null, null);
} }
@ -2312,6 +2438,9 @@ public class Quester implements Comparable<Quester> {
e.printStackTrace(); e.printStackTrace();
} }
} }
final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type);
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
/** /**
@ -2321,22 +2450,29 @@ public class Quester implements Comparable<Quester> {
* @param entity The mob being tamed * @param entity The mob being tamed
*/ */
public void tameMob(final Quest quest, final EntityType entity) { 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)) { if (getQuestData(quest).mobsTamed.containsKey(entity)) {
getQuestData(quest).mobsTamed.put(entity, (getQuestData(quest).mobsTamed.get(entity) + 1)); getQuestData(quest).mobsTamed.put(entity, (getQuestData(quest).mobsTamed.get(entity) + 1));
final int mobsToTame = getCurrentStage(quest).mobsToTame.get(entity); final int mobsToTame = getCurrentStage(quest).mobsToTame.get(entity);
if (getQuestData(quest).mobsTamed.get(entity).equals(mobsToTame)) { 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); new ItemStack(Material.AIR, mobsToTame), null, entity, null, null, null, null, null, null);
// Multiplayer // Multiplayer
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).mobsTamed.put(entity, getQuestData(quest).mobsTamed.get(entity)); 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); new ItemStack(Material.AIR, mobsToTame), null, entity, null, null, null, null, null, null);
return 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<Quester> {
* @param color The wool color of the sheep being sheared * @param color The wool color of the sheep being sheared
*/ */
public void shearSheep(final Quest quest, final DyeColor color) { 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)) { if (getQuestData(quest).sheepSheared.containsKey(color)) {
getQuestData(quest).sheepSheared.put(color, (getQuestData(quest).sheepSheared.get(color) + 1)); getQuestData(quest).sheepSheared.put(color, (getQuestData(quest).sheepSheared.get(color) + 1));
final int sheepToShear = getCurrentStage(quest).sheepToShear.get(color); final int sheepToShear = getCurrentStage(quest).sheepToShear.get(color);
if (getQuestData(quest).sheepSheared.get(color).equals(sheepToShear)) { 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); new ItemStack(Material.AIR, sheepToShear), null, null, null, null, null, color, null, null);
// Multiplayer // Multiplayer
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).sheepSheared.put(color, getQuestData(quest).sheepSheared.get(color)); 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); new ItemStack(Material.AIR, sheepToShear), null, null, null, null, null, color, null, null);
return 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<Quester> {
* @param evt The event during which the password was entered * @param evt The event during which the password was entered
*/ */
public void sayPassword(final Quest quest, final AsyncPlayerChatEvent evt) { 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; boolean done;
for (final LinkedList<String> passes : getCurrentStage(quest).passwordPhrases) { for (final LinkedList<String> passes : getCurrentStage(quest).passwordPhrases) {
done = false; done = false;
for (final String pass : passes) { for (final String pass : passes) {
if (pass.equalsIgnoreCase(evt.getMessage())) { if (pass.equalsIgnoreCase(evt.getMessage())) {
evt.setCancelled(true); evt.setCancelled(true);
final String display = getCurrentStage(quest).passwordDisplays.get(getCurrentStage(quest).passwordPhrases final String display = getCurrentStage(quest).passwordDisplays.get(getCurrentStage(quest)
.indexOf(passes)); .passwordPhrases.indexOf(passes));
getQuestData(quest).passwordsSaid.put(display, true); getQuestData(quest).passwordsSaid.put(display, true);
done = true; done = true;
plugin.getServer().getScheduler().runTask(plugin, () -> { 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); new ItemStack(Material.AIR, 1), null, null, null, null, null, null, display, null);
// Multiplayer // Multiplayer
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> { dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
q.getQuestData(quest).passwordsSaid.put(display, true); 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); new ItemStack(Material.AIR, 1), null, null, null, null, null, null, display, null);
return null; return null;
}); });
@ -2400,15 +2547,18 @@ public class Quester implements Comparable<Quester> {
break; break;
} }
} }
final QuesterPostUpdateObjectiveEvent postEvent = new QuesterPostUpdateObjectiveEvent(this, quest, type);
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
/** /**
* Complete quest objective * Complete quest objective
* *
* @param quest * @param quest
* Quest containing the objective * Quest containing the objective
* @param objective * @param objective
* Type of objective, e.g. "password" or "damageBlock" * Type of objective
* @param increment * @param increment
* Final amount material being applied * Final amount material being applied
* @param goal * @param goal
@ -2431,9 +2581,9 @@ public class Quester implements Comparable<Quester> {
* See CustomObjective class * See CustomObjective class
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void finishObjective(final Quest quest, final String objective, final ItemStack increment, final ItemStack goal, public void finishObjective(final Quest quest, final ObjectiveType objective, final ItemStack increment,
final Enchantment enchantment, final EntityType mob, final String extra, final NPC npc, final Location location, final DyeColor color, final ItemStack goal, final Enchantment enchantment, final EntityType mob, final String extra,
final String pass, final CustomObjective co) { final NPC npc, final Location location, final DyeColor color, final String pass, final CustomObjective co) {
final Player p = getPlayer(); final Player p = getPlayer();
if (getCurrentStage(quest).objectiveOverrides.isEmpty() == false) { if (getCurrentStage(quest).objectiveOverrides.isEmpty() == false) {
for (final String s: getCurrentStage(quest).objectiveOverrides) { for (final String s: getCurrentStage(quest).objectiveOverrides) {
@ -2444,10 +2594,10 @@ public class Quester implements Comparable<Quester> {
} }
p.sendMessage(message); p.sendMessage(message);
} }
} else if (objective.equalsIgnoreCase("password")) { } else if (objective.equals(ObjectiveType.PASSWORD)) {
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + pass; final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + pass;
p.sendMessage(message); 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") + " <item>"; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "break") + " <item>";
message = message + " " + goal.getAmount() + "/" + goal.getAmount(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta() if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta()
@ -2456,7 +2606,7 @@ public class Quester implements Comparable<Quester> {
} else { } else {
p.sendMessage(message.replace("<item>", ItemUtil.getName(increment))); p.sendMessage(message.replace("<item>", 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") String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "damage")
+ " <item>"; + " <item>";
message = message + " " + goal.getAmount() + "/" + goal.getAmount(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
@ -2466,7 +2616,7 @@ public class Quester implements Comparable<Quester> {
} else { } else {
p.sendMessage(message.replace("<item>", ItemUtil.getName(increment))); p.sendMessage(message.replace("<item>", 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") + " <item>"; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "place") + " <item>";
message = message + " " + goal.getAmount() + "/" + goal.getAmount(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta() if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta()
@ -2475,7 +2625,7 @@ public class Quester implements Comparable<Quester> {
} else { } else {
p.sendMessage(message.replace("<item>", ItemUtil.getName(increment))); p.sendMessage(message.replace("<item>", 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") + " <item>"; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "use") + " <item>";
message = message + " " + goal.getAmount() + "/" + goal.getAmount(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta() if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta()
@ -2484,7 +2634,7 @@ public class Quester implements Comparable<Quester> {
} else { } else {
p.sendMessage(message.replace("<item>", ItemUtil.getName(increment))); p.sendMessage(message.replace("<item>", 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") + " <item>"; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "cut") + " <item>";
message = message + " " + goal.getAmount() + "/" + goal.getAmount(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta() if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta()
@ -2493,7 +2643,7 @@ public class Quester implements Comparable<Quester> {
} else { } else {
p.sendMessage(message.replace("<item>", ItemUtil.getName(increment))); p.sendMessage(message.replace("<item>", 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 ItemStack is = getCurrentStage(quest).itemsToCraft.get(getCurrentStage(quest).itemsToCraft.indexOf(goal));
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "craftItem") final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "craftItem")
+ " " + is.getAmount() + "/" + is.getAmount(); + " " + is.getAmount() + "/" + is.getAmount();
@ -2503,7 +2653,7 @@ public class Quester implements Comparable<Quester> {
} else { } else {
p.sendMessage(message.replace("<item>", ItemUtil.getName(is))); p.sendMessage(message.replace("<item>", 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 ItemStack is = getCurrentStage(quest).itemsToSmelt.get(getCurrentStage(quest).itemsToSmelt.indexOf(goal));
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "smeltItem") final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "smeltItem")
+ " " + is.getAmount() + "/" + is.getAmount(); + " " + is.getAmount() + "/" + is.getAmount();
@ -2513,7 +2663,7 @@ public class Quester implements Comparable<Quester> {
} else { } else {
p.sendMessage(message.replace("<item>", ItemUtil.getName(is))); p.sendMessage(message.replace("<item>", 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 ItemStack is = getCurrentStage(quest).itemsToEnchant.get(getCurrentStage(quest).itemsToEnchant.indexOf(goal));
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "enchItem") final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "enchItem")
+ " " + is.getAmount() + "/" + is.getAmount(); + " " + is.getAmount() + "/" + is.getAmount();
@ -2523,7 +2673,7 @@ public class Quester implements Comparable<Quester> {
} else { } else {
p.sendMessage(message.replace("<item>", ItemUtil.getName(is))); p.sendMessage(message.replace("<item>", 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 ItemStack is = getCurrentStage(quest).itemsToBrew.get(getCurrentStage(quest).itemsToBrew.indexOf(goal));
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "brewItem") final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "brewItem")
+ " " + is.getAmount() + "/" + is.getAmount(); + " " + is.getAmount() + "/" + is.getAmount();
@ -2534,7 +2684,7 @@ public class Quester implements Comparable<Quester> {
} else { } else {
p.sendMessage(message.replace("<item>", ItemUtil.getName(is))); p.sendMessage(message.replace("<item>", 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 final ItemStack is = getCurrentStage(quest).itemsToConsume.get(getCurrentStage(quest).itemsToConsume
.indexOf(goal)); .indexOf(goal));
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "consumeItem") final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "consumeItem")
@ -2545,7 +2695,7 @@ public class Quester implements Comparable<Quester> {
} else { } else {
p.sendMessage(message.replace("<item>", ItemUtil.getName(is))); p.sendMessage(message.replace("<item>", ItemUtil.getName(is)));
} }
} else if (objective.equalsIgnoreCase("deliverItem")) { } else if (objective.equals(ObjectiveType.DELIVER_ITEM)) {
String obj = Lang.get(p, "deliver"); String obj = Lang.get(p, "deliver");
obj = obj.replace("<npc>", plugin.getDependencies().getNPCName(getCurrentStage(quest).itemDeliveryTargets obj = obj.replace("<npc>", plugin.getDependencies().getNPCName(getCurrentStage(quest).itemDeliveryTargets
.get(getCurrentStage(quest).itemsToDeliver.indexOf(goal)))); .get(getCurrentStage(quest).itemsToDeliver.indexOf(goal))));
@ -2558,51 +2708,51 @@ public class Quester implements Comparable<Quester> {
} else { } else {
p.sendMessage(message.replace("<item>", ItemUtil.getName(is))); p.sendMessage(message.replace("<item>", 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") + " "; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "milkCow") + " ";
message = message + " " + goal.getAmount() + "/" + goal.getAmount(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
p.sendMessage(message); 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") + " "; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "catchFish") + " ";
message = message + " " + goal.getAmount() + "/" + goal.getAmount(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
p.sendMessage(message); 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") + " <mob>"; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "kill") + " <mob>";
message = message + " " + goal.getAmount() + "/" + goal.getAmount(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
if (plugin.getSettings().canTranslateNames()) { if (plugin.getSettings().canTranslateNames()) {
plugin.getLocaleQuery().sendMessage(p, message, mob, extra); plugin.getLocaleQuery().sendMessage(p, message, mob, extra);
} else { } else {
p.sendMessage(message.replace("<mob>", MiscUtil.getProperMobName(mob))); p.sendMessage(message.replace("<mob>", 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"); String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "killPlayer");
message = message + " " + goal.getAmount() + "/" + goal.getAmount(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
p.sendMessage(message); p.sendMessage(message);
} else if (objective.equalsIgnoreCase("talkToNPC")) { } else if (objective.equals(ObjectiveType.TALK_TO_NPC)) {
String obj = Lang.get(p, "talkTo"); String obj = Lang.get(p, "talkTo");
obj = obj.replace("<npc>", plugin.getDependencies().getNPCName(npc.getId())); obj = obj.replace("<npc>", plugin.getDependencies().getNPCName(npc.getId()));
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + obj; final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + obj;
p.sendMessage(message); 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") + " " String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "kill") + " "
+ npc.getName(); + npc.getName();
message = message + " " + goal.getAmount() + "/" + goal.getAmount(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
p.sendMessage(message); 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") + " <mob>"; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "tame") + " <mob>";
message = message + " " + goal.getAmount() + "/" + goal.getAmount(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
if (plugin.getSettings().canTranslateNames()) { if (plugin.getSettings().canTranslateNames()) {
plugin.getLocaleQuery().sendMessage(p, message, mob, extra); plugin.getLocaleQuery().sendMessage(p, message, mob, extra);
} else { } else {
p.sendMessage(message.replace("<mob>", MiscUtil.getProperMobName(mob))); p.sendMessage(message.replace("<mob>", MiscUtil.snakeCaseToUpperCamelCase(mob.name())));
} }
} else if (objective.equalsIgnoreCase("shearSheep")) { } else if (objective.equals(ObjectiveType.SHEAR_SHEEP)) {
String obj = Lang.get(p, "shearSheep"); String obj = Lang.get(p, "shearSheep");
obj = obj.replace("<color>", color.name().toLowerCase()); obj = obj.replace("<color>", color.name().toLowerCase());
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + obj; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + obj;
message = message + " " + goal.getAmount() + "/" + goal.getAmount(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
p.sendMessage(message); p.sendMessage(message);
} else if (objective.equalsIgnoreCase("reachLocation")) { } else if (objective.equals(ObjectiveType.REACH_LOCATION)) {
String obj = Lang.get(p, "goTo"); String obj = Lang.get(p, "goTo");
try { try {
obj = obj.replace("<location>", getCurrentStage(quest).locationNames.get(getCurrentStage(quest) obj = obj.replace("<location>", getCurrentStage(quest).locationNames.get(getCurrentStage(quest)
@ -2642,6 +2792,45 @@ public class Quester implements Comparable<Quester> {
quest.nextStage(this, true); 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 * Check whether this Quester has completed all objectives for their current stage
@ -2650,7 +2839,7 @@ public class Quester implements Comparable<Quester> {
* @return true if all stage objectives are marked complete * @return true if all stage objectives are marked complete
*/ */
public boolean testComplete(final Quest quest) { 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())) { if (s.startsWith(ChatColor.GREEN.toString())) {
return false; return false;
} }

View File

@ -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<String, ObjectiveType> NAME_MAP = new HashMap<String, ObjectiveType>();
private static final Map<Byte, ObjectiveType> ID_MAP = new HashMap<Byte, ObjectiveType>();
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);
}
}

View File

@ -37,7 +37,7 @@ public class QuesterPostChangeStageEvent extends QuesterEvent {
/** /**
* Returns the quest involved in this event * 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() { public Quest getQuest() {
return quest; return quest;

View File

@ -32,7 +32,7 @@ public class QuesterPostCompleteQuestEvent extends QuesterEvent {
/** /**
* Returns the quest involved in this event * 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() { public Quest getQuest() {
return quest; return quest;

View File

@ -32,7 +32,7 @@ public class QuesterPostFailQuestEvent extends QuesterEvent {
/** /**
* Returns the quest involved in this event * 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() { public Quest getQuest() {
return quest; return quest;

View File

@ -32,7 +32,7 @@ public class QuesterPostStartQuestEvent extends QuesterEvent {
/** /**
* Returns the quest involved in this event * 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() { public Quest getQuest() {
return quest; return quest;

View File

@ -39,7 +39,7 @@ public class QuesterPreChangeStageEvent extends QuesterEvent implements Cancella
/** /**
* Returns the quest involved in this event * 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() { public Quest getQuest() {
return quest; return quest;

View File

@ -34,7 +34,7 @@ public class QuesterPreCompleteQuestEvent extends QuesterEvent implements Cancel
/** /**
* Returns the quest involved in this event * 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() { public Quest getQuest() {
return quest; return quest;

View File

@ -34,7 +34,7 @@ public class QuesterPreFailQuestEvent extends QuesterEvent implements Cancellabl
/** /**
* Returns the quest involved in this event * 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() { public Quest getQuest() {
return quest; return quest;

View File

@ -34,7 +34,7 @@ public class QuesterPreStartQuestEvent extends QuesterEvent implements Cancellab
/** /**
* Returns the quest involved in this event * 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() { public Quest getQuest() {
return quest; return quest;