mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-23 11:05:38 +01:00
Support line breaks in start/complete messages, fixes #754
This commit is contained in:
parent
70f1d718ae
commit
0137eedec8
@ -265,7 +265,7 @@ public class Event {
|
||||
public void fire(Quester quester, Quest quest) {
|
||||
Player player = quester.getPlayer();
|
||||
if (message != null) {
|
||||
player.sendMessage(plugin.parseString(message, quest, player));
|
||||
player.sendMessage(plugin.parseStringWithPossibleLineBreaks(message, quest, player));
|
||||
}
|
||||
if (clearInv == true) {
|
||||
player.getInventory().clear();
|
||||
|
@ -40,7 +40,6 @@ import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import me.blackvein.quests.exceptions.InvalidStageException;
|
||||
import me.blackvein.quests.util.ItemUtil;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
||||
public class Quest {
|
||||
@ -155,11 +154,7 @@ public class Quest {
|
||||
public void nextStage(Quester q) {
|
||||
String stageCompleteMessage = q.getCurrentStage(this).completeMessage;
|
||||
if (stageCompleteMessage != null) {
|
||||
String s = plugin.parseString(stageCompleteMessage, this, q.getPlayer());
|
||||
if(plugin.getDependencies().getPlaceholderApi() != null) {
|
||||
s = PlaceholderAPI.setPlaceholders(q.getPlayer(), s);
|
||||
}
|
||||
q.getPlayer().sendMessage(s);
|
||||
q.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageCompleteMessage, this, q.getPlayer()));
|
||||
}
|
||||
if (plugin.getSettings().canUseCompass()) {
|
||||
q.resetCompass();
|
||||
@ -239,7 +234,7 @@ public class Quest {
|
||||
plugin.showObjectives(this, quester, false);
|
||||
String stageStartMessage = quester.getCurrentStage(this).startMessage;
|
||||
if (stageStartMessage != null) {
|
||||
quester.getPlayer().sendMessage(plugin.parseString(stageStartMessage, this, quester.getPlayer()));
|
||||
quester.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageStartMessage, this, quester.getPlayer()));
|
||||
}
|
||||
quester.updateJournal();
|
||||
}
|
||||
@ -444,7 +439,7 @@ public class Quest {
|
||||
q.completedQuests.add(name);
|
||||
}
|
||||
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()) {
|
||||
if (entry.getValue().getName().equals(getName())) {
|
||||
plugin.getServer().getScheduler().cancelTask(entry.getKey());
|
||||
@ -455,9 +450,7 @@ public class Quest {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (String msg : ps.split("<br>")) {
|
||||
player.sendMessage(ChatColor.AQUA + msg);
|
||||
}
|
||||
player.sendMessage(ps);
|
||||
}
|
||||
}, 40);
|
||||
if (rews.getMoney() > 0 && plugin.getDependencies().getVaultEconomy() != null) {
|
||||
|
@ -494,7 +494,7 @@ public class Quester {
|
||||
plugin.showObjectives(q, this, false);
|
||||
String stageStartMessage = stage.startMessage;
|
||||
if (stageStartMessage != null) {
|
||||
getPlayer().sendMessage(plugin.parseString(stageStartMessage, q, getPlayer()));
|
||||
getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageStartMessage, q, getPlayer()));
|
||||
}
|
||||
if (stage.chatEvents.isEmpty() == false) {
|
||||
for (String chatTrigger : stage.chatEvents.keySet()) {
|
||||
@ -1367,7 +1367,7 @@ public class Quester {
|
||||
getQuestData(quest).itemsDelivered.put(found, (amount + i.getAmount()));
|
||||
player.getInventory().setItem(player.getInventory().first(i), null);
|
||||
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).itemDeliveryTargets.get(getCurrentStage(quest).itemsToDeliver.indexOf(found))));
|
||||
player.sendMessage(message);
|
||||
@ -2793,7 +2793,7 @@ public class Quester {
|
||||
(long) (getCurrentStage(quest).delay * 0.02));
|
||||
if (getCurrentStage(quest).delayMessage != null) {
|
||||
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();
|
||||
|
@ -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) {
|
||||
String parsed = parseString(s);
|
||||
if (parsed.contains("<npc>")) {
|
||||
|
@ -77,7 +77,7 @@ public class StageTimer implements Runnable {
|
||||
plugin.showObjectives(quest, quester, false);
|
||||
String stageStartMessage = quester.getCurrentStage(quest).getStartMessage();
|
||||
if (stageStartMessage != null) {
|
||||
quester.getPlayer().sendMessage(Quests.parseString(stageStartMessage, quest));
|
||||
quester.getPlayer().sendMessage(Quests.parseStringWithPossibleLineBreaks(stageStartMessage, quest));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user