From 0919a84dacb5b80e6349cc3ab2393ee6ab8c07e1 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 1 Dec 2018 02:57:47 -0500 Subject: [PATCH] Fix stages not working after delay, fixes #289 --- .../java/me/blackvein/quests/Quester.java | 8 +++- .../java/me/blackvein/quests/StageTimer.java | 39 ++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/blackvein/quests/Quester.java b/src/main/java/me/blackvein/quests/Quester.java index cdf8ffa08..46ba61a6f 100644 --- a/src/main/java/me/blackvein/quests/Quester.java +++ b/src/main/java/me/blackvein/quests/Quester.java @@ -1061,6 +1061,8 @@ public class Quester { return; } if (questData.mobsKilled.contains(e) == false) { + for (EntityType ee : questData.mobsKilled) { + } return; } Stage currentStage = getCurrentStage(quest); @@ -2443,7 +2445,11 @@ public class Quester { } getQuestData(quest).delayStartTime = System.currentTimeMillis(); } - + + /** + * Pause the stage timer. Useful when a player quits + * @param quest The quest of which the timer is for + */ public void stopStageTimer(Quest quest) { if (getQuestData(quest).delayTimeLeft > -1) { getQuestData(quest).delayTimeLeft = getQuestData(quest).delayTimeLeft - (System.currentTimeMillis() - getQuestData(quest).delayStartTime); diff --git a/src/main/java/me/blackvein/quests/StageTimer.java b/src/main/java/me/blackvein/quests/StageTimer.java index 5f3143c08..279d4f967 100644 --- a/src/main/java/me/blackvein/quests/StageTimer.java +++ b/src/main/java/me/blackvein/quests/StageTimer.java @@ -13,6 +13,9 @@ package me.blackvein.quests; import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import me.blackvein.quests.util.Lang; @@ -29,6 +32,7 @@ public class StageTimer implements Runnable { plugin = quests; } + @SuppressWarnings("deprecation") @Override public void run() { if (quester.getQuestData(quest).delayOver) { @@ -52,7 +56,7 @@ public class StageTimer implements Runnable { currentStage.finishEvent.fire(quester, quest); } quester.hardStagePut(quest, stageNum); - quester.addEmptiesFor(quest, 0); + quester.addEmptiesFor(quest, stageNum); quester.getCurrentStage(quest).delay = -1; // Line added to fix Github issue #505 quester.getQuestData(quest).delayStartTime = 0; quester.getQuestData(quest).delayTimeLeft = -1; @@ -60,7 +64,38 @@ public class StageTimer implements Runnable { msg = msg.replace("", quest.name); player.sendMessage(ChatColor.GOLD + msg); for (String s : quester.getObjectivesReal(quest)) { - player.sendMessage(s); + try { + // TODO ensure all applicable strings are translated + String sbegin = s.substring(s.indexOf(ChatColor.AQUA.toString()) + 2); + String serial = sbegin.substring(0, sbegin.indexOf(ChatColor.GREEN.toString())); + + String enchant = ""; + if (s.contains(ChatColor.LIGHT_PURPLE.toString())) { + String ebegin = s.substring(s.indexOf(ChatColor.LIGHT_PURPLE.toString()) + 2); + enchant = ebegin.substring(0, ebegin.indexOf(ChatColor.GREEN.toString())); + } + + // Order is important + if (Enchantment.getByName(Lang.getKey(enchant).replace("ENCHANTMENT_", "")) != null) { + Material m = Material.matchMaterial(serial); + Enchantment e = Enchantment.getByName(Lang.getKey(enchant).replace("ENCHANTMENT_", "")); + plugin.query.sendMessage(player, s.replace(serial, "").replace(enchant, ""), m, e); + continue; + } else if (Material.matchMaterial(serial) != null) { + Material m = Material.matchMaterial(serial); + plugin.query.sendMessage(player, s.replace(serial, ""), m); + continue; + } else { + try { + EntityType type = EntityType.valueOf(serial.toUpperCase().replace(" ", "_")); + plugin.query.sendMessage(player, s.replace(serial, ""), type); + } catch (IllegalArgumentException e) { + player.sendMessage(s); + } + } + } catch (IndexOutOfBoundsException e) { + player.sendMessage(s); + } } String stageStartMessage = quester.getCurrentStage(quest).startMessage; if (stageStartMessage != null) {