Chat formatting still WIP...

This commit is contained in:
Norbi Peti 2016-06-29 14:36:25 +02:00
parent 4c8f6f024e
commit 1543a11049

View file

@ -72,7 +72,8 @@ public class ChatProcessing {
colormode = ChatFormatter.Color.Green; colormode = ChatFormatter.Color.Green;
// If greentext, ignore channel or player colors // If greentext, ignore channel or player colors
formatters.add(new ChatFormatter(Pattern.compile("(.+)"), colormode, "")); formatters
.add(new ChatFormatter(Pattern.compile("(.+)"), colormode, ""));
String formattedmessage = message; String formattedmessage = message;
formattedmessage = formattedmessage.replace("\\", "\\\\"); formattedmessage = formattedmessage.replace("\\", "\\\\");
@ -85,18 +86,18 @@ public class ChatProcessing {
formatters formatters
.add(new ChatFormatter( .add(new ChatFormatter(
Pattern.compile("(?<!\\\\)\\*\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*\\*"), Pattern.compile("(?<!\\\\)\\*\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*\\*"),
ChatFormatter.Format.Bold, "$1$2")); ChatFormatter.Format.Bold, "$1"));
formatters.add(new ChatFormatter(Pattern formatters.add(new ChatFormatter(Pattern
.compile("(?<!\\\\)\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*"), .compile("(?<!\\\\)\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*"),
ChatFormatter.Format.Italic, "$1$2")); ChatFormatter.Format.Italic, "$1"));
formatters.add(new ChatFormatter(Pattern formatters.add(new ChatFormatter(Pattern
.compile("(?<!\\\\)\\_((?:\\\\\\_|[^\\_])+[^\\_\\\\])\\_"), .compile("(?<!\\\\)\\_((?:\\\\\\_|[^\\_])+[^\\_\\\\])\\_"),
ChatFormatter.Format.Italic, "$1$2")); ChatFormatter.Format.Italic, "$1"));
// URLs + Rainbow text // URLs + Rainbow text
formatters.add(new ChatFormatter(Pattern formatters.add(new ChatFormatter(Pattern
.compile("(http[\\w:/?=$\\-_.+!*'(),]+)"), .compile("(http[\\w:/?=$\\-_.+!*'(),]+)"),
ChatFormatter.Format.Underlined, "", "$1")); ChatFormatter.Format.Underlined, "$1"));
// TODO: Only format name mentions outisde open_url // TODO: Only format name mentions outisde open_url
/* /*
* formattedmessage = formattedmessage .replace( item, String.format( * formattedmessage = formattedmessage .replace( item, String.format(
@ -112,7 +113,7 @@ public class ChatProcessing {
sb.append(")"); sb.append(")");
formatters.add(new ChatFormatter(Pattern.compile(sb.toString()), formatters.add(new ChatFormatter(Pattern.compile(sb.toString()),
ChatFormatter.Color.Aqua, "", (String match) -> { ChatFormatter.Color.Aqua, (String match) -> {
Player p = Bukkit.getPlayer(match); Player p = Bukkit.getPlayer(match);
if (p == null) { if (p == null) {
System.out.println("Error: Can't find player " + match System.out.println("Error: Can't find player " + match
@ -137,7 +138,6 @@ public class ChatProcessing {
.add(new ChatFormatter( .add(new ChatFormatter(
Pattern.compile(sb.toString()), Pattern.compile(sb.toString()),
ChatFormatter.Color.Aqua, ChatFormatter.Color.Aqua,
"",
(String match) -> { (String match) -> {
for (String n : PlayerListener.nicknames.keySet()) { for (String n : PlayerListener.nicknames.keySet()) {
String nwithoutformatting = new String(n); String nwithoutformatting = new String(n);
@ -193,10 +193,10 @@ public class ChatProcessing {
pingedconsole = false; pingedconsole = false;
formatters.add(new ChatFormatter(Pattern.compile("(?i)" formatters.add(new ChatFormatter(Pattern.compile("(?i)"
+ Pattern.quote("@console")), ChatFormatter.Color.Aqua, "", ( + Pattern.quote("@console")), ChatFormatter.Color.Aqua, (
String match) -> { String match) -> {
if (!pingedconsole) { if (!pingedconsole) {
System.out.println("\007"); System.out.print("\007");
pingedconsole = true; pingedconsole = true;
} }
return true; return true;
@ -244,11 +244,11 @@ public class ChatProcessing {
(mp != null && mp.PlayerName.equals("\nAlpha_Bacca44") ? "\nDeaths: " (mp != null && mp.PlayerName.equals("\nAlpha_Bacca44") ? "\nDeaths: "
+ PlayerListener.AlphaDeaths + PlayerListener.AlphaDeaths
: ""))); : "")));
json.append("{\"text\":\"> \",\"color\":\"white\"},"); json.append("{\"text\":\"> \",\"color\":\"white\"}");
formatters formatters
.add(new ChatFormatter(Pattern.compile("#(\\w+)"), .add(new ChatFormatter(Pattern.compile("#(\\w+)"),
ChatFormatter.Color.Blue, "", ChatFormatter.Color.Blue,
"https://twitter.com/hashtag/$1")); "https://twitter.com/hashtag/$1"));
/* /*
@ -267,8 +267,12 @@ public class ChatProcessing {
* , colormode, original, original)); } * , colormode, original, original)); }
*/ */
json.append(String.format("{\"text\":\"%s\",\"color\":\"%s\"}]", /*
ChatFormatter.Combine(formatters, formattedmessage), colormode)); * json.append(String.format("{\"text\":\"%s\",\"color\":\"%s\"}]",
* ChatFormatter.Combine(formatters, formattedmessage), colormode));
*/
json.append(ChatFormatter.Combine(formatters, formattedmessage));
json.append("]");
String jsonstr = json.toString(); String jsonstr = json.toString();
if (jsonstr.length() >= 32767) { if (jsonstr.length() >= 32767) {
sender.sendMessage("§cError: Message too large. Try shortening it, or remove hashtags and other formatting."); sender.sendMessage("§cError: Message too large. Try shortening it, or remove hashtags and other formatting.");