i18n-spigot/src/main/java/com/blackypaw/mc/i18n/chat/ChatComponentDeserializer.java
/**
	 * Creates a text component given its JSON representation. Both the shorthand notation as
	 * a raw string as well as the notation as a full-blown JSON object are supported.
	 *
	 * @param json The JSON element to be deserialized into a text component
	 *
	 * @return The deserialized TextComponent
	 */
Creates a text component given its JSON representation. Both the shorthand notation as
a raw string as well as the notation as a full-blown JSON object are supported.

@param json The JSON element to be deserialized into a text component

@return The deserialized TextComponent
Creates a text component given its JSON representation . Both the shorthand notation as a raw string as well as the notation as a full - blown JSON object are supported . @param json The JSON element to be deserialized into a text component @return The deserialized TextComponent
private TextComponent deserializeTextComponent( JsonElement json ) {
		final TextComponent component = new TextComponent( "" );
		if ( json.isJsonPrimitive() ) {
			JsonPrimitive primitive = json.getAsJsonPrimitive();
			if ( primitive.isString() ) {
				component.setText( primitive.getAsString() );
			}
		} else if ( json.isJsonObject() ) {
			JsonObject object = json.getAsJsonObject();
			if ( object.has( "text" ) ) {
				JsonElement textElement = object.get( "text" );
				if ( textElement.isJsonPrimitive() ) {
					JsonPrimitive textPrimitive = textElement.getAsJsonPrimitive();
					if ( textPrimitive.isString() ) {
						component.setText( textPrimitive.getAsString() );
					}
				}
			}
			if ( object.has( "extra" ) ) {
				JsonElement extraElement = object.get( "extra" );
				if ( extraElement.isJsonArray() ) {
					JsonArray extraArray = extraElement.getAsJsonArray();
					for ( int i = 0; i < extraArray.size(); ++i ) {
						JsonElement fieldElement = extraArray.get( i );
						component.addChild( this.deserializeComponent( fieldElement ) );
					}
				}
			}
		}
		return component;
	}
private TextComponent deserializeTextComponent ( JsonElement json ) { final TextComponent component = new TextComponent ( "" ) ; if ( json . isJsonPrimitive ( ) ) { JsonPrimitive primitive = json . getAsJsonPrimitive ( ) ; if ( primitive . isString ( ) ) { component . setText ( primitive . getAsString ( ) ) ; } } else if ( json . isJsonObject ( ) ) { JsonObject object = json . getAsJsonObject ( ) ; if ( object . has ( "text" ) ) { JsonElement textElement = object . get ( "text" ) ; if ( textElement . isJsonPrimitive ( ) ) { JsonPrimitive textPrimitive = textElement . getAsJsonPrimitive ( ) ; if ( textPrimitive . isString ( ) ) { component . setText ( textPrimitive . getAsString ( ) ) ; } } } if ( object . has ( "extra" ) ) { JsonElement extraElement = object . get ( "extra" ) ; if ( extraElement . isJsonArray ( ) ) { JsonArray extraArray = extraElement . getAsJsonArray ( ) ; for ( int i = 0 ; i < extraArray . size ( ) ; ++ i ) { JsonElement fieldElement = extraArray . get ( i ) ; component . addChild ( this . deserializeComponent ( fieldElement ) ) ; } } } } return component ; }
Creates a text component given its JSON representation.
Creates a text component given its JSON representation .