Skip to content

Commit

Permalink
automatically process URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 29, 2019
1 parent 2a74620 commit 802a1e7
Showing 1 changed file with 22 additions and 1 deletion.
Expand Up @@ -254,7 +254,28 @@ else if (code == 'r' || code == 'R') {
}
i++;
started = i + 1;
}
}
else if (i + "https://a.".length() < chars.length && chars[i] == 'h' && chars[i + 1] == 't' && chars[i + 2] == 't' && chars[i + 3] == 'p') {
String subStr = str.substring(i, i + "https://a.".length());
if (subStr.startsWith("https://") || subStr.startsWith("http://")) {
int nextSpace = str.indexOf(' ', i);
if (nextSpace == -1) {
nextSpace = str.length();
}
String url = str.substring(i, nextSpace);
nextText.setText(nextText.getText() + str.substring(started, i));
outputList.add(nextText);
TextComponent lastText = nextText;
nextText = new TextComponent(lastText);
nextText.setText("");
TextComponent clickableText = new TextComponent(url);
clickableText.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
lastText.addExtra(clickableText);
i = nextSpace;
started = nextSpace;
continue;
}
}
}
nextText.setText(nextText.getText() + str.substring(started));
if (!nextText.getText().isEmpty()) {
Expand Down

0 comments on commit 802a1e7

Please sign in to comment.