Return cancelled objective events

This commit is contained in:
PikaMug 2022-12-10 05:18:41 -05:00
parent 35819b619c
commit cd4818bfee
5 changed files with 437 additions and 412 deletions

View File

@ -52,10 +52,13 @@ public class BlockListener implements Listener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGH) // Because HIGHEST conflicts with AutoSell by extendedclip @EventHandler(priority = EventPriority.HIGH) // Because HIGHEST conflicts with AutoSell by extendedclip
public void onBlockBreak(final BlockBreakEvent evt) { public void onBlockBreak(final BlockBreakEvent event) {
final Player player = evt.getPlayer(); if (event.isCancelled()) {
return;
}
final Player player = event.getPlayer();
if (plugin.canUseQuests(player.getUniqueId())) { if (plugin.canUseQuests(player.getUniqueId())) {
final ItemStack blockItemStack = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState() final ItemStack blockItemStack = new ItemStack(event.getBlock().getType(), 1, event.getBlock().getState()
.getData().toItemStack().getDurability()); .getData().toItemStack().getDurability());
final Quester quester = plugin.getQuester(player.getUniqueId()); final Quester quester = plugin.getQuester(player.getUniqueId());
final ObjectiveType breakType = ObjectiveType.BREAK_BLOCK; final ObjectiveType breakType = ObjectiveType.BREAK_BLOCK;
@ -65,111 +68,109 @@ public class BlockListener implements Listener {
final Set<String> dispatchedPlaceQuestIDs = new HashSet<>(); final Set<String> dispatchedPlaceQuestIDs = new HashSet<>();
final Set<String> dispatchedCutQuestIDs = new HashSet<>(); final Set<String> dispatchedCutQuestIDs = new HashSet<>();
for (final IQuest quest : plugin.getLoadedQuests()) { for (final IQuest quest : plugin.getLoadedQuests()) {
if (!evt.isCancelled()) { if (!quester.meetsCondition(quest, true)) {
if (!quester.meetsCondition(quest, true)) { continue;
}
if (quester.getCurrentQuestsTemp().containsKey(quest)) {
final IStage currentStage = quester.getCurrentStage(quest);
if (currentStage == null) {
plugin.getLogger().severe("Player " + player.getName() + " (" + player.getUniqueId()
+ ") has invalid stage for quest " + quest.getName() + " (" + quest.getId() + ")");
continue; continue;
} }
if (quester.getCurrentQuestsTemp().containsKey(quest)) { if (currentStage.containsObjective(breakType)) {
final IStage currentStage = quester.getCurrentStage(quest); if (quest.getOptions().canIgnoreSilkTouch()
if (currentStage == null) { && player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
plugin.getLogger().severe("Player " + player.getName() + " (" + player.getUniqueId() ActionBarProvider.sendActionBar(player, ChatColor.RED + Lang
+ ") has invalid stage for quest " + quest.getName() + " (" + quest.getId() + ")"); .get(player, "optionSilkTouchFail").replace("<quest>", quest.getName()));
continue; } else {
} quester.breakBlock(quest, blockItemStack);
if (currentStage.containsObjective(breakType)) {
if (quest.getOptions().canIgnoreSilkTouch()
&& player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
ActionBarProvider.sendActionBar(player, ChatColor.RED + Lang
.get(player, "optionSilkTouchFail").replace("<quest>", quest.getName()));
} else {
quester.breakBlock(quest, blockItemStack);
dispatchedBreakQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, breakType, dispatchedBreakQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, breakType,
(final IQuester q, final IQuest cq) -> {
if (!dispatchedBreakQuestIDs.contains(cq.getId())) {
q.breakBlock(cq, blockItemStack);
}
return null;
}));
}
}
if (quest.getOptions().canIgnoreBlockReplace()) {
// Ignore blocks broken once replaced (self)
if (currentStage.containsObjective(placeType)) {
for (final ItemStack is : quester.getQuestData(quest).blocksPlaced) {
if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
ItemStack toPlace = new ItemStack(is.getType(), 64);
for (final ItemStack stack : currentStage.getBlocksToPlace()) {
if (ItemUtil.compareItems(is, stack, true) == 0) {
toPlace = stack;
}
}
final QuesterPreUpdateObjectiveEvent preEvent
= new QuesterPreUpdateObjectiveEvent(quester, quest,
new BukkitObjective(placeType, is.getAmount(), toPlace.getAmount()));
plugin.getServer().getPluginManager().callEvent(preEvent);
final int index = quester.getQuestData(quest).blocksPlaced.indexOf(is);
final int newAmount = is.getAmount() - 1;
is.setAmount(newAmount);
quester.getQuestData(quest).blocksPlaced.set(index, is);
final QuesterPostUpdateObjectiveEvent postEvent
= new QuesterPostUpdateObjectiveEvent(quester, quest,
new BukkitObjective(placeType, newAmount, toPlace.getAmount()));
plugin.getServer().getPluginManager().callEvent(postEvent);
}
}
}
// Ignore blocks broken once replaced (party support)
dispatchedPlaceQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, placeType,
(final IQuester q, final IQuest cq) -> { (final IQuester q, final IQuest cq) -> {
if (!dispatchedPlaceQuestIDs.contains(cq.getId())) { if (!dispatchedBreakQuestIDs.contains(cq.getId())) {
for (final ItemStack is : q.getQuestData(cq).blocksPlaced) { q.breakBlock(cq, blockItemStack);
if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
ItemStack toPlace = new ItemStack(is.getType(), 64);
for (final ItemStack stack : quester.getCurrentStage(cq).getBlocksToPlace()) {
if (ItemUtil.compareItems(is, stack, true) == 0) {
toPlace = stack;
}
}
final QuesterPreUpdateObjectiveEvent preEvent
= new QuesterPreUpdateObjectiveEvent((Quester) q, cq,
new BukkitObjective(placeType, is.getAmount(), toPlace.getAmount()));
plugin.getServer().getPluginManager().callEvent(preEvent);
final int index = q.getQuestData(cq).blocksPlaced.indexOf(is);
final int newAmount = is.getAmount() - 1;
is.setAmount(newAmount);
q.getQuestData(cq).blocksPlaced.set(index, is);
final QuesterPostUpdateObjectiveEvent postEvent
= new QuesterPostUpdateObjectiveEvent((Quester) q, cq,
new BukkitObjective(placeType, newAmount, toPlace.getAmount()));
plugin.getServer().getPluginManager().callEvent(postEvent);
}
}
} }
return null; return null;
})); }));
} }
if (currentStage.containsObjective(cutType)) { }
if (player.getItemInHand().getType().equals(Material.SHEARS)) { if (quest.getOptions().canIgnoreBlockReplace()) {
quester.cutBlock(quest, blockItemStack); // Ignore blocks broken once replaced (self)
if (currentStage.containsObjective(placeType)) {
for (final ItemStack is : quester.getQuestData(quest).blocksPlaced) {
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
ItemStack toPlace = new ItemStack(is.getType(), 64);
for (final ItemStack stack : currentStage.getBlocksToPlace()) {
if (ItemUtil.compareItems(is, stack, true) == 0) {
toPlace = stack;
}
}
final QuesterPreUpdateObjectiveEvent preEvent
= new QuesterPreUpdateObjectiveEvent(quester, quest,
new BukkitObjective(placeType, is.getAmount(), toPlace.getAmount()));
plugin.getServer().getPluginManager().callEvent(preEvent);
final int index = quester.getQuestData(quest).blocksPlaced.indexOf(is);
final int newAmount = is.getAmount() - 1;
is.setAmount(newAmount);
quester.getQuestData(quest).blocksPlaced.set(index, is);
final QuesterPostUpdateObjectiveEvent postEvent
= new QuesterPostUpdateObjectiveEvent(quester, quest,
new BukkitObjective(placeType, newAmount, toPlace.getAmount()));
plugin.getServer().getPluginManager().callEvent(postEvent);
}
} }
} }
dispatchedCutQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, cutType, // Ignore blocks broken once replaced (party support)
dispatchedPlaceQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, placeType,
(final IQuester q, final IQuest cq) -> { (final IQuester q, final IQuest cq) -> {
if (!dispatchedCutQuestIDs.contains(cq.getId())) { if (!dispatchedPlaceQuestIDs.contains(cq.getId())) {
if (player.getItemInHand().getType().equals(Material.SHEARS)) { for (final ItemStack is : q.getQuestData(cq).blocksPlaced) {
q.cutBlock(cq, blockItemStack); if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
ItemStack toPlace = new ItemStack(is.getType(), 64);
for (final ItemStack stack : quester.getCurrentStage(cq).getBlocksToPlace()) {
if (ItemUtil.compareItems(is, stack, true) == 0) {
toPlace = stack;
}
}
final QuesterPreUpdateObjectiveEvent preEvent
= new QuesterPreUpdateObjectiveEvent((Quester) q, cq,
new BukkitObjective(placeType, is.getAmount(), toPlace.getAmount()));
plugin.getServer().getPluginManager().callEvent(preEvent);
final int index = q.getQuestData(cq).blocksPlaced.indexOf(is);
final int newAmount = is.getAmount() - 1;
is.setAmount(newAmount);
q.getQuestData(cq).blocksPlaced.set(index, is);
final QuesterPostUpdateObjectiveEvent postEvent
= new QuesterPostUpdateObjectiveEvent((Quester) q, cq,
new BukkitObjective(placeType, newAmount, toPlace.getAmount()));
plugin.getServer().getPluginManager().callEvent(postEvent);
}
} }
} }
return null; return null;
})); }));
} }
if (currentStage.containsObjective(cutType)) {
if (player.getItemInHand().getType().equals(Material.SHEARS)) {
quester.cutBlock(quest, blockItemStack);
}
}
dispatchedCutQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, cutType,
(final IQuester q, final IQuest cq) -> {
if (!dispatchedCutQuestIDs.contains(cq.getId())) {
if (player.getItemInHand().getType().equals(Material.SHEARS)) {
q.cutBlock(cq, blockItemStack);
}
}
return null;
}));
} }
} }
} }
@ -177,10 +178,13 @@ public class BlockListener implements Listener {
@SuppressWarnings("deprecation") // since 1.13 @SuppressWarnings("deprecation") // since 1.13
@EventHandler @EventHandler
public void onBlockDamage(final BlockDamageEvent evt) { public void onBlockDamage(final BlockDamageEvent event) {
final Player player = evt.getPlayer(); if (event.isCancelled()) {
return;
}
final Player player = event.getPlayer();
if (plugin.canUseQuests(player.getUniqueId())) { if (plugin.canUseQuests(player.getUniqueId())) {
final ItemStack blockItemStack = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState() final ItemStack blockItemStack = new ItemStack(event.getBlock().getType(), 1, event.getBlock().getState()
.getData().toItemStack().getDurability()); .getData().toItemStack().getDurability());
final IQuester quester = plugin.getQuester(player.getUniqueId()); final IQuester quester = plugin.getQuester(player.getUniqueId());
final ObjectiveType type = ObjectiveType.DAMAGE_BLOCK; final ObjectiveType type = ObjectiveType.DAMAGE_BLOCK;
@ -208,10 +212,13 @@ public class BlockListener implements Listener {
@SuppressWarnings("deprecation") // since 1.13 @SuppressWarnings("deprecation") // since 1.13
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPlace(final BlockPlaceEvent evt) { public void onBlockPlace(final BlockPlaceEvent event) {
final Player player = evt.getPlayer(); if (event.isCancelled()) {
return;
}
final Player player = event.getPlayer();
if (plugin.canUseQuests(player.getUniqueId())) { if (plugin.canUseQuests(player.getUniqueId())) {
final ItemStack blockItemStack = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState() final ItemStack blockItemStack = new ItemStack(event.getBlock().getType(), 1, event.getBlock().getState()
.getData().toItemStack().getDurability()); .getData().toItemStack().getDurability());
final Quester quester = plugin.getQuester(player.getUniqueId()); final Quester quester = plugin.getQuester(player.getUniqueId());
final ObjectiveType placeType = ObjectiveType.PLACE_BLOCK; final ObjectiveType placeType = ObjectiveType.PLACE_BLOCK;
@ -219,113 +226,114 @@ public class BlockListener implements Listener {
final Set<String> dispatchedPlaceQuestIDs = new HashSet<>(); final Set<String> dispatchedPlaceQuestIDs = new HashSet<>();
final Set<String> dispatchedBreakQuestIDs = new HashSet<>(); final Set<String> dispatchedBreakQuestIDs = new HashSet<>();
for (final IQuest quest : plugin.getLoadedQuests()) { for (final IQuest quest : plugin.getLoadedQuests()) {
if (!evt.isCancelled()) { if (!quester.meetsCondition(quest, true)) {
if (!quester.meetsCondition(quest, true)) { continue;
continue; }
if (quester.getCurrentQuestsTemp().containsKey(quest)) {
final IStage currentStage = quester.getCurrentStage(quest);
if (currentStage.containsObjective(placeType)) {
quester.placeBlock(quest, blockItemStack);
} }
if (quester.getCurrentQuestsTemp().containsKey(quest)) { if (quest.getOptions().canIgnoreBlockReplace()) {
final IStage currentStage = quester.getCurrentStage(quest); // Ignore blocks replaced once broken (self)
if (currentStage.containsObjective(breakType)) {
if (currentStage.containsObjective(placeType)) { for (final ItemStack is : quester.getQuestData(quest).blocksBroken) {
quester.placeBlock(quest, blockItemStack); if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
} ItemStack toBreak = new ItemStack(is.getType(), 64);
for (final ItemStack stack : currentStage.getBlocksToBreak()) {
if (quest.getOptions().canIgnoreBlockReplace()) { if (ItemUtil.compareItems(is, stack, true) == 0) {
// Ignore blocks replaced once broken (self) toBreak = stack;
if (currentStage.containsObjective(breakType)) {
for (final ItemStack is : quester.getQuestData(quest).blocksBroken) {
if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
ItemStack toBreak = new ItemStack(is.getType(), 64);
for (final ItemStack stack : currentStage.getBlocksToBreak()) {
if (ItemUtil.compareItems(is, stack, true) == 0) {
toBreak = stack;
}
} }
final QuesterPreUpdateObjectiveEvent preEvent
= new QuesterPreUpdateObjectiveEvent(quester, quest,
new BukkitObjective(placeType, is.getAmount(), toBreak.getAmount()));
plugin.getServer().getPluginManager().callEvent(preEvent);
final int index = quester.getQuestData(quest).blocksBroken.indexOf(is);
final int newAmount = is.getAmount() - 1;
is.setAmount(newAmount);
quester.getQuestData(quest).blocksBroken.set(index, is);
final QuesterPostUpdateObjectiveEvent postEvent
= new QuesterPostUpdateObjectiveEvent(quester, quest,
new BukkitObjective(placeType, newAmount, toBreak.getAmount()));
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
final QuesterPreUpdateObjectiveEvent preEvent
= new QuesterPreUpdateObjectiveEvent(quester, quest,
new BukkitObjective(placeType, is.getAmount(), toBreak.getAmount()));
plugin.getServer().getPluginManager().callEvent(preEvent);
final int index = quester.getQuestData(quest).blocksBroken.indexOf(is);
final int newAmount = is.getAmount() - 1;
is.setAmount(newAmount);
quester.getQuestData(quest).blocksBroken.set(index, is);
final QuesterPostUpdateObjectiveEvent postEvent
= new QuesterPostUpdateObjectiveEvent(quester, quest,
new BukkitObjective(placeType, newAmount, toBreak.getAmount()));
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
} }
// Ignore blocks replaced once broken (party support) }
dispatchedBreakQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, breakType, // Ignore blocks replaced once broken (party support)
(final IQuester q, final IQuest cq) -> { dispatchedBreakQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, breakType,
if (!dispatchedBreakQuestIDs.contains(cq.getId())) { (final IQuester q, final IQuest cq) -> {
for (final ItemStack is : q.getQuestData(cq).blocksBroken) { if (!dispatchedBreakQuestIDs.contains(cq.getId())) {
if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) { for (final ItemStack is : q.getQuestData(cq).blocksBroken) {
ItemStack toBreak = new ItemStack(is.getType(), 64); if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
for (final ItemStack stack : quester.getCurrentStage(cq).getBlocksToBreak()) { ItemStack toBreak = new ItemStack(is.getType(), 64);
if (ItemUtil.compareItems(is, stack, true) == 0) { for (final ItemStack stack : quester.getCurrentStage(cq).getBlocksToBreak()) {
toBreak = stack; if (ItemUtil.compareItems(is, stack, true) == 0) {
} toBreak = stack;
} }
final QuesterPreUpdateObjectiveEvent preEvent
= new QuesterPreUpdateObjectiveEvent((Quester) q, cq,
new BukkitObjective(breakType, is.getAmount(), toBreak.getAmount()));
plugin.getServer().getPluginManager().callEvent(preEvent);
final int index = q.getQuestData(cq).blocksBroken.indexOf(is);
final int newAmount = is.getAmount() - 1;
is.setAmount(newAmount);
q.getQuestData(cq).blocksBroken.set(index, is);
final QuesterPostUpdateObjectiveEvent postEvent
= new QuesterPostUpdateObjectiveEvent((Quester) q, cq,
new BukkitObjective(breakType, newAmount, toBreak.getAmount()));
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
final QuesterPreUpdateObjectiveEvent preEvent
= new QuesterPreUpdateObjectiveEvent((Quester) q, cq,
new BukkitObjective(breakType, is.getAmount(), toBreak.getAmount()));
plugin.getServer().getPluginManager().callEvent(preEvent);
final int index = q.getQuestData(cq).blocksBroken.indexOf(is);
final int newAmount = is.getAmount() - 1;
is.setAmount(newAmount);
q.getQuestData(cq).blocksBroken.set(index, is);
final QuesterPostUpdateObjectiveEvent postEvent
= new QuesterPostUpdateObjectiveEvent((Quester) q, cq,
new BukkitObjective(breakType, newAmount, toBreak.getAmount()));
plugin.getServer().getPluginManager().callEvent(postEvent);
} }
} }
return null; }
})); return null;
} }));
} }
dispatchedPlaceQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, placeType,
(final IQuester q, final IQuest cq) -> {
if (!dispatchedPlaceQuestIDs.contains(cq.getId())) {
q.placeBlock(cq, blockItemStack);
}
return null;
}));
} }
dispatchedPlaceQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, placeType,
(final IQuester q, final IQuest cq) -> {
if (!dispatchedPlaceQuestIDs.contains(cq.getId())) {
q.placeBlock(cq, blockItemStack);
}
return null;
}));
} }
} }
} }
@SuppressWarnings("deprecation") // since 1.13 @SuppressWarnings("deprecation") // since 1.13
@EventHandler @EventHandler
public void onBlockUse(final PlayerInteractEvent evt) { public void onBlockUse(final PlayerInteractEvent event) {
if (event.isCancelled()) {
return;
}
EquipmentSlot e = null; EquipmentSlot e = null;
try { try {
e = evt.getHand(); e = event.getHand();
} catch (final NoSuchMethodError err) { } catch (final NoSuchMethodError err) {
// Do nothing, getHand() not present pre-1.9 // Do nothing, getHand() not present pre-1.9
} }
if (e == null || e.equals(EquipmentSlot.HAND)) { // If the event is fired by HAND (main hand) if (e == null || e.equals(EquipmentSlot.HAND)) { // If the event is fired by HAND (main hand)
final Player player = evt.getPlayer(); final Player player = event.getPlayer();
if (plugin.canUseQuests(evt.getPlayer().getUniqueId())) { if (plugin.canUseQuests(event.getPlayer().getUniqueId())) {
final IQuester quester = plugin.getQuester(player.getUniqueId()); final IQuester quester = plugin.getQuester(player.getUniqueId());
if (quester.isSelectingBlock()) { if (quester.isSelectingBlock()) {
return; return;
} }
if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if (!evt.isCancelled() && evt.getClickedBlock() != null) { if (!event.isCancelled() && event.getClickedBlock() != null) {
final ItemStack blockItemStack = new ItemStack(evt.getClickedBlock().getType(), 1, evt final ItemStack blockItemStack = new ItemStack(event.getClickedBlock().getType(), 1, event
.getClickedBlock().getState().getData().toItemStack().getDurability()); .getClickedBlock().getState().getData().toItemStack().getDurability());
final ObjectiveType type = ObjectiveType.USE_BLOCK; final ObjectiveType type = ObjectiveType.USE_BLOCK;
final Set<String> dispatchedQuestIDs = new HashSet<>(); final Set<String> dispatchedQuestIDs = new HashSet<>();

View File

@ -54,19 +54,19 @@ public class CitizensListener implements Listener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onNPCRightClick(final NPCRightClickEvent evt) { public void onNPCRightClick(final NPCRightClickEvent event) {
if (plugin.getDependencies().getCitizens() == null) { if (plugin.getDependencies().getCitizens() == null) {
return; return;
} }
if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getClicker().getUniqueId())) { if (plugin.getQuestFactory().getSelectingNpcs().contains(event.getClicker().getUniqueId())) {
if (evt.getNPC() == null) { if (event.getNPC() == null) {
plugin.getLogger().severe("NPC was null while selecting by right-click"); plugin.getLogger().severe("NPC was null while selecting by right-click");
return; return;
} }
evt.getClicker().acceptConversationInput(String.valueOf(evt.getNPC().getUniqueId())); event.getClicker().acceptConversationInput(String.valueOf(event.getNPC().getUniqueId()));
} }
if (!evt.getClicker().isConversing()) { if (!event.getClicker().isConversing()) {
final Player player = evt.getClicker(); final Player player = event.getClicker();
final IQuester quester = plugin.getQuester(player.getUniqueId()); final IQuester quester = plugin.getQuester(player.getUniqueId());
for (final IQuest quest : quester.getCurrentQuestsTemp().keySet()) { for (final IQuest quest : quester.getCurrentQuestsTemp().keySet()) {
if (quester.getCurrentStage(quest).containsObjective(ObjectiveType.DELIVER_ITEM)) { if (quester.getCurrentStage(quest).containsObjective(ObjectiveType.DELIVER_ITEM)) {
@ -81,7 +81,7 @@ public class CitizensListener implements Listener {
matches.add(currentIndex); matches.add(currentIndex);
} }
} }
final NPC clicked = evt.getNPC(); final NPC clicked = event.getNPC();
if (!matches.isEmpty()) { if (!matches.isEmpty()) {
for (final Integer match : matches) { for (final Integer match : matches) {
final UUID uuid = quester.getCurrentStage(quest).getItemDeliveryTargets().get(match); final UUID uuid = quester.getCurrentStage(quest).getItemDeliveryTargets().get(match);
@ -194,18 +194,18 @@ public class CitizensListener implements Listener {
continue; continue;
} }
if (quester.getCurrentStage(quest).containsObjective(ObjectiveType.TALK_TO_NPC)) { if (quester.getCurrentStage(quest).containsObjective(ObjectiveType.TALK_TO_NPC)) {
if (quester.getCurrentStage(quest).getNpcsToInteract().contains(evt.getNPC().getUniqueId())) { if (quester.getCurrentStage(quest).getNpcsToInteract().contains(event.getNPC().getUniqueId())) {
final int npcIndex = quester.getCurrentStage(quest).getNpcsToInteract().indexOf(evt.getNPC() final int npcIndex = quester.getCurrentStage(quest).getNpcsToInteract().indexOf(event.getNPC()
.getUniqueId()); .getUniqueId());
if (quester.getQuestData(quest) != null && npcIndex > -1 if (quester.getQuestData(quest) != null && npcIndex > -1
&& !quester.getQuestData(quest).npcsInteracted.get(npcIndex)) { && !quester.getQuestData(quest).npcsInteracted.get(npcIndex)) {
hasObjective = true; hasObjective = true;
} }
quester.interactWithNPC(quest, evt.getNPC().getUniqueId()); quester.interactWithNPC(quest, event.getNPC().getUniqueId());
} }
} }
} }
if (hasObjective || !plugin.getQuestNpcUuids().contains(evt.getNPC().getUniqueId())) { if (hasObjective || !plugin.getQuestNpcUuids().contains(event.getNPC().getUniqueId())) {
return; return;
} }
boolean hasAtLeastOneGUI = false; boolean hasAtLeastOneGUI = false;
@ -214,7 +214,7 @@ public class CitizensListener implements Listener {
if (quester.getCurrentQuestsTemp().containsKey(q)) { if (quester.getCurrentQuestsTemp().containsKey(q)) {
continue; continue;
} }
if (q.getNpcStart() != null && q.getNpcStart().equals(evt.getNPC().getUniqueId())) { if (q.getNpcStart() != null && q.getNpcStart().equals(event.getNPC().getUniqueId())) {
if (plugin.getSettings().canIgnoreLockedQuests() if (plugin.getSettings().canIgnoreLockedQuests()
&& (!quester.getCompletedQuestsTemp().contains(q) && (!quester.getCompletedQuestsTemp().contains(q)
|| q.getPlanner().getCooldown() > -1)) { || q.getPlanner().getCooldown() > -1)) {
@ -240,7 +240,7 @@ public class CitizensListener implements Listener {
quester.takeQuest(q, false); quester.takeQuest(q, false);
} else { } else {
if (q.getGUIDisplay() != null) { if (q.getGUIDisplay() != null) {
quester.showGUIDisplay(evt.getNPC().getUniqueId(), npcQuests); quester.showGUIDisplay(event.getNPC().getUniqueId(), npcQuests);
} else { } else {
for (final String msg : extracted(quester).split("<br>")) { for (final String msg : extracted(quester).split("<br>")) {
player.sendMessage(msg); player.sendMessage(msg);
@ -251,11 +251,11 @@ public class CitizensListener implements Listener {
} }
} else if (npcQuests.size() > 1) { } else if (npcQuests.size() > 1) {
if (hasAtLeastOneGUI) { if (hasAtLeastOneGUI) {
quester.showGUIDisplay(evt.getNPC().getUniqueId(), npcQuests); quester.showGUIDisplay(event.getNPC().getUniqueId(), npcQuests);
} else { } else {
final Conversation c = plugin.getNpcConversationFactory().buildConversation(player); final Conversation c = plugin.getNpcConversationFactory().buildConversation(player);
c.getContext().setSessionData("npcQuests", npcQuests); c.getContext().setSessionData("npcQuests", npcQuests);
c.getContext().setSessionData("npc", evt.getNPC().getName()); c.getContext().setSessionData("npc", event.getNPC().getName());
c.begin(); c.begin();
} }
} else { } else {
@ -265,31 +265,31 @@ public class CitizensListener implements Listener {
} }
@EventHandler @EventHandler
public void onNPCLeftClick(final NPCLeftClickEvent evt) { public void onNPCLeftClick(final NPCLeftClickEvent event) {
if (plugin.getDependencies().getCitizens() == null) { if (plugin.getDependencies().getCitizens() == null) {
return; return;
} }
if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getClicker().getUniqueId())) { if (plugin.getQuestFactory().getSelectingNpcs().contains(event.getClicker().getUniqueId())) {
if (evt.getNPC() == null) { if (event.getNPC() == null) {
plugin.getLogger().severe("NPC was null while selecting by left-click"); plugin.getLogger().severe("NPC was null while selecting by left-click");
return; return;
} }
evt.getClicker().acceptConversationInput(String.valueOf(evt.getNPC().getUniqueId())); event.getClicker().acceptConversationInput(String.valueOf(event.getNPC().getUniqueId()));
} }
} }
@EventHandler @EventHandler
public void onNPCDeath(final NPCDeathEvent evt) { public void onNPCDeath(final NPCDeathEvent event) {
if (plugin.getDependencies().getCitizens() == null) { if (plugin.getDependencies().getCitizens() == null) {
return; return;
} }
if (evt.getNPC() == null || evt.getNPC().getEntity() == null if (event.getNPC() == null || event.getNPC().getEntity() == null
|| evt.getNPC().getEntity().getLastDamageCause() == null) { || event.getNPC().getEntity().getLastDamageCause() == null) {
return; return;
} }
if (evt.getNPC().getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) { if (event.getNPC().getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
final EntityDamageByEntityEvent damageEvent final EntityDamageByEntityEvent damageEvent
= (EntityDamageByEntityEvent) evt.getNPC().getEntity().getLastDamageCause(); = (EntityDamageByEntityEvent) event.getNPC().getEntity().getLastDamageCause();
final Entity damager = damageEvent.getDamager(); final Entity damager = damageEvent.getDamager();
if (plugin.getDependencies().getCitizens().getNPCRegistry().isNPC(damager)) { if (plugin.getDependencies().getCitizens().getNPCRegistry().isNPC(damager)) {
return; return;
@ -311,13 +311,13 @@ public class CitizensListener implements Listener {
if (quester.getCurrentQuestsTemp().containsKey(quest) if (quester.getCurrentQuestsTemp().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective(type)) { && quester.getCurrentStage(quest).containsObjective(type)) {
quester.killNPC(quest, evt.getNPC().getUniqueId()); quester.killNPC(quest, event.getNPC().getUniqueId());
} }
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type, dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type,
(final IQuester q, final IQuest cq) -> { (final IQuester q, final IQuest cq) -> {
if (!dispatchedQuestIDs.contains(cq.getId())) { if (!dispatchedQuestIDs.contains(cq.getId())) {
q.killNPC(cq, evt.getNPC().getUniqueId()); q.killNPC(cq, event.getNPC().getUniqueId());
} }
return null; return null;
})); }));

View File

@ -41,14 +41,14 @@ public class ItemListener implements Listener {
} }
@EventHandler @EventHandler
public void onCraftItem(final CraftItemEvent evt) { public void onCraftItem(final CraftItemEvent event) {
if (evt.getAction().equals(InventoryAction.NOTHING)) { if (event.getAction().equals(InventoryAction.NOTHING)) {
return; return;
} }
if (evt.getWhoClicked() instanceof Player) { if (event.getWhoClicked() instanceof Player) {
final Player player = (Player) evt.getWhoClicked(); final Player player = (Player) event.getWhoClicked();
if (plugin.canUseQuests(player.getUniqueId())) { if (plugin.canUseQuests(player.getUniqueId())) {
final ItemStack craftedItem = getCraftedItem(evt); final ItemStack craftedItem = getCraftedItem(event);
final IQuester quester = plugin.getQuester(player.getUniqueId()); final IQuester quester = plugin.getQuester(player.getUniqueId());
final ObjectiveType type = ObjectiveType.CRAFT_ITEM; final ObjectiveType type = ObjectiveType.CRAFT_ITEM;
final Set<String> dispatchedQuestIDs = new HashSet<>(); final Set<String> dispatchedQuestIDs = new HashSet<>();
@ -74,12 +74,12 @@ public class ItemListener implements Listener {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private ItemStack getCraftedItem(final CraftItemEvent evt) { private ItemStack getCraftedItem(final CraftItemEvent event) {
if (evt.isShiftClick()) { if (event.isShiftClick()) {
final ItemStack recipeResult = evt.getRecipe().getResult(); final ItemStack recipeResult = event.getRecipe().getResult();
final int resultAmt = recipeResult.getAmount(); // Bread = 1, Cookie = 8, etc. final int resultAmt = recipeResult.getAmount(); // Bread = 1, Cookie = 8, etc.
int leastIngredient = -1; int leastIngredient = -1;
for (final ItemStack item : evt.getInventory().getMatrix()) { for (final ItemStack item : event.getInventory().getMatrix()) {
if (item != null && !item.getType().equals(Material.AIR)) { if (item != null && !item.getType().equals(Material.AIR)) {
final int re = item.getAmount() * resultAmt; final int re = item.getAmount() * resultAmt;
if (leastIngredient == -1 || re < leastIngredient) { if (leastIngredient == -1 || re < leastIngredient) {
@ -89,17 +89,17 @@ public class ItemListener implements Listener {
} }
return new ItemStack(recipeResult.getType(), leastIngredient, recipeResult.getDurability()); return new ItemStack(recipeResult.getType(), leastIngredient, recipeResult.getDurability());
} }
return evt.getCurrentItem(); return event.getCurrentItem();
} }
@EventHandler @EventHandler
public void onInventoryClick(final InventoryClickEvent evt) { public void onInventoryClick(final InventoryClickEvent event) {
if (evt.getWhoClicked() instanceof Player) { if (event.getWhoClicked() instanceof Player) {
final Player player = (Player) evt.getWhoClicked(); final Player player = (Player) event.getWhoClicked();
if (evt.getInventory().getType() == InventoryType.FURNACE if (event.getInventory().getType() == InventoryType.FURNACE
|| evt.getInventory().getType().name().equals("BLAST_FURNACE") || event.getInventory().getType().name().equals("BLAST_FURNACE")
|| evt.getInventory().getType().name().equals("SMOKER")) { || event.getInventory().getType().name().equals("SMOKER")) {
if (evt.getSlotType() == SlotType.RESULT) { if (event.getSlotType() == SlotType.RESULT) {
final IQuester quester = plugin.getQuester(player.getUniqueId()); final IQuester quester = plugin.getQuester(player.getUniqueId());
final ObjectiveType type = ObjectiveType.SMELT_ITEM; final ObjectiveType type = ObjectiveType.SMELT_ITEM;
final Set<String> dispatchedQuestIDs = new HashSet<>(); final Set<String> dispatchedQuestIDs = new HashSet<>();
@ -110,19 +110,19 @@ public class ItemListener implements Listener {
if (quester.getCurrentQuestsTemp().containsKey(quest) if (quester.getCurrentQuestsTemp().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective(type)) { && quester.getCurrentStage(quest).containsObjective(type)) {
quester.smeltItem(quest, evt.getCurrentItem()); quester.smeltItem(quest, event.getCurrentItem());
} }
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type, (final IQuester q, final IQuest cq) -> { dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type, (final IQuester q, final IQuest cq) -> {
if (!dispatchedQuestIDs.contains(cq.getId())) { if (!dispatchedQuestIDs.contains(cq.getId())) {
q.smeltItem(cq, evt.getCurrentItem()); q.smeltItem(cq, event.getCurrentItem());
} }
return null; return null;
})); }));
} }
} }
} else if (evt.getInventory().getType() == InventoryType.BREWING) { } else if (event.getInventory().getType() == InventoryType.BREWING) {
if (evt.getSlotType() == SlotType.CRAFTING) { if (event.getSlotType() == SlotType.CRAFTING) {
final IQuester quester = plugin.getQuester(player.getUniqueId()); final IQuester quester = plugin.getQuester(player.getUniqueId());
final ObjectiveType type = ObjectiveType.BREW_ITEM; final ObjectiveType type = ObjectiveType.BREW_ITEM;
final Set<String> dispatchedQuestIDs = new HashSet<>(); final Set<String> dispatchedQuestIDs = new HashSet<>();
@ -133,12 +133,12 @@ public class ItemListener implements Listener {
if (quester.getCurrentQuestsTemp().containsKey(quest) if (quester.getCurrentQuestsTemp().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective(type)) { && quester.getCurrentStage(quest).containsObjective(type)) {
quester.brewItem(quest, evt.getCurrentItem()); quester.brewItem(quest, event.getCurrentItem());
} }
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type, (final IQuester q, final IQuest cq) -> { dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type, (final IQuester q, final IQuest cq) -> {
if (!dispatchedQuestIDs.contains(cq.getId())) { if (!dispatchedQuestIDs.contains(cq.getId())) {
q.brewItem(cq, evt.getCurrentItem()); q.brewItem(cq, event.getCurrentItem());
} }
return null; return null;
})); }));
@ -149,12 +149,12 @@ public class ItemListener implements Listener {
} }
@EventHandler @EventHandler
public void onEnchantItem(final EnchantItemEvent evt) { public void onEnchantItem(final EnchantItemEvent event) {
if (plugin.canUseQuests(evt.getEnchanter().getUniqueId())) { if (plugin.canUseQuests(event.getEnchanter().getUniqueId())) {
final ItemStack enchantedItem = evt.getItem().clone(); final ItemStack enchantedItem = event.getItem().clone();
enchantedItem.setAmount(1); enchantedItem.setAmount(1);
enchantedItem.addUnsafeEnchantments(evt.getEnchantsToAdd()); enchantedItem.addUnsafeEnchantments(event.getEnchantsToAdd());
final IQuester quester = plugin.getQuester(evt.getEnchanter().getUniqueId()); final IQuester quester = plugin.getQuester(event.getEnchanter().getUniqueId());
final ObjectiveType type = ObjectiveType.ENCHANT_ITEM; final ObjectiveType type = ObjectiveType.ENCHANT_ITEM;
final Set<String> dispatchedQuestIDs = new HashSet<>(); final Set<String> dispatchedQuestIDs = new HashSet<>();
for (final IQuest quest : plugin.getLoadedQuests()) { for (final IQuest quest : plugin.getLoadedQuests()) {
@ -165,7 +165,7 @@ public class ItemListener implements Listener {
if (quester.getCurrentQuestsTemp().containsKey(quest) if (quester.getCurrentQuestsTemp().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective(type)) { && quester.getCurrentStage(quest).containsObjective(type)) {
if (enchantedItem.getType().equals(Material.BOOK)) { if (enchantedItem.getType().equals(Material.BOOK)) {
quester.enchantBook(quest, enchantedItem, evt.getEnchantsToAdd()); quester.enchantBook(quest, enchantedItem, event.getEnchantsToAdd());
} else { } else {
quester.enchantItem(quest, enchantedItem); quester.enchantItem(quest, enchantedItem);
} }
@ -174,7 +174,7 @@ public class ItemListener implements Listener {
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type, (final IQuester q, final IQuest cq) -> { dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type, (final IQuester q, final IQuest cq) -> {
if (!dispatchedQuestIDs.contains(cq.getId())) { if (!dispatchedQuestIDs.contains(cq.getId())) {
if (enchantedItem.getType().equals(Material.BOOK)) { if (enchantedItem.getType().equals(Material.BOOK)) {
q.enchantBook(cq, enchantedItem, evt.getEnchantsToAdd()); q.enchantBook(cq, enchantedItem, event.getEnchantsToAdd());
} else { } else {
q.enchantItem(cq, enchantedItem); q.enchantItem(cq, enchantedItem);
} }
@ -187,11 +187,11 @@ public class ItemListener implements Listener {
@EventHandler @EventHandler
public void onConsumeItem(final PlayerItemConsumeEvent evt) { public void onConsumeItem(final PlayerItemConsumeEvent event) {
if (plugin.canUseQuests(evt.getPlayer().getUniqueId())) { if (plugin.canUseQuests(event.getPlayer().getUniqueId())) {
final ItemStack consumedItem = evt.getItem().clone(); final ItemStack consumedItem = event.getItem().clone();
consumedItem.setAmount(1); consumedItem.setAmount(1);
final IQuester quester = plugin.getQuester(evt.getPlayer().getUniqueId()); final IQuester quester = plugin.getQuester(event.getPlayer().getUniqueId());
final ObjectiveType type = ObjectiveType.CONSUME_ITEM; final ObjectiveType type = ObjectiveType.CONSUME_ITEM;
final Set<String> dispatchedQuestIDs = new HashSet<>(); final Set<String> dispatchedQuestIDs = new HashSet<>();
for (final IQuest quest : plugin.getLoadedQuests()) { for (final IQuest quest : plugin.getLoadedQuests()) {

View File

@ -82,49 +82,49 @@ public class PlayerListener implements Listener {
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryClickEvent(final InventoryClickEvent evt) { public void onInventoryClickEvent(final InventoryClickEvent event) {
final InventoryAction ac = evt.getAction(); final InventoryAction ac = event.getAction();
if (ac.equals(InventoryAction.NOTHING)) { if (ac.equals(InventoryAction.NOTHING)) {
return; return;
} }
if (ItemUtil.isItem(evt.getCurrentItem()) && ItemUtil.isJournal(evt.getCurrentItem())) { if (ItemUtil.isItem(event.getCurrentItem()) && ItemUtil.isJournal(event.getCurrentItem())) {
if (ac.equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) || ac.equals(InventoryAction.DROP_ALL_SLOT) if (ac.equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) || ac.equals(InventoryAction.DROP_ALL_SLOT)
|| ac.equals(InventoryAction.DROP_ONE_SLOT)) { || ac.equals(InventoryAction.DROP_ONE_SLOT)) {
evt.setCancelled(true); event.setCancelled(true);
return; return;
} }
} else if (ItemUtil.isItem(evt.getCurrentItem()) && ItemUtil.isJournal(evt.getCursor())) { } else if (ItemUtil.isItem(event.getCurrentItem()) && ItemUtil.isJournal(event.getCursor())) {
if (ac.equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) || ac.equals(InventoryAction.DROP_ALL_CURSOR) if (ac.equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) || ac.equals(InventoryAction.DROP_ALL_CURSOR)
|| ac.equals(InventoryAction.DROP_ONE_CURSOR)) { || ac.equals(InventoryAction.DROP_ONE_CURSOR)) {
evt.setCancelled(true); event.setCancelled(true);
return; return;
} }
} else if (ac.equals(InventoryAction.SWAP_WITH_CURSOR) || ac.equals(InventoryAction.HOTBAR_SWAP) } else if (ac.equals(InventoryAction.SWAP_WITH_CURSOR) || ac.equals(InventoryAction.HOTBAR_SWAP)
|| ac.equals(InventoryAction.HOTBAR_MOVE_AND_READD)) { || ac.equals(InventoryAction.HOTBAR_MOVE_AND_READD)) {
if (evt.getHotbarButton() > -1) { if (event.getHotbarButton() > -1) {
final ItemStack item = evt.getWhoClicked().getInventory().getItem(evt.getHotbarButton()); final ItemStack item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
if (ItemUtil.isItem(item) && ItemUtil.isJournal(item)) { if (ItemUtil.isItem(item) && ItemUtil.isJournal(item)) {
evt.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
} }
if (ItemUtil.isItem(evt.getCurrentItem()) && ItemUtil.isJournal(evt.getCurrentItem()) if (ItemUtil.isItem(event.getCurrentItem()) && ItemUtil.isJournal(event.getCurrentItem())
|| ItemUtil.isItem(evt.getCursor()) && ItemUtil.isJournal(evt.getCursor())) { || ItemUtil.isItem(event.getCursor()) && ItemUtil.isJournal(event.getCursor())) {
int upper = evt.getView().getTopInventory().getSize(); int upper = event.getView().getTopInventory().getSize();
if (evt.getView().getTopInventory().getType().equals(InventoryType.CRAFTING)) if (event.getView().getTopInventory().getType().equals(InventoryType.CRAFTING))
upper += 4; upper += 4;
final int lower = evt.getView().getBottomInventory().getSize(); final int lower = event.getView().getBottomInventory().getSize();
final int relative = evt.getRawSlot() - upper; final int relative = event.getRawSlot() - upper;
if (relative < 0 || relative >= (lower)) { if (relative < 0 || relative >= (lower)) {
evt.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
final Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId()); final Quester quester = plugin.getQuester(event.getWhoClicked().getUniqueId());
final Player player = (Player) evt.getWhoClicked(); final Player player = (Player) event.getWhoClicked();
if (evt.getView().getTitle().contains(Lang.get(player, "quests"))) { if (event.getView().getTitle().contains(Lang.get(player, "quests"))) {
final ItemStack clicked = evt.getCurrentItem(); final ItemStack clicked = event.getCurrentItem();
if (ItemUtil.isItem(clicked)) { if (ItemUtil.isItem(clicked)) {
for (final IQuest quest : plugin.getLoadedQuests()) { for (final IQuest quest : plugin.getLoadedQuests()) {
final Quest bukkitQuest = (Quest)quest; final Quest bukkitQuest = (Quest)quest;
@ -137,28 +137,28 @@ public class PlayerListener implements Listener {
e.printStackTrace(); e.printStackTrace();
} }
} }
evt.getWhoClicked().closeInventory(); event.getWhoClicked().closeInventory();
break; break;
} }
} }
} }
evt.setCancelled(true); event.setCancelled(true);
} }
} }
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryDragEvent(final InventoryDragEvent evt) { public void onInventoryDragEvent(final InventoryDragEvent event) {
if (ItemUtil.isItem(evt.getOldCursor()) && ItemUtil.isJournal(evt.getOldCursor()) if (ItemUtil.isItem(event.getOldCursor()) && ItemUtil.isJournal(event.getOldCursor())
|| ItemUtil.isItem(evt.getCursor()) && ItemUtil.isJournal(evt.getCursor())) { || ItemUtil.isItem(event.getCursor()) && ItemUtil.isJournal(event.getCursor())) {
int upper = evt.getView().getTopInventory().getSize(); int upper = event.getView().getTopInventory().getSize();
if (evt.getView().getTopInventory().getType().equals(InventoryType.CRAFTING)) if (event.getView().getTopInventory().getType().equals(InventoryType.CRAFTING))
upper += 4; upper += 4;
final int lower = evt.getView().getBottomInventory().getSize(); final int lower = event.getView().getBottomInventory().getSize();
for (int relative : evt.getRawSlots()) { for (int relative : event.getRawSlots()) {
relative -= upper; relative -= upper;
if (relative < 0 || relative >= (lower)) { if (relative < 0 || relative >= (lower)) {
evt.setCancelled(true); event.setCancelled(true);
break; break;
} }
} }
@ -166,62 +166,62 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerDropItem(final PlayerDropItemEvent evt) { public void onPlayerDropItem(final PlayerDropItemEvent event) {
if (ItemUtil.isJournal(evt.getItemDrop().getItemStack())) { if (ItemUtil.isJournal(event.getItemDrop().getItemStack())) {
if (!evt.getPlayer().hasPermission("quests.admin.drop")) { if (!event.getPlayer().hasPermission("quests.admin.drop")) {
evt.setCancelled(true); event.setCancelled(true);
} }
} }
} }
@SuppressWarnings("deprecation") // since 1.13 @SuppressWarnings("deprecation") // since 1.13
@EventHandler @EventHandler
public void onPlayerInteract(final PlayerInteractEvent evt) { public void onPlayerInteract(final PlayerInteractEvent event) {
EquipmentSlot e = null; EquipmentSlot e = null;
try { try {
e = evt.getHand(); e = event.getHand();
} catch (final NoSuchMethodError err) { } catch (final NoSuchMethodError err) {
// Do nothing, getHand() not present pre-1.9 // Do nothing, getHand() not present pre-1.9
} }
if (e == null || e.equals(EquipmentSlot.HAND)) { // If the event is fired by HAND (main hand) if (e == null || e.equals(EquipmentSlot.HAND)) { // If the event is fired by HAND (main hand)
if (ItemUtil.isJournal(evt.getPlayer().getItemInHand())) { if (ItemUtil.isJournal(event.getPlayer().getItemInHand())) {
final Player player = evt.getPlayer(); final Player player = event.getPlayer();
if (evt.hasBlock()) { if (event.hasBlock()) {
if (evt.getClickedBlock() == null) { if (event.getClickedBlock() == null) {
return; return;
} }
if (evt.getClickedBlock().getType().name().equals("LECTERN")) { if (event.getClickedBlock().getType().name().equals("LECTERN")) {
evt.setCancelled(true); event.setCancelled(true);
Lang.send(player, ChatColor.RED + Lang.get(evt.getPlayer(), "journalDenied") Lang.send(player, ChatColor.RED + Lang.get(event.getPlayer(), "journalDenied")
.replace("<journal>", Lang.get(evt.getPlayer(), "journalTitle"))); .replace("<journal>", Lang.get(event.getPlayer(), "journalTitle")));
return; return;
} }
if (plugin.getSettings().canAllowPranks() if (plugin.getSettings().canAllowPranks()
&& evt.getClickedBlock().getType().name().contains("PORTAL")) { && event.getClickedBlock().getType().name().contains("PORTAL")) {
evt.setCancelled(true); event.setCancelled(true);
Lang.send(player, " " + ChatColor.AQUA + ChatColor.UNDERLINE Lang.send(player, " " + ChatColor.AQUA + ChatColor.UNDERLINE
+ "https://www.youtube.com/watch?v=dQw4w9WgXcQ"); + "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
return; return;
} }
} }
if (plugin.getSettings().canAllowPranks() if (plugin.getSettings().canAllowPranks()
&& evt.getPlayer().getInventory().getHelmet() != null && event.getPlayer().getInventory().getHelmet() != null
&& (evt.getPlayer().getInventory().getHelmet().getType().name().equals("PUMPKIN") && (event.getPlayer().getInventory().getHelmet().getType().name().equals("PUMPKIN")
|| evt.getPlayer().getInventory().getHelmet().getType().name().equals("CARVED_PUMPKIN"))) { || event.getPlayer().getInventory().getHelmet().getType().name().equals("CARVED_PUMPKIN"))) {
if (!evt.getAction().equals(Action.RIGHT_CLICK_AIR)) { if (!event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
Lang.send(player, " " + ChatColor.AQUA + ChatColor.UNDERLINE Lang.send(player, " " + ChatColor.AQUA + ChatColor.UNDERLINE
+ "https://www.youtube.com/watch?v=v4IC7qaNr7I"); + "https://www.youtube.com/watch?v=v4IC7qaNr7I");
} }
evt.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
if (plugin.canUseQuests(evt.getPlayer().getUniqueId())) { if (plugin.canUseQuests(event.getPlayer().getUniqueId())) {
final IQuester quester = plugin.getQuester(evt.getPlayer().getUniqueId()); final IQuester quester = plugin.getQuester(event.getPlayer().getUniqueId());
final Player player = evt.getPlayer(); final Player player = event.getPlayer();
if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
boolean hasObjective = false; boolean hasObjective = false;
if (!evt.isCancelled()) { if (!event.isCancelled()) {
for (final IQuest quest : plugin.getLoadedQuests()) { for (final IQuest quest : plugin.getLoadedQuests()) {
if (quester.getCurrentQuestsTemp().containsKey(quest) if (quester.getCurrentQuestsTemp().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective(ObjectiveType.USE_BLOCK)) { && quester.getCurrentStage(quest).containsObjective(ObjectiveType.USE_BLOCK)) {
@ -230,9 +230,9 @@ public class PlayerListener implements Listener {
} }
} }
if (!hasObjective) { if (!hasObjective) {
if (plugin.getQuestFactory().getSelectedBlockStarts().containsKey(evt.getPlayer() if (plugin.getQuestFactory().getSelectedBlockStarts().containsKey(event.getPlayer()
.getUniqueId())) { .getUniqueId())) {
final Block block = evt.getClickedBlock(); final Block block = event.getClickedBlock();
if (block == null) { if (block == null) {
return; return;
} }
@ -246,10 +246,10 @@ public class PlayerListener implements Listener {
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")"); + ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
} }
evt.setCancelled(true); event.setCancelled(true);
} else if (plugin.getActionFactory().getSelectedExplosionLocations().containsKey(evt.getPlayer() } else if (plugin.getActionFactory().getSelectedExplosionLocations().containsKey(event.getPlayer()
.getUniqueId())) { .getUniqueId())) {
final Block block = evt.getClickedBlock(); final Block block = event.getClickedBlock();
if (block == null) { if (block == null) {
return; return;
} }
@ -263,10 +263,10 @@ public class PlayerListener implements Listener {
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")"); + ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
} }
evt.setCancelled(true); event.setCancelled(true);
} else if (plugin.getActionFactory().getSelectedEffectLocations().containsKey(evt.getPlayer() } else if (plugin.getActionFactory().getSelectedEffectLocations().containsKey(event.getPlayer()
.getUniqueId())) { .getUniqueId())) {
final Block block = evt.getClickedBlock(); final Block block = event.getClickedBlock();
if (block == null) { if (block == null) {
return; return;
} }
@ -280,10 +280,10 @@ public class PlayerListener implements Listener {
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")"); + ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
} }
evt.setCancelled(true); event.setCancelled(true);
} else if (plugin.getActionFactory().getSelectedMobLocations().containsKey(evt.getPlayer() } else if (plugin.getActionFactory().getSelectedMobLocations().containsKey(event.getPlayer()
.getUniqueId())) { .getUniqueId())) {
final Block block = evt.getClickedBlock(); final Block block = event.getClickedBlock();
if (block == null) { if (block == null) {
return; return;
} }
@ -297,10 +297,10 @@ public class PlayerListener implements Listener {
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")"); + ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
} }
evt.setCancelled(true); event.setCancelled(true);
} else if (plugin.getActionFactory().getSelectedLightningLocations().containsKey(evt.getPlayer() } else if (plugin.getActionFactory().getSelectedLightningLocations().containsKey(event.getPlayer()
.getUniqueId())) { .getUniqueId())) {
final Block block = evt.getClickedBlock(); final Block block = event.getClickedBlock();
if (block == null) { if (block == null) {
return; return;
} }
@ -314,10 +314,10 @@ public class PlayerListener implements Listener {
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")"); + ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
} }
evt.setCancelled(true); event.setCancelled(true);
} else if (plugin.getActionFactory().getSelectedTeleportLocations().containsKey(evt.getPlayer() } else if (plugin.getActionFactory().getSelectedTeleportLocations().containsKey(event.getPlayer()
.getUniqueId())) { .getUniqueId())) {
final Block block = evt.getClickedBlock(); final Block block = event.getClickedBlock();
if (block == null) { if (block == null) {
return; return;
} }
@ -331,10 +331,10 @@ public class PlayerListener implements Listener {
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")"); + ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
} }
evt.setCancelled(true); event.setCancelled(true);
} else if (plugin.getQuestFactory().getSelectedKillLocations().containsKey(evt.getPlayer() } else if (plugin.getQuestFactory().getSelectedKillLocations().containsKey(event.getPlayer()
.getUniqueId())) { .getUniqueId())) {
final Block block = evt.getClickedBlock(); final Block block = event.getClickedBlock();
if (block == null) { if (block == null) {
return; return;
} }
@ -348,10 +348,10 @@ public class PlayerListener implements Listener {
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")"); + ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
} }
evt.setCancelled(true); event.setCancelled(true);
} else if (plugin.getQuestFactory().getSelectedReachLocations().containsKey(evt.getPlayer() } else if (plugin.getQuestFactory().getSelectedReachLocations().containsKey(event.getPlayer()
.getUniqueId())) { .getUniqueId())) {
final Block block = evt.getClickedBlock(); final Block block = event.getClickedBlock();
if (block == null) { if (block == null) {
return; return;
} }
@ -365,11 +365,11 @@ public class PlayerListener implements Listener {
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")"); + ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
} }
evt.setCancelled(true); event.setCancelled(true);
} else if (!player.isConversing()) { } else if (!player.isConversing()) {
for (final IQuest q : plugin.getLoadedQuests()) { for (final IQuest q : plugin.getLoadedQuests()) {
if (q.getBlockStart() != null && evt.getClickedBlock() != null) { if (q.getBlockStart() != null && event.getClickedBlock() != null) {
if (q.getBlockStart().equals(evt.getClickedBlock().getLocation())) { if (q.getBlockStart().equals(event.getClickedBlock().getLocation())) {
if (quester.getCurrentQuestsTemp().size() >= plugin.getSettings().getMaxQuests() if (quester.getCurrentQuestsTemp().size() >= plugin.getSettings().getMaxQuests()
&& plugin.getSettings().getMaxQuests() > 0) { && plugin.getSettings().getMaxQuests() > 0) {
String msg = Lang.get(player, "questMaxAllowed"); String msg = Lang.get(player, "questMaxAllowed");
@ -424,16 +424,16 @@ public class PlayerListener implements Listener {
} }
} }
} }
if (evt.getItem() != null && evt.getItem().getType().equals(Material.COMPASS)) { if (event.getItem() != null && event.getItem().getType().equals(Material.COMPASS)) {
if (!quester.canUseCompass()) { if (!quester.canUseCompass()) {
return; return;
} }
if (evt.getAction().equals(Action.LEFT_CLICK_AIR) if (event.getAction().equals(Action.LEFT_CLICK_AIR)
|| evt.getAction().equals(Action.LEFT_CLICK_BLOCK)) { || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
quester.resetCompass(); quester.resetCompass();
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "compassReset")); Lang.send(player, ChatColor.YELLOW + Lang.get(player, "compassReset"));
} else if (evt.getAction().equals(Action.RIGHT_CLICK_AIR) } else if (event.getAction().equals(Action.RIGHT_CLICK_AIR)
|| evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
quester.findNextCompassTarget(true); quester.findNextCompassTarget(true);
} }
} }
@ -443,11 +443,11 @@ public class PlayerListener implements Listener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@EventHandler @EventHandler
public void onPlayerInteractEntity(final PlayerInteractEntityEvent evt) { public void onPlayerInteractEntity(final PlayerInteractEntityEvent event) {
if (evt.getRightClicked().getType() == EntityType.ITEM_FRAME) { if (event.getRightClicked().getType() == EntityType.ITEM_FRAME) {
final Player player = evt.getPlayer(); final Player player = event.getPlayer();
if (ItemUtil.isJournal(player.getItemInHand())) { if (ItemUtil.isJournal(player.getItemInHand())) {
evt.setCancelled(true); event.setCancelled(true);
Lang.send(player, ChatColor.RED + Lang.get(player, "journalDenied") Lang.send(player, ChatColor.RED + Lang.get(player, "journalDenied")
.replace("<journal>", Lang.get(player, "journalTitle"))); .replace("<journal>", Lang.get(player, "journalTitle")));
} }
@ -455,9 +455,12 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerBucketFill(final PlayerBucketFillEvent evt) { public void onPlayerBucketFill(final PlayerBucketFillEvent event) {
if (evt.getItemStack() != null && evt.getItemStack().getType() == Material.MILK_BUCKET) { if (event.isCancelled()) {
final Player player = evt.getPlayer(); return;
}
if (event.getItemStack() != null && event.getItemStack().getType() == Material.MILK_BUCKET) {
final Player player = event.getPlayer();
if (plugin.canUseQuests(player.getUniqueId())) { if (plugin.canUseQuests(player.getUniqueId())) {
final IQuester quester = plugin.getQuester(player.getUniqueId()); final IQuester quester = plugin.getQuester(player.getUniqueId());
final ObjectiveType type = ObjectiveType.MILK_COW; final ObjectiveType type = ObjectiveType.MILK_COW;
@ -485,9 +488,12 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerChat(final AsyncPlayerChatEvent evt) { public void onPlayerChat(final AsyncPlayerChatEvent event) {
if (plugin.canUseQuests(evt.getPlayer().getUniqueId())) { if (event.isCancelled()) {
final IQuester quester = plugin.getQuester(evt.getPlayer().getUniqueId()); return;
}
if (plugin.canUseQuests(event.getPlayer().getUniqueId())) {
final IQuester quester = plugin.getQuester(event.getPlayer().getUniqueId());
for (final IQuest quest : plugin.getLoadedQuests()) { for (final IQuest quest : plugin.getLoadedQuests()) {
if (!quester.meetsCondition(quest, true)) { if (!quester.meetsCondition(quest, true)) {
continue; continue;
@ -499,7 +505,7 @@ public class PlayerListener implements Listener {
continue; continue;
} }
if (!currentStage.getChatActions().isEmpty()) { if (!currentStage.getChatActions().isEmpty()) {
final String chat = evt.getMessage(); final String chat = event.getMessage();
for (final String s : currentStage.getChatActions().keySet()) { for (final String s : currentStage.getChatActions().keySet()) {
if (s.equalsIgnoreCase(chat)) { if (s.equalsIgnoreCase(chat)) {
new BukkitRunnable() { new BukkitRunnable() {
@ -516,18 +522,18 @@ public class PlayerListener implements Listener {
final Set<String> dispatchedQuestIDs = new HashSet<>(); final Set<String> dispatchedQuestIDs = new HashSet<>();
if (quester.getCurrentStage(quest).containsObjective(type)) { if (quester.getCurrentStage(quest).containsObjective(type)) {
for (final String pass : quester.getCurrentStage(quest).getPasswordPhrases()) { for (final String pass : quester.getCurrentStage(quest).getPasswordPhrases()) {
if (pass.equalsIgnoreCase(evt.getMessage())) { if (pass.equalsIgnoreCase(event.getMessage())) {
evt.setCancelled(true); event.setCancelled(true);
break; break;
} }
} }
quester.sayPassword(quest, evt); quester.sayPassword(quest, event);
} }
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type, dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type,
(final IQuester q, final IQuest cq) -> { (final IQuester q, final IQuest cq) -> {
if (!dispatchedQuestIDs.contains(cq.getId())) { if (!dispatchedQuestIDs.contains(cq.getId())) {
q.sayPassword(cq, evt); q.sayPassword(cq, event);
} }
return null; return null;
})); }));
@ -537,19 +543,19 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent evt) { public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
if (plugin.canUseQuests(evt.getPlayer().getUniqueId())) { if (plugin.canUseQuests(event.getPlayer().getUniqueId())) {
final IQuester quester = plugin.getQuester(evt.getPlayer().getUniqueId()); final IQuester quester = plugin.getQuester(event.getPlayer().getUniqueId());
if (!quester.getCurrentQuestsTemp().isEmpty()) { if (!quester.getCurrentQuestsTemp().isEmpty()) {
for (final IQuest quest : quester.getCurrentQuestsTemp().keySet()) { for (final IQuest quest : quester.getCurrentQuestsTemp().keySet()) {
if (!quest.getOptions().canAllowCommands()) { if (!quest.getOptions().canAllowCommands()) {
if (!evt.getMessage().startsWith("/quest")) { if (!event.getMessage().startsWith("/quest")) {
final Player player = evt.getPlayer(); final Player player = event.getPlayer();
Lang.send(player, ChatColor.RED + Lang.get(player, "optCommandsDenied") Lang.send(player, ChatColor.RED + Lang.get(player, "optCommandsDenied")
.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED)); .replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED));
evt.setCancelled(true); event.setCancelled(true);
plugin.getLogger().info("Player " + player.getName() + " tried to use command " plugin.getLogger().info("Player " + player.getName() + " tried to use command "
+ evt.getMessage() + " but was denied because they are currently on quest " + event.getMessage() + " but was denied because they are currently on quest "
+ quest.getName()); + quest.getName());
return; return;
} }
@ -561,7 +567,7 @@ public class PlayerListener implements Listener {
continue; continue;
} }
if (!currentStage.getCommandActions().isEmpty()) { if (!currentStage.getCommandActions().isEmpty()) {
final String command = evt.getMessage(); final String command = event.getMessage();
for (final String s : currentStage.getCommandActions().keySet()) { for (final String s : currentStage.getCommandActions().keySet()) {
if (command.equalsIgnoreCase("/" + s)) { if (command.equalsIgnoreCase("/" + s)) {
currentStage.getCommandActions().get(s).fire(quester, quest); currentStage.getCommandActions().get(s).fire(quester, quest);
@ -574,11 +580,14 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerShearEntity(final PlayerShearEntityEvent evt) { public void onPlayerShearEntity(final PlayerShearEntityEvent event) {
if (evt.getEntity().getType() == EntityType.SHEEP) { if (event.isCancelled()) {
final Player player = evt.getPlayer(); return;
}
if (event.getEntity().getType() == EntityType.SHEEP) {
final Player player = event.getPlayer();
if (plugin.canUseQuests(player.getUniqueId())) { if (plugin.canUseQuests(player.getUniqueId())) {
final Sheep sheep = (Sheep) evt.getEntity(); final Sheep sheep = (Sheep) event.getEntity();
final IQuester quester = plugin.getQuester(player.getUniqueId()); final IQuester quester = plugin.getQuester(player.getUniqueId());
final ObjectiveType type = ObjectiveType.SHEAR_SHEEP; final ObjectiveType type = ObjectiveType.SHEAR_SHEEP;
final Set<String> dispatchedQuestIDs = new HashSet<>(); final Set<String> dispatchedQuestIDs = new HashSet<>();
@ -605,9 +614,12 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onEntityTame(final EntityTameEvent evt) { public void onEntityTame(final EntityTameEvent event) {
if (evt.getOwner() instanceof Player) { if (event.isCancelled()) {
final Player player = (Player) evt.getOwner(); return;
}
if (event.getOwner() instanceof Player) {
final Player player = (Player) event.getOwner();
if (plugin.canUseQuests(player.getUniqueId())) { if (plugin.canUseQuests(player.getUniqueId())) {
final IQuester quester = plugin.getQuester(player.getUniqueId()); final IQuester quester = plugin.getQuester(player.getUniqueId());
final ObjectiveType type = ObjectiveType.TAME_MOB; final ObjectiveType type = ObjectiveType.TAME_MOB;
@ -619,13 +631,13 @@ public class PlayerListener implements Listener {
if (quester.getCurrentQuestsTemp().containsKey(quest) if (quester.getCurrentQuestsTemp().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective(type)) { && quester.getCurrentStage(quest).containsObjective(type)) {
quester.tameMob(quest, evt.getEntityType()); quester.tameMob(quest, event.getEntityType());
} }
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type, dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type,
(final IQuester q, final IQuest cq) -> { (final IQuester q, final IQuest cq) -> {
if (!dispatchedQuestIDs.contains(cq.getId())) { if (!dispatchedQuestIDs.contains(cq.getId())) {
q.tameMob(cq, evt.getEntityType()); q.tameMob(cq, event.getEntityType());
} }
return null; return null;
})); }));
@ -635,32 +647,33 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onEntityDeath(final EntityDeathEvent evt) { public void onEntityDeath(final EntityDeathEvent event) {
if (evt.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) { if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
final EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) evt.getEntity().getLastDamageCause(); final EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) event.getEntity()
.getLastDamageCause();
final Entity damager = damageEvent.getDamager(); final Entity damager = damageEvent.getDamager();
if (damager instanceof Projectile) { if (damager instanceof Projectile) {
final Projectile projectile = (Projectile) damager; final Projectile projectile = (Projectile) damager;
if (projectile.getShooter() != null && projectile.getShooter() instanceof Entity) { if (projectile.getShooter() != null && projectile.getShooter() instanceof Entity) {
preKillMob((Entity)projectile.getShooter(), evt.getEntity()); preKillMob((Entity)projectile.getShooter(), event.getEntity());
} }
} else if (damager instanceof TNTPrimed) { } else if (damager instanceof TNTPrimed) {
final TNTPrimed tnt = (TNTPrimed) damager; final TNTPrimed tnt = (TNTPrimed) damager;
final Entity source = tnt.getSource(); final Entity source = tnt.getSource();
if (source != null && source.isValid()) { if (source != null && source.isValid()) {
preKillMob(source, evt.getEntity()); preKillMob(source, event.getEntity());
} }
} else if (damager instanceof Wolf) { } else if (damager instanceof Wolf) {
final Wolf wolf = (Wolf) damager; final Wolf wolf = (Wolf) damager;
if (wolf.isTamed() && wolf.getOwner() != null) { if (wolf.isTamed() && wolf.getOwner() != null) {
final IQuester quester = plugin.getQuester(wolf.getOwner().getUniqueId()); final IQuester quester = plugin.getQuester(wolf.getOwner().getUniqueId());
if (quester != null) { if (quester != null) {
preKillPlayer(quester.getPlayer(), evt.getEntity()); preKillPlayer(quester.getPlayer(), event.getEntity());
} }
} }
} else { } else {
preKillMob(damager, evt.getEntity()); preKillMob(damager, event.getEntity());
} }
} }
} }
@ -707,39 +720,40 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerDeath(final PlayerDeathEvent evt) { public void onPlayerDeath(final PlayerDeathEvent event) {
if (evt.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) { if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
final EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) evt.getEntity().getLastDamageCause(); final EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) event.getEntity()
.getLastDamageCause();
final Entity damager = damageEvent.getDamager(); final Entity damager = damageEvent.getDamager();
if (evt.getEntity().getUniqueId().equals(damager.getUniqueId())) { if (event.getEntity().getUniqueId().equals(damager.getUniqueId())) {
return; return;
} }
if (damager instanceof Projectile) { if (damager instanceof Projectile) {
final Projectile projectile = (Projectile) damager; final Projectile projectile = (Projectile) damager;
if (projectile.getShooter() != null && projectile.getShooter() instanceof Entity) { if (projectile.getShooter() != null && projectile.getShooter() instanceof Entity) {
preKillPlayer((Entity)projectile.getShooter(), evt.getEntity()); preKillPlayer((Entity)projectile.getShooter(), event.getEntity());
} }
} else if (damager instanceof TNTPrimed) { } else if (damager instanceof TNTPrimed) {
final TNTPrimed tnt = (TNTPrimed) damager; final TNTPrimed tnt = (TNTPrimed) damager;
final Entity source = tnt.getSource(); final Entity source = tnt.getSource();
if (source != null) { if (source != null) {
if (source.isValid()) { if (source.isValid()) {
preKillPlayer(source, evt.getEntity()); preKillPlayer(source, event.getEntity());
} }
} }
} else if (damager instanceof Wolf) { } else if (damager instanceof Wolf) {
final Wolf wolf = (Wolf) damager; final Wolf wolf = (Wolf) damager;
if (wolf.isTamed() && wolf.getOwner() != null) { if (wolf.isTamed() && wolf.getOwner() != null) {
final IQuester quester = plugin.getQuester(wolf.getOwner().getUniqueId()); final IQuester quester = plugin.getQuester(wolf.getOwner().getUniqueId());
preKillPlayer(quester.getPlayer(), evt.getEntity()); preKillPlayer(quester.getPlayer(), event.getEntity());
} }
} else { } else {
preKillPlayer(damager, evt.getEntity()); preKillPlayer(damager, event.getEntity());
} }
} }
final Player target = evt.getEntity(); final Player target = event.getEntity();
if (plugin.canUseQuests(target.getUniqueId())) { if (plugin.canUseQuests(target.getUniqueId())) {
final IQuester quester = plugin.getQuester(target.getUniqueId()); final IQuester quester = plugin.getQuester(target.getUniqueId());
for (final IQuest quest : quester.getCurrentQuestsTemp().keySet()) { for (final IQuest quest : quester.getCurrentQuestsTemp().keySet()) {
@ -750,14 +764,14 @@ public class PlayerListener implements Listener {
} }
} }
ItemStack found = null; ItemStack found = null;
for (final ItemStack stack : evt.getDrops()) { for (final ItemStack stack : event.getDrops()) {
if (ItemUtil.isJournal(stack)) { if (ItemUtil.isJournal(stack)) {
found = stack; found = stack;
break; break;
} }
} }
if (found != null) { if (found != null) {
evt.getDrops().remove(found); event.getDrops().remove(found);
} }
} }
@ -811,8 +825,11 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerFish(final PlayerFishEvent evt) { public void onPlayerFish(final PlayerFishEvent event) {
final Player player = evt.getPlayer(); if (event.isCancelled()) {
return;
}
final Player player = event.getPlayer();
if (plugin.canUseQuests(player.getUniqueId())) { if (plugin.canUseQuests(player.getUniqueId())) {
final IQuester quester = plugin.getQuester(player.getUniqueId()); final IQuester quester = plugin.getQuester(player.getUniqueId());
final ObjectiveType type = ObjectiveType.CATCH_FISH; final ObjectiveType type = ObjectiveType.CATCH_FISH;
@ -822,7 +839,7 @@ public class PlayerListener implements Listener {
continue; continue;
} }
if (evt.getState().equals(State.CAUGHT_FISH)) { if (event.getState().equals(State.CAUGHT_FISH)) {
if (quester.getCurrentQuestsTemp().containsKey(quest) if (quester.getCurrentQuestsTemp().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective(type)) { && quester.getCurrentStage(quest).containsObjective(type)) {
quester.catchFish(quest); quester.catchFish(quest);
@ -862,12 +879,12 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerJoin(final PlayerJoinEvent evt) { public void onPlayerJoin(final PlayerJoinEvent event) {
final Player player = evt.getPlayer(); final Player player = event.getPlayer();
if (player.hasPermission("quests.admin.update")) { if (player.hasPermission("quests.admin.update")) {
new UpdateChecker(plugin, 3711).getVersion(version -> { new UpdateChecker(plugin, 3711).getVersion(version -> {
if (!plugin.getDescription().getVersion().split("-")[0].equalsIgnoreCase(version)) { if (!plugin.getDescription().getVersion().split("-")[0].equalsIgnoreCase(version)) {
evt.getPlayer().sendMessage(ChatColor.GRAY + "[" + ChatColor.YELLOW + "Quests" + ChatColor.GRAY event.getPlayer().sendMessage(ChatColor.GRAY + "[" + ChatColor.YELLOW + "Quests" + ChatColor.GRAY
+ "] " + ChatColor.GREEN + Lang.get(player, "updateTo").replace("<version>", + "] " + ChatColor.GREEN + Lang.get(player, "updateTo").replace("<version>",
version).replace("<url>", ChatColor.DARK_AQUA + "" + ChatColor.UNDERLINE version).replace("<url>", ChatColor.DARK_AQUA + "" + ChatColor.UNDERLINE
+ plugin.getDescription().getWebsite())); + plugin.getDescription().getWebsite()));
@ -918,9 +935,9 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerQuit(final PlayerQuitEvent evt) { public void onPlayerQuit(final PlayerQuitEvent event) {
if (plugin.canUseQuests(evt.getPlayer().getUniqueId())) { if (plugin.canUseQuests(event.getPlayer().getUniqueId())) {
final IQuester quester = plugin.getQuester(evt.getPlayer().getUniqueId()); final IQuester quester = plugin.getQuester(event.getPlayer().getUniqueId());
for (final IQuest quest : quester.getCurrentQuestsTemp().keySet()) { for (final IQuest quest : quester.getCurrentQuestsTemp().keySet()) {
final IStage currentStage = quester.getCurrentStage(quest); final IStage currentStage = quester.getCurrentStage(quest);
if (currentStage == null) { if (currentStage == null) {
@ -950,9 +967,9 @@ public class PlayerListener implements Listener {
quester.saveData(); quester.saveData();
} }
if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getPlayer().getUniqueId())) { if (plugin.getQuestFactory().getSelectingNpcs().contains(event.getPlayer().getUniqueId())) {
final Set<UUID> temp = plugin.getQuestFactory().getSelectingNpcs(); final Set<UUID> temp = plugin.getQuestFactory().getSelectingNpcs();
temp.remove(evt.getPlayer().getUniqueId()); temp.remove(event.getPlayer().getUniqueId());
plugin.getQuestFactory().setSelectingNpcs(temp); plugin.getQuestFactory().setSelectingNpcs(temp);
} }
final ConcurrentSkipListSet<IQuester> temp = (ConcurrentSkipListSet<IQuester>) plugin.getOfflineQuesters(); final ConcurrentSkipListSet<IQuester> temp = (ConcurrentSkipListSet<IQuester>) plugin.getOfflineQuesters();
@ -962,19 +979,19 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerMove(final PlayerMoveEvent evt) { public void onPlayerMove(final PlayerMoveEvent event) {
if (evt.getTo() == null) { if (event.getTo() == null) {
return; return;
} }
if (evt.getFrom().getBlock().equals(evt.getTo().getBlock())) { if (event.getFrom().getBlock().equals(event.getTo().getBlock())) {
return; return;
} }
if (plugin.getDependencies().getCitizens() != null) { if (plugin.getDependencies().getCitizens() != null) {
if (CitizensAPI.getNPCRegistry().isNPC(evt.getPlayer())) { if (CitizensAPI.getNPCRegistry().isNPC(event.getPlayer())) {
return; return;
} }
} }
playerMove(evt.getPlayer().getUniqueId(), evt.getTo()); playerMove(event.getPlayer().getUniqueId(), event.getTo());
} }
/** /**

View File

@ -33,37 +33,37 @@ public class ZnpcsListener implements Listener {
} }
@EventHandler @EventHandler
public void onNPCInteract(final NPCInteractEvent evt) { public void onNPCInteract(final NPCInteractEvent event) {
if (evt.isLeftClick()) { if (event.isLeftClick()) {
if (plugin.getDependencies().getZnpcs() == null) { if (plugin.getDependencies().getZnpcs() == null) {
return; return;
} }
if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getPlayer().getUniqueId())) { if (plugin.getQuestFactory().getSelectingNpcs().contains(event.getPlayer().getUniqueId())) {
if (evt.getNpc() == null) { if (event.getNpc() == null) {
plugin.getLogger().severe("ZNPC was null while selecting by left-click"); plugin.getLogger().severe("ZNPC was null while selecting by left-click");
return; return;
} }
evt.getPlayer().acceptConversationInput(String.valueOf(evt.getNpc().getUUID())); event.getPlayer().acceptConversationInput(String.valueOf(event.getNpc().getUUID()));
evt.getPlayer().sendMessage(ChatColor.RED + "Warning: " + ChatColor.RESET event.getPlayer().sendMessage(ChatColor.RED + "Warning: " + ChatColor.RESET
+ "ZNPCs is not fully supported and will break after server restart. Please ask its developer " + "ZNPCs is not fully supported and will break after server restart. Please ask its developer "
+ "to fix this at https://github.com/gonalez/znpc-servers/issues/36"); + "to fix this at https://github.com/gonalez/znpc-servers/issues/36");
} }
} else if (evt.isRightClick()) { } else if (event.isRightClick()) {
if (plugin.getDependencies().getCitizens() == null) { if (plugin.getDependencies().getCitizens() == null) {
return; return;
} }
if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getPlayer().getUniqueId())) { if (plugin.getQuestFactory().getSelectingNpcs().contains(event.getPlayer().getUniqueId())) {
if (evt.getNpc() == null) { if (event.getNpc() == null) {
plugin.getLogger().severe("ZNPC was null while selecting by right-click"); plugin.getLogger().severe("ZNPC was null while selecting by right-click");
return; return;
} }
evt.getPlayer().acceptConversationInput(String.valueOf(evt.getNpc().getUUID())); event.getPlayer().acceptConversationInput(String.valueOf(event.getNpc().getUUID()));
evt.getPlayer().sendMessage(ChatColor.RED + "Warning: " + ChatColor.RESET event.getPlayer().sendMessage(ChatColor.RED + "Warning: " + ChatColor.RESET
+ "ZNPCs is not fully supported and will break after server restart. Please ask its developer " + "ZNPCs is not fully supported and will break after server restart. Please ask its developer "
+ "to fix this at https://github.com/gonalez/znpc-servers/issues/36"); + "to fix this at https://github.com/gonalez/znpc-servers/issues/36");
} }
if (!evt.getPlayer().isConversing()) { if (!event.getPlayer().isConversing()) {
final Player player = evt.getPlayer(); final Player player = event.getPlayer();
final IQuester quester = plugin.getQuester(player.getUniqueId()); final IQuester quester = plugin.getQuester(player.getUniqueId());
for (final IQuest quest : quester.getCurrentQuestsTemp().keySet()) { for (final IQuest quest : quester.getCurrentQuestsTemp().keySet()) {
if (quester.getCurrentStage(quest).containsObjective(ObjectiveType.DELIVER_ITEM)) { if (quester.getCurrentStage(quest).containsObjective(ObjectiveType.DELIVER_ITEM)) {
@ -78,7 +78,7 @@ public class ZnpcsListener implements Listener {
matches.add(currentIndex); matches.add(currentIndex);
} }
} }
final NPC clicked = evt.getNpc(); final NPC clicked = event.getNpc();
if (!matches.isEmpty()) { if (!matches.isEmpty()) {
for (final Integer match : matches) { for (final Integer match : matches) {
final UUID uuid = quester.getCurrentStage(quest).getItemDeliveryTargets().get(match); final UUID uuid = quester.getCurrentStage(quest).getItemDeliveryTargets().get(match);
@ -191,18 +191,18 @@ public class ZnpcsListener implements Listener {
continue; continue;
} }
if (quester.getCurrentStage(quest).containsObjective(ObjectiveType.TALK_TO_NPC)) { if (quester.getCurrentStage(quest).containsObjective(ObjectiveType.TALK_TO_NPC)) {
if (quester.getCurrentStage(quest).getNpcsToInteract().contains(evt.getNpc().getUUID())) { if (quester.getCurrentStage(quest).getNpcsToInteract().contains(event.getNpc().getUUID())) {
final int npcIndex = quester.getCurrentStage(quest).getNpcsToInteract().indexOf(evt.getNpc() final int npcIndex = quester.getCurrentStage(quest).getNpcsToInteract().indexOf(event.getNpc()
.getUUID()); .getUUID());
if (quester.getQuestData(quest) != null && npcIndex > -1 if (quester.getQuestData(quest) != null && npcIndex > -1
&& !quester.getQuestData(quest).npcsInteracted.get(npcIndex)) { && !quester.getQuestData(quest).npcsInteracted.get(npcIndex)) {
hasObjective = true; hasObjective = true;
} }
quester.interactWithNPC(quest, evt.getNpc().getUUID()); quester.interactWithNPC(quest, event.getNpc().getUUID());
} }
} }
} }
if (hasObjective || !plugin.getQuestNpcUuids().contains(evt.getNpc().getUUID())) { if (hasObjective || !plugin.getQuestNpcUuids().contains(event.getNpc().getUUID())) {
return; return;
} }
boolean hasAtLeastOneGUI = false; boolean hasAtLeastOneGUI = false;
@ -211,7 +211,7 @@ public class ZnpcsListener implements Listener {
if (quester.getCurrentQuestsTemp().containsKey(q)) { if (quester.getCurrentQuestsTemp().containsKey(q)) {
continue; continue;
} }
if (q.getNpcStart() != null && q.getNpcStart().equals(evt.getNpc().getUUID())) { if (q.getNpcStart() != null && q.getNpcStart().equals(event.getNpc().getUUID())) {
if (plugin.getSettings().canIgnoreLockedQuests() if (plugin.getSettings().canIgnoreLockedQuests()
&& (!quester.getCompletedQuestsTemp().contains(q) && (!quester.getCompletedQuestsTemp().contains(q)
|| q.getPlanner().getCooldown() > -1)) { || q.getPlanner().getCooldown() > -1)) {
@ -237,7 +237,7 @@ public class ZnpcsListener implements Listener {
quester.takeQuest(q, false); quester.takeQuest(q, false);
} else { } else {
if (q.getGUIDisplay() != null) { if (q.getGUIDisplay() != null) {
quester.showGUIDisplay(evt.getNpc().getUUID(), npcQuests); quester.showGUIDisplay(event.getNpc().getUUID(), npcQuests);
} else { } else {
for (final String msg : extracted(quester).split("<br>")) { for (final String msg : extracted(quester).split("<br>")) {
player.sendMessage(msg); player.sendMessage(msg);
@ -248,11 +248,11 @@ public class ZnpcsListener implements Listener {
} }
} else if (npcQuests.size() > 1) { } else if (npcQuests.size() > 1) {
if (hasAtLeastOneGUI) { if (hasAtLeastOneGUI) {
quester.showGUIDisplay(evt.getNpc().getUUID(), npcQuests); quester.showGUIDisplay(event.getNpc().getUUID(), npcQuests);
} else { } else {
final Conversation c = plugin.getNpcConversationFactory().buildConversation(player); final Conversation c = plugin.getNpcConversationFactory().buildConversation(player);
c.getContext().setSessionData("npcQuests", npcQuests); c.getContext().setSessionData("npcQuests", npcQuests);
c.getContext().setSessionData("npc", evt.getNpc().getGameProfile().getName()); c.getContext().setSessionData("npc", event.getNpc().getGameProfile().getName());
c.begin(); c.begin();
} }
} else { } else {