Support line breaks in start/complete messages, fixes #754

This commit is contained in:
BuildTools 2019-03-30 00:00:14 -04:00
parent 70f1d718ae
commit 0137eedec8
5 changed files with 44 additions and 16 deletions

View File

@ -265,7 +265,7 @@ public class Event {
public void fire(Quester quester, Quest quest) { public void fire(Quester quester, Quest quest) {
Player player = quester.getPlayer(); Player player = quester.getPlayer();
if (message != null) { if (message != null) {
player.sendMessage(plugin.parseString(message, quest, player)); player.sendMessage(plugin.parseStringWithPossibleLineBreaks(message, quest, player));
} }
if (clearInv == true) { if (clearInv == true) {
player.getInventory().clear(); player.getInventory().clear();

View File

@ -40,7 +40,6 @@ import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.blackvein.quests.exceptions.InvalidStageException; import me.blackvein.quests.exceptions.InvalidStageException;
import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang; import me.blackvein.quests.util.Lang;
import me.clip.placeholderapi.PlaceholderAPI;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
public class Quest { public class Quest {
@ -155,11 +154,7 @@ public class Quest {
public void nextStage(Quester q) { public void nextStage(Quester q) {
String stageCompleteMessage = q.getCurrentStage(this).completeMessage; String stageCompleteMessage = q.getCurrentStage(this).completeMessage;
if (stageCompleteMessage != null) { if (stageCompleteMessage != null) {
String s = plugin.parseString(stageCompleteMessage, this, q.getPlayer()); q.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageCompleteMessage, this, q.getPlayer()));
if(plugin.getDependencies().getPlaceholderApi() != null) {
s = PlaceholderAPI.setPlaceholders(q.getPlayer(), s);
}
q.getPlayer().sendMessage(s);
} }
if (plugin.getSettings().canUseCompass()) { if (plugin.getSettings().canUseCompass()) {
q.resetCompass(); q.resetCompass();
@ -239,7 +234,7 @@ public class Quest {
plugin.showObjectives(this, quester, false); plugin.showObjectives(this, quester, false);
String stageStartMessage = quester.getCurrentStage(this).startMessage; String stageStartMessage = quester.getCurrentStage(this).startMessage;
if (stageStartMessage != null) { if (stageStartMessage != null) {
quester.getPlayer().sendMessage(plugin.parseString(stageStartMessage, this, quester.getPlayer())); quester.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageStartMessage, this, quester.getPlayer()));
} }
quester.updateJournal(); quester.updateJournal();
} }
@ -444,7 +439,7 @@ public class Quest {
q.completedQuests.add(name); q.completedQuests.add(name);
} }
String none = ChatColor.GRAY + "- (" + Lang.get(player, "none") + ")"; String none = ChatColor.GRAY + "- (" + Lang.get(player, "none") + ")";
final String ps = plugin.parseString(finished, this, player); final String[] ps = plugin.parseStringWithPossibleLineBreaks(ChatColor.AQUA + finished, this, player);
for (Map.Entry<Integer, Quest> entry : q.timers.entrySet()) { for (Map.Entry<Integer, Quest> entry : q.timers.entrySet()) {
if (entry.getValue().getName().equals(getName())) { if (entry.getValue().getName().equals(getName())) {
plugin.getServer().getScheduler().cancelTask(entry.getKey()); plugin.getServer().getScheduler().cancelTask(entry.getKey());
@ -455,9 +450,7 @@ public class Quest {
@Override @Override
public void run() { public void run() {
for (String msg : ps.split("<br>")) { player.sendMessage(ps);
player.sendMessage(ChatColor.AQUA + msg);
}
} }
}, 40); }, 40);
if (rews.getMoney() > 0 && plugin.getDependencies().getVaultEconomy() != null) { if (rews.getMoney() > 0 && plugin.getDependencies().getVaultEconomy() != null) {

View File

@ -494,7 +494,7 @@ public class Quester {
plugin.showObjectives(q, this, false); plugin.showObjectives(q, this, false);
String stageStartMessage = stage.startMessage; String stageStartMessage = stage.startMessage;
if (stageStartMessage != null) { if (stageStartMessage != null) {
getPlayer().sendMessage(plugin.parseString(stageStartMessage, q, getPlayer())); getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageStartMessage, q, getPlayer()));
} }
if (stage.chatEvents.isEmpty() == false) { if (stage.chatEvents.isEmpty() == false) {
for (String chatTrigger : stage.chatEvents.keySet()) { for (String chatTrigger : stage.chatEvents.keySet()) {
@ -1367,7 +1367,7 @@ public class Quester {
getQuestData(quest).itemsDelivered.put(found, (amount + i.getAmount())); getQuestData(quest).itemsDelivered.put(found, (amount + i.getAmount()));
player.getInventory().setItem(player.getInventory().first(i), null); player.getInventory().setItem(player.getInventory().first(i), null);
player.updateInventory(); player.updateInventory();
String message = Quests.parseString(getCurrentStage(quest).deliverMessages.get(new Random().nextInt( String[] message = Quests.parseStringWithPossibleLineBreaks(getCurrentStage(quest).deliverMessages.get(new Random().nextInt(
getCurrentStage(quest).deliverMessages.size())), plugin.getDependencies().getCitizens().getNPCRegistry().getById( getCurrentStage(quest).deliverMessages.size())), plugin.getDependencies().getCitizens().getNPCRegistry().getById(
getCurrentStage(quest).itemDeliveryTargets.get(getCurrentStage(quest).itemsToDeliver.indexOf(found)))); getCurrentStage(quest).itemDeliveryTargets.get(getCurrentStage(quest).itemsToDeliver.indexOf(found))));
player.sendMessage(message); player.sendMessage(message);
@ -2793,7 +2793,7 @@ public class Quester {
(long) (getCurrentStage(quest).delay * 0.02)); (long) (getCurrentStage(quest).delay * 0.02));
if (getCurrentStage(quest).delayMessage != null) { if (getCurrentStage(quest).delayMessage != null) {
Player p = plugin.getServer().getPlayer(id); Player p = plugin.getServer().getPlayer(id);
p.sendMessage(plugin.parseString((getCurrentStage(quest).delayMessage), quest, p)); p.sendMessage(plugin.parseStringWithPossibleLineBreaks((getCurrentStage(quest).delayMessage), quest, p));
} }
} }
getQuestData(quest).delayStartTime = System.currentTimeMillis(); getQuestData(quest).delayStartTime = System.currentTimeMillis();

View File

@ -2634,6 +2634,41 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
} }
} }
public String[] parseStringWithPossibleLineBreaks(String s, Quest quest, Player player) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
if (quest.npcStart != null) {
parsed = parsed.replace("<npc>", quest.npcStart.getName());
} else {
Bukkit.getLogger().warning(quest.getName() + " quest uses <npc> tag but doesn't have an NPC start set");
}
}
if (depends.getPlaceholderApi() != null && player != null) {
parsed = PlaceholderAPI.setPlaceholders(player, parsed);
}
return parsed.split("\n");
}
public static String[] parseStringWithPossibleLineBreaks(String s, Quest quest) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
if (quest.npcStart != null) {
parsed = parsed.replace("<npc>", quest.npcStart.getName());
} else {
Bukkit.getLogger().warning(quest.getName() + " quest uses <npc> tag but doesn't have an NPC start set");
}
}
return parsed.split("\n");
}
public static String[] parseStringWithPossibleLineBreaks(String s, NPC npc) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
parsed = parsed.replace("<npc>", npc.getName());
}
return parsed.split("\n");
}
public static String parseString(String s, Quest quest) { public static String parseString(String s, Quest quest) {
String parsed = parseString(s); String parsed = parseString(s);
if (parsed.contains("<npc>")) { if (parsed.contains("<npc>")) {

View File

@ -77,7 +77,7 @@ public class StageTimer implements Runnable {
plugin.showObjectives(quest, quester, false); plugin.showObjectives(quest, quester, false);
String stageStartMessage = quester.getCurrentStage(quest).getStartMessage(); String stageStartMessage = quester.getCurrentStage(quest).getStartMessage();
if (stageStartMessage != null) { if (stageStartMessage != null) {
quester.getPlayer().sendMessage(Quests.parseString(stageStartMessage, quest)); quester.getPlayer().sendMessage(Quests.parseStringWithPossibleLineBreaks(stageStartMessage, quest));
} }
} }