Skip to content

Commit

Permalink
fix narrate tag parsing, fixes #2080
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 29, 2019
1 parent a6e5008 commit de6fa21
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
Expand Up @@ -105,7 +105,7 @@ public void execute(ScriptEntry scriptEntry) {

}
if (format != null) {
text = new ElementTag(format.getFormattedText(scriptEntry));
text = new ElementTag(format.getFormattedText(text.asString(), scriptEntry));
}

for (PlayerTag player : targets) {
Expand Down
Expand Up @@ -110,7 +110,7 @@ public void execute(ScriptEntry scriptEntry) {

boolean perPlayer = perPlayerObj != null && perPlayerObj.asBoolean();
BukkitTagContext context = new BukkitTagContext(scriptEntry, false);
if (!perPlayer) {
if (!perPlayer || targets == null) {
text = TagManager.tag(text, context);
}

Expand All @@ -124,7 +124,7 @@ public void execute(ScriptEntry scriptEntry) {

FormatScriptContainer format = formatObj == null ? null : (FormatScriptContainer) formatObj.getContainer();
if (targets == null) {
Bukkit.getServer().getConsoleSender().sendMessage(format != null ? format.getFormattedText(scriptEntry) : text);
Bukkit.getServer().getConsoleSender().sendMessage(format != null ? format.getFormattedText(text, scriptEntry) : text);
return;
}

Expand All @@ -134,7 +134,7 @@ public void execute(ScriptEntry scriptEntry) {
if (perPlayer) {
personalText = TagManager.tag(personalText, context);
}
player.getPlayerEntity().spigot().sendMessage(FormattedTextHelper.parse(format != null ? format.getFormattedText(scriptEntry) : personalText));
player.getPlayerEntity().spigot().sendMessage(FormattedTextHelper.parse(format != null ? format.getFormattedText(personalText, scriptEntry) : personalText));
}
else {
Debug.echoError("Narrated to non-existent or offline player!");
Expand Down
Expand Up @@ -125,7 +125,7 @@ public void execute(ScriptEntry scriptEntry) {
+ (flag != null ? ArgumentHelper.debugObj("Flag_Name", flag) : ""));
}

String message = format != null ? format.getFormattedText(scriptEntry) : text.asString();
String message = format != null ? format.getFormattedText(text.asString(), scriptEntry) : text.asString();

// Use Bukkit to broadcast the message to everybody in the server.
if (type == AnnounceType.ALL) {
Expand Down
@@ -1,6 +1,6 @@
package com.denizenscript.denizen.scripts.containers.core;

import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizen.objects.NPCTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.tags.BukkitTagContext;
Expand Down Expand Up @@ -39,10 +39,8 @@ public String getFormat() {
return getString("format", "<text>");
}

public String getFormattedText(ScriptEntry entry) {
return getFormattedText(entry.getElement("text").asString(),
((BukkitScriptEntryData) entry.entryData).getNPC(),
((BukkitScriptEntryData) entry.entryData).getPlayer());
public String getFormattedText(String text, ScriptEntry entry) {
return getFormattedText(text, Utilities.getEntryNPC(entry), Utilities.getEntryPlayer(entry));
}

public String getFormattedText(String textToReplace, NPCTag npc, PlayerTag player) {
Expand Down

0 comments on commit de6fa21

Please sign in to comment.