From f176271b8fc5d49b4b03f3d36615652369b12a52 Mon Sep 17 00:00:00 2001 From: PikaMug Date: Thu, 5 Sep 2019 18:16:43 -0400 Subject: [PATCH 01/27] Address issues with party functionality --- .../java/me/blackvein/quests/Quester.java | 14 +- .../quests/listeners/PlayerListener.java | 237 +++++++++++++++++- 2 files changed, 228 insertions(+), 23 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index 64c28dcab..2881810e4 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -1077,18 +1077,6 @@ public class Quester { } } } - - // Multiplayer - if (quest.getOptions().getShareProgressLevel() == 1) { - List mq = getMultiplayerQuesters(quest); - if (mq != null) { - for (Quester q : mq) { - if (q.getCurrentQuests().containsKey(quest)) { - q.breakBlock(quest, m); - } - } - } - } } /** @@ -3125,7 +3113,7 @@ public class Quester { } /** - * Get a list of follow Questers in a party or group + * Get a list of fellow Questers in a party or group * * @param quest The quest which uses a linked plugin, i.e. Parties or DungeonsXL * @return null if quest is null, no linked plugins, or party/group is null diff --git a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index 6dbfdee92..f316805c8 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -16,6 +16,7 @@ import java.io.File; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -208,6 +209,18 @@ public class PlayerListener implements Listener { ItemStack i = new ItemStack(evt.getClickedBlock().getType(), 1, evt.getClickedBlock().getState().getData().toItemStack().getDurability()); quester.useBlock(quest, i); hasObjective = true; + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.useBlock(quest, i); + } + } + } + } } } } @@ -358,6 +371,18 @@ public class PlayerListener implements Listener { } if (quester.containsObjective(quest, "password")) { quester.sayPassword(quest, evt); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.sayPassword(quest, evt); + } + } + } + } } } } @@ -409,6 +434,18 @@ public class PlayerListener implements Listener { if (quester.containsObjective(quest, "damageBlock")) { ItemStack i = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability()); quester.damageBlock(quest, i); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.damageBlock(quest, i); + } + } + } + } } } } @@ -424,6 +461,18 @@ public class PlayerListener implements Listener { if (evt.isCancelled() == false) { ItemStack i = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability()); quester.placeBlock(quest, i); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.placeBlock(quest, i); + } + } + } + } } } } @@ -441,6 +490,18 @@ public class PlayerListener implements Listener { if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false) { ItemStack i = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability()); quester.breakBlock(quest, i); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.breakBlock(quest, i); + } + } + } + } } } if (quester.containsObjective(quest, "placeBlock")) { @@ -456,6 +517,18 @@ public class PlayerListener implements Listener { if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) { ItemStack i = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability()); quester.cutBlock(quest, i); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.cutBlock(quest, i); + } + } + } + } } } } @@ -471,6 +544,18 @@ public class PlayerListener implements Listener { if (evt.getEntity().getType() == EntityType.SHEEP && quester.containsObjective(quest, "shearSheep")) { Sheep sheep = (Sheep) evt.getEntity(); quester.shearSheep(quest, sheep.getColor()); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.shearSheep(quest, sheep.getColor()); + } + } + } + } } } } @@ -485,6 +570,18 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "tameMob")) { quester.tameMob(quest, evt.getEntityType()); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.tameMob(quest, evt.getEntityType()); + } + } + } + } } } } @@ -515,8 +612,32 @@ public class PlayerListener implements Listener { } } quester.craftItem(quest, new ItemStack(result.getType(), numberOfItems, result.getDurability())); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.craftItem(quest, new ItemStack(result.getType(), numberOfItems, result.getDurability())); + } + } + } + } } else { quester.craftItem(quest, evt.getCurrentItem()); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.craftItem(quest, evt.getCurrentItem()); + } + } + } + } } } } @@ -533,6 +654,18 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "smeltItem")) { quester.smeltItem(quest, evt.getCurrentItem()); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.smeltItem(quest, evt.getCurrentItem()); + } + } + } + } } } } @@ -542,6 +675,18 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "brewItem")) { quester.brewItem(quest, evt.getCurrentItem()); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.brewItem(quest, evt.getCurrentItem()); + } + } + } + } } } } @@ -557,6 +702,18 @@ public class PlayerListener implements Listener { if (quester.containsObjective(quest, "enchantItem")) { for (Enchantment e : evt.getEnchantsToAdd().keySet()) { quester.enchantItem(quest, e, evt.getItem().getType()); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.enchantItem(quest, e, evt.getItem().getType()); + } + } + } + } } } } @@ -573,24 +730,24 @@ public class PlayerListener implements Listener { if (damager instanceof Projectile) { Projectile projectile = (Projectile) damager; if (projectile.getShooter() != null && projectile.getShooter() instanceof Entity) { - killMob((Entity)projectile.getShooter(), evt.getEntity()); + preKillMob((Entity)projectile.getShooter(), evt.getEntity()); } } else if (damager instanceof TNTPrimed) { TNTPrimed tnt = (TNTPrimed) damager; Entity source = tnt.getSource(); if (source != null && source.isValid()) { - killMob(source, evt.getEntity()); + preKillMob(source, evt.getEntity()); } } else if (damager instanceof Wolf) { Wolf wolf = (Wolf) damager; if (wolf.isTamed() && wolf.getOwner() != null) { Quester quester = plugin.getQuester(wolf.getOwner().getUniqueId()); if (quester != null) { - killPlayer(quester.getPlayer(), evt.getEntity()); + preKillPlayer(quester.getPlayer(), evt.getEntity()); } } } else { - killMob(damager, evt.getEntity()); + preKillMob(damager, evt.getEntity()); } } } @@ -603,7 +760,7 @@ public class PlayerListener implements Listener { * @param target the entity being attacked * @since 3.1.4 */ - public void killMob(Entity damager, Entity target) { + public void preKillMob(Entity damager, Entity target) { if (!plugin.canUseQuests(damager.getUniqueId())) { return; } @@ -614,6 +771,18 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "killNPC")) { quester.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target)); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target)); + } + } + } + } } } return; @@ -623,6 +792,18 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "killMob")) { quester.killMob(quest, target.getLocation(), target.getType()); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.killMob(quest, target.getLocation(), target.getType()); + } + } + } + } } } } @@ -642,24 +823,24 @@ public class PlayerListener implements Listener { if (damager instanceof Projectile) { Projectile projectile = (Projectile) damager; if (projectile.getShooter() != null && projectile.getShooter() instanceof Entity) { - killPlayer((Entity)projectile.getShooter(), evt.getEntity()); + preKillPlayer((Entity)projectile.getShooter(), evt.getEntity()); } } else if (damager instanceof TNTPrimed) { TNTPrimed tnt = (TNTPrimed) damager; Entity source = tnt.getSource(); if (source != null) { if (source.isValid()) { - killPlayer(source, evt.getEntity()); + preKillPlayer(source, evt.getEntity()); } } } else if (damager instanceof Wolf) { Wolf wolf = (Wolf) damager; if (wolf.isTamed()) { Quester quester = plugin.getQuester(wolf.getOwner().getUniqueId()); - killPlayer(quester.getPlayer(), evt.getEntity()); + preKillPlayer(quester.getPlayer(), evt.getEntity()); } } else { - killPlayer(damager, evt.getEntity()); + preKillPlayer(damager, evt.getEntity()); } } } @@ -695,7 +876,7 @@ public class PlayerListener implements Listener { * @param target the entity being attacked * @since 3.1.4 */ - public void killPlayer(Entity damager, Entity target) { + public void preKillPlayer(Entity damager, Entity target) { if (damager == null) { return; } @@ -712,6 +893,18 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "killPlayer")) { quester.killPlayer(quest, (Player)target); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.killPlayer(quest, (Player)target); + } + } + } + } } } } @@ -725,6 +918,18 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "catchFish") && evt.getState().equals(State.CAUGHT_FISH)) { quester.catchFish(quest); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.catchFish(quest); + } + } + } + } } } } @@ -851,6 +1056,18 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "reachLocation")) { quester.reachLocation(quest, evt.getTo()); + + // Multiplayer + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = quester.getMultiplayerQuesters(quest); + if (mq != null) { + for (Quester q : mq) { + if (q.getCurrentQuests().containsKey(quest)) { + q.reachLocation(quest, evt.getTo()); + } + } + } + } } } } From 3ff05fb5a837d7f81a58b7eb6353f639875bbb7d Mon Sep 17 00:00:00 2001 From: AlessioDP Date: Fri, 6 Sep 2019 11:05:20 +0200 Subject: [PATCH 02/27] Different multiplayer implementation --- .../main/java/me/blackvein/quests/Quest.java | 1514 ++++++------ .../java/me/blackvein/quests/Quester.java | 72 +- .../quests/listeners/PlayerListener.java | 2062 ++++++++--------- 3 files changed, 1786 insertions(+), 1862 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Quest.java b/main/src/main/java/me/blackvein/quests/Quest.java index 6fcd38966..9e74895e9 100644 --- a/main/src/main/java/me/blackvein/quests/Quest.java +++ b/main/src/main/java/me/blackvein/quests/Quest.java @@ -1,758 +1,758 @@ -/******************************************************************************************************* - * 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; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; - -import com.codisimus.plugins.phatloots.PhatLootsAPI; -import com.codisimus.plugins.phatloots.loot.CommandLoot; -import com.codisimus.plugins.phatloots.loot.LootBundle; -import com.gmail.nossr50.datatypes.skills.SkillType; -import com.gmail.nossr50.util.player.UserManager; -import com.herocraftonline.heroes.characters.Hero; - -import me.blackvein.quests.actions.Action; -import me.blackvein.quests.events.quester.QuesterPostChangeStageEvent; -import me.blackvein.quests.events.quester.QuesterPostCompleteQuestEvent; -import me.blackvein.quests.events.quester.QuesterPostFailQuestEvent; -import me.blackvein.quests.events.quester.QuesterPreChangeStageEvent; -import me.blackvein.quests.events.quester.QuesterPreCompleteQuestEvent; -import me.blackvein.quests.events.quester.QuesterPreFailQuestEvent; -import me.blackvein.quests.exceptions.InvalidStageException; -import me.blackvein.quests.util.ItemUtil; -import me.blackvein.quests.util.Lang; -import me.clip.placeholderapi.PlaceholderAPI; -import net.citizensnpcs.api.npc.NPC; - -public class Quest { - - protected Quests plugin; - private String name; - protected String description; - protected String finished; - protected String region = null; - protected ItemStack guiDisplay = null; - private LinkedList orderedStages = new LinkedList(); - protected NPC npcStart; - protected Location blockStart; - protected Action initialAction; - private Requirements reqs = new Requirements(); - private Planner pln = new Planner(); - private Rewards rews = new Rewards(); - private Options opts = new Options(); - - public Requirements getRequirements() { - return reqs; - } - - public Planner getPlanner() { - return pln; - } - - public Rewards getRewards() { - return rews; - } - - public Options getOptions() { - return opts; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getFinished() { - return finished; - } - - public void setFinished(String finished) { - this.finished = finished; - } - - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - - public ItemStack getGUIDisplay() { - return guiDisplay; - } - - public void setGUIDisplay(ItemStack guiDisplay) { - this.guiDisplay = guiDisplay; - } - - public Stage getStage(int index) { - try { - return orderedStages.get(index); - } catch (Exception e) { - return null; - } - } - - public LinkedList getStages() { - return orderedStages; - } - - public NPC getNpcStart() { - return npcStart; - } - - public void setNpcStart(NPC npcStart) { - this.npcStart = npcStart; - } - - public Location getBlockStart() { - return blockStart; - } - - public void setBlockStart(Location blockStart) { - this.blockStart = blockStart; - } - - public Action getInitialAction() { - return initialAction; - } - - public void setInitialAction(Action initialAction) { - this.initialAction = initialAction; - } - - /** - * Force player to proceed to the next ordered stage - * - * @param q Player to force - */ - public void nextStage(Quester q) { - if (q.getCurrentStage(this) == null) { - plugin.getLogger().severe("Current stage was null for quester " + q.getPlayer().getUniqueId()); - return; - } - String stageCompleteMessage = q.getCurrentStage(this).completeMessage; - if (stageCompleteMessage != null) { - q.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageCompleteMessage, this, q.getPlayer())); - } - if (plugin.getSettings().canUseCompass()) { - q.resetCompass(); - q.findCompassTarget(); - } - if (q.getCurrentStage(this).delay < 0) { - if (q.currentQuests.get(this) == (orderedStages.size() - 1)) { - if (q.getCurrentStage(this).script != null) { - plugin.getDenizenTrigger().runDenizenScript(q.getCurrentStage(this).script, q); - } - if (q.getCurrentStage(this).finishEvent != null) { - q.getCurrentStage(this).finishEvent.fire(q, this); - } - completeQuest(q); - } else { - try { - if (q.getCurrentStage(this).finishEvent != null) { - q.getCurrentStage(this).finishEvent.fire(q, this); - } - setStage(q, q.currentQuests.get(this) + 1); - } catch (InvalidStageException e) { - e.printStackTrace(); - } - - // Multiplayer - try { - if (opts.getShareProgressLevel() == 3) { - List mq = q.getMultiplayerQuesters(this); - if (mq != null) { - for (Quester qq : mq) { - if (qq.getCurrentQuests().containsKey(this)) { - setStage(qq, qq.currentQuests.get(this) + 1); - } - } - } - } - } catch (InvalidStageException e) { - e.printStackTrace(); - } - } - if (q.getQuestData(this) != null) { - q.getQuestData(this).delayStartTime = 0; - q.getQuestData(this).delayTimeLeft = -1; - } - } else { - q.startStageTimer(this); - } - q.updateJournal(); - } - - /** - * Force player to proceed to the specified stage - * @param quester Player to force - * @param stage Stage number to specify - * @throws InvalidStageException if stage does not exist - */ - public void setStage(Quester quester, int stage) throws InvalidStageException { - if (orderedStages.size() - 1 < stage) { - throw new InvalidStageException(this, stage); - } - Stage currentStage = quester.getCurrentStage(this); - Stage nextStage = getStage(stage); - QuesterPreChangeStageEvent preEvent = new QuesterPreChangeStageEvent(quester, this, currentStage, nextStage); - plugin.getServer().getPluginManager().callEvent(preEvent); - if (preEvent.isCancelled()) { - return; - } - quester.hardQuit(this); - quester.hardStagePut(this, stage); - quester.addEmptiesFor(this, stage); - if (currentStage.script != null) { - plugin.getDenizenTrigger().runDenizenScript(quester.getCurrentStage(this).script, quester); - } - /* - * if (quester.getCurrentStage(this).finishEvent != null) { quester.getCurrentStage(this).finishEvent.fire(quester); } - */ - if (nextStage.startEvent != null) { - nextStage.startEvent.fire(quester, this); - } - updateCompass(quester, nextStage); - String msg = Lang.get(quester.getPlayer(), "questObjectivesTitle"); - msg = msg.replace("", name); - quester.getPlayer().sendMessage(ChatColor.GOLD + msg); - plugin.showObjectives(this, quester, false); - String stageStartMessage = quester.getCurrentStage(this).startMessage; - if (stageStartMessage != null) { - quester.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageStartMessage, this, quester.getPlayer())); - } - quester.updateJournal(); - QuesterPostChangeStageEvent postEvent = new QuesterPostChangeStageEvent(quester, this, currentStage, nextStage); - plugin.getServer().getPluginManager().callEvent(postEvent); - } - - /** - * Set location-objective target for compass.

