mirror of
https://github.com/PikaMug/Quests.git
synced 2024-12-22 17:17:38 +01:00
Remove nearly duplicate method for getting objectives. Bump version
This commit is contained in:
parent
3e5115d64d
commit
24ffc562ff
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
|
||||
<groupId>me.blackvein.quests</groupId>
|
||||
<artifactId>quests</artifactId>
|
||||
<version>3.5.2</version>
|
||||
<version>3.5.3</version>
|
||||
<name>quests</name>
|
||||
<url>https://github.com/FlyingPikachu/Quests/</url>
|
||||
<packaging>jar</packaging>
|
||||
|
@ -162,12 +162,7 @@ public class Quest {
|
||||
String msg = Lang.get(quester.getPlayer(), "questObjectivesTitle");
|
||||
msg = msg.replaceAll("<quest>", 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));
|
||||
|
@ -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("<quest>", 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, "<item>").replace(enchant, "<enchantment>"), m, e);
|
||||
continue;
|
||||
} else if (Material.matchMaterial(serial) != null) {
|
||||
Material m = Material.matchMaterial(serial);
|
||||
plugin.query.sendMessage(player, s.replace(serial, "<item>"), m);
|
||||
continue;
|
||||
} else {
|
||||
try {
|
||||
EntityType type = EntityType.valueOf(serial.toUpperCase().replace(" ", "_"));
|
||||
plugin.query.sendMessage(player, s.replace(serial, "<mob>"), 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));
|
||||
@ -474,7 +440,16 @@ public class Quester {
|
||||
}
|
||||
}
|
||||
|
||||
public LinkedList<String> getObjectivesReal(Quest quest) {
|
||||
/**
|
||||
* 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<String> getObjectives(Quest quest, boolean ignoreOverrides) {
|
||||
if (!ignoreOverrides) {
|
||||
if (getCurrentStage(quest) != null) {
|
||||
if (getCurrentStage(quest).objectiveOverride != null) {
|
||||
LinkedList<String> objectives = new LinkedList<String>();
|
||||
@ -482,11 +457,7 @@ public class Quester {
|
||||
return objectives;
|
||||
}
|
||||
}
|
||||
return getObjectives(quest);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public LinkedList<String> getObjectives(Quest quest) {
|
||||
if (getQuestData(quest) == null)
|
||||
return new LinkedList<String>();
|
||||
LinkedList<String> unfinishedObjectives = new LinkedList<String>();
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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("<quest>", q.name);
|
||||
player.sendMessage(ChatColor.GOLD + msg);
|
||||
showObjectives(q, quester, false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "noActiveQuest"));
|
||||
}
|
||||
} else {
|
||||
showQuestDetails(cs, args);
|
||||
}
|
||||
@ -1857,32 +1873,51 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
/**
|
||||
* 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 {
|
||||
if (getQuester(player.getUniqueId()).getQuestData(q).delayStartTime == 0) {
|
||||
String msg = Lang.get(player, "questObjectivesTitle");
|
||||
msg = msg.replaceAll("<quest>", 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();
|
||||
}
|
||||
// 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, "<item>").replace(enchant, "<enchantment>"), m, e);
|
||||
continue;
|
||||
} else if (Material.matchMaterial(serial) != null) {
|
||||
Material m = Material.matchMaterial(serial);
|
||||
query.sendMessage(quester.getPlayer(), s.replace(serial, "<item>"), m);
|
||||
continue;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "noActiveQuest"));
|
||||
try {
|
||||
EntityType type = EntityType.valueOf(serial.toUpperCase().replace(" ", "_"));
|
||||
query.sendMessage(quester.getPlayer(), s.replace(serial, "<mob>"), 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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>", 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, "<item>").replace(enchant, "<enchantment>"), m, e);
|
||||
continue;
|
||||
} else if (Material.matchMaterial(serial) != null) {
|
||||
Material m = Material.matchMaterial(serial);
|
||||
plugin.query.sendMessage(player, s.replace(serial, "<item>"), m);
|
||||
continue;
|
||||
} else {
|
||||
try {
|
||||
EntityType type = EntityType.valueOf(serial.toUpperCase().replace(" ", "_"));
|
||||
plugin.query.sendMessage(player, s.replace(serial, "<mob>"), 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));
|
||||
|
Loading…
Reference in New Issue
Block a user