Skip to content

Commit

Permalink
#3514: Add separator property to SelectorComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
Outfluencer authored and md-5 committed Oct 4, 2023
1 parent 1ef4d27 commit 68b2df2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions chat/src/main/java/net/md_5/bungee/api/chat/SelectorComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public final class SelectorComponent extends BaseComponent
*/
private String selector;

/**
* The separator of multiple selected entities.
* <br>
* The default is {@code {"color": "gray", "text": ", "}}.
*/
private BaseComponent separator;

/**
* Creates a selector component from the original to clone it.
*
Expand All @@ -42,6 +49,17 @@ public SelectorComponent(SelectorComponent original)
{
super( original );
setSelector( original.getSelector() );
setSeparator( original.getSeparator() );
}

/**
* Creates a selector component from the selector
*
* @param selector the selector as a String
*/
public SelectorComponent(String selector)
{
setSelector( selector );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public SelectorComponent deserialize(JsonElement element, Type type, JsonDeseria
throw new JsonParseException( "Could not parse JSON: missing 'selector' property" );
}
SelectorComponent component = new SelectorComponent( object.get( "selector" ).getAsString() );

if ( object.has( "separator" ) )
{
component.setSeparator( ComponentSerializer.deserialize( object.get( "separator" ).getAsString() ) );
}

deserialize( object, component, context );
return component;
}
Expand All @@ -32,6 +38,11 @@ public JsonElement serialize(SelectorComponent component, Type type, JsonSeriali
JsonObject object = new JsonObject();
serialize( object, component, context );
object.addProperty( "selector", component.getSelector() );

if ( component.getSeparator() != null )
{
object.addProperty( "separator", ComponentSerializer.toString( component.getSeparator() ) );
}
return object;
}
}

0 comments on commit 68b2df2

Please sign in to comment.