Advertisement
Exception_Prototype

Untitled

Sep 24th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1.   private String[] parseLine(String chatText)
  2.   {
  3.     String[] authorText = { "", "" };
  4.     Pattern pattern = Pattern.compile("^(?:\\[[^\\]]*\\]\\s*)*<(?:[^>]*[^>\\w])?(\\w{2,16})(?:\\s*\\([^\\)]*\\))?>+(.*)");
  5.     Matcher matcher = pattern.matcher(chatText);
  6.     if (matcher.find())
  7.     {
  8.       authorText[0] = matcher.group(1);
  9.       authorText[1] = matcher.group(2);
  10.     }
  11.     else
  12.     {
  13.       pattern = Pattern.compile("^(?:(?:\\[[^\\]]*\\]|(?:([^\\w\\s]?)([^\\w\\s])(?:(?!\\2).)+\\2\\1))\\s*)*(\\w{2,16})(?:\\s*\\([^\\)]*\\))?:(.*)");
  14.       matcher = pattern.matcher(chatText);
  15.       if (matcher.find())
  16.       {
  17.         authorText[0] = matcher.group(3);
  18.         authorText[1] = matcher.group(4);
  19.       }
  20.       else
  21.       {
  22.         pattern = Pattern.compile("^(?:(?:\\[[^\\]]*\\]|(?:([^\\w\\s]?)([^\\w\\s])(?:(?!\\2).)+.*\\2\\1))\\s*)*([\\W&&\\S])(\\w{2,16})\\3+(?:\\s*\\([^\\)]*\\))?:?(.*)");
  23.         matcher = pattern.matcher(chatText);
  24.         if (matcher.find())
  25.         {
  26.           authorText[0] = matcher.group(4);
  27.           authorText[1] = matcher.group(5);
  28.         }
  29.         else
  30.         {
  31.           pattern = Pattern.compile("^([^\\*]?)[\\*]*\\w*\\s*(?:\\1\\[[^\\]]*\\])?[\\s]*(\\w{2,16})(?::|(?:\\s*>))(.*)");
  32.           matcher = pattern.matcher(chatText);
  33.           if (matcher.find())
  34.           {
  35.             authorText[0] = matcher.group(2);
  36.             authorText[1] = matcher.group(3);
  37.           }
  38.           else
  39.           {
  40.             pattern = Pattern.compile("(?:[^:]*[^:\\w])?(\\w{2,16})(?:\\s*\\([^\\)]*\\))?(?::|(?:\\s*>))(.*)");
  41.             matcher = pattern.matcher(chatText);
  42.             if (matcher.find())
  43.             {
  44.               authorText[0] = matcher.group(1);
  45.               authorText[1] = matcher.group(2);
  46.             }
  47.           }
  48.         }
  49.       }
  50.     }
  51.     if (this.customChatParseLine != null)
  52.     {
  53.       pattern = Pattern.compile(this.customChatParseLine.getRegex());
  54.       matcher = pattern.matcher(chatText);
  55.       if (matcher.find())
  56.       {
  57.         int[] possibleAuthorRefs = this.customChatParseLine.getNameRefs();
  58.         for (int t = 0; t < possibleAuthorRefs.length; t++)
  59.         {
  60.           String possibleAuthor = matcher.group(possibleAuthorRefs[t]);
  61.           if (possibleAuthor != null) {
  62.             authorText[0] = possibleAuthor;
  63.           }
  64.         }
  65.         authorText[1] = matcher.group(this.customChatParseLine.getTextRef());
  66.       }
  67.     }
  68.     return authorText;
  69.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement