diff --git a/main/src/main/java/me/blackvein/quests/Quest.java b/main/src/main/java/me/blackvein/quests/Quest.java index f4763fdfb..3816e4167 100644 --- a/main/src/main/java/me/blackvein/quests/Quest.java +++ b/main/src/main/java/me/blackvein/quests/Quest.java @@ -160,12 +160,13 @@ public class Quest { * * @param q Player to force */ - public void nextStage(Quester q) { - if (q.getCurrentStage(this) == null) { + public void nextStage(Quester q, boolean enableShareProgress) { + Stage currentStage = q.getCurrentStage(this); + if (currentStage == null) { plugin.getLogger().severe("Current stage was null for quester " + q.getPlayer().getUniqueId()); return; } - String stageCompleteMessage = q.getCurrentStage(this).completeMessage; + String stageCompleteMessage = currentStage.completeMessage; if (stageCompleteMessage != null) { q.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageCompleteMessage, this, q.getPlayer())); } @@ -173,19 +174,29 @@ public class Quest { q.resetCompass(); q.findCompassTarget(); } - if (q.getCurrentStage(this).delay < 0) { + if (currentStage.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 (currentStage.script != null) { + plugin.getDenizenTrigger().runDenizenScript(currentStage.script, q); } - if (q.getCurrentStage(this).finishEvent != null) { - q.getCurrentStage(this).finishEvent.fire(q, this); + if (currentStage.finishEvent != null) { + currentStage.finishEvent.fire(q, this); } completeQuest(q); + + // Multiplayer + if (enableShareProgress && opts.getShareProgressLevel() == 3) { + List mq = q.getMultiplayerQuestersByQuest(this); + for (Quester qq : mq) { + if (currentStage.equals(qq.getCurrentStage(this))) { + completeQuest(qq); + } + } + } } else { try { - if (q.getCurrentStage(this).finishEvent != null) { - q.getCurrentStage(this).finishEvent.fire(q, this); + if (currentStage.finishEvent != null) { + currentStage.finishEvent.fire(q, this); } setStage(q, q.currentQuests.get(this) + 1); } catch (InvalidStageException e) { @@ -193,15 +204,13 @@ public class Quest { } // Multiplayer - try { - if (opts.getShareProgressLevel() == 3) { - List mq = q.getMultiplayerQuestersByQuest(this); - for (Quester qq : mq) { - setStage(qq, qq.currentQuests.get(this) + 1); + if (enableShareProgress && opts.getShareProgressLevel() == 3) { + List mq = q.getMultiplayerQuestersByQuest(this); + for (Quester qq : mq) { + if (currentStage.equals(qq.getCurrentStage(this))) { + nextStage(qq, false); } } - } catch (InvalidStageException e) { - e.printStackTrace(); } } if (q.getQuestData(this) != null) { diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index 325a6934e..7d349db3a 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -1975,17 +1975,31 @@ public class Quester { } p.sendMessage(message); } + Stage currentStage = getCurrentStage(quest); if (testComplete(quest)) { - quest.nextStage(this); + quest.nextStage(this, true); } // Multiplayer + /* wip new method + if (true && quest.getOptions().getShareProgressLevel() == 2) { + List mq = getMultiplayerQuestersByQuest(this); + for (Quester qq : mq) { + if (currentStage.equals(qq.getCurrentStage(quest))) { + completeQuest(qq); + } + } + } + */ + /* old method if (quest.getOptions().getShareProgressLevel() == 2) { List mq = getMultiplayerQuestersByQuest(quest); for (Quester q : mq) { - quest.nextStage(q); + if (q.getCurrentStage(quest).equals(this.getCurrentStage(quest))) { + quest.nextStage(q, false); + } } - } + }*/ } /** 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 d415e4bfe..1ee24a8ee 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java +++ b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java @@ -1,1388 +1,1388 @@ -/******************************************************************************************************* - * 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.io.IOException; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.Map.Entry; - -import me.blackvein.quests.Quest; -import me.blackvein.quests.Quester; -import me.blackvein.quests.Quests; -import me.blackvein.quests.Requirements; -import me.blackvein.quests.Stage; -import me.blackvein.quests.events.command.QuestsCommandPreQuestsJournalEvent; -import me.blackvein.quests.events.editor.quests.QuestsEditorPreOpenMainPromptEvent; -import me.blackvein.quests.events.quest.QuestQuitEvent; -import me.blackvein.quests.exceptions.InvalidStageException; -import me.blackvein.quests.util.ItemUtil; -import me.blackvein.quests.util.Lang; -import me.blackvein.quests.util.MiscUtil; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.conversations.Conversable; -import org.bukkit.conversations.Conversation; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -public class CmdExecutor implements CommandExecutor { - private final Quests plugin; - public HashMap commands = new HashMap(); - public HashMap adminCommands = new HashMap(); - - public CmdExecutor(Quests plugin) { - this.plugin = plugin; - init(); - } - - @Override - public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { - if (cs instanceof Player) { - if (!plugin.canUseQuests(((Player) cs).getUniqueId())) { - cs.sendMessage(ChatColor.RED + Lang.get((Player) cs, "noPermission")); - return true; - } - } - String error = checkCommand(cmd.getName(), args); - if (error != null) { - cs.sendMessage(error); - return true; - } - if (cmd.getName().equalsIgnoreCase("quest")) { - return questCommandHandler(cs, args); - } else if (cmd.getName().equalsIgnoreCase("quests")) { - return questsCommandHandler(cs, args); - } else if (cmd.getName().equalsIgnoreCase("questadmin")) { - return questAdminCommandHandler(cs, args); - } - return false; - } - - private void init() { - // [] - required - // {} - optional - if (plugin.getSettings().canTranslateSubCommands()) { - commands.put(Lang.get("COMMAND_LIST"), 1); // list {page} - commands.put(Lang.get("COMMAND_TAKE"), 2); // take [quest] - commands.put(Lang.get("COMMAND_QUIT"), 2); // quit [quest] - commands.put(Lang.get("COMMAND_EDITOR"), 1); // editor - commands.put(Lang.get("COMMAND_EVENTS_EDITOR"), 1); // events - commands.put(Lang.get("COMMAND_STATS"), 1); // stats - commands.put(Lang.get("COMMAND_TOP"), 2); // top {number} - commands.put(Lang.get("COMMAND_INFO"), 1); // info - commands.put(Lang.get("COMMAND_JOURNAL"), 1); // journal - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_STATS"), 2); // stats [player] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_GIVE"), 3); // give [player] [quest] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_QUIT"), 3); // quit [player] [quest] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_REMOVE"), 3); // remove [player] [quest] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_POINTS"), 3); // points [player] [amount] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_TAKEPOINTS"), 3); // takepoints [player] [amount] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_GIVEPOINTS"), 3); // givepoints [player] [amount] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_POINTSALL"), 2); // pointsall [amount] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_FINISH"), 3); // finish [player] [quest] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_NEXTSTAGE"), 3); // nextstage [player] [quest] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_SETSTAGE"), 4); // setstage [player] [quest] [stage] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_RESET"), 2); // reset [player] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_TOGGLEGUI"), 2); // togglegui [npc id] - adminCommands.put(Lang.get("COMMAND_QUESTADMIN_RELOAD"), 1); // reload - } else { - commands.put("list", 1); // list {page} - commands.put("take", 2); // take [quest] - commands.put("quit", 2); // quit [quest] - commands.put("editor", 1); // editor - commands.put("actions", 1); // actions - commands.put("events", 1); // LEGACY - events - commands.put("stats", 1); // stats - commands.put("top", 2); // top [number] - commands.put("info", 1); // info - commands.put("journal", 1); // journal - adminCommands.put("stats", 2); // stats [player] - adminCommands.put("give", 3); // give [player] [quest] - adminCommands.put("quit", 3); // quit [player] [quest] - adminCommands.put("remove", 3); // remove [player] [quest] - adminCommands.put("points", 3); // points [player] [amount] - adminCommands.put("takepoints", 3); // takepoints [player] [amount] - adminCommands.put("givepoints", 3); // givepoints [player] [amount] - adminCommands.put("pointsall", 2); // pointsall [amount] - adminCommands.put("finish", 3); // finish [player] [quest] - adminCommands.put("nextstage", 3); // nextstage [player] [quest] - adminCommands.put("setstage", 4); // setstage [player] [quest] [stage] - adminCommands.put("reset", 2); // reset [player] - adminCommands.put("togglegui", 2); // togglegui [npc id] - adminCommands.put("reload", 1); // reload - } - } - - public String checkCommand(String cmd, String[] args) { - if (cmd.equalsIgnoreCase("quest") || args.length == 0) { - return null; - } - if (cmd.equalsIgnoreCase("quests")) { - if (commands.containsKey(args[0].toLowerCase())) { - int min = commands.get(args[0].toLowerCase()); - if (args.length < min) { - return getQuestsCommandUsage(args[0]); - } else { - return null; - } - } - return ChatColor.YELLOW + Lang.get("questsUnknownCommand"); - } else if (cmd.equalsIgnoreCase("questsadmin") || cmd.equalsIgnoreCase("questadmin")) { - if (adminCommands.containsKey(args[0].toLowerCase())) { - int min = adminCommands.get(args[0].toLowerCase()); - if (args.length < min) { - return getQuestadminCommandUsage(args[0]); - } else { - return null; - } - } - return ChatColor.YELLOW + Lang.get("questsUnknownAdminCommand"); - } - return "NULL"; - } - - private boolean questCommandHandler(final CommandSender cs, String[] args) { - if (cs instanceof Player) { - if (((Player) cs).hasPermission("quests.quest")) { - if (args.length == 0) { - Player player = (Player) cs; - Quester quester = plugin.getQuester(player.getUniqueId()); - if (quester.getCurrentQuests().isEmpty() == false) { - for (Quest q : quester.getCurrentQuests().keySet()) { - Stage stage = quester.getCurrentStage(q); - q.updateCompass(quester, stage); - if (plugin.getQuester(player.getUniqueId()).getQuestData(q).delayStartTime == 0) { - String msg = Lang.get(player, "questObjectivesTitle"); - msg = msg.replace("", q.getName()); - player.sendMessage(ChatColor.GOLD + msg); - plugin.showObjectives(q, quester, false); - } else { - long time = plugin.getQuester(player.getUniqueId()).getStageTime(q); - String msg = ChatColor.YELLOW + "(" + Lang.get(player, "delay") + ") " + ChatColor.RED + Lang.get(player, "plnTooEarly"); - msg = msg.replace("", q.getName()); - msg = msg.replace("