Created
July 11, 2014 12:15
-
-
Save DarkSeraphim/33a1f135557fbca93575 to your computer and use it in GitHub Desktop.
Splits messages in coloured JSON parts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Pattern colour = Pattern.compile(ChatColor.COLOR_CHAR+"([0-9a-fk-or])(.*)", Pattern.CASE_INSENSITIVE); | |
| public FancifulMessage foo(String msg) | |
| { | |
| String[] pieces = msg.replace(ChatColor.COLOR_CHAR.toString(), "\0"+ChatColor.COLOR_CHAR).split("\0"); | |
| int i = 0; | |
| FancifulMessage fm; | |
| // Perhaps reset | |
| String part; | |
| Matcher m; | |
| while(i < pieces.length); | |
| { | |
| part = pieces[i].trim(); | |
| m = colour.matcher(part); | |
| if(!m.matches()) | |
| { | |
| ChatColor c = ChatColor.getByColorChar(m.group(1)); | |
| if(c.isColor()) | |
| fm.color(c); | |
| else | |
| fm.style(c); | |
| part = m.group(2).trim(); | |
| } | |
| if(!part.isEmpty()) | |
| { | |
| fm.text(part); | |
| fm.then(); | |
| } | |
| i++; | |
| } | |
| return fm; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment