Пример #1
0
        /// <summary>
        /// Gets the raw JSON string
        /// </summary>
        /// <returns>the raw JSON string used by the game</returns>
        public virtual string GetJsonString()
        {
            List <string> outString = new List <string>();

            if (!(Color is null) && !(RGBColor is null))
            {
                throw new InvalidOperationException("Cannot get json string since both " + nameof(Color) + " and" + nameof(RGBColor) + " is set.");
            }
            if (!(Color is null))
            {
                outString.Add("\"color\":\"" + Color + "\"");
            }
            if (!(RGBColor is null))
            {
                outString.Add("\"color\":\"" + RGBColor.GetHexColor() + "\"");
            }
            if (!(Obfuscated is null))
            {
                outString.Add("\"obfuscated\":" + Obfuscated.ToMinecraftBool());
            }
            if (!(Bold is null))
            {
                outString.Add("\"bold\":" + Bold.ToMinecraftBool());
            }
            if (!(Italic is null))
            {
                outString.Add("\"italic\":" + Italic.ToMinecraftBool());
            }
            if (!(Strikethrough is null))
            {
                outString.Add("\"strikethrough\":" + Strikethrough.ToMinecraftBool());
            }
            if (!(Underline is null))
            {
                outString.Add("\"underlined\":" + Underline.ToMinecraftBool());
            }
            if (!(Reset is null))
            {
                outString.Add("\"reset\":" + Reset.ToMinecraftBool());
            }
            if (!(ShiftClickInsertion is null))
            {
                outString.Add("\"insertion\":\"" + ShiftClickInsertion.Escape() + "\"");
            }
            if (!(Font is null))
            {
                outString.Add("\"font\":\"" + Font.Escape() + "\"");
            }
            if (!(ClickEvent is null))
            {
                outString.Add(ClickEvent.GetEventString());
            }
            if (!(HoverEvent is null))
            {
                outString.Add(HoverEvent.GetEventString());
            }
            if (!(Extra is null) && Extra.Length != 0)
            {
                outString.Add("\"extra\":[" + string.Join(",", Extra.Select(j => j.GetJsonString())) + "]");
            }
            outString.Add(GetSpecificJsonString());

            return("{" + string.Join(",", outString) + "}");
        }