#3514: Add separator property to SelectorComponent

This commit is contained in:
Outfluencer 2023-10-05 07:21:13 +11:00 committed by md_5
parent 1ef4d27dbe
commit 68b2df2b1e
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 29 additions and 0 deletions

View File

@ -33,6 +33,13 @@ public final class SelectorComponent extends BaseComponent
*/ */
private String selector; 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. * Creates a selector component from the original to clone it.
* *
@ -42,6 +49,17 @@ public final class SelectorComponent extends BaseComponent
{ {
super( original ); super( original );
setSelector( original.getSelector() ); 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 @Override

View File

@ -22,6 +22,12 @@ public class SelectorComponentSerializer extends BaseComponentSerializer impleme
throw new JsonParseException( "Could not parse JSON: missing 'selector' property" ); throw new JsonParseException( "Could not parse JSON: missing 'selector' property" );
} }
SelectorComponent component = new SelectorComponent( object.get( "selector" ).getAsString() ); SelectorComponent component = new SelectorComponent( object.get( "selector" ).getAsString() );
if ( object.has( "separator" ) )
{
component.setSeparator( ComponentSerializer.deserialize( object.get( "separator" ).getAsString() ) );
}
deserialize( object, component, context ); deserialize( object, component, context );
return component; return component;
} }
@ -32,6 +38,11 @@ public class SelectorComponentSerializer extends BaseComponentSerializer impleme
JsonObject object = new JsonObject(); JsonObject object = new JsonObject();
serialize( object, component, context ); serialize( object, component, context );
object.addProperty( "selector", component.getSelector() ); object.addProperty( "selector", component.getSelector() );
if ( component.getSeparator() != null )
{
object.addProperty( "separator", ComponentSerializer.toString( component.getSeparator() ) );
}
return object; return object;
} }
} }