#3514: Add separator property to SelectorComponent
This commit is contained in:
parent
1ef4d27dbe
commit
68b2df2b1e
@ -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.
|
||||
*
|
||||
@ -42,6 +49,17 @@ public final class SelectorComponent extends BaseComponent
|
||||
{
|
||||
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
|
||||
|
@ -22,6 +22,12 @@ public class SelectorComponentSerializer extends BaseComponentSerializer impleme
|
||||
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;
|
||||
}
|
||||
@ -32,6 +38,11 @@ public class SelectorComponentSerializer extends BaseComponentSerializer impleme
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user