- * - * Method may be called as often as needed. - * - * @param quester The quester to have their compass updated - * @param nextStage The stage to process for targets - * @return true if successful - */ - public boolean updateCompass(Quester quester, Stage nextStage) { - if (!plugin.getSettings().canUseCompass()) { - return false; - } - if (quester == null) { - return false; - } - if (nextStage == null) { - return false; - } - Location targetLocation = null; - if (nextStage.citizensToInteract != null && nextStage.citizensToInteract.size() > 0) { - targetLocation = plugin.getNPCLocation(nextStage.citizensToInteract.getFirst()); - } else if (nextStage.citizensToKill != null && nextStage.citizensToKill.size() > 0) { - targetLocation = plugin.getNPCLocation(nextStage.citizensToKill.getFirst()); - } else if (nextStage.locationsToReach != null && nextStage.locationsToReach.size() > 0) { - targetLocation = nextStage.locationsToReach.getFirst(); - } else if (nextStage.itemDeliveryTargets != null && nextStage.itemDeliveryTargets.size() > 0) { - NPC npc = plugin.getDependencies().getCitizens().getNPCRegistry().getById(nextStage.itemDeliveryTargets.getFirst()); - targetLocation = npc.getStoredLocation(); - } - if (targetLocation != null && targetLocation.getWorld() != null) { - if (targetLocation.getWorld().getName().equals(quester.getPlayer().getWorld().getName())) { - quester.getPlayer().setCompassTarget(targetLocation); - } - } - return targetLocation != null; - } - - /** - * Check that a quester has met all Requirements to accept this quest - * - * @param quester The quester to check - * @return true if all Requirements have been met - */ - public boolean testRequirements(Quester quester) { - return testRequirements(quester.getPlayer()); - } - - /** - * Check that a player has met all Requirements to accept this quest - * - * @param player The player to check - * @return true if all Requirements have been met - */ - protected boolean testRequirements(Player player) { - Quester quester = plugin.getQuester(player.getUniqueId()); - if (reqs.getMoney() != 0 && plugin.getDependencies().getVaultEconomy() != null) { - if (plugin.getDependencies().getVaultEconomy().getBalance(Bukkit.getOfflinePlayer(player.getUniqueId())) < reqs.getMoney()) { - return false; - } - } - PlayerInventory inventory = player.getInventory(); - int num = 0; - for (ItemStack is : reqs.getItems()) { - for (ItemStack stack : inventory.getContents()) { - if (stack != null) { - if (ItemUtil.compareItems(is, stack, true) == 0) { - num += stack.getAmount(); - } - } - } - if (num < is.getAmount()) { - return false; - } - num = 0; - } - for (String s : reqs.getPermissions()) { - if (player.hasPermission(s) == false) { - return false; - } - } - for (String s : reqs.getMcmmoSkills()) { - final SkillType st = Quests.getMcMMOSkill(s); - final int lvl = reqs.getMcmmoAmounts().get(reqs.getMcmmoSkills().indexOf(s)); - if (UserManager.getPlayer(player).getProfile().getSkillLevel(st) < lvl) { - return false; - } - } - if (reqs.getHeroesPrimaryClass() != null) { - if (plugin.testPrimaryHeroesClass(reqs.getHeroesPrimaryClass(), player.getUniqueId()) == false) { - return false; - } - } - if (reqs.getHeroesSecondaryClass() != null) { - if (plugin.testSecondaryHeroesClass(reqs.getHeroesSecondaryClass(), player.getUniqueId()) == false) { - return false; - } - } - for (String s : reqs.getCustomRequirements().keySet()) { - CustomRequirement found = null; - for (CustomRequirement cr : plugin.getCustomRequirements()) { - if (cr.getName().equalsIgnoreCase(s)) { - found = cr; - break; - } - } - if (found != null) { - if (found.testRequirement(player, reqs.getCustomRequirements().get(s)) == false) { - return false; - } - } else { - plugin.getLogger().warning("Quester \"" + player.getName() + "\" attempted to take Quest \"" + name + "\", but the Custom Requirement \"" + s - + "\" could not be found. Does it still exist?"); - } - } - if (quester.questPoints < reqs.getQuestPoints()) { - return false; - } - if (quester.completedQuests.containsAll(reqs.getNeededQuests()) == false) { - return false; - } - for (String q : reqs.getBlockQuests()) { - Quest questObject = new Quest(); - questObject.name = q; - if (quester.completedQuests.contains(q) || quester.currentQuests.containsKey(questObject)) { - return false; - } - } - return true; - } - - /** - * Proceed to finish this quest, issuing any rewards - * - * @param q The quester finishing this quest - */ - @SuppressWarnings("deprecation") - public void completeQuest(Quester q) { - QuesterPreCompleteQuestEvent preEvent = new QuesterPreCompleteQuestEvent(q, this); - plugin.getServer().getPluginManager().callEvent(preEvent); - if (preEvent.isCancelled()) { - return; - } - final Player player = plugin.getServer().getPlayer(q.getUUID()); - q.hardQuit(this); - if (!q.completedQuests.contains(name)) { - q.completedQuests.add(name); - } - String none = ChatColor.GRAY + "- (" + Lang.get(player, "none") + ")"; - final String[] ps = plugin.parseStringWithPossibleLineBreaks(ChatColor.AQUA + finished, this, player); - for (Map.Entry entry : q.timers.entrySet()) { - if (entry.getValue().getName().equals(getName())) { - plugin.getServer().getScheduler().cancelTask(entry.getKey()); - q.timers.remove(entry.getKey()); - } - } - Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { - - @Override - public void run() { - player.sendMessage(ps); - } - }, 40); - if (rews.getMoney() > 0 && plugin.getDependencies().getVaultEconomy() != null) { - plugin.getDependencies().getVaultEconomy().depositPlayer(q.getOfflinePlayer(), rews.getMoney()); - none = null; - } - if (pln.getCooldown() > -1) { - q.completedTimes.put(this.name, System.currentTimeMillis()); - if (q.amountsCompleted.containsKey(this.name)) { - q.amountsCompleted.put(this.name, q.amountsCompleted.get(this.name) + 1); - } else { - q.amountsCompleted.put(this.name, 1); - } - } - for (ItemStack i : rews.getItems()) { - try { - Quests.addItem(player, i); - } catch (Exception e) { - plugin.getLogger().severe("Unable to add null reward item to inventory of " - + player.getName() + " upon completion of quest " + name); - player.sendMessage(ChatColor.RED + "Quests encountered a problem with an item. " - + "Please contact an administrator."); - } - none = null; - } - for (String s : rews.getCommands()) { - String temp = s.replace("", player.getName()); - if (plugin.getDependencies().getPlaceholderApi() != null) { - temp = PlaceholderAPI.setPlaceholders(player, temp); - } - final String command = temp; - if (Bukkit.isPrimaryThread()) { - Bukkit.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command); - } else { - Bukkit.getScheduler().runTask(plugin, new Runnable() { - - @Override - public void run() { - Bukkit.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command); - } - }); - } - none = null; - } - for (String s : rews.getPermissions()) { - if (plugin.getDependencies().getVaultPermission() != null) { - plugin.getDependencies().getVaultPermission().playerAdd(player, s); - } - none = null; - } - for (String s : rews.getMcmmoSkills()) { - UserManager.getPlayer(player).getProfile().addLevels(Quests.getMcMMOSkill(s), rews.getMcmmoAmounts().get(rews.getMcmmoSkills().indexOf(s))); - none = null; - } - for (String s : rews.getHeroesClasses()) { - Hero hero = plugin.getHero(player.getUniqueId()); - hero.addExp(rews.getHeroesAmounts().get(rews.getHeroesClasses().indexOf(s)), plugin.getDependencies().getHeroes().getClassManager().getClass(s), player.getLocation()); - none = null; - } - LinkedList phatLootItems = new LinkedList(); - int phatLootExp = 0; - LinkedList phatLootMessages = new LinkedList(); - for (String s : rews.getPhatLoots()) { - LootBundle lb = PhatLootsAPI.getPhatLoot(s).rollForLoot(); - if (lb.getExp() > 0) { - phatLootExp += lb.getExp(); - player.giveExp(lb.getExp()); - } - if (lb.getMoney() > 0) { - if (plugin.getDependencies().getVaultEconomy() != null) { - plugin.getDependencies().getVaultEconomy().depositPlayer(Bukkit.getOfflinePlayer(player.getUniqueId()), lb.getMoney()); - } - } - if (lb.getItemList().isEmpty() == false) { - phatLootItems.addAll(lb.getItemList()); - for (ItemStack is : lb.getItemList()) { - try { - Quests.addItem(player, is); - } catch (Exception e) { - plugin.getLogger().severe("Unable to add PhatLoots item to inventory of " - + player.getName() + " upon completion of quest " + name); - player.sendMessage(ChatColor.RED + "Quests encountered a problem with an item. " - + "Please contact an administrator."); - } - } - } - if (lb.getCommandList().isEmpty() == false) { - for (CommandLoot cl : lb.getCommandList()) { - cl.execute(player); - } - } - if (lb.getMessageList().isEmpty() == false) { - phatLootMessages.addAll(lb.getMessageList()); - } - } - if (rews.getExp() > 0) { - player.giveExp(rews.getExp()); - none = null; - } - String complete = Lang.get(player, "questCompleteTitle"); - complete = complete.replace("", ChatColor.YELLOW + name + ChatColor.GOLD); - player.sendMessage(ChatColor.GOLD + complete); - player.sendMessage(ChatColor.GREEN + Lang.get(player, "questRewardsTitle")); - if (plugin.getSettings().canShowQuestTitles()) { - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "title " + player.getName() - + " title " + "{\"text\":\"" + Lang.get(player, "quest") + " " + Lang.get(player, "complete") + "\",\"color\":\"gold\"}"); - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "title " + player.getName() - + " subtitle " + "{\"text\":\"" + name + "\",\"color\":\"yellow\"}"); - } - if (rews.getQuestPoints() > 0) { - player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getQuestPoints() + " " + Lang.get(player, "questPoints")); - q.questPoints += rews.getQuestPoints(); - none = null; - } - for (ItemStack i : rews.getItems()) { - String text = "error"; - if (i.hasItemMeta() && i.getItemMeta().hasDisplayName()) { - if (i.getEnchantments().isEmpty()) { - text = "- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.GRAY + " x " + i.getAmount(); - } else { - text = "- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName() + ChatColor.RESET; - try { - if (!i.getItemMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS)) { - text += ChatColor.GRAY + " " + Lang.get(player, "with") + ChatColor.DARK_PURPLE; - for (Entry e : i.getEnchantments().entrySet()) { - text += " " + ItemUtil.getPrettyEnchantmentName(e.getKey()) + ":" + e.getValue(); - } - } - } catch (Throwable tr) { - // Do nothing, hasItemFlag() not introduced until 1.8.6 - } - text += ChatColor.GRAY + " x " + i.getAmount(); - } - } else if (i.getDurability() != 0) { - if (i.getEnchantments().isEmpty()) { - text = "- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ":" + i.getDurability() + ChatColor.GRAY + " x " + i.getAmount(); - } else { - text = "- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ":" + i.getDurability() + ChatColor.GRAY + " " + Lang.get(player, "with"); - for (Entry e : i.getEnchantments().entrySet()) { - text += " " + ItemUtil.getPrettyEnchantmentName(e.getKey()) + ":" + e.getValue(); - } - text += ChatColor.GRAY + " x " + i.getAmount(); - } - } else { - if (i.getEnchantments().isEmpty()) { - text = "- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ChatColor.GRAY + " x " + i.getAmount(); - } else { - text = "- " + ChatColor.DARK_GREEN + ItemUtil.getName(i); - try { - if (!i.getItemMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS)) { - text += ChatColor.GRAY + " " + Lang.get(player, "with"); - for (Entry e : i.getEnchantments().entrySet()) { - text += " " + ItemUtil.getPrettyEnchantmentName(e.getKey()) + ":" + e.getValue(); - } - } - } catch (Throwable tr) { - // Do nothing, hasItemFlag() not introduced until 1.8.6 - } - text += ChatColor.GRAY + " x " + i.getAmount(); - } - } - player.sendMessage(text); - none = null; - } - for (ItemStack i : phatLootItems) { - if (i.hasItemMeta() && i.getItemMeta().hasDisplayName()) { - if (i.getEnchantments().isEmpty()) { - player.sendMessage("- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.GRAY + " x " + i.getAmount()); - } else { - player.sendMessage("- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.GRAY + " x " + i.getAmount() + ChatColor.DARK_PURPLE + " " + Lang.get(player, "enchantedItem")); - } - } else if (i.getDurability() != 0) { - if (i.getEnchantments().isEmpty()) { - player.sendMessage("- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ":" + i.getDurability() + ChatColor.GRAY + " x " + i.getAmount()); - } else { - player.sendMessage("- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ":" + i.getDurability() + ChatColor.GRAY + " x " + i.getAmount() + ChatColor.DARK_PURPLE + " " + Lang.get(player, "enchantedItem")); - } - } else { - if (i.getEnchantments().isEmpty()) { - player.sendMessage("- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ChatColor.GRAY + " x " + i.getAmount()); - } else { - player.sendMessage("- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ChatColor.GRAY + " x " + i.getAmount() + ChatColor.DARK_PURPLE + " " + Lang.get(player, "enchantedItem")); - } - } - none = null; - } - if (rews.getMoney() > 1) { - player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getMoney() + " " + ChatColor.DARK_PURPLE + plugin.getCurrency(true)); - none = null; - } else if (rews.getMoney() == 1) { - player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getMoney() + " " + ChatColor.DARK_PURPLE + plugin.getCurrency(false)); - none = null; - } - if (rews.getExp() > 0 || phatLootExp > 0) { - int tot = rews.getExp() + phatLootExp; - player.sendMessage("- " + ChatColor.DARK_GREEN + tot + ChatColor.DARK_PURPLE + " " + Lang.get(player, "experience")); - none = null; - } - if (rews.getCommands().isEmpty() == false) { - int index = 0; - for (String s : rews.getCommands()) { - if (rews.getCommandsOverrideDisplay().isEmpty() == false && rews.getCommandsOverrideDisplay().size() >= index) { - if (rews.getCommandsOverrideDisplay().size() > index) { - if (!rews.getCommandsOverrideDisplay().get(index).trim().equals("")) { - player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getCommandsOverrideDisplay().get(index)); - } - } - } else { - player.sendMessage("- " + ChatColor.DARK_GREEN + s); - } - index++; - } - none = null; - } - if (rews.getMcmmoSkills().isEmpty() == false) { - for (String s : rews.getMcmmoSkills()) { - player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getMcmmoAmounts().get(rews.getMcmmoSkills().indexOf(s)) + " " + ChatColor.DARK_PURPLE + s + " " + Lang.get(player, "experience")); - } - none = null; - } - if (rews.getHeroesClasses().isEmpty() == false) { - for (String s : rews.getHeroesClasses()) { - player.sendMessage("- " + ChatColor.AQUA + rews.getHeroesAmounts().get(rews.getHeroesClasses().indexOf(s)) + " " + ChatColor.BLUE + s + " " + Lang.get(player, "experience")); - } - none = null; - } - if (phatLootMessages.isEmpty() == false) { - for (String s : phatLootMessages) { - player.sendMessage("- " + s); - } - none = null; - } - for (String s : rews.getCustomRewards().keySet()) { - CustomReward found = null; - for (CustomReward cr : plugin.getCustomRewards()) { - if (cr.getName().equalsIgnoreCase(s)) { - found = cr; - break; - } - } - if (found != null) { - Map datamap = rews.getCustomRewards().get(found.getName()); - String message = found.getRewardName(); - if (message != null) { - for (String key : datamap.keySet()) { - message = message.replace("%" + key + "%", datamap.get(key).toString()); - } - player.sendMessage("- " + ChatColor.GOLD + message); - } else { - plugin.getLogger().warning("Failed to notify player: Custom Reward does not have an assigned name"); - } - found.giveReward(player, rews.getCustomRewards().get(s)); - } else { - plugin.getLogger().warning("Quester \"" + player.getName() + "\" completed the Quest \"" + name + "\", but the Custom Reward \"" + s + "\" could not be found. Does it still exist?"); - } - none = null; - } - if (none != null) { - player.sendMessage(none); - } - q.saveData(); - player.updateInventory(); - q.updateJournal(); - q.findCompassTarget(); - QuesterPostCompleteQuestEvent postEvent = new QuesterPostCompleteQuestEvent(q, this); - plugin.getServer().getPluginManager().callEvent(postEvent); - - // Multiplayer - if (opts.getShareProgressLevel() == 4) { - List mq = q.getMultiplayerQuesters(this); - if (mq != null) { - for (Quester qq : mq) { - if (qq.getCurrentQuests().containsKey(this)) { - completeQuest(qq); - } - } - } - } - } - - /** - * Force player to quit quest and inform them of their failure - * - * @param q The player to ejected - */ - @SuppressWarnings("deprecation") - public void failQuest(Quester q) { - QuesterPreFailQuestEvent preEvent = new QuesterPreFailQuestEvent(q, this); - plugin.getServer().getPluginManager().callEvent(preEvent); - if (preEvent.isCancelled()) { - return; - } - if (plugin.getServer().getPlayer(q.getUUID()) != null) { - Player player = plugin.getServer().getPlayer(q.getUUID()); - player.sendMessage(ChatColor.GOLD + Lang.get(player, "questObjectivesTitle").replace("", name)); - player.sendMessage(ChatColor.RED + Lang.get(player, "questFailed")); - q.hardQuit(this); - q.saveData(); - player.updateInventory(); - } else { - q.hardQuit(this); - q.saveData(); - } - q.updateJournal(); - QuesterPostFailQuestEvent postEvent = new QuesterPostFailQuestEvent(q, this); - plugin.getServer().getPluginManager().callEvent(postEvent); - } - - /** - * Checks if quester is in WorldGuard region - * - * @param quester The quester to check - * @return true if quester is in region - */ - public boolean isInRegion(Quester quester) { - return isInRegion(quester.getPlayer()); - } - - /** - * Checks if player is in WorldGuard region - * - * @param player The player to check - * @return true if player is in region - */ - private boolean isInRegion(Player player) { - if (region == null) { - return false; - } - if (plugin.getDependencies().getWorldGuardApi().getApplicableRegionsIDs(player.getWorld(), player.getLocation()).contains(region)) { - return true; - } - return false; - } +/******************************************************************************************************* + * 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; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import com.codisimus.plugins.phatloots.PhatLootsAPI; +import com.codisimus.plugins.phatloots.loot.CommandLoot; +import com.codisimus.plugins.phatloots.loot.LootBundle; +import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.util.player.UserManager; +import com.herocraftonline.heroes.characters.Hero; + +import me.blackvein.quests.actions.Action; +import me.blackvein.quests.events.quester.QuesterPostChangeStageEvent; +import me.blackvein.quests.events.quester.QuesterPostCompleteQuestEvent; +import me.blackvein.quests.events.quester.QuesterPostFailQuestEvent; +import me.blackvein.quests.events.quester.QuesterPreChangeStageEvent; +import me.blackvein.quests.events.quester.QuesterPreCompleteQuestEvent; +import me.blackvein.quests.events.quester.QuesterPreFailQuestEvent; +import me.blackvein.quests.exceptions.InvalidStageException; +import me.blackvein.quests.util.ItemUtil; +import me.blackvein.quests.util.Lang; +import me.clip.placeholderapi.PlaceholderAPI; +import net.citizensnpcs.api.npc.NPC; + +public class Quest { + + protected Quests plugin; + private String name; + protected String description; + protected String finished; + protected String region = null; + protected ItemStack guiDisplay = null; + private LinkedList orderedStages = new LinkedList(); + protected NPC npcStart; + protected Location blockStart; + protected Action initialAction; + private Requirements reqs = new Requirements(); + private Planner pln = new Planner(); + private Rewards rews = new Rewards(); + private Options opts = new Options(); + + public Requirements getRequirements() { + return reqs; + } + + public Planner getPlanner() { + return pln; + } + + public Rewards getRewards() { + return rews; + } + + public Options getOptions() { + return opts; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getFinished() { + return finished; + } + + public void setFinished(String finished) { + this.finished = finished; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + + public ItemStack getGUIDisplay() { + return guiDisplay; + } + + public void setGUIDisplay(ItemStack guiDisplay) { + this.guiDisplay = guiDisplay; + } + + public Stage getStage(int index) { + try { + return orderedStages.get(index); + } catch (Exception e) { + return null; + } + } + + public LinkedList getStages() { + return orderedStages; + } + + public NPC getNpcStart() { + return npcStart; + } + + public void setNpcStart(NPC npcStart) { + this.npcStart = npcStart; + } + + public Location getBlockStart() { + return blockStart; + } + + public void setBlockStart(Location blockStart) { + this.blockStart = blockStart; + } + + public Action getInitialAction() { + return initialAction; + } + + public void setInitialAction(Action initialAction) { + this.initialAction = initialAction; + } + + /** + * Force player to proceed to the next ordered stage + * + * @param q Player to force + */ + public void nextStage(Quester q) { + if (q.getCurrentStage(this) == null) { + plugin.getLogger().severe("Current stage was null for quester " + q.getPlayer().getUniqueId()); + return; + } + String stageCompleteMessage = q.getCurrentStage(this).completeMessage; + if (stageCompleteMessage != null) { + q.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageCompleteMessage, this, q.getPlayer())); + } + if (plugin.getSettings().canUseCompass()) { + q.resetCompass(); + q.findCompassTarget(); + } + if (q.getCurrentStage(this).delay < 0) { + if (q.currentQuests.get(this) == (orderedStages.size() - 1)) { + if (q.getCurrentStage(this).script != null) { + plugin.getDenizenTrigger().runDenizenScript(q.getCurrentStage(this).script, q); + } + if (q.getCurrentStage(this).finishEvent != null) { + q.getCurrentStage(this).finishEvent.fire(q, this); + } + completeQuest(q); + } else { + try { + if (q.getCurrentStage(this).finishEvent != null) { + q.getCurrentStage(this).finishEvent.fire(q, this); + } + setStage(q, q.currentQuests.get(this) + 1); + } catch (InvalidStageException e) { + e.printStackTrace(); + } + + // Multiplayer + try { + if (opts.getShareProgressLevel() == 3) { + List mq = q.getMultiplayerQuesters(); + if (mq != null) { + for (Quester qq : mq) { + if (qq.getCurrentQuests().containsKey(this)) { + setStage(qq, qq.currentQuests.get(this) + 1); + } + } + } + } + } catch (InvalidStageException e) { + e.printStackTrace(); + } + } + if (q.getQuestData(this) != null) { + q.getQuestData(this).delayStartTime = 0; + q.getQuestData(this).delayTimeLeft = -1; + } + } else { + q.startStageTimer(this); + } + q.updateJournal(); + } + + /** + * Force player to proceed to the specified stage + * @param quester Player to force + * @param stage Stage number to specify + * @throws InvalidStageException if stage does not exist + */ + public void setStage(Quester quester, int stage) throws InvalidStageException { + if (orderedStages.size() - 1 < stage) { + throw new InvalidStageException(this, stage); + } + Stage currentStage = quester.getCurrentStage(this); + Stage nextStage = getStage(stage); + QuesterPreChangeStageEvent preEvent = new QuesterPreChangeStageEvent(quester, this, currentStage, nextStage); + plugin.getServer().getPluginManager().callEvent(preEvent); + if (preEvent.isCancelled()) { + return; + } + quester.hardQuit(this); + quester.hardStagePut(this, stage); + quester.addEmptiesFor(this, stage); + if (currentStage.script != null) { + plugin.getDenizenTrigger().runDenizenScript(quester.getCurrentStage(this).script, quester); + } + /* + * if (quester.getCurrentStage(this).finishEvent != null) { quester.getCurrentStage(this).finishEvent.fire(quester); } + */ + if (nextStage.startEvent != null) { + nextStage.startEvent.fire(quester, this); + } + updateCompass(quester, nextStage); + String msg = Lang.get(quester.getPlayer(), "questObjectivesTitle"); + msg = msg.replace("", name); + quester.getPlayer().sendMessage(ChatColor.GOLD + msg); + plugin.showObjectives(this, quester, false); + String stageStartMessage = quester.getCurrentStage(this).startMessage; + if (stageStartMessage != null) { + quester.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageStartMessage, this, quester.getPlayer())); + } + quester.updateJournal(); + QuesterPostChangeStageEvent postEvent = new QuesterPostChangeStageEvent(quester, this, currentStage, nextStage); + plugin.getServer().getPluginManager().callEvent(postEvent); + } + + /** + * Set location-objective target for compass.

+ * + * Method may be called as often as needed. + * + * @param quester The quester to have their compass updated + * @param nextStage The stage to process for targets + * @return true if successful + */ + public boolean updateCompass(Quester quester, Stage nextStage) { + if (!plugin.getSettings().canUseCompass()) { + return false; + } + if (quester == null) { + return false; + } + if (nextStage == null) { + return false; + } + Location targetLocation = null; + if (nextStage.citizensToInteract != null && nextStage.citizensToInteract.size() > 0) { + targetLocation = plugin.getNPCLocation(nextStage.citizensToInteract.getFirst()); + } else if (nextStage.citizensToKill != null && nextStage.citizensToKill.size() > 0) { + targetLocation = plugin.getNPCLocation(nextStage.citizensToKill.getFirst()); + } else if (nextStage.locationsToReach != null && nextStage.locationsToReach.size() > 0) { + targetLocation = nextStage.locationsToReach.getFirst(); + } else if (nextStage.itemDeliveryTargets != null && nextStage.itemDeliveryTargets.size() > 0) { + NPC npc = plugin.getDependencies().getCitizens().getNPCRegistry().getById(nextStage.itemDeliveryTargets.getFirst()); + targetLocation = npc.getStoredLocation(); + } + if (targetLocation != null && targetLocation.getWorld() != null) { + if (targetLocation.getWorld().getName().equals(quester.getPlayer().getWorld().getName())) { + quester.getPlayer().setCompassTarget(targetLocation); + } + } + return targetLocation != null; + } + + /** + * Check that a quester has met all Requirements to accept this quest + * + * @param quester The quester to check + * @return true if all Requirements have been met + */ + public boolean testRequirements(Quester quester) { + return testRequirements(quester.getPlayer()); + } + + /** + * Check that a player has met all Requirements to accept this quest + * + * @param player The player to check + * @return true if all Requirements have been met + */ + protected boolean testRequirements(Player player) { + Quester quester = plugin.getQuester(player.getUniqueId()); + if (reqs.getMoney() != 0 && plugin.getDependencies().getVaultEconomy() != null) { + if (plugin.getDependencies().getVaultEconomy().getBalance(Bukkit.getOfflinePlayer(player.getUniqueId())) < reqs.getMoney()) { + return false; + } + } + PlayerInventory inventory = player.getInventory(); + int num = 0; + for (ItemStack is : reqs.getItems()) { + for (ItemStack stack : inventory.getContents()) { + if (stack != null) { + if (ItemUtil.compareItems(is, stack, true) == 0) { + num += stack.getAmount(); + } + } + } + if (num < is.getAmount()) { + return false; + } + num = 0; + } + for (String s : reqs.getPermissions()) { + if (player.hasPermission(s) == false) { + return false; + } + } + for (String s : reqs.getMcmmoSkills()) { + final SkillType st = Quests.getMcMMOSkill(s); + final int lvl = reqs.getMcmmoAmounts().get(reqs.getMcmmoSkills().indexOf(s)); + if (UserManager.getPlayer(player).getProfile().getSkillLevel(st) < lvl) { + return false; + } + } + if (reqs.getHeroesPrimaryClass() != null) { + if (plugin.testPrimaryHeroesClass(reqs.getHeroesPrimaryClass(), player.getUniqueId()) == false) { + return false; + } + } + if (reqs.getHeroesSecondaryClass() != null) { + if (plugin.testSecondaryHeroesClass(reqs.getHeroesSecondaryClass(), player.getUniqueId()) == false) { + return false; + } + } + for (String s : reqs.getCustomRequirements().keySet()) { + CustomRequirement found = null; + for (CustomRequirement cr : plugin.getCustomRequirements()) { + if (cr.getName().equalsIgnoreCase(s)) { + found = cr; + break; + } + } + if (found != null) { + if (found.testRequirement(player, reqs.getCustomRequirements().get(s)) == false) { + return false; + } + } else { + plugin.getLogger().warning("Quester \"" + player.getName() + "\" attempted to take Quest \"" + name + "\", but the Custom Requirement \"" + s + + "\" could not be found. Does it still exist?"); + } + } + if (quester.questPoints < reqs.getQuestPoints()) { + return false; + } + if (quester.completedQuests.containsAll(reqs.getNeededQuests()) == false) { + return false; + } + for (String q : reqs.getBlockQuests()) { + Quest questObject = new Quest(); + questObject.name = q; + if (quester.completedQuests.contains(q) || quester.currentQuests.containsKey(questObject)) { + return false; + } + } + return true; + } + + /** + * Proceed to finish this quest, issuing any rewards + * + * @param q The quester finishing this quest + */ + @SuppressWarnings("deprecation") + public void completeQuest(Quester q) { + QuesterPreCompleteQuestEvent preEvent = new QuesterPreCompleteQuestEvent(q, this); + plugin.getServer().getPluginManager().callEvent(preEvent); + if (preEvent.isCancelled()) { + return; + } + final Player player = plugin.getServer().getPlayer(q.getUUID()); + q.hardQuit(this); + if (!q.completedQuests.contains(name)) { + q.completedQuests.add(name); + } + String none = ChatColor.GRAY + "- (" + Lang.get(player, "none") + ")"; + final String[] ps = plugin.parseStringWithPossibleLineBreaks(ChatColor.AQUA + finished, this, player); + for (Map.Entry entry : q.timers.entrySet()) { + if (entry.getValue().getName().equals(getName())) { + plugin.getServer().getScheduler().cancelTask(entry.getKey()); + q.timers.remove(entry.getKey()); + } + } + Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { + + @Override + public void run() { + player.sendMessage(ps); + } + }, 40); + if (rews.getMoney() > 0 && plugin.getDependencies().getVaultEconomy() != null) { + plugin.getDependencies().getVaultEconomy().depositPlayer(q.getOfflinePlayer(), rews.getMoney()); + none = null; + } + if (pln.getCooldown() > -1) { + q.completedTimes.put(this.name, System.currentTimeMillis()); + if (q.amountsCompleted.containsKey(this.name)) { + q.amountsCompleted.put(this.name, q.amountsCompleted.get(this.name) + 1); + } else { + q.amountsCompleted.put(this.name, 1); + } + } + for (ItemStack i : rews.getItems()) { + try { + Quests.addItem(player, i); + } catch (Exception e) { + plugin.getLogger().severe("Unable to add null reward item to inventory of " + + player.getName() + " upon completion of quest " + name); + player.sendMessage(ChatColor.RED + "Quests encountered a problem with an item. " + + "Please contact an administrator."); + } + none = null; + } + for (String s : rews.getCommands()) { + String temp = s.replace("", player.getName()); + if (plugin.getDependencies().getPlaceholderApi() != null) { + temp = PlaceholderAPI.setPlaceholders(player, temp); + } + final String command = temp; + if (Bukkit.isPrimaryThread()) { + Bukkit.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command); + } else { + Bukkit.getScheduler().runTask(plugin, new Runnable() { + + @Override + public void run() { + Bukkit.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command); + } + }); + } + none = null; + } + for (String s : rews.getPermissions()) { + if (plugin.getDependencies().getVaultPermission() != null) { + plugin.getDependencies().getVaultPermission().playerAdd(player, s); + } + none = null; + } + for (String s : rews.getMcmmoSkills()) { + UserManager.getPlayer(player).getProfile().addLevels(Quests.getMcMMOSkill(s), rews.getMcmmoAmounts().get(rews.getMcmmoSkills().indexOf(s))); + none = null; + } + for (String s : rews.getHeroesClasses()) { + Hero hero = plugin.getHero(player.getUniqueId()); + hero.addExp(rews.getHeroesAmounts().get(rews.getHeroesClasses().indexOf(s)), plugin.getDependencies().getHeroes().getClassManager().getClass(s), player.getLocation()); + none = null; + } + LinkedList phatLootItems = new LinkedList(); + int phatLootExp = 0; + LinkedList phatLootMessages = new LinkedList(); + for (String s : rews.getPhatLoots()) { + LootBundle lb = PhatLootsAPI.getPhatLoot(s).rollForLoot(); + if (lb.getExp() > 0) { + phatLootExp += lb.getExp(); + player.giveExp(lb.getExp()); + } + if (lb.getMoney() > 0) { + if (plugin.getDependencies().getVaultEconomy() != null) { + plugin.getDependencies().getVaultEconomy().depositPlayer(Bukkit.getOfflinePlayer(player.getUniqueId()), lb.getMoney()); + } + } + if (lb.getItemList().isEmpty() == false) { + phatLootItems.addAll(lb.getItemList()); + for (ItemStack is : lb.getItemList()) { + try { + Quests.addItem(player, is); + } catch (Exception e) { + plugin.getLogger().severe("Unable to add PhatLoots item to inventory of " + + player.getName() + " upon completion of quest " + name); + player.sendMessage(ChatColor.RED + "Quests encountered a problem with an item. " + + "Please contact an administrator."); + } + } + } + if (lb.getCommandList().isEmpty() == false) { + for (CommandLoot cl : lb.getCommandList()) { + cl.execute(player); + } + } + if (lb.getMessageList().isEmpty() == false) { + phatLootMessages.addAll(lb.getMessageList()); + } + } + if (rews.getExp() > 0) { + player.giveExp(rews.getExp()); + none = null; + } + String complete = Lang.get(player, "questCompleteTitle"); + complete = complete.replace("", ChatColor.YELLOW + name + ChatColor.GOLD); + player.sendMessage(ChatColor.GOLD + complete); + player.sendMessage(ChatColor.GREEN + Lang.get(player, "questRewardsTitle")); + if (plugin.getSettings().canShowQuestTitles()) { + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "title " + player.getName() + + " title " + "{\"text\":\"" + Lang.get(player, "quest") + " " + Lang.get(player, "complete") + "\",\"color\":\"gold\"}"); + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "title " + player.getName() + + " subtitle " + "{\"text\":\"" + name + "\",\"color\":\"yellow\"}"); + } + if (rews.getQuestPoints() > 0) { + player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getQuestPoints() + " " + Lang.get(player, "questPoints")); + q.questPoints += rews.getQuestPoints(); + none = null; + } + for (ItemStack i : rews.getItems()) { + String text = "error"; + if (i.hasItemMeta() && i.getItemMeta().hasDisplayName()) { + if (i.getEnchantments().isEmpty()) { + text = "- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.GRAY + " x " + i.getAmount(); + } else { + text = "- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName() + ChatColor.RESET; + try { + if (!i.getItemMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS)) { + text += ChatColor.GRAY + " " + Lang.get(player, "with") + ChatColor.DARK_PURPLE; + for (Entry e : i.getEnchantments().entrySet()) { + text += " " + ItemUtil.getPrettyEnchantmentName(e.getKey()) + ":" + e.getValue(); + } + } + } catch (Throwable tr) { + // Do nothing, hasItemFlag() not introduced until 1.8.6 + } + text += ChatColor.GRAY + " x " + i.getAmount(); + } + } else if (i.getDurability() != 0) { + if (i.getEnchantments().isEmpty()) { + text = "- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ":" + i.getDurability() + ChatColor.GRAY + " x " + i.getAmount(); + } else { + text = "- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ":" + i.getDurability() + ChatColor.GRAY + " " + Lang.get(player, "with"); + for (Entry e : i.getEnchantments().entrySet()) { + text += " " + ItemUtil.getPrettyEnchantmentName(e.getKey()) + ":" + e.getValue(); + } + text += ChatColor.GRAY + " x " + i.getAmount(); + } + } else { + if (i.getEnchantments().isEmpty()) { + text = "- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ChatColor.GRAY + " x " + i.getAmount(); + } else { + text = "- " + ChatColor.DARK_GREEN + ItemUtil.getName(i); + try { + if (!i.getItemMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS)) { + text += ChatColor.GRAY + " " + Lang.get(player, "with"); + for (Entry e : i.getEnchantments().entrySet()) { + text += " " + ItemUtil.getPrettyEnchantmentName(e.getKey()) + ":" + e.getValue(); + } + } + } catch (Throwable tr) { + // Do nothing, hasItemFlag() not introduced until 1.8.6 + } + text += ChatColor.GRAY + " x " + i.getAmount(); + } + } + player.sendMessage(text); + none = null; + } + for (ItemStack i : phatLootItems) { + if (i.hasItemMeta() && i.getItemMeta().hasDisplayName()) { + if (i.getEnchantments().isEmpty()) { + player.sendMessage("- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.GRAY + " x " + i.getAmount()); + } else { + player.sendMessage("- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.GRAY + " x " + i.getAmount() + ChatColor.DARK_PURPLE + " " + Lang.get(player, "enchantedItem")); + } + } else if (i.getDurability() != 0) { + if (i.getEnchantments().isEmpty()) { + player.sendMessage("- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ":" + i.getDurability() + ChatColor.GRAY + " x " + i.getAmount()); + } else { + player.sendMessage("- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ":" + i.getDurability() + ChatColor.GRAY + " x " + i.getAmount() + ChatColor.DARK_PURPLE + " " + Lang.get(player, "enchantedItem")); + } + } else { + if (i.getEnchantments().isEmpty()) { + player.sendMessage("- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ChatColor.GRAY + " x " + i.getAmount()); + } else { + player.sendMessage("- " + ChatColor.DARK_GREEN + ItemUtil.getName(i) + ChatColor.GRAY + " x " + i.getAmount() + ChatColor.DARK_PURPLE + " " + Lang.get(player, "enchantedItem")); + } + } + none = null; + } + if (rews.getMoney() > 1) { + player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getMoney() + " " + ChatColor.DARK_PURPLE + plugin.getCurrency(true)); + none = null; + } else if (rews.getMoney() == 1) { + player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getMoney() + " " + ChatColor.DARK_PURPLE + plugin.getCurrency(false)); + none = null; + } + if (rews.getExp() > 0 || phatLootExp > 0) { + int tot = rews.getExp() + phatLootExp; + player.sendMessage("- " + ChatColor.DARK_GREEN + tot + ChatColor.DARK_PURPLE + " " + Lang.get(player, "experience")); + none = null; + } + if (rews.getCommands().isEmpty() == false) { + int index = 0; + for (String s : rews.getCommands()) { + if (rews.getCommandsOverrideDisplay().isEmpty() == false && rews.getCommandsOverrideDisplay().size() >= index) { + if (rews.getCommandsOverrideDisplay().size() > index) { + if (!rews.getCommandsOverrideDisplay().get(index).trim().equals("")) { + player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getCommandsOverrideDisplay().get(index)); + } + } + } else { + player.sendMessage("- " + ChatColor.DARK_GREEN + s); + } + index++; + } + none = null; + } + if (rews.getMcmmoSkills().isEmpty() == false) { + for (String s : rews.getMcmmoSkills()) { + player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getMcmmoAmounts().get(rews.getMcmmoSkills().indexOf(s)) + " " + ChatColor.DARK_PURPLE + s + " " + Lang.get(player, "experience")); + } + none = null; + } + if (rews.getHeroesClasses().isEmpty() == false) { + for (String s : rews.getHeroesClasses()) { + player.sendMessage("- " + ChatColor.AQUA + rews.getHeroesAmounts().get(rews.getHeroesClasses().indexOf(s)) + " " + ChatColor.BLUE + s + " " + Lang.get(player, "experience")); + } + none = null; + } + if (phatLootMessages.isEmpty() == false) { + for (String s : phatLootMessages) { + player.sendMessage("- " + s); + } + none = null; + } + for (String s : rews.getCustomRewards().keySet()) { + CustomReward found = null; + for (CustomReward cr : plugin.getCustomRewards()) { + if (cr.getName().equalsIgnoreCase(s)) { + found = cr; + break; + } + } + if (found != null) { + Map datamap = rews.getCustomRewards().get(found.getName()); + String message = found.getRewardName(); + if (message != null) { + for (String key : datamap.keySet()) { + message = message.replace("%" + key + "%", datamap.get(key).toString()); + } + player.sendMessage("- " + ChatColor.GOLD + message); + } else { + plugin.getLogger().warning("Failed to notify player: Custom Reward does not have an assigned name"); + } + found.giveReward(player, rews.getCustomRewards().get(s)); + } else { + plugin.getLogger().warning("Quester \"" + player.getName() + "\" completed the Quest \"" + name + "\", but the Custom Reward \"" + s + "\" could not be found. Does it still exist?"); + } + none = null; + } + if (none != null) { + player.sendMessage(none); + } + q.saveData(); + player.updateInventory(); + q.updateJournal(); + q.findCompassTarget(); + QuesterPostCompleteQuestEvent postEvent = new QuesterPostCompleteQuestEvent(q, this); + plugin.getServer().getPluginManager().callEvent(postEvent); + + // Multiplayer + if (opts.getShareProgressLevel() == 4) { + List mq = q.getMultiplayerQuesters(); + if (mq != null) { + for (Quester qq : mq) { + if (qq.getCurrentQuests().containsKey(this)) { + completeQuest(qq); + } + } + } + } + } + + /** + * Force player to quit quest and inform them of their failure + * + * @param q The player to ejected + */ + @SuppressWarnings("deprecation") + public void failQuest(Quester q) { + QuesterPreFailQuestEvent preEvent = new QuesterPreFailQuestEvent(q, this); + plugin.getServer().getPluginManager().callEvent(preEvent); + if (preEvent.isCancelled()) { + return; + } + if (plugin.getServer().getPlayer(q.getUUID()) != null) { + Player player = plugin.getServer().getPlayer(q.getUUID()); + player.sendMessage(ChatColor.GOLD + Lang.get(player, "questObjectivesTitle").replace("", name)); + player.sendMessage(ChatColor.RED + Lang.get(player, "questFailed")); + q.hardQuit(this); + q.saveData(); + player.updateInventory(); + } else { + q.hardQuit(this); + q.saveData(); + } + q.updateJournal(); + QuesterPostFailQuestEvent postEvent = new QuesterPostFailQuestEvent(q, this); + plugin.getServer().getPluginManager().callEvent(postEvent); + } + + /** + * Checks if quester is in WorldGuard region + * + * @param quester The quester to check + * @return true if quester is in region + */ + public boolean isInRegion(Quester quester) { + return isInRegion(quester.getPlayer()); + } + + /** + * Checks if player is in WorldGuard region + * + * @param player The player to check + * @return true if player is in region + */ + private boolean isInRegion(Player player) { + if (region == null) { + return false; + } + if (plugin.getDependencies().getWorldGuardApi().getApplicableRegionsIDs(player.getWorld(), player.getLocation()).contains(region)) { + return true; + } + return false; + } } \ No newline at end of file diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index 2881810e4..cd5cfe801 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -26,6 +26,7 @@ import java.util.Random; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.BiFunction; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -1669,7 +1670,7 @@ public class Quester { * Mark location as reached if the Quester has such an objective * * @param quest The quest for which the location is being reached - * @param n The location being reached + * @param l The location being reached */ public void reachLocation(Quest quest, Location l) { if (getQuestData(quest).locationsReached == null) { @@ -1980,7 +1981,7 @@ public class Quester { // Multiplayer if (quest.getOptions().getShareProgressLevel() == 2) { - List mq = getMultiplayerQuesters(quest); + List mq = getMultiplayerQuesters(); if (mq != null) { for (Quester q : mq) { if (q.getCurrentQuests().containsKey(quest)) { @@ -3113,41 +3114,52 @@ public class Quester { } /** - * Get a list of fellow Questers in a party or group - * - * @param quest The quest which uses a linked plugin, i.e. Parties or DungeonsXL - * @return null if quest is null, no linked plugins, or party/group is null + * Dispatch any event to the right quest if multiplayer enabled + * + * @param eventName The event name + * @param fun The function to execute, the event call */ - public List getMultiplayerQuesters(Quest quest) { - if (quest == null) { - return null; - } - if (plugin.getDependencies().getPartiesApi() != null) { - if (quest.getOptions().getUsePartiesPlugin()) { - Party party = plugin.getDependencies().getPartiesApi().getParty(plugin.getDependencies().getPartiesApi().getPartyPlayer(getUUID()).getPartyName()); - if (party != null) { - List mq = new LinkedList(); - for (UUID id : party.getMembers()) { - if (!id.equals(getUUID())) { - mq.add(plugin.getQuester(id)); - } + public void dispatchMultiplayerEvent(String eventName, BiFunction fun) { + List mq = getMultiplayerQuesters(); + if (mq != null) { + for (Quester q : mq) { + for (Quest quest : q.getCurrentQuests().keySet()) { + if (q.containsObjective(quest, eventName) && quest.getOptions().getShareProgressLevel() == 1) { + fun.apply(q, quest); } - return mq; } } } - if (plugin.getDependencies().getDungeonsApi() != null) { - if (quest.getOptions().getUseDungeonsXLPlugin()) { - DGroup group = DGroup.getByPlayer(getPlayer()); - if (group != null) { - List mq = new LinkedList(); - for (UUID id : group.getPlayers()) { - if (!id.equals(getUUID())) { - mq.add(plugin.getQuester(id)); - } + } + + /** + * Get a list of fellow Questers in a party or group + * + * @return null if no linked plugins, or party/group is null + */ + public List getMultiplayerQuesters() { + if (plugin.getDependencies().getPartiesApi() != null) { + Party party = plugin.getDependencies().getPartiesApi().getParty(plugin.getDependencies().getPartiesApi().getPartyPlayer(getUUID()).getPartyName()); + if (party != null) { + List mq = new LinkedList(); + for (UUID id : party.getMembers()) { + if (!id.equals(getUUID())) { + mq.add(plugin.getQuester(id)); } - return mq; } + return mq; + } + } + if (plugin.getDependencies().getDungeonsApi() != null) { + DGroup group = DGroup.getByPlayer(getPlayer()); + if (group != null) { + List mq = new LinkedList(); + for (UUID id : group.getPlayers()) { + if (!id.equals(getUUID())) { + mq.add(plugin.getQuester(id)); + } + } + return mq; } } return null; diff --git a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index f316805c8..ee8fe3e2e 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -1,1076 +1,988 @@ -/******************************************************************************************************* - * 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.listeners; - -import java.io.File; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.entity.Sheep; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.entity.Wolf; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockDamageEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.enchantment.EnchantItemEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityTameEvent; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.inventory.CraftItemEvent; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.inventory.InventoryType.SlotType; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerChangedWorldEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerFishEvent; -import org.bukkit.event.player.PlayerFishEvent.State; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerShearEntityEvent; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; - -import me.blackvein.quests.Quest; -import me.blackvein.quests.Quester; -import me.blackvein.quests.Quests; -import me.blackvein.quests.Stage; -import me.blackvein.quests.util.ItemUtil; -import me.blackvein.quests.util.Lang; -import net.citizensnpcs.api.CitizensAPI; - -public class PlayerListener implements Listener { - - final Quests plugin; - - public PlayerListener(Quests newPlugin) { - plugin = newPlugin; - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onInventoryClickEvent(InventoryClickEvent evt) { - InventoryAction ac = evt.getAction(); - if (ItemUtil.isItem(evt.getCurrentItem()) && ItemUtil.isJournal(evt.getCurrentItem())) { - if (ac.equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) || ac.equals(InventoryAction.DROP_ALL_SLOT) || ac.equals(InventoryAction.DROP_ONE_SLOT)) { - evt.setCancelled(true); - return; - } - } else if (ItemUtil.isItem(evt.getCurrentItem()) && ItemUtil.isJournal(evt.getCursor())) { - if (ac.equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) || ac.equals(InventoryAction.DROP_ALL_CURSOR) || ac.equals(InventoryAction.DROP_ONE_CURSOR)) { - evt.setCancelled(true); - return; - } - } - if (ItemUtil.isItem(evt.getCurrentItem()) && ItemUtil.isJournal(evt.getCurrentItem()) || ItemUtil.isItem(evt.getCursor()) && ItemUtil.isJournal(evt.getCursor())) { - int upper = evt.getView().getTopInventory().getSize(); - if (evt.getView().getTopInventory().getType().equals(InventoryType.CRAFTING)) - upper += 4; - int lower = evt.getView().getBottomInventory().getSize(); - int relative = evt.getRawSlot() - upper; - if (relative < 0 || relative >= (lower)) { - evt.setCancelled(true); - return; - } - } - Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId()); - Player player = (Player) evt.getWhoClicked(); - if (evt.getView().getTitle().contains(Lang.get(player, "quests"))) { - ItemStack clicked = evt.getCurrentItem(); - if (clicked != null) { - for (Quest quest : plugin.getQuests()) { - if (quest.getGUIDisplay() != null) { - if (ItemUtil.compareItems(clicked, quest.getGUIDisplay(), false) == 0) { - if (quester.getCurrentQuests().size() >= plugin.getSettings().getMaxQuests() && plugin.getSettings().getMaxQuests() > 0) { - String msg = Lang.get(player, "questMaxAllowed"); - msg = msg.replace("", String.valueOf(plugin.getSettings().getMaxQuests())); - player.sendMessage(ChatColor.YELLOW + msg); - } else if (quester.getCompletedQuests().contains(quest.getName()) && quest.getPlanner().getCooldown() < 0) { - String completed = Lang.get(player, "questAlreadyCompleted"); - completed = completed.replace("", ChatColor.AQUA + quest.getName() + ChatColor.YELLOW); - player.sendMessage(ChatColor.YELLOW + completed); - } else { - boolean takeable = true; - if (quester.getCompletedQuests().contains(quest.getName())) { - if (quester.getCooldownDifference(quest) > 0) { - String early = Lang.get(player, "questTooEarly"); - early = early.replace("", ChatColor.AQUA + quest.getName() + ChatColor.YELLOW); - early = early.replace("

* * Accepted strings are: breakBlock, damageBlock, placeBlock, useBlock, - * cutBlock, catchFish, enchantItem, killMob, deliverItem, killPlayer, - * talkToNPC, killNPC, tameMob, shearSheep, password, reachLocation + * cutBlock, craftItem, smeltItem, enchantItem, brewItem, catchFish, + * killMob, deliverItem, killPlayer, talkToNPC, killNPC, tameMob, + * shearSheep, password, reachLocation * * @deprecated Use containsObjective() instead * @param quest The quest to check objectives of @@ -950,8 +951,9 @@ public class Quester { * Check if player's current stage has the specified objective

* * Accepted strings are: breakBlock, damageBlock, placeBlock, useBlock, - * cutBlock, catchFish, enchantItem, killMob, deliverItem, killPlayer, - * talkToNPC, killNPC, tameMob, shearSheep, password, reachLocation + * cutBlock, craftItem, smeltItem, enchantItem, brewItem, catchFish, + * killMob, deliverItem, killPlayer, talkToNPC, killNPC, tameMob, + * shearSheep, password, reachLocation * * @param quest The quest to check objectives of * @param s The type of objective to check for @@ -1080,7 +1082,7 @@ public class Quester { // Multiplayer final ItemStack finalBroken = broken; final ItemStack finalToBreak = toBreak; - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).blocksBroken.set(getQuestData(quest).blocksBroken.indexOf(finalBroken), newBroken); q.finishObjective(quest, "breakBlock", m, finalToBreak, null, null, null, null, null, null, null, null); return null; @@ -1145,7 +1147,7 @@ public class Quester { // Multiplayer final ItemStack finalDamaged = damaged; final ItemStack finalToDamage = toDamage; - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).blocksDamaged.set(getQuestData(quest).blocksDamaged.indexOf(finalDamaged), newDamaged); q.finishObjective(quest, "damageBlock", m, finalToDamage, null, null, null, null, null, null, null, null); return null; @@ -1210,7 +1212,7 @@ public class Quester { // Multiplayer final ItemStack finalPlaced = placed; final ItemStack finalToPlace = toPlace; - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).blocksPlaced.set(getQuestData(quest).blocksPlaced.indexOf(finalPlaced), newplaced); q.finishObjective(quest, "damageBlock", m, finalToPlace, null, null, null, null, null, null, null, null); return null; @@ -1275,7 +1277,7 @@ public class Quester { // Multiplayer final ItemStack finalUsed = used; final ItemStack finalToUse = toUse; - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).blocksUsed.set(getQuestData(quest).blocksUsed.indexOf(finalUsed), newUsed); q.finishObjective(quest, "useBlock", m, finalToUse, null, null, null, null, null, null, null, null); return null; @@ -1340,7 +1342,7 @@ public class Quester { // Multiplayer final ItemStack finalCut = cut; final ItemStack finalToCut = toCut; - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).blocksCut.set(getQuestData(quest).blocksCut.indexOf(finalCut), newCut); q.finishObjective(quest, "cutBlock", m, finalToCut, null, null, null, null, null, null, null, null); return null; @@ -1383,7 +1385,7 @@ public class Quester { // Multiplayer final ItemStack finalFound = found; - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).itemsCrafted.put(finalFound, req); q.finishObjective(quest, "craftItem", new ItemStack(m, 1), finalFound, null, null, null, null, null, null, null, null); return null; @@ -1428,7 +1430,7 @@ public class Quester { // Multiplayer final ItemStack finalFound = found; - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).itemsSmelted.put(finalFound, req); q.finishObjective(quest, "smeltItem", new ItemStack(m, 1), finalFound, null, null, null, null, null, null, null, null); return null; @@ -1461,7 +1463,7 @@ public class Quester { finishObjective(quest, "enchantItem", new ItemStack(m, 1), finalToEnchant, e, null, null, null, null, null, null, null); // Multiplayer - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).itemsEnchanted.put(entry.getKey(), num); q.finishObjective(quest, "enchantItem", new ItemStack(m, 1), finalToEnchant, null, null, null, null, null, null, null, null); return null; @@ -1509,7 +1511,7 @@ public class Quester { // Multiplayer final ItemStack finalFound = found; - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).itemsBrewed.put(finalFound, req); q.finishObjective(quest, "brewItem", new ItemStack(m, 1), finalFound, null, null, null, null, null, null, null, null); return null; @@ -1535,7 +1537,7 @@ public class Quester { finishObjective(quest, "catchFish", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, fishToCatch), null, null, null, null, null, null, null, null); // Multiplayer - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).setFishCaught(fishToCatch); q.finishObjective(quest, "catchFish", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, fishToCatch), null, null, null, null, null, null, null, null); return null; @@ -1589,7 +1591,7 @@ public class Quester { new ItemStack(Material.AIR, numberOfSpecificMobNeedsToBeKilledInCurrentStage), null, e, null, null, null, null, null, null); // Multiplayer - dispatchMultiplayerEventShareObjective(quest, currentStage, (Quester q) -> { + dispatchMultiplayerObjectives(quest, currentStage, (Quester q) -> { q.getQuestData(quest).mobNumKilled.set(indexOfMobKilled, newNumberOfSpecificMobKilled); q.finishObjective(quest, "killMob", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, numberOfSpecificMobNeedsToBeKilledInCurrentStage), null, e, null, null, null, null, null, null); @@ -1613,7 +1615,7 @@ public class Quester { finishObjective(quest, "killPlayer", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, playersToKill), null, null, null, null, null, null, null, null); // Multiplayer - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).setPlayersKilled(getQuestData(quest).getPlayersKilled()); q.finishObjective(quest, "killPlayer", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, playersToKill), null, null, null, null, null, null, null, null); return null; @@ -1671,7 +1673,7 @@ public class Quester { finishObjective(quest, "deliverItem", new ItemStack(m, 1), found, null, null, null, null, null, null, null, null); // Multiplayer - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).itemsDelivered.put(found, req); q.finishObjective(quest, "deliverItem", new ItemStack(m, 1), found, null, null, null, null, null, null, null, null); return null; @@ -1732,7 +1734,7 @@ public class Quester { // Multiplayer final ItemStack finalFound = found; - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).itemsDelivered.put(finalFound, req); q.finishObjective(quest, "deliverItem", new ItemStack(m, 1), finalFound, null, null, null, null, null, null, null, null); return null; @@ -1764,7 +1766,7 @@ public class Quester { finishObjective(quest, "talkToNPC", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), null, null, null, n, null, null, null, null); // Multiplayer - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).citizensInteracted.put(n.getId(), true); q.finishObjective(quest, "talkToNPC", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), null, null, null, n, null, null, null, null); return null; @@ -1789,7 +1791,7 @@ public class Quester { finishObjective(quest, "killNPC", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, npcsToKill), null, null, null, n, null, null, null, null); // Multiplayer - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).citizenNumKilled.set(index, getQuestData(quest).citizenNumKilled.get(index)); q.finishObjective(quest, "killNPC", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, npcsToKill), null, null, null, n, null, null, null, null); return null; @@ -1834,7 +1836,7 @@ public class Quester { // Multiplayer final int finalIndex = index; - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { if (finalIndex >= getQuestData(quest).hasReached.size()) { q.getQuestData(quest).hasReached.add(true); } else { @@ -1874,7 +1876,7 @@ public class Quester { finishObjective(quest, "tameMob", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, mobsToTame), null, entity, null, null, null, null, null, null); // Multiplayer - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).mobsTamed.put(entity, getQuestData(quest).mobsTamed.get(entity)); q.finishObjective(quest, "tameMob", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, mobsToTame), null, entity, null, null, null, null, null, null); return null; @@ -1897,7 +1899,7 @@ public class Quester { finishObjective(quest, "shearSheep", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, sheepToShear), null, null, null, null, null, color, null, null); // Multiplayer - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).sheepSheared.put(color, getQuestData(quest).sheepSheared.get(color)); q.finishObjective(quest, "shearSheep", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, sheepToShear), null, null, null, null, null, color, null, null); return null; @@ -1926,7 +1928,7 @@ public class Quester { finishObjective(quest, "password", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), null, null, null, null, null, null, display, null); // Multiplayer - dispatchMultiplayerEventShareObjective(quest, getCurrentStage(quest), (Quester q) -> { + dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (Quester q) -> { q.getQuestData(quest).passwordsSaid.put(display, true); q.finishObjective(quest, "password", new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1), null, null, null, null, null, null, display, null); return null; @@ -3266,16 +3268,21 @@ public class Quester { } /** - * Dispatch any event to the right quest if multiplayer enabled + * Dispatch player event to fellow questers

+ * + * Accepted strings are: breakBlock, damageBlock, placeBlock, useBlock, + * cutBlock, craftItem, smeltItem, enchantItem, brewItem, catchFish, + * killMob, deliverItem, killPlayer, talkToNPC, killNPC, tameMob, + * shearSheep, password, reachLocation * - * @param eventName the event name - * @param fun the function to execute, the event call + * @param objectiveType The type of objective to progress + * @param fun The function to execute, the event call */ - public void dispatchMultiplayerEvent(String eventName, BiFunction fun) { + public void dispatchMultiplayerEverything(String objectiveType, BiFunction fun) { Map mq = getMultiplayerQuesters(); for (Entry q : mq.entrySet()) { for (Quest quest : q.getKey().getCurrentQuests().keySet()) { - if (q.getKey().containsObjective(quest, eventName) + if (q.getKey().containsObjective(quest, objectiveType) && quest.getOptions().getShareProgressLevel() == 1 && ((quest.getOptions().getUsePartiesPlugin() && q.getValue().parties) || (quest.getOptions().getUseDungeonsXLPlugin() && q.getValue().dungeonxl))) { @@ -3286,13 +3293,13 @@ public class Quester { } /** - * Dispatch a finish objective multiplayer event + * Dispatch finish objective to fellow questers * - * @param quest the current quest - * @param currentStage the current stage of the quest - * @param fun the function to execute, the event call + * @param quest The current quest + * @param currentStage The current stage of the quest + * @param fun The function to execute, the event call */ - public void dispatchMultiplayerEventShareObjective(Quest quest, Stage currentStage, Function fun) { + public void dispatchMultiplayerObjectives(Quest quest, Stage currentStage, Function fun) { if (quest.getOptions().getShareProgressLevel() == 2) { List mq = getMultiplayerQuestersByQuest(quest); for (Quester q : mq) { diff --git a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index 844f06fd3..dfc1329ae 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -213,7 +213,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("useBlock", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("useBlock", (Quester q, Quest quest) -> { q.useBlock(quest, blockItemStack); return null; }); @@ -369,7 +369,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("password", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("password", (Quester q, Quest quest) -> { q.sayPassword(quest, evt); return null; }); @@ -427,7 +427,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("placeBlock", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("placeBlock", (Quester q, Quest quest) -> { q.placeBlock(quest, blockItemStack); return null; }); @@ -450,7 +450,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("placeBlock", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("placeBlock", (Quester q, Quest quest) -> { q.placeBlock(quest, blockItemStack); return null; }); @@ -489,13 +489,13 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("breakBlock", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("breakBlock", (Quester q, Quest quest) -> { if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false) { q.breakBlock(quest, blockItemStack); } return null; }); - quester.dispatchMultiplayerEvent("placeBlock", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("placeBlock", (Quester q, Quest quest) -> { for (ItemStack is : q.getQuestData(quest).blocksPlaced) { if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) { int index = q.getQuestData(quest).blocksPlaced.indexOf(is); @@ -505,7 +505,7 @@ public class PlayerListener implements Listener { } return null; }); - quester.dispatchMultiplayerEvent("cutBlock", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("cutBlock", (Quester q, Quest quest) -> { if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) { q.cutBlock(quest, blockItemStack); } @@ -527,7 +527,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("shearSheep", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("shearSheep", (Quester q, Quest quest) -> { q.shearSheep(quest, sheep.getColor()); return null; }); @@ -548,7 +548,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("tameMob", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("tameMob", (Quester q, Quest quest) -> { q.tameMob(quest, evt.getEntityType()); return null; }); @@ -571,7 +571,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("craftItem", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("craftItem", (Quester q, Quest quest) -> { q.craftItem(quest, craftedItem); return null; }); @@ -615,7 +615,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("smeltItem", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("smeltItem", (Quester q, Quest quest) -> { q.smeltItem(quest, evt.getCurrentItem()); return null; }); @@ -630,7 +630,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("brewItem", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("brewItem", (Quester q, Quest quest) -> { q.brewItem(quest, evt.getCurrentItem()); return null; }); @@ -652,7 +652,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("enchantItem", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("enchantItem", (Quester q, Quest quest) -> { for (Enchantment e : evt.getEnchantsToAdd().keySet()) { q.enchantItem(quest, e, evt.getItem().getType()); } @@ -716,7 +716,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("killNPC", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("killNPC", (Quester q, Quest quest) -> { q.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target)); return null; }); @@ -731,7 +731,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("killMob", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("killMob", (Quester q, Quest quest) -> { q.killMob(quest, target.getLocation(), target.getType()); return null; }); @@ -826,7 +826,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("killPlayer", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("killPlayer", (Quester q, Quest quest) -> { q.killPlayer(quest, (Player)target); return null; }); @@ -845,7 +845,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("catchFish", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("catchFish", (Quester q, Quest quest) -> { q.catchFish(quest); return null; }); @@ -977,7 +977,7 @@ public class PlayerListener implements Listener { } // Multiplayer - quester.dispatchMultiplayerEvent("reachLocation", (Quester q, Quest quest) -> { + quester.dispatchMultiplayerEverything("reachLocation", (Quester q, Quest quest) -> { q.reachLocation(quest, evt.getTo()); return null; }); From cad906965aef5c99641a0d244b84c75d9677b1a4 Mon Sep 17 00:00:00 2001 From: PikaMug Date: Fri, 13 Sep 2019 11:13:01 -0400 Subject: [PATCH 18/27] Add option for fellow party members to receive progress outside quest --- .../java/me/blackvein/quests/Options.java | 9 + .../main/java/me/blackvein/quests/Quest.java | 4 +- .../me/blackvein/quests/QuestFactory.java | 6 + .../java/me/blackvein/quests/Quester.java | 73 ++++-- .../main/java/me/blackvein/quests/Quests.java | 3 + .../quests/listeners/PlayerListener.java | 235 +++++++++--------- .../quests/prompts/OptionsPrompt.java | 18 +- .../java/me/blackvein/quests/util/CK.java | 1 + main/src/main/resources/strings.yml | 1 + 9 files changed, 214 insertions(+), 136 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Options.java b/main/src/main/java/me/blackvein/quests/Options.java index f559231c7..2f3dd8158 100644 --- a/main/src/main/java/me/blackvein/quests/Options.java +++ b/main/src/main/java/me/blackvein/quests/Options.java @@ -18,6 +18,7 @@ public class Options { private boolean useDungeonsXLPlugin = false; private boolean usePartiesPlugin = true; private int shareProgressLevel = 1; + private boolean requireSameQuest = true; public boolean getAllowCommands() { return allowCommands; @@ -58,4 +59,12 @@ public class Options { public void setShareProgressLevel(int shareProgressLevel) { this.shareProgressLevel = shareProgressLevel; } + + public boolean getRequireSameQuest() { + return requireSameQuest; + } + + public void setRequireSameQuest(boolean requireSameQuest) { + this.requireSameQuest = requireSameQuest; + } } \ No newline at end of file diff --git a/main/src/main/java/me/blackvein/quests/Quest.java b/main/src/main/java/me/blackvein/quests/Quest.java index 1a0a3f926..b88d4f9d8 100644 --- a/main/src/main/java/me/blackvein/quests/Quest.java +++ b/main/src/main/java/me/blackvein/quests/Quest.java @@ -208,7 +208,7 @@ public class Quest { // Multiplayer if (opts.getShareProgressLevel() == 3) { - List mq = quester.getMultiplayerQuestersByQuest(this); + List mq = quester.getMultiplayerQuesters(this); for (Quester qq : mq) { if (currentStage.equals(qq.getCurrentStage(this))) { nextStage(qq, allowSharedProgress); @@ -694,7 +694,7 @@ public class Quest { // Multiplayer if (opts.getShareProgressLevel() == 4) { - List mq = q.getMultiplayerQuestersByQuest(this); + List mq = q.getMultiplayerQuesters(this); for (Quester qq : mq) { completeQuest(qq); } diff --git a/main/src/main/java/me/blackvein/quests/QuestFactory.java b/main/src/main/java/me/blackvein/quests/QuestFactory.java index eea29a726..eb1a20034 100644 --- a/main/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/main/src/main/java/me/blackvein/quests/QuestFactory.java @@ -999,6 +999,7 @@ public class QuestFactory implements ConversationAbandonedListener { boolean useDungeonsXLPluginOpt = false; boolean usePartiesPluginOpt = true; Integer shareProgressLevelOpt = 1; + boolean requireSameQuestOpt = true; if (cc.getSessionData(CK.Q_START_NPC) != null) { npcStart = (Integer) cc.getSessionData(CK.Q_START_NPC); } @@ -1129,6 +1130,9 @@ public class QuestFactory implements ConversationAbandonedListener { if (cc.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL) != null) { shareProgressLevelOpt = (Integer) cc.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL); } + if (cc.getSessionData(CK.OPT_USE_PARTIES_PLUGIN) != null) { + requireSameQuestOpt = (Boolean) cc.getSessionData(CK.OPT_REQUIRE_SAME_QUEST); + } cs.set("name", name); cs.set("npc-giver-id", npcStart); cs.set("block-start", blockStart); @@ -1593,6 +1597,7 @@ public class QuestFactory implements ConversationAbandonedListener { sch.set("use-dungeonsxl-plugin", useDungeonsXLPluginOpt); sch.set("use-parties-plugin", usePartiesPluginOpt); sch.set("share-progress-level", shareProgressLevelOpt); + sch.set("require-same-quest", requireSameQuestOpt); } @SuppressWarnings("deprecation") @@ -1713,6 +1718,7 @@ public class QuestFactory implements ConversationAbandonedListener { cc.setSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN, opt.getUseDungeonsXLPlugin()); cc.setSessionData(CK.OPT_USE_PARTIES_PLUGIN, opt.getUsePartiesPlugin()); cc.setSessionData(CK.OPT_SHARE_PROGRESS_LEVEL, opt.getShareProgressLevel()); + cc.setSessionData(CK.OPT_REQUIRE_SAME_QUEST, opt.getRequireSameQuest()); // Stages (Objectives) int index = 1; for (Stage stage : q.getStages()) { diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index 611431a94..a86f8d10a 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -26,7 +26,6 @@ import java.util.Random; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import java.util.function.BiFunction; import java.util.function.Function; import org.bukkit.Bukkit; @@ -3278,16 +3277,14 @@ public class Quester { * @param objectiveType The type of objective to progress * @param fun The function to execute, the event call */ - public void dispatchMultiplayerEverything(String objectiveType, BiFunction fun) { - Map mq = getMultiplayerQuesters(); - for (Entry q : mq.entrySet()) { - for (Quest quest : q.getKey().getCurrentQuests().keySet()) { - if (q.getKey().containsObjective(quest, objectiveType) - && quest.getOptions().getShareProgressLevel() == 1 - && ((quest.getOptions().getUsePartiesPlugin() && q.getValue().parties) - || (quest.getOptions().getUseDungeonsXLPlugin() && q.getValue().dungeonxl))) { - fun.apply(q.getKey(), quest); + public void dispatchMultiplayerEverything(Quest quest, String objectiveType, Function fun) { + if (quest.getOptions().getShareProgressLevel() == 1) { + List mq = getMultiplayerQuesters(quest); + for (Quester q : mq) { + if (q.containsObjective(quest, objectiveType) || !quest.getOptions().getRequireSameQuest()) { + fun.apply(q); } + } } } @@ -3301,9 +3298,10 @@ public class Quester { */ public void dispatchMultiplayerObjectives(Quest quest, Stage currentStage, Function fun) { if (quest.getOptions().getShareProgressLevel() == 2) { - List mq = getMultiplayerQuestersByQuest(quest); + List mq = getMultiplayerQuesters(quest); for (Quester q : mq) { - if (q.getCurrentQuests().containsKey(quest) && currentStage.equals(q.getCurrentStage(quest))) { + if ((q.getCurrentQuests().containsKey(quest) && currentStage.equals(q.getCurrentStage(quest))) + || !quest.getOptions().getRequireSameQuest()) { fun.apply(q); } } @@ -3315,7 +3313,7 @@ public class Quester { * * @return empty if no linked plugins, or party/group is null */ - public Map getMultiplayerQuesters() { + /*public Map getMultiplayerQuesters() { Map ret = new LinkedHashMap<>(); if (plugin.getDependencies().getPartiesApi() != null) { Party party = plugin.getDependencies().getPartiesApi().getParty(plugin.getDependencies().getPartiesApi().getPartyPlayer(getUUID()).getPartyName()); @@ -3342,7 +3340,7 @@ public class Quester { } } return ret; - } + }*/ /** * Get a map of fellow Questers in a party or group @@ -3351,7 +3349,7 @@ public class Quester { * @param quest the quest to check * @return empty if no linked plugins, or party/group is null */ - public List getMultiplayerQuestersByQuest(Quest quest) { + /*public List getMultiplayerQuestersByQuest(Quest quest) { List ret = new LinkedList<>(); Map mq = getMultiplayerQuesters(); for (Entry q : mq.entrySet()) { @@ -3364,9 +3362,9 @@ public class Quester { } return ret; - } + }*/ - public class MultiplayerType { + /*public class MultiplayerType { public boolean parties; public boolean dungeonxl; @@ -3374,6 +3372,47 @@ public class Quester { this.parties = parties; this.dungeonxl = dungeonxl; } + }*/ + + /** + * Get a list of follow Questers in a party or group + * + * @param quest The quest which uses a linked plugin, i.e. Parties or DungeonsXL + * @return null if quest is null, no linked plugins, or party/group is null + */ + public List getMultiplayerQuesters(Quest quest) { + if (quest == null) { + return null; + } + if (plugin.getDependencies().getPartiesApi() != null) { + if (quest.getOptions().getUsePartiesPlugin()) { + Party party = plugin.getDependencies().getPartiesApi().getParty(plugin.getDependencies().getPartiesApi().getPartyPlayer(getUUID()).getPartyName()); + if (party != null) { + List mq = new LinkedList(); + for (UUID id : party.getMembers()) { + if (!id.equals(getUUID())) { + mq.add(plugin.getQuester(id)); + } + } + return mq; + } + } + } + if (plugin.getDependencies().getDungeonsApi() != null) { + if (quest.getOptions().getUseDungeonsXLPlugin()) { + DGroup group = DGroup.getByPlayer(getPlayer()); + if (group != null) { + List mq = new LinkedList(); + for (UUID id : group.getPlayers()) { + if (!id.equals(getUUID())) { + mq.add(plugin.getQuester(id)); + } + } + return mq; + } + } + } + return null; } /** diff --git a/main/src/main/java/me/blackvein/quests/Quests.java b/main/src/main/java/me/blackvein/quests/Quests.java index d40f069bc..71e66a16e 100644 --- a/main/src/main/java/me/blackvein/quests/Quests.java +++ b/main/src/main/java/me/blackvein/quests/Quests.java @@ -1946,6 +1946,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener if (config.contains("quests." + questKey + ".options.share-progress-level")) { opts.setShareProgressLevel(config.getInt("quests." + questKey + ".options.share-progress-level")); } + if (config.contains("quests." + questKey + ".options.require-same-quest")) { + opts.setRequireSameQuest(config.getBoolean("quests." + questKey + ".options.require-same-quest")); + } } private void skipQuestProcess(String[] msgs) throws SkipQuest { diff --git a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index dfc1329ae..1eb98948e 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -1,4 +1,5 @@ /******************************************************************************************************* + * 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 @@ -209,14 +210,14 @@ public class PlayerListener implements Listener { if (quester.containsObjective(quest, "useBlock")) { quester.useBlock(quest, blockItemStack); hasObjective = true; + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "useBlock", (Quester q) -> { + q.useBlock(quest, blockItemStack); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("useBlock", (Quester q, Quest quest) -> { - q.useBlock(quest, blockItemStack); - return null; - }); } if (!hasObjective) { if (plugin.getQuestFactory().getSelectedBlockStarts().containsKey(evt.getPlayer().getUniqueId())) { @@ -365,14 +366,14 @@ public class PlayerListener implements Listener { } if (quester.containsObjective(quest, "password")) { quester.sayPassword(quest, evt); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "password", (Quester q) -> { + q.sayPassword(quest, evt); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("password", (Quester q, Quest quest) -> { - q.sayPassword(quest, evt); - return null; - }); } } } @@ -423,14 +424,14 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "damageBlock")) { quester.damageBlock(quest, blockItemStack); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> { + q.placeBlock(quest, blockItemStack); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("placeBlock", (Quester q, Quest quest) -> { - q.placeBlock(quest, blockItemStack); - return null; - }); } } @@ -445,15 +446,15 @@ public class PlayerListener implements Listener { if (quester.containsObjective(quest, "placeBlock")) { if (evt.isCancelled() == false) { quester.placeBlock(quest, blockItemStack); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> { + q.placeBlock(quest, blockItemStack); + return null; + }); } } } - - // Multiplayer - quester.dispatchMultiplayerEverything("placeBlock", (Quester q, Quest quest) -> { - q.placeBlock(quest, blockItemStack); - return null; - }); } } @@ -469,6 +470,14 @@ public class PlayerListener implements Listener { if (quester.containsObjective(quest, "breakBlock")) { if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false) { quester.breakBlock(quest, blockItemStack); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "breakBlock", (Quester q) -> { + if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false) { + q.breakBlock(quest, blockItemStack); + } + return null; + }); } } if (quester.containsObjective(quest, "placeBlock")) { @@ -477,40 +486,36 @@ public class PlayerListener implements Listener { int index = quester.getQuestData(quest).blocksPlaced.indexOf(is); is.setAmount(is.getAmount() - 1); quester.getQuestData(quest).blocksPlaced.set(index, is); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> { + for (ItemStack is2 : q.getQuestData(quest).blocksPlaced) { + if (evt.getBlock().getType().equals(is2.getType()) && is2.getAmount() > 0) { + int index2 = q.getQuestData(quest).blocksPlaced.indexOf(is2); + is2.setAmount(is2.getAmount() - 1); + q.getQuestData(quest).blocksPlaced.set(index2, is2); + } + } + return null; + }); } } } if (quester.containsObjective(quest, "cutBlock")) { if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) { quester.cutBlock(quest, blockItemStack); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "cutBlock", (Quester q) -> { + if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) { + q.cutBlock(quest, blockItemStack); + } + return null; + }); } } } } - - // Multiplayer - quester.dispatchMultiplayerEverything("breakBlock", (Quester q, Quest quest) -> { - if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false) { - q.breakBlock(quest, blockItemStack); - } - return null; - }); - quester.dispatchMultiplayerEverything("placeBlock", (Quester q, Quest quest) -> { - for (ItemStack is : q.getQuestData(quest).blocksPlaced) { - if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) { - int index = q.getQuestData(quest).blocksPlaced.indexOf(is); - is.setAmount(is.getAmount() - 1); - q.getQuestData(quest).blocksPlaced.set(index, is); - } - } - return null; - }); - quester.dispatchMultiplayerEverything("cutBlock", (Quester q, Quest quest) -> { - if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) { - q.cutBlock(quest, blockItemStack); - } - return null; - }); } } @@ -523,14 +528,14 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "shearSheep")) { quester.shearSheep(quest, sheep.getColor()); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "shearSheep", (Quester q) -> { + q.shearSheep(quest, sheep.getColor()); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("shearSheep", (Quester q, Quest quest) -> { - q.shearSheep(quest, sheep.getColor()); - return null; - }); } } } @@ -544,14 +549,14 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "tameMob")) { quester.tameMob(quest, evt.getEntityType()); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "tameMob", (Quester q) -> { + q.tameMob(quest, evt.getEntityType()); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("tameMob", (Quester q, Quest quest) -> { - q.tameMob(quest, evt.getEntityType()); - return null; - }); } } } @@ -567,14 +572,14 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "craftItem")) { quester.craftItem(quest, craftedItem); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "craftItem", (Quester q) -> { + q.craftItem(quest, craftedItem); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("craftItem", (Quester q, Quest quest) -> { - q.craftItem(quest, craftedItem); - return null; - }); } } } @@ -611,14 +616,14 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "smeltItem")) { quester.smeltItem(quest, evt.getCurrentItem()); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "smeltItem", (Quester q) -> { + q.smeltItem(quest, evt.getCurrentItem()); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("smeltItem", (Quester q, Quest quest) -> { - q.smeltItem(quest, evt.getCurrentItem()); - return null; - }); } } else if (evt.getInventory().getType() == InventoryType.BREWING) { if (evt.getSlotType() == SlotType.CRAFTING) { @@ -626,14 +631,14 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "brewItem")) { quester.brewItem(quest, evt.getCurrentItem()); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "brewItem", (Quester q) -> { + q.brewItem(quest, evt.getCurrentItem()); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("brewItem", (Quester q, Quest quest) -> { - q.brewItem(quest, evt.getCurrentItem()); - return null; - }); } } } @@ -647,17 +652,15 @@ public class PlayerListener implements Listener { if (quester.containsObjective(quest, "enchantItem")) { for (Enchantment e : evt.getEnchantsToAdd().keySet()) { quester.enchantItem(quest, e, evt.getItem().getType()); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "enchantItem", (Quester q) -> { + q.enchantItem(quest, e, evt.getItem().getType()); + return null; + }); } } } - - // Multiplayer - quester.dispatchMultiplayerEverything("enchantItem", (Quester q, Quest quest) -> { - for (Enchantment e : evt.getEnchantsToAdd().keySet()) { - q.enchantItem(quest, e, evt.getItem().getType()); - } - return null; - }); } } @@ -712,14 +715,14 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "killNPC")) { quester.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target)); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "killNPC", (Quester q) -> { + q.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target)); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("killNPC", (Quester q, Quest quest) -> { - q.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target)); - return null; - }); return; } } @@ -727,14 +730,14 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "killMob")) { quester.killMob(quest, target.getLocation(), target.getType()); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "killMob", (Quester q) -> { + q.killMob(quest, target.getLocation(), target.getType()); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("killMob", (Quester q, Quest quest) -> { - q.killMob(quest, target.getLocation(), target.getType()); - return null; - }); } } @@ -822,14 +825,14 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "killPlayer")) { quester.killPlayer(quest, (Player)target); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "killPlayer", (Quester q) -> { + q.killPlayer(quest, (Player)target); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("killPlayer", (Quester q, Quest quest) -> { - q.killPlayer(quest, (Player)target); - return null; - }); } } @@ -841,14 +844,14 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "catchFish") && evt.getState().equals(State.CAUGHT_FISH)) { quester.catchFish(quest); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "catchFish", (Quester q) -> { + q.catchFish(quest); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("catchFish", (Quester q, Quest quest) -> { - q.catchFish(quest); - return null; - }); } } @@ -973,14 +976,14 @@ public class PlayerListener implements Listener { for (Quest quest : quester.getCurrentQuests().keySet()) { if (quester.containsObjective(quest, "reachLocation")) { quester.reachLocation(quest, evt.getTo()); + + // Multiplayer + quester.dispatchMultiplayerEverything(quest, "reachLocation", (Quester q) -> { + q.reachLocation(quest, evt.getTo()); + return null; + }); } } - - // Multiplayer - quester.dispatchMultiplayerEverything("reachLocation", (Quester q, Quest quest) -> { - q.reachLocation(quest, evt.getTo()); - return null; - }); } } } diff --git a/main/src/main/java/me/blackvein/quests/prompts/OptionsPrompt.java b/main/src/main/java/me/blackvein/quests/prompts/OptionsPrompt.java index 179f30d86..37713ed9a 100644 --- a/main/src/main/java/me/blackvein/quests/prompts/OptionsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/prompts/OptionsPrompt.java @@ -339,7 +339,7 @@ public class OptionsPrompt extends NumericPrompt { public class MultiplayerPrompt extends NumericPrompt { - private final int size = 4; + private final int size = 5; public int getSize() { return size; @@ -358,6 +358,8 @@ public class OptionsPrompt extends NumericPrompt { case 3: return ChatColor.BLUE; case 4: + return ChatColor.BLUE; + case 5: return ChatColor.GREEN; default: return null; @@ -397,6 +399,16 @@ public class OptionsPrompt extends NumericPrompt { + ChatColor.AQUA + String.valueOf(shareOpt) + ChatColor.YELLOW + ")"; } case 4: + if (context.getSessionData(CK.OPT_REQUIRE_SAME_QUEST) == null) { + boolean defaultOpt = new Options().getRequireSameQuest(); + return ChatColor.YELLOW + Lang.get("optRequireSameQuest") + " (" + + (defaultOpt ? ChatColor.GREEN + String.valueOf(defaultOpt) : ChatColor.RED + String.valueOf(defaultOpt)) + ChatColor.YELLOW + ")"; + } else { + boolean requireOpt = (Boolean) context.getSessionData(CK.OPT_REQUIRE_SAME_QUEST); + return ChatColor.YELLOW + Lang.get("optRequireSameQuest") + " (" + + (requireOpt ? ChatColor.GREEN + String.valueOf(requireOpt) : ChatColor.RED + String.valueOf(requireOpt)) + ChatColor.YELLOW + ")"; + } + case 5: return ChatColor.YELLOW + Lang.get("done"); default: return null; @@ -431,6 +443,10 @@ public class OptionsPrompt extends NumericPrompt { tempPrompt = new MultiplayerPrompt(); return new LevelPrompt(); case 4: + tempKey = CK.OPT_REQUIRE_SAME_QUEST; + tempPrompt = new MultiplayerPrompt(); + return new TrueFalsePrompt(); + case 5: tempKey = null; tempPrompt = null; try { diff --git a/main/src/main/java/me/blackvein/quests/util/CK.java b/main/src/main/java/me/blackvein/quests/util/CK.java index 0f050ffe9..ab409d82f 100644 --- a/main/src/main/java/me/blackvein/quests/util/CK.java +++ b/main/src/main/java/me/blackvein/quests/util/CK.java @@ -137,6 +137,7 @@ public class CK { public static final String OPT_USE_DUNGEONSXL_PLUGIN = "useDungeonsXLPluginOpt"; public static final String OPT_USE_PARTIES_PLUGIN = "usePartiesPluginOpt"; public static final String OPT_SHARE_PROGRESS_LEVEL = "shareProgressLevelOpt"; + public static final String OPT_REQUIRE_SAME_QUEST = "requireSameQuestOpt"; // Events public static final String E_OLD_EVENT = "oldEvent"; public static final String E_NAME = "evtName"; diff --git a/main/src/main/resources/strings.yml b/main/src/main/resources/strings.yml index 2c2465877..42bf1a833 100644 --- a/main/src/main/resources/strings.yml +++ b/main/src/main/resources/strings.yml @@ -475,6 +475,7 @@ optCommandsDenied: "You cannot use commands during ." optUseDungeonsXLPlugin: "Use DungeonsXL plugin" optUsePartiesPlugin: "Use Parties plugin" optShareProgressLevel: "Level of progress sharing" +optRequireSameQuest: "Require same quest" rewSetMoney: "Set money reward" rewSetQuestPoints: "Set Quest Points reward" rewSetItems: "Set item rewards" From e45412ad25429606e05441fe68372bde13ce0e05 Mon Sep 17 00:00:00 2001 From: PikaMug Date: Sat, 14 Sep 2019 01:33:09 -0400 Subject: [PATCH 19/27] Attempt to support both types of progress sharing --- .../me/blackvein/quests/listeners/PlayerListener.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index 1eb98948e..48704e822 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -727,11 +727,12 @@ public class PlayerListener implements Listener { } } Quester quester = plugin.getQuester(damager.getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "killMob")) { + LinkedList allQuests = plugin.getQuests(); + for (Quest quest : allQuests) { + if ((quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "killMob")) + || !quest.getOptions().getRequireSameQuest()) { quester.killMob(quest, target.getLocation(), target.getType()); - - // Multiplayer + quester.dispatchMultiplayerEverything(quest, "killMob", (Quester q) -> { q.killMob(quest, target.getLocation(), target.getType()); return null; From c7ebc22eedf7e1ee2c80a679c712f3e4746cb73b Mon Sep 17 00:00:00 2001 From: AlessioDP Date: Sat, 14 Sep 2019 12:33:53 +0200 Subject: [PATCH 20/27] Fixed multiplayer check --- .../me/blackvein/quests/listeners/PlayerListener.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index 48704e822..3147abe55 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -729,10 +729,13 @@ public class PlayerListener implements Listener { Quester quester = plugin.getQuester(damager.getUniqueId()); LinkedList allQuests = plugin.getQuests(); for (Quest quest : allQuests) { - if ((quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "killMob")) - || !quest.getOptions().getRequireSameQuest()) { + boolean multiplayer = !quest.getOptions().getRequireSameQuest(); + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "killMob")) { quester.killMob(quest, target.getLocation(), target.getType()); - + multiplayer = true; + } + + if (multiplayer) { quester.dispatchMultiplayerEverything(quest, "killMob", (Quester q) -> { q.killMob(quest, target.getLocation(), target.getType()); return null; From c268dca82fe24d5a8a574e2034657b87610c180f Mon Sep 17 00:00:00 2001 From: AlessioDP Date: Sat, 14 Sep 2019 12:34:30 +0200 Subject: [PATCH 21/27] Fixed NullPointer due to wrong objective --- main/src/main/java/me/blackvein/quests/Quester.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index a86f8d10a..d2fd2eb6e 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -3281,7 +3281,7 @@ public class Quester { if (quest.getOptions().getShareProgressLevel() == 1) { List mq = getMultiplayerQuesters(quest); for (Quester q : mq) { - if (q.containsObjective(quest, objectiveType) || !quest.getOptions().getRequireSameQuest()) { + if (q.containsObjective(quest, objectiveType)) { fun.apply(q); } From 17ac3b9430891bdbf0a2d1b94e273fa598de8c99 Mon Sep 17 00:00:00 2001 From: PikaMug Date: Sat, 14 Sep 2019 22:43:12 -0400 Subject: [PATCH 22/27] Support both types of progress sharing w/o overriding quest option --- main/src/main/java/me/blackvein/quests/Quester.java | 7 +++++-- .../blackvein/quests/listeners/PlayerListener.java | 12 ++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index d2fd2eb6e..de59efe73 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -3282,9 +3282,12 @@ public class Quester { List mq = getMultiplayerQuesters(quest); for (Quester q : mq) { if (q.containsObjective(quest, objectiveType)) { - fun.apply(q); + if (quest.getOptions().getRequireSameQuest() && this.containsObjective(quest, objectiveType)) { + fun.apply(q); + } else if (!quest.getOptions().getRequireSameQuest()) { + fun.apply(q); + } } - } } } diff --git a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index 3147abe55..31ba57792 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -729,18 +729,14 @@ public class PlayerListener implements Listener { Quester quester = plugin.getQuester(damager.getUniqueId()); LinkedList allQuests = plugin.getQuests(); for (Quest quest : allQuests) { - boolean multiplayer = !quest.getOptions().getRequireSameQuest(); if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "killMob")) { quester.killMob(quest, target.getLocation(), target.getType()); - multiplayer = true; } - if (multiplayer) { - quester.dispatchMultiplayerEverything(quest, "killMob", (Quester q) -> { - q.killMob(quest, target.getLocation(), target.getType()); - return null; - }); - } + quester.dispatchMultiplayerEverything(quest, "killMob", (Quester q) -> { + q.killMob(quest, target.getLocation(), target.getType()); + return null; + }); } } } From 515a1aa2161ac409c76d46333288f058905229f5 Mon Sep 17 00:00:00 2001 From: AlessioDP Date: Sun, 15 Sep 2019 21:43:53 +0200 Subject: [PATCH 23/27] Improved multiplayer everything method --- main/src/main/java/me/blackvein/quests/Quester.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index de59efe73..ea9a8c0c2 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -3282,9 +3282,7 @@ public class Quester { List mq = getMultiplayerQuesters(quest); for (Quester q : mq) { if (q.containsObjective(quest, objectiveType)) { - if (quest.getOptions().getRequireSameQuest() && this.containsObjective(quest, objectiveType)) { - fun.apply(q); - } else if (!quest.getOptions().getRequireSameQuest()) { + if (!quest.getOptions().getRequireSameQuest() || this.containsObjective(quest, objectiveType)) { fun.apply(q); } } From ba6cf5f620423c6eb555a64389344015046dab82 Mon Sep 17 00:00:00 2001 From: PikaMug Date: Sun, 15 Sep 2019 21:41:54 -0400 Subject: [PATCH 24/27] Avoid exception if there are no party members --- main/src/main/java/me/blackvein/quests/Quester.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index ea9a8c0c2..cbac951ed 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -3280,6 +3280,9 @@ public class Quester { public void dispatchMultiplayerEverything(Quest quest, String objectiveType, Function fun) { if (quest.getOptions().getShareProgressLevel() == 1) { List mq = getMultiplayerQuesters(quest); + if (mq == null) { + return; + } for (Quester q : mq) { if (q.containsObjective(quest, objectiveType)) { if (!quest.getOptions().getRequireSameQuest() || this.containsObjective(quest, objectiveType)) { @@ -3379,17 +3382,17 @@ public class Quester { * Get a list of follow Questers in a party or group * * @param quest The quest which uses a linked plugin, i.e. Parties or DungeonsXL - * @return null if quest is null, no linked plugins, or party/group is null + * @return Potentially empty list of Questers or null for invalid quest */ public List getMultiplayerQuesters(Quest quest) { if (quest == null) { return null; } + List mq = new LinkedList(); if (plugin.getDependencies().getPartiesApi() != null) { if (quest.getOptions().getUsePartiesPlugin()) { Party party = plugin.getDependencies().getPartiesApi().getParty(plugin.getDependencies().getPartiesApi().getPartyPlayer(getUUID()).getPartyName()); if (party != null) { - List mq = new LinkedList(); for (UUID id : party.getMembers()) { if (!id.equals(getUUID())) { mq.add(plugin.getQuester(id)); @@ -3403,7 +3406,6 @@ public class Quester { if (quest.getOptions().getUseDungeonsXLPlugin()) { DGroup group = DGroup.getByPlayer(getPlayer()); if (group != null) { - List mq = new LinkedList(); for (UUID id : group.getPlayers()) { if (!id.equals(getUUID())) { mq.add(plugin.getQuester(id)); @@ -3413,7 +3415,7 @@ public class Quester { } } } - return null; + return mq; } /** From aaecb130f27587945fa6edf7be617f987a56647d Mon Sep 17 00:00:00 2001 From: PikaMug Date: Mon, 16 Sep 2019 00:37:09 -0400 Subject: [PATCH 25/27] Refresh Quest objects on reload, fixes #811 --- .../main/java/me/blackvein/quests/Quest.java | 33 +++++++++++-------- .../main/java/me/blackvein/quests/Quests.java | 7 +++- .../quests/listeners/CmdExecutor.java | 12 +++++-- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Quest.java b/main/src/main/java/me/blackvein/quests/Quest.java index b88d4f9d8..c6a1e84fd 100644 --- a/main/src/main/java/me/blackvein/quests/Quest.java +++ b/main/src/main/java/me/blackvein/quests/Quest.java @@ -49,6 +49,7 @@ import net.citizensnpcs.api.npc.NPC; public class Quest { protected Quests plugin; + protected String id; private String name; protected String description; protected String finished; @@ -63,20 +64,8 @@ public class Quest { private Rewards rews = new Rewards(); private Options opts = new Options(); - public Requirements getRequirements() { - return reqs; - } - - public Planner getPlanner() { - return pln; - } - - public Rewards getRewards() { - return rews; - } - - public Options getOptions() { - return opts; + public String getId() { + return id; } public String getName() { @@ -155,6 +144,22 @@ public class Quest { this.initialAction = initialAction; } + public Requirements getRequirements() { + return reqs; + } + + public Planner getPlanner() { + return pln; + } + + public Rewards getRewards() { + return rews; + } + + public Options getOptions() { + return opts; + } + /** * Force player to proceed to the next ordered stage * diff --git a/main/src/main/java/me/blackvein/quests/Quests.java b/main/src/main/java/me/blackvein/quests/Quests.java index 71e66a16e..e69378348 100644 --- a/main/src/main/java/me/blackvein/quests/Quests.java +++ b/main/src/main/java/me/blackvein/quests/Quests.java @@ -1339,9 +1339,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } /** - * Reload quests, player data, actions, config settings, lang and modules, in that order + * Reload quests, actions, config settings, lang and modules, and player data */ public void reloadQuests() { + for (Quester quester : questers) { + quester.saveData(); + } quests.clear(); events.clear(); @@ -1360,6 +1363,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } loadModules(); for (Quester quester : questers) { + quester.loadData(); for (Quest q : quester.currentQuests.keySet()) { quester.checkQuest(q); } @@ -1465,6 +1469,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener try { // main "skip quest" try/catch block Quest quest = new Quest(); failedToLoad = false; + quest.id = questKey; if (config.contains("quests." + questKey + ".name")) { quest.setName(parseString(config.getString("quests." + questKey + ".name"), quest)); } else { diff --git a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java index 1ee24a8ee..27d533457 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java +++ b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java @@ -673,10 +673,16 @@ public class CmdExecutor implements CommandExecutor { if (args.length == 1) { player.sendMessage(ChatColor.YELLOW + Lang.get(player, "COMMAND_TAKE_USAGE")); } else { - Quest questToFind = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' ')); + final Quest questToFind = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' ')); + final Quester quester = plugin.getQuester(player.getUniqueId()); if (questToFind != null) { - final Quest q = questToFind; - plugin.getQuester(player.getUniqueId()).offerQuest(q, true); + for (Quest q : quester.getCurrentQuests().keySet()) { + if (q.getId().equals(questToFind.getId())) { + player.sendMessage(ChatColor.RED + Lang.get(player, "questAlreadyOn")); + return; + } + } + quester.offerQuest(questToFind, true); } else { player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questNotFound")); } From f31730ce732cf6f1348990ffff64f610d245940c Mon Sep 17 00:00:00 2001 From: PikaMug Date: Mon, 16 Sep 2019 22:19:07 -0400 Subject: [PATCH 26/27] Apply support to all objective types --- .../quests/listeners/PlayerListener.java | 310 ++++++++---------- 1 file changed, 142 insertions(+), 168 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index 31ba57792..8928e1fc4 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -205,18 +205,16 @@ public class PlayerListener implements Listener { boolean hasObjective = false; if (evt.isCancelled() == false) { final ItemStack blockItemStack = new ItemStack(evt.getClickedBlock().getType(), 1, evt.getClickedBlock().getState().getData().toItemStack().getDurability()); - - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "useBlock")) { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "useBlock")) { quester.useBlock(quest, blockItemStack); hasObjective = true; - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "useBlock", (Quester q) -> { - q.useBlock(quest, blockItemStack); - return null; - }); } + + quester.dispatchMultiplayerEverything(quest, "useBlock", (Quester q) -> { + q.useBlock(quest, blockItemStack); + return null; + }); } } if (!hasObjective) { @@ -340,8 +338,8 @@ public class PlayerListener implements Listener { public void onPlayerChat(AsyncPlayerChatEvent evt) { if (plugin.canUseQuests(evt.getPlayer().getUniqueId())) { final Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId()); - if (quester.getCurrentQuests().isEmpty() == false) { - for (final Quest quest : quester.getCurrentQuests().keySet()) { + for (final Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest)) { final Stage currentStage = quester.getCurrentStage(quest); if (currentStage == null) { plugin.getLogger().severe("currentStage was null for " + quester.getUUID().toString() + " on chat for quest " + quest.getName()); @@ -366,14 +364,13 @@ public class PlayerListener implements Listener { } if (quester.containsObjective(quest, "password")) { quester.sayPassword(quest, evt); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "password", (Quester q) -> { - q.sayPassword(quest, evt); - return null; - }); } } + + quester.dispatchMultiplayerEverything(quest, "password", (Quester q) -> { + q.sayPassword(quest, evt); + return null; + }); } } } @@ -419,18 +416,16 @@ public class PlayerListener implements Listener { public void onBlockDamage(BlockDamageEvent evt) { if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) { final ItemStack blockItemStack = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability()); - Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "damageBlock")) { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "damageBlock")) { quester.damageBlock(quest, blockItemStack); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> { - q.placeBlock(quest, blockItemStack); - return null; - }); } + + quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> { + q.placeBlock(quest, blockItemStack); + return null; + }); } } } @@ -440,19 +435,17 @@ public class PlayerListener implements Listener { public void onBlockPlace(BlockPlaceEvent evt) { if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) { final ItemStack blockItemStack = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability()); - Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "placeBlock")) { - if (evt.isCancelled() == false) { + for (Quest quest : plugin.getQuests()) { + if (evt.isCancelled() == false) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "placeBlock")) { quester.placeBlock(quest, blockItemStack); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> { - q.placeBlock(quest, blockItemStack); - return null; - }); } + + quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> { + q.placeBlock(quest, blockItemStack); + return null; + }); } } } @@ -463,57 +456,50 @@ public class PlayerListener implements Listener { public void onBlockBreak(BlockBreakEvent evt) { if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) { final ItemStack blockItemStack = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability()); - Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { + for (Quest quest : plugin.getQuests()) { if (evt.isCancelled() == false) { - if (quester.containsObjective(quest, "breakBlock")) { - if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "breakBlock")) { + if (!evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { quester.breakBlock(quest, blockItemStack); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "breakBlock", (Quester q) -> { - if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false) { - q.breakBlock(quest, blockItemStack); - } - return null; - }); } } - if (quester.containsObjective(quest, "placeBlock")) { + quester.dispatchMultiplayerEverything(quest, "breakBlock", (Quester q) -> { + if (!evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { + q.breakBlock(quest, blockItemStack); + } + return null; + }); + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "placeBlock")) { for (ItemStack is : quester.getQuestData(quest).blocksPlaced) { if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) { int index = quester.getQuestData(quest).blocksPlaced.indexOf(is); is.setAmount(is.getAmount() - 1); quester.getQuestData(quest).blocksPlaced.set(index, is); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> { - for (ItemStack is2 : q.getQuestData(quest).blocksPlaced) { - if (evt.getBlock().getType().equals(is2.getType()) && is2.getAmount() > 0) { - int index2 = q.getQuestData(quest).blocksPlaced.indexOf(is2); - is2.setAmount(is2.getAmount() - 1); - q.getQuestData(quest).blocksPlaced.set(index2, is2); - } - } - return null; - }); } } } - if (quester.containsObjective(quest, "cutBlock")) { + quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> { + for (ItemStack is : q.getQuestData(quest).blocksPlaced) { + if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) { + int index = q.getQuestData(quest).blocksPlaced.indexOf(is); + is.setAmount(is.getAmount() - 1); + q.getQuestData(quest).blocksPlaced.set(index, is); + } + } + return null; + }); + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "cutBlock")) { if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) { quester.cutBlock(quest, blockItemStack); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "cutBlock", (Quester q) -> { - if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) { - q.cutBlock(quest, blockItemStack); - } - return null; - }); } } + quester.dispatchMultiplayerEverything(quest, "cutBlock", (Quester q) -> { + if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) { + q.cutBlock(quest, blockItemStack); + } + return null; + }); } } } @@ -525,16 +511,15 @@ public class PlayerListener implements Listener { if (plugin.canUseQuests(evt.getPlayer().getUniqueId())) { Sheep sheep = (Sheep) evt.getEntity(); Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "shearSheep")) { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "shearSheep")) { quester.shearSheep(quest, sheep.getColor()); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "shearSheep", (Quester q) -> { - q.shearSheep(quest, sheep.getColor()); - return null; - }); } + + quester.dispatchMultiplayerEverything(quest, "shearSheep", (Quester q) -> { + q.shearSheep(quest, sheep.getColor()); + return null; + }); } } } @@ -546,16 +531,15 @@ public class PlayerListener implements Listener { Player p = (Player) evt.getOwner(); if (plugin.canUseQuests(p.getUniqueId())) { Quester quester = plugin.getQuester(p.getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "tameMob")) { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "tameMob")) { quester.tameMob(quest, evt.getEntityType()); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "tameMob", (Quester q) -> { - q.tameMob(quest, evt.getEntityType()); - return null; - }); } + + quester.dispatchMultiplayerEverything(quest, "tameMob", (Quester q) -> { + q.tameMob(quest, evt.getEntityType()); + return null; + }); } } } @@ -569,16 +553,15 @@ public class PlayerListener implements Listener { if (plugin.checkQuester(evt.getWhoClicked().getUniqueId()) == false) { final ItemStack craftedItem = getCraftedItem(evt); Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "craftItem")) { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "craftItem")) { quester.craftItem(quest, craftedItem); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "craftItem", (Quester q) -> { - q.craftItem(quest, craftedItem); - return null; - }); } + + quester.dispatchMultiplayerEverything(quest, "craftItem", (Quester q) -> { + q.craftItem(quest, craftedItem); + return null; + }); } } } @@ -613,31 +596,29 @@ public class PlayerListener implements Listener { if (evt.getInventory().getType() == InventoryType.FURNACE) { if (evt.getSlotType() == SlotType.RESULT) { Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "smeltItem")) { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "smeltItem")) { quester.smeltItem(quest, evt.getCurrentItem()); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "smeltItem", (Quester q) -> { - q.smeltItem(quest, evt.getCurrentItem()); - return null; - }); } + + quester.dispatchMultiplayerEverything(quest, "smeltItem", (Quester q) -> { + q.smeltItem(quest, evt.getCurrentItem()); + return null; + }); } } } else if (evt.getInventory().getType() == InventoryType.BREWING) { if (evt.getSlotType() == SlotType.CRAFTING) { Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "brewItem")) { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "brewItem")) { quester.brewItem(quest, evt.getCurrentItem()); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "brewItem", (Quester q) -> { - q.brewItem(quest, evt.getCurrentItem()); - return null; - }); } + + quester.dispatchMultiplayerEverything(quest, "brewItem", (Quester q) -> { + q.brewItem(quest, evt.getCurrentItem()); + return null; + }); } } } @@ -648,18 +629,19 @@ public class PlayerListener implements Listener { public void onEnchantItem(EnchantItemEvent evt) { if (plugin.canUseQuests(evt.getEnchanter().getUniqueId())) { Quester quester = plugin.getQuester(evt.getEnchanter().getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "enchantItem")) { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "enchantItem")) { for (Enchantment e : evt.getEnchantsToAdd().keySet()) { quester.enchantItem(quest, e, evt.getItem().getType()); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "enchantItem", (Quester q) -> { - q.enchantItem(quest, e, evt.getItem().getType()); - return null; - }); } } + + quester.dispatchMultiplayerEverything(quest, "enchantItem", (Quester q) -> { + for (Enchantment e : evt.getEnchantsToAdd().keySet()) { + q.enchantItem(quest, e, evt.getItem().getType()); + } + return null; + }); } } } @@ -709,34 +691,29 @@ public class PlayerListener implements Listener { return; } if (damager instanceof Player) { - if (plugin.getDependencies().getCitizens() != null) { - if (CitizensAPI.getNPCRegistry().isNPC(target)) { - Quester quester = plugin.getQuester(damager.getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "killNPC")) { - quester.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target)); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "killNPC", (Quester q) -> { - q.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target)); - return null; - }); - } - } - return; - } - } Quester quester = plugin.getQuester(damager.getUniqueId()); - LinkedList allQuests = plugin.getQuests(); - for (Quest quest : allQuests) { - if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "killMob")) { - quester.killMob(quest, target.getLocation(), target.getType()); + if (plugin.getDependencies().getCitizens() != null && CitizensAPI.getNPCRegistry().isNPC(target)) { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "killNPC")) { + quester.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target)); + } + + quester.dispatchMultiplayerEverything(quest, "killNPC", (Quester q) -> { + q.killNPC(quest, CitizensAPI.getNPCRegistry().getNPC(target)); + return null; + }); + } + } else { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "killMob")) { + quester.killMob(quest, target.getLocation(), target.getType()); + } + + quester.dispatchMultiplayerEverything(quest, "killMob", (Quester q) -> { + q.killMob(quest, target.getLocation(), target.getType()); + return null; + }); } - - quester.dispatchMultiplayerEverything(quest, "killMob", (Quester q) -> { - q.killMob(quest, target.getLocation(), target.getType()); - return null; - }); } } } @@ -822,16 +799,15 @@ public class PlayerListener implements Listener { } } Quester quester = plugin.getQuester(damager.getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "killPlayer")) { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "killPlayer")) { quester.killPlayer(quest, (Player)target); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "killPlayer", (Quester q) -> { - q.killPlayer(quest, (Player)target); - return null; - }); } + + quester.dispatchMultiplayerEverything(quest, "killPlayer", (Quester q) -> { + q.killPlayer(quest, (Player)target); + return null; + }); } } } @@ -841,16 +817,15 @@ public class PlayerListener implements Listener { Player player = evt.getPlayer(); if (plugin.canUseQuests(player.getUniqueId())) { Quester quester = plugin.getQuester(player.getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "catchFish") && evt.getState().equals(State.CAUGHT_FISH)) { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "catchFish") && evt.getState().equals(State.CAUGHT_FISH)) { quester.catchFish(quest); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "catchFish", (Quester q) -> { - q.catchFish(quest); - return null; - }); } + + quester.dispatchMultiplayerEverything(quest, "catchFish", (Quester q) -> { + q.catchFish(quest); + return null; + }); } } } @@ -973,16 +948,15 @@ public class PlayerListener implements Listener { if (plugin.getQuester(evt.getPlayer().getUniqueId()) != null) { if (plugin.canUseQuests(evt.getPlayer().getUniqueId())) { Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId()); - for (Quest quest : quester.getCurrentQuests().keySet()) { - if (quester.containsObjective(quest, "reachLocation")) { + for (Quest quest : plugin.getQuests()) { + if (quester.getCurrentQuests().containsKey(quest) && quester.containsObjective(quest, "reachLocation")) { quester.reachLocation(quest, evt.getTo()); - - // Multiplayer - quester.dispatchMultiplayerEverything(quest, "reachLocation", (Quester q) -> { - q.reachLocation(quest, evt.getTo()); - return null; - }); } + + quester.dispatchMultiplayerEverything(quest, "reachLocation", (Quester q) -> { + q.reachLocation(quest, evt.getTo()); + return null; + }); } } } From cb2a6f31a2b498447037d36d70df356f45aa87d8 Mon Sep 17 00:00:00 2001 From: PikaMug Date: Mon, 16 Sep 2019 22:38:01 -0400 Subject: [PATCH 27/27] Remove unused work --- .../java/me/blackvein/quests/Quester.java | 66 ------------------- 1 file changed, 66 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index cbac951ed..4a7c1a143 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -3312,72 +3312,6 @@ public class Quester { } } - /** - * Get a map of fellow Questers in a party or group - * - * @return empty if no linked plugins, or party/group is null - */ - /*public Map getMultiplayerQuesters() { - Map ret = new LinkedHashMap<>(); - if (plugin.getDependencies().getPartiesApi() != null) { - Party party = plugin.getDependencies().getPartiesApi().getParty(plugin.getDependencies().getPartiesApi().getPartyPlayer(getUUID()).getPartyName()); - if (party != null) { - for (UUID id : party.getMembers()) { - if (!id.equals(getUUID())) { - ret.put(plugin.getQuester(id), new MultiplayerType(true, false)); - } - } - } - } - if (plugin.getDependencies().getDungeonsApi() != null) { - DGroup group = DGroup.getByPlayer(getPlayer()); - if (group != null) { - for (UUID id : group.getPlayers()) { - if (!id.equals(getUUID())) { - Quester q = plugin.getQuester(id); - if (ret.containsKey(plugin.getQuester(id))) - ret.get(q).dungeonxl = true; - else - ret.put(q, new MultiplayerType(false, true)); - } - } - } - } - return ret; - }*/ - - /** - * Get a map of fellow Questers in a party or group - * that are doing the given quest - * - * @param quest the quest to check - * @return empty if no linked plugins, or party/group is null - */ - /*public List getMultiplayerQuestersByQuest(Quest quest) { - List ret = new LinkedList<>(); - Map mq = getMultiplayerQuesters(); - for (Entry q : mq.entrySet()) { - if (q.getKey().getCurrentQuests().containsKey(quest)) { - if ((quest.getOptions().getUsePartiesPlugin() && q.getValue().parties) - || (quest.getOptions().getUseDungeonsXLPlugin() && q.getValue().dungeonxl)) { - ret.add(q.getKey()); - } - } - - } - return ret; - }*/ - - /*public class MultiplayerType { - public boolean parties; - public boolean dungeonxl; - - public MultiplayerType(boolean parties, boolean dungeonxl) { - this.parties = parties; - this.dungeonxl = dungeonxl; - } - }*/ - /** * Get a list of follow Questers in a party or group *