Ejemplo n.º 1
0
    public JsonElement serialize(
        IChatComponent p_serialize_1_,
        Type p_serialize_2_,
        JsonSerializationContext p_serialize_3_) {
      if (p_serialize_1_ instanceof ChatComponentText
          && p_serialize_1_.getChatStyle().isEmpty()
          && p_serialize_1_.getSiblings().isEmpty()) {
        return new JsonPrimitive(
            ((ChatComponentText) p_serialize_1_).getChatComponentText_TextValue());
      } else {
        JsonObject var4 = new JsonObject();

        if (!p_serialize_1_.getChatStyle().isEmpty()) {
          this.serializeChatStyle(p_serialize_1_.getChatStyle(), var4, p_serialize_3_);
        }

        if (!p_serialize_1_.getSiblings().isEmpty()) {
          JsonArray var5 = new JsonArray();
          Iterator var6 = p_serialize_1_.getSiblings().iterator();

          while (var6.hasNext()) {
            IChatComponent var7 = (IChatComponent) var6.next();
            var5.add(this.serialize(var7, var7.getClass(), p_serialize_3_));
          }

          var4.add("extra", var5);
        }

        if (p_serialize_1_ instanceof ChatComponentText) {
          var4.addProperty(
              "text", ((ChatComponentText) p_serialize_1_).getChatComponentText_TextValue());
        } else if (p_serialize_1_ instanceof ChatComponentTranslation) {
          ChatComponentTranslation var11 = (ChatComponentTranslation) p_serialize_1_;
          var4.addProperty("translate", var11.getKey());

          if (var11.getFormatArgs() != null && var11.getFormatArgs().length > 0) {
            JsonArray var14 = new JsonArray();
            Object[] var16 = var11.getFormatArgs();
            int var8 = var16.length;

            for (int var9 = 0; var9 < var8; ++var9) {
              Object var10 = var16[var9];

              if (var10 instanceof IChatComponent) {
                var14.add(this.serialize((IChatComponent) var10, var10.getClass(), p_serialize_3_));
              } else {
                var14.add(new JsonPrimitive(String.valueOf(var10)));
              }
            }

            var4.add("with", var14);
          }
        } else if (p_serialize_1_ instanceof ChatComponentScore) {
          ChatComponentScore var12 = (ChatComponentScore) p_serialize_1_;
          JsonObject var15 = new JsonObject();
          var15.addProperty("name", var12.func_179995_g());
          var15.addProperty("objective", var12.func_179994_h());
          var15.addProperty("value", var12.getUnformattedTextForChat());
          var4.add("score", var15);
        } else {
          if (!(p_serialize_1_ instanceof ChatComponentSelector)) {
            throw new IllegalArgumentException(
                "Don\'t know how to serialize " + p_serialize_1_ + " as a Component");
          }

          ChatComponentSelector var13 = (ChatComponentSelector) p_serialize_1_;
          var4.addProperty("selector", var13.func_179992_g());
        }

        return var4;
      }
    }
Ejemplo n.º 2
0
    public JsonElement serialize(
        IChatComponent p_serialize_1_,
        Type p_serialize_2_,
        JsonSerializationContext p_serialize_3_) {
      if (p_serialize_1_ instanceof ChatComponentText
          && p_serialize_1_.getChatStyle().isEmpty()
          && p_serialize_1_.getSiblings().isEmpty()) {
        return new JsonPrimitive(
            ((ChatComponentText) p_serialize_1_).getChatComponentText_TextValue());
      } else {
        JsonObject jsonobject = new JsonObject();

        if (!p_serialize_1_.getChatStyle().isEmpty()) {
          this.serializeChatStyle(p_serialize_1_.getChatStyle(), jsonobject, p_serialize_3_);
        }

        if (!p_serialize_1_.getSiblings().isEmpty()) {
          JsonArray jsonarray = new JsonArray();
          Iterator iterator = p_serialize_1_.getSiblings().iterator();

          while (iterator.hasNext()) {
            IChatComponent ichatcomponent1 = (IChatComponent) iterator.next();
            jsonarray.add(
                this.serialize(ichatcomponent1, ichatcomponent1.getClass(), p_serialize_3_));
          }

          jsonobject.add("extra", jsonarray);
        }

        if (p_serialize_1_ instanceof ChatComponentText) {
          jsonobject.addProperty(
              "text", ((ChatComponentText) p_serialize_1_).getChatComponentText_TextValue());
        } else if (p_serialize_1_ instanceof ChatComponentTranslation) {
          ChatComponentTranslation chatcomponenttranslation =
              (ChatComponentTranslation) p_serialize_1_;
          jsonobject.addProperty("translate", chatcomponenttranslation.getKey());

          if (chatcomponenttranslation.getFormatArgs() != null
              && chatcomponenttranslation.getFormatArgs().length > 0) {
            JsonArray jsonarray1 = new JsonArray();
            Object[] aobject = chatcomponenttranslation.getFormatArgs();
            int i = aobject.length;

            for (int j = 0; j < i; ++j) {
              Object object = aobject[j];

              if (object instanceof IChatComponent) {
                jsonarray1.add(
                    this.serialize((IChatComponent) object, object.getClass(), p_serialize_3_));
              } else {
                jsonarray1.add(new JsonPrimitive(String.valueOf(object)));
              }
            }

            jsonobject.add("with", jsonarray1);
          }
        } else if (p_serialize_1_ instanceof ChatComponentScore) {
          ChatComponentScore chatcomponentscore = (ChatComponentScore) p_serialize_1_;
          JsonObject jsonobject1 = new JsonObject();
          jsonobject1.addProperty("name", chatcomponentscore.func_179995_g());
          jsonobject1.addProperty("objective", chatcomponentscore.func_179994_h());
          jsonobject1.addProperty("value", chatcomponentscore.getUnformattedTextForChat());
          jsonobject.add("score", jsonobject1);
        } else {
          if (!(p_serialize_1_ instanceof ChatComponentSelector)) {
            throw new IllegalArgumentException(
                "Don\'t know how to serialize " + p_serialize_1_ + " as a Component");
          }

          ChatComponentSelector chatcomponentselector = (ChatComponentSelector) p_serialize_1_;
          jsonobject.addProperty("selector", chatcomponentselector.func_179992_g());
        }

        return jsonobject;
      }
    }