Skip to content
This repository has been archived by the owner on Aug 31, 2019. It is now read-only.

Commit

Permalink
Don't autolink the MOTD
Browse files Browse the repository at this point in the history
  • Loading branch information
jedediah committed Mar 8, 2016
1 parent b73af4f commit 49e837f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/net/md_5/bungee/api/ServerPing.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void setFavicon(Favicon favicon)

@Deprecated
public void setDescription(String description) {
this.description = new TextComponent( TextComponent.fromLegacyText( description ) );
this.description = new TextComponent( TextComponent.fromLegacyText( description, false ) );
}

@Deprecated
Expand Down
58 changes: 35 additions & 23 deletions chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ public class TextComponent extends BaseComponent

private static final Pattern url = Pattern.compile( "^(?:(https?)://)?([-\\w_\\.]{2,}\\.[a-z]{2,4})(/\\S*)?$" );

/**
* Calls {@link #fromLegacyText(String, boolean)} with autolink true
*/
public static BaseComponent[] fromLegacyText(String message) {
return fromLegacyText(message, true);
}

/**
* Converts the old formatting system that used
* {@link net.md_5.bungee.api.ChatColor#COLOR_CHAR} into the new json based
* system.
*
* @param message the text to convert
* @param autolink detect links and make them clickable
* @return the components needed to print the message to the client
*/
public static BaseComponent[] fromLegacyText(String message)
public static BaseComponent[] fromLegacyText(String message, boolean autolink)
{
ArrayList<BaseComponent> components = new ArrayList<BaseComponent>();
StringBuilder builder = new StringBuilder();
Expand Down Expand Up @@ -87,34 +95,38 @@ public static BaseComponent[] fromLegacyText(String message)
}
continue;
}
int pos = message.indexOf( ' ', i );
if ( pos == -1 )
{
pos = message.length();
}
if ( matcher.region( i, pos ).find() )
{ //Web link handling

if ( builder.length() > 0 )
if(autolink) {
int pos = message.indexOf( ' ', i );
if ( pos == -1 )
{
pos = message.length();
}
if ( matcher.region( i, pos ).find() )
{ //Web link handling

if ( builder.length() > 0 )
{
TextComponent old = component;
component = new TextComponent( old );
old.setText( builder.toString() );
builder = new StringBuilder();
components.add( old );
}

TextComponent old = component;
component = new TextComponent( old );
old.setText( builder.toString() );
builder = new StringBuilder();
components.add( old );
String urlString = message.substring( i, pos );
component.setText( urlString );
component.setClickEvent( new ClickEvent( ClickEvent.Action.OPEN_URL,
urlString.startsWith( "http" ) ? urlString : "http://" + urlString ) );
components.add( component );
i += pos - i - 1;
component = old;
continue;
}

TextComponent old = component;
component = new TextComponent( old );
String urlString = message.substring( i, pos );
component.setText( urlString );
component.setClickEvent( new ClickEvent( ClickEvent.Action.OPEN_URL,
urlString.startsWith( "http" ) ? urlString : "http://" + urlString ) );
components.add( component );
i += pos - i - 1;
component = old;
continue;
}

builder.append( c );
}
if ( builder.length() > 0 )
Expand Down

0 comments on commit 49e837f

Please sign in to comment.