From 68b2df2b1ed6559c0cf09bfb56060a330cb383eb Mon Sep 17 00:00:00 2001 From: Outfluencer <48880402+Outfluencer@users.noreply.github.com> Date: Thu, 5 Oct 2023 07:21:13 +1100 Subject: [PATCH] #3514: Add separator property to SelectorComponent --- .../bungee/api/chat/SelectorComponent.java | 18 ++++++++++++++++++ .../chat/SelectorComponentSerializer.java | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/chat/src/main/java/net/md_5/bungee/api/chat/SelectorComponent.java b/chat/src/main/java/net/md_5/bungee/api/chat/SelectorComponent.java index 132dfabee..ff1e260bc 100644 --- a/chat/src/main/java/net/md_5/bungee/api/chat/SelectorComponent.java +++ b/chat/src/main/java/net/md_5/bungee/api/chat/SelectorComponent.java @@ -33,6 +33,13 @@ public final class SelectorComponent extends BaseComponent */ private String selector; + /** + * The separator of multiple selected entities. + *
+ * 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 diff --git a/chat/src/main/java/net/md_5/bungee/chat/SelectorComponentSerializer.java b/chat/src/main/java/net/md_5/bungee/chat/SelectorComponentSerializer.java index 0176a298c..4cdc463bf 100644 --- a/chat/src/main/java/net/md_5/bungee/chat/SelectorComponentSerializer.java +++ b/chat/src/main/java/net/md_5/bungee/chat/SelectorComponentSerializer.java @@ -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; } }