diff --git a/pom.xml b/pom.xml
index 430d9c848..b6b8081ca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
me.blackvein.quests
quests
- 3.5.2
+ 3.5.3
quests
https://github.com/FlyingPikachu/Quests/
jar
diff --git a/src/main/java/me/blackvein/quests/Quest.java b/src/main/java/me/blackvein/quests/Quest.java
index 3120e7285..2e36d805c 100644
--- a/src/main/java/me/blackvein/quests/Quest.java
+++ b/src/main/java/me/blackvein/quests/Quest.java
@@ -162,12 +162,7 @@ public class Quest {
String msg = Lang.get(quester.getPlayer(), "questObjectivesTitle");
msg = msg.replaceAll("", name);
quester.getPlayer().sendMessage(ChatColor.GOLD + msg);
- for (String s : quester.getObjectivesReal(this)) {
- if(Quests.placeholder != null) {
- s = PlaceholderAPI.setPlaceholders(quester.getPlayer(), s);
- }
- quester.getPlayer().sendMessage(s);
- }
+ plugin.showObjectives(this, quester, false);
String stageStartMessage = quester.getCurrentStage(this).startMessage;
if (stageStartMessage != null) {
quester.getPlayer().sendMessage(Quests.parseString(stageStartMessage, this));
diff --git a/src/main/java/me/blackvein/quests/Quester.java b/src/main/java/me/blackvein/quests/Quester.java
index 703c2817a..4541d0e04 100644
--- a/src/main/java/me/blackvein/quests/Quester.java
+++ b/src/main/java/me/blackvein/quests/Quester.java
@@ -265,8 +265,8 @@ public class Quester {
currentLength += quest.name.length();
currentLines += (quest.name.length() / 19);
}
- if (getObjectivesReal(quest) != null) {
- for (String obj : getObjectivesReal(quest)) {
+ if (getObjectives(quest, false) != null) {
+ for (String obj : getObjectives(quest, false)) {
// Length/Line check
if ((currentLength + obj.length() > 240) || (currentLines + ((obj.length() % 19) == 0 ? (obj.length() / 19) : ((obj.length() / 19) + 1))) > 13) {
book.addPage(page);
@@ -309,7 +309,6 @@ public class Quester {
return null;
}
- @SuppressWarnings("deprecation")
public void takeQuest(Quest q, boolean override) {
Player player = getPlayer();
long start = -1;
@@ -413,40 +412,7 @@ public class Quester {
String msg = Lang.get(getPlayer(), "questObjectivesTitle");
msg = msg.replace("", q.name);
getPlayer().sendMessage(ChatColor.GOLD + msg);
- for (String s : getObjectivesReal(q)) {
- 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);
- }
- }
+ plugin.showObjectives(q, this, false);
String stageStartMessage = stage.startMessage;
if (stageStartMessage != null) {
getPlayer().sendMessage(Quests.parseString(stageStartMessage, q));
@@ -473,20 +439,25 @@ public class Quester {
player.sendMessage(q.failRequirements);
}
}
-
- public LinkedList getObjectivesReal(Quest quest) {
- if (getCurrentStage(quest) != null) {
- if (getCurrentStage(quest).objectiveOverride != null) {
- LinkedList objectives = new LinkedList();
- objectives.add(ChatColor.GREEN + getCurrentStage(quest).objectiveOverride);
- return objectives;
+
+ /**
+ * Get all objectives for a quest.
+ *
+ * @param quest The quest to get objectives of
+ * @param ignoreOverrides Whether to ignore OP-specified objectives-overrides
+ * @return
+ */
+ @SuppressWarnings("deprecation")
+ public LinkedList getObjectives(Quest quest, boolean ignoreOverrides) {
+ if (!ignoreOverrides) {
+ if (getCurrentStage(quest) != null) {
+ if (getCurrentStage(quest).objectiveOverride != null) {
+ LinkedList objectives = new LinkedList();
+ objectives.add(ChatColor.GREEN + getCurrentStage(quest).objectiveOverride);
+ return objectives;
+ }
}
}
- return getObjectives(quest);
- }
-
- @SuppressWarnings("deprecation")
- public LinkedList getObjectives(Quest quest) {
if (getQuestData(quest) == null)
return new LinkedList();
LinkedList unfinishedObjectives = new LinkedList();
@@ -1450,7 +1421,7 @@ public class Quester {
}
public boolean testComplete(Quest quest) {
- for (String s : getObjectives(quest)) {
+ for (String s : getObjectives(quest, true)) {
if (s.startsWith(ChatColor.GREEN.toString())) {
return false;
}
diff --git a/src/main/java/me/blackvein/quests/Quests.java b/src/main/java/me/blackvein/quests/Quests.java
index b0eb6e5e1..7ab774752 100644
--- a/src/main/java/me/blackvein/quests/Quests.java
+++ b/src/main/java/me/blackvein/quests/Quests.java
@@ -98,6 +98,7 @@ import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.LocaleQuery;
import me.blackvein.quests.util.MiscUtil;
+import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizencore.scripts.ScriptRegistry;
@@ -1704,7 +1705,22 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (cs instanceof Player) {
if (((Player) cs).hasPermission("quests.quest")) {
if (args.length == 0) {
- showObjectives((Player) cs);
+ Player player = (Player) cs;
+ Quester quester = getQuester(player.getUniqueId());
+ if (quester.currentQuests.isEmpty() == false) {
+ for (Quest q : quester.currentQuests.keySet()) {
+ Stage stage = quester.getCurrentStage(q);
+ q.updateCompass(quester, stage);
+ if (getQuester(player.getUniqueId()).getQuestData(q).delayStartTime == 0) {
+ String msg = Lang.get(player, "questObjectivesTitle");
+ msg = msg.replaceAll("", q.name);
+ player.sendMessage(ChatColor.GOLD + msg);
+ showObjectives(q, quester, false);
+ }
+ }
+ } else {
+ player.sendMessage(ChatColor.YELLOW + Lang.get(player, "noActiveQuest"));
+ }
} else {
showQuestDetails(cs, args);
}
@@ -1856,33 +1872,52 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
cs.sendMessage(ChatColor.RED + Lang.get("NoPermission"));
}
}
-
- private void showObjectives(final Player player) {
- Quester quester = getQuester(player.getUniqueId());
- if (quester.currentQuests.isEmpty() == false) {
- for (Quest q : quester.currentQuests.keySet()) {
- Stage stage = quester.getCurrentStage(q);
- q.updateCompass(quester, stage);
- try {
- if (getQuester(player.getUniqueId()).getQuestData(q).delayStartTime == 0) {
- String msg = Lang.get(player, "questObjectivesTitle");
- msg = msg.replaceAll("", q.name);
- player.sendMessage(ChatColor.GOLD + msg);
- try {
- for (String s : getQuester(player.getUniqueId()).getObjectivesReal(q)) {
- player.sendMessage(s);
- }
- } catch (NullPointerException e) {
- getLogger().severe("Objectives were null for " + q.name + ". Include quests.yml in Github #238");
- e.printStackTrace();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
+
+ /**
+ * Show all objectives for a quest. Respects PlaceholderAPI and translations, when enabled.
+ *
+ * @param quest The quest to show objectives of
+ * @param quester The player to show objectives to
+ */
+ @SuppressWarnings("deprecation")
+ public void showObjectives(Quest quest, Quester quester, boolean ignoreOverrides) {
+ for (String s : quester.getObjectives(quest, false)) {
+ if (placeholder != null) {
+ s = PlaceholderAPI.setPlaceholders(quester.getPlayer(), 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_", ""));
+ query.sendMessage(quester.getPlayer(), s.replace(serial, "
- ").replace(enchant, ""), m, e);
+ continue;
+ } else if (Material.matchMaterial(serial) != null) {
+ Material m = Material.matchMaterial(serial);
+ query.sendMessage(quester.getPlayer(), s.replace(serial, "
- "), m);
+ continue;
+ } else {
+ try {
+ EntityType type = EntityType.valueOf(serial.toUpperCase().replace(" ", "_"));
+ query.sendMessage(quester.getPlayer(), s.replace(serial, ""), type);
+ } catch (IllegalArgumentException e) {
+ getLogger().severe("Entity type " + serial + " is not valid for Bukkit " + bukkitVersion + ", please report on Github.");
+ quester.getPlayer().sendMessage(s);
+ }
+ }
+ } catch (IndexOutOfBoundsException e) {
+ quester.getPlayer().sendMessage(s);
}
- } else {
- player.sendMessage(ChatColor.YELLOW + Lang.get(player, "noActiveQuest"));
}
}
diff --git a/src/main/java/me/blackvein/quests/StageTimer.java b/src/main/java/me/blackvein/quests/StageTimer.java
index 279d4f967..332945459 100644
--- a/src/main/java/me/blackvein/quests/StageTimer.java
+++ b/src/main/java/me/blackvein/quests/StageTimer.java
@@ -13,9 +13,6 @@
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;
@@ -32,7 +29,6 @@ public class StageTimer implements Runnable {
plugin = quests;
}
- @SuppressWarnings("deprecation")
@Override
public void run() {
if (quester.getQuestData(quest).delayOver) {
@@ -63,40 +59,7 @@ public class StageTimer implements Runnable {
String msg = Lang.get(player, "questObjectivesTitle");
msg = msg.replace("", quest.name);
player.sendMessage(ChatColor.GOLD + msg);
- for (String s : quester.getObjectivesReal(quest)) {
- 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);
- }
- }
+ plugin.showObjectives(quest, quester, false);
String stageStartMessage = quester.getCurrentStage(quest).startMessage;
if (stageStartMessage != null) {
quester.getPlayer().sendMessage(Quests.parseString(stageStartMessage, quest));