Skip to content

Commit

Permalink
Fix the chat format control
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 6, 2015
1 parent 5a9d10b commit afb984d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Expand Up @@ -114,9 +114,7 @@ else if (determination.toUpperCase().startsWith("FORMAT:")) {
String name = determination.substring(7);
FormatScriptContainer format = ScriptRegistry.getScriptContainer(name);
if (format == null) dB.echoError("Could not find format script matching '" + name + '\'');
else event.setFormat(format.getFormattedText(event.getMessage()
.replace("&", "&amp").replace("%", "&pc"), null, player)
.replace("&pc", "%").replace("&amp", "&"));
else event.setFormat(format.getFormatText(null, player));
} else if (!determination.equals("none")) {
event.setMessage(determination);
}
Expand Down
Expand Up @@ -89,6 +89,8 @@ public void breakDown() {
// "CANCELLED" to stop the player from chatting.
// Element(String) to change the message.
// "FORMAT:" to set the format script the message should use.
// Note: Use <text> in the format script first for the name, then <text> for the actual text.
// Name can be used like <player.flag[custom_name]||<text>> if you don't want to use the actual name.
//
// -->
@EventHandler
Expand All @@ -108,9 +110,7 @@ else if (determination.toUpperCase().startsWith("FORMAT:")) {
String name = determination.substring(7);
FormatScriptContainer format = ScriptRegistry.getScriptContainer(name);
if (format == null) dB.echoError("Could not find format script matching '" + name + '\'');
else event.setFormat(format.getFormattedText(event.getMessage()
.replace("&", "&amp").replace("%", "&pc"), null, player)
.replace("&pc", "%").replace("&amp", "&"));
else event.setFormat(format.getFormatText(null, player));
}
else if (!determination.equals("none")) {
event.setMessage(determination);
Expand Down
Expand Up @@ -76,8 +76,8 @@ public String getFormat() {

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

public String getFormattedText(String textToReplace, dNPC npc, dPlayer player) {
Expand All @@ -87,4 +87,13 @@ public String getFormattedText(String textToReplace, dNPC npc, dPlayer player) {
debug = Boolean.valueOf(getString("DEBUG"));
return TagManager.tag(text, new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this)));
}

public String getFormatText(dNPC npc, dPlayer player) {
String text = getFormat().replace("<text>", String.valueOf((char)0x00));
boolean debug = true;
if (contains("DEBUG"))
debug = Boolean.valueOf(getString("DEBUG"));
return TagManager.tag(text, new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this)))
.replace(String.valueOf((char)0x00), "%s");
}
}

0 comments on commit afb984d

Please sign in to comment